Skip to content

Commit e51804f

Browse files
committed
chore: support for proofs array in credential request
1 parent 40ab713 commit e51804f

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

packages/issuer/lib/VcIssuer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ export class VcIssuer {
678678
throw Error(`Format ${format} not supported yet`)
679679
}
680680

681-
const verifyFn = jwtVerifyCallback ?? this._jwtVerifyCallback
681+
const verifyFn: JWTVerifyCallback | undefined = jwtVerifyCallback ?? this._jwtVerifyCallback
682682
if (typeof verifyFn !== 'function') {
683683
throw Error(JWT_VERIFY_CONFIG_ERROR)
684684
}
@@ -690,15 +690,27 @@ export class VcIssuer {
690690
throw Error('Credential request may not contain both proof and proofs parameters')
691691
}
692692

693-
// Normalize candidates into a single array
693+
// Normalize candidates into a single array of ProofOfPossession objects
694694
const proofCandidates: Array<ProofOfPossession> = []
695695

696696
if (credReq.proof) {
697697
proofCandidates.push(credReq.proof)
698698
} else if (credReq.proofs) {
699699
// Handle "proofs": prioritize 'jwt' as it's the only fully supported type
700700
if (Array.isArray(credReq.proofs.jwt)) {
701-
proofCandidates.push(...credReq.proofs.jwt)
701+
// Map to ProofOfPossession objects, handling both string and object formats
702+
for (const jwtProof of credReq.proofs.jwt) {
703+
if (typeof jwtProof === 'string') {
704+
// Handle case where jwt array contains strings instead of ProofOfPossession objects
705+
proofCandidates.push({
706+
proof_type: 'jwt',
707+
jwt: jwtProof,
708+
})
709+
} else if (jwtProof && typeof jwtProof === 'object' && 'jwt' in jwtProof) {
710+
// Handle proper ProofOfPossession object
711+
proofCandidates.push(jwtProof)
712+
}
713+
}
702714
}
703715

704716
// Check if there are no supported proofs found
@@ -716,7 +728,7 @@ export class VcIssuer {
716728

717729
for (const proof of proofCandidates) {
718730
try {
719-
jwtVerifyResult = await verifyFn(proof)
731+
jwtVerifyResult = await verifyFn({ jwt: proof.jwt })
720732
break
721733
} catch (error) {
722734
const msg = error instanceof Error ? error.message : String(error)

0 commit comments

Comments
 (0)