From 6822dfec553f1ff6957bedb7875fa4d40a57c06e Mon Sep 17 00:00:00 2001 From: sksadjad <86593551+sksadjad@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:26:53 +0200 Subject: [PATCH] feat: added support for creating credentialOffer deeplink based on a uri Signed-off-by: sksadjad <86593551+sksadjad@users.noreply.github.com> --- .../lib/functions/CredentialOfferUtils.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/issuer/lib/functions/CredentialOfferUtils.ts b/packages/issuer/lib/functions/CredentialOfferUtils.ts index e14e88a6..7147b422 100644 --- a/packages/issuer/lib/functions/CredentialOfferUtils.ts +++ b/packages/issuer/lib/functions/CredentialOfferUtils.ts @@ -4,17 +4,24 @@ import { v4 as uuidv4 } from 'uuid' export function createCredentialOfferURI( issuerMetadata?: IssuerMetadata, // todo: probably it's wise to create another builder for CredentialOfferPayload that will generate different kinds of CredentialOfferPayload - opts?: { state?: string; credentialOffer?: CredentialOfferPayload; preAuthorizedCode?: string; userPinRequired?: boolean } + opts?: { + state?: string + credentialOffer?: CredentialOfferPayload + credentialOfferUri?: string + scheme?: string + preAuthorizedCode?: string + userPinRequired?: boolean + } ): string { - // openid-credential-offer://credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com - // %22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCr - // edential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et... - // FYUaBy%22%7D - if (!issuerMetadata && !opts?.credentialOffer) { + if (!issuerMetadata && !opts?.credentialOffer && !opts?.credentialOfferUri) { throw new Error('You have to provide issuerMetadata or credentialOffer object for creating a deeplink') } + const scheme = opts?.scheme ? opts.scheme : 'openid-credential-offer' + if (opts?.credentialOfferUri) { + return `${scheme}://?credential_offer_uri=${opts?.credentialOfferUri}` + } if (opts?.credentialOffer) { - return `openid-credential-offer://?credential_offer=${encodeJsonAsURI(opts.credentialOffer)}` + return `${scheme}://?credential_offer=${encodeJsonAsURI(opts.credentialOffer)}` } const credentialOfferPayload = { credential_issuer: issuerMetadata?.credential_issuer, @@ -34,5 +41,5 @@ export function createCredentialOfferURI( user_pin_required: opts.userPinRequired ? opts.userPinRequired : false, } } - return `openid-credential-offer://?credential_offer=${encodeJsonAsURI(credentialOfferPayload)}` + return `${scheme}://?credential_offer=${encodeJsonAsURI(credentialOfferPayload)}` }