From 3c23bab83569e04a4b5846fed83ce00d68e8ddce Mon Sep 17 00:00:00 2001 From: Niels Klomp Date: Wed, 27 Sep 2023 04:49:18 +0200 Subject: [PATCH] fix: Fix credential offer matching against metadata --- packages/common/lib/functions/IssuerMetadataUtils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/common/lib/functions/IssuerMetadataUtils.ts b/packages/common/lib/functions/IssuerMetadataUtils.ts index 342ade39..7323d8fa 100644 --- a/packages/common/lib/functions/IssuerMetadataUtils.ts +++ b/packages/common/lib/functions/IssuerMetadataUtils.ts @@ -70,14 +70,22 @@ export function getSupportedCredential(opts?: { const supportedFormats: (CredentialOfferFormat | string)[] = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc']; const credentialSupportedOverlap: CredentialSupported[] = []; - if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) { + if (opts?.types && typeof opts?.types === 'string') { + const supported = credentialsSupported.filter( + (sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)), + ) + if (supported) { + credentialSupportedOverlap.push(...supported); + } + } /*else if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) { + const supported = credentialsSupported.filter( (sup) => sup.id === initiationTypes![0] || (arrayEqualsIgnoreOrder(sup.types, initiationTypes!) && sup.types.includes(initiationTypes![0])), ); if (supported) { credentialSupportedOverlap.push(...supported); } - } else { + }*/ else { // Make sure we include Verifiable Credential both on the offer side as well as in the metadata side, to ensure consistency of the issuer does not. if (initiationTypes && !initiationTypes.includes('VerifiableCredential')) { initiationTypes.push('VerifiableCredential');