From a59450a14c955942c01acf81fef1feb26bd190f0 Mon Sep 17 00:00:00 2001 From: sanderPostma Date: Thu, 14 Nov 2024 16:21:17 +0100 Subject: [PATCH] chore: presentationsArray fixes --- .../lib/authorization-response/AuthorizationResponse.ts | 2 +- packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/siop-oid4vp/lib/authorization-response/AuthorizationResponse.ts b/packages/siop-oid4vp/lib/authorization-response/AuthorizationResponse.ts index 578bc295..5d9b8f3b 100644 --- a/packages/siop-oid4vp/lib/authorization-response/AuthorizationResponse.ts +++ b/packages/siop-oid4vp/lib/authorization-response/AuthorizationResponse.ts @@ -214,7 +214,7 @@ export class AuthorizationResponse { let nonce: string | undefined = this._payload.nonce if (this._payload?.vp_token) { const presentations = this.payload.vp_token ? await extractPresentationsFromVpToken(this.payload.vp_token, opts) : [] - const presentationsArray = Array.isArray(presentations) ? presentations : [presentations] + const presentationsArray = presentations ? (Array.isArray(presentations) ? presentations : [presentations]) : [] // We do not verify them, as that is done elsewhere. So we simply can take the first nonce nonce = presentationsArray diff --git a/packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts b/packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts index 5ea4f4ed..831be175 100644 --- a/packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts +++ b/packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts @@ -102,7 +102,7 @@ export const verifyPresentations = async ( return null } - const presentationsArray = Array.isArray(presentations) ? presentations : [presentations] + const presentationsArray = presentations ? (Array.isArray(presentations) ? presentations : [presentations]) : [] const presentationsWithoutMdoc = presentationsArray.filter((p) => p.format !== 'mso_mdoc') const nonces = new Set(presentationsWithoutMdoc.map(extractNonceFromWrappedVerifiablePresentation)) @@ -281,7 +281,7 @@ export const assertValidVerifiablePresentations = async (args: { hasher?: Hasher } }) => { - const presentationsArray = Array.isArray(args.presentations) ? args.presentations : [args.presentations] + const presentationsArray = args.presentations ? (Array.isArray(args.presentations) ? args.presentations : [args.presentations]) : [] if ( (!args.presentationDefinitions || args.presentationDefinitions.filter((a) => a.definition).length === 0) && (!presentationsArray || (Array.isArray(presentationsArray) && presentationsArray.filter((vp) => vp.presentation).length === 0))