Skip to content

Commit e99d181

Browse files
committed
chore: support array of vp_token as map value
1 parent 34b969f commit e99d181

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

packages/siop-oid4vp/lib/authorization-response/OpenID4VP.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,26 @@ export const extractDcqlPresentationFromDcqlVpToken = (
104104
opts?: { hasher?: HasherSync },
105105
): PresentationSubmission => {
106106
return Object.fromEntries(
107-
Object.entries(DcqlPresentation.parse(vpToken)).map(([credentialQueryId, vp]) => [
107+
Object.entries(DcqlPresentation.parse(vpToken)).map(([credentialQueryId, vp]) => {
108+
let singleVp: W3CVerifiablePresentation | CompactSdJwtVc | string
109+
110+
if (Array.isArray(vp)) {
111+
if (vp.length === 0) {
112+
throw new Error(`DCQL query '${credentialQueryId}' has empty array of presentations`)
113+
}
114+
if (vp.length > 1) {
115+
throw new Error(`DCQL query '${credentialQueryId}' has multiple presentations (${vp.length}), but only one is supported atm`)
116+
}
117+
singleVp = vp[0]
118+
} else {
119+
singleVp = vp
120+
}
121+
122+
return [
108123
credentialQueryId,
109-
CredentialMapper.toWrappedVerifiablePresentation(vp as W3CVerifiablePresentation | CompactSdJwtVc | string, {hasher: opts?.hasher}),
110-
]),
124+
CredentialMapper.toWrappedVerifiablePresentation(singleVp as W3CVerifiablePresentation | CompactSdJwtVc | string, {hasher: opts?.hasher}),
125+
]
126+
}),
111127
)
112128
}
113129

0 commit comments

Comments
 (0)