Skip to content

Commit

Permalink
chore: unwrap single-element array in extractPresentationsFromVpToken
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Nov 14, 2024
1 parent 5e12677 commit d73a336
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export const verifyPresentations = async (
verifyOpts: VerifyAuthorizationResponseOpts,
): Promise<VerifiedOpenID4VPSubmission | null> => {
const presentations = authorizationResponse.payload.vp_token
? await extractPresentationsFromVpToken(authorizationResponse.payload.vp_token, { hasher: verifyOpts.hasher })
: []
? await extractPresentationsFromVpToken(authorizationResponse.payload.vp_token, { hasher: verifyOpts.hasher }) : undefined
const presentationDefinitions = verifyOpts.presentationDefinitions
? Array.isArray(verifyOpts.presentationDefinitions)
? verifyOpts.presentationDefinitions
Expand Down Expand Up @@ -135,11 +134,14 @@ export const extractPresentationsFromVpToken = async (
vpToken: Array<W3CVerifiablePresentation | CompactSdJwtVc | string> | W3CVerifiablePresentation | CompactSdJwtVc | string,
opts?: { hasher?: Hasher },
): Promise<WrappedVerifiablePresentation[] | WrappedVerifiablePresentation> => {
if (Array.isArray(vpToken)) {
return vpToken.map((vp) => CredentialMapper.toWrappedVerifiablePresentation(vp, { hasher: opts?.hasher }))
const tokens = Array.isArray(vpToken) ? vpToken : [vpToken];
const wrappedTokens = tokens.map(vp =>
CredentialMapper.toWrappedVerifiablePresentation(vp, { hasher: opts?.hasher })
);

return tokens.length === 1 ? wrappedTokens[0] : wrappedTokens;
}
return CredentialMapper.toWrappedVerifiablePresentation(vpToken, { hasher: opts?.hasher })
}

export const createPresentationSubmission = async (
verifiablePresentations: W3CVerifiablePresentation[],
opts?: { presentationDefinitions: (PresentationDefinitionWithLocation | IPresentationDefinition)[] },
Expand Down

0 comments on commit d73a336

Please sign in to comment.