11import type { CallbackContext } from '@openid4vc/oauth2'
2+ import { parseWithErrorHandling } from '@openid4vc/utils'
23import { Openid4vciError } from '../../../error/Openid4vciError'
4+ import { DataIntegrityProof , zDataIntegrityProof } from './z-di-vp-proof-type'
35
46export interface VerifyCredentialRequestDiVpProofOptions {
57 /**
@@ -39,21 +41,17 @@ export async function verifyCredentialRequestDiVpProof(options: VerifyCredential
3941 throw new Openid4vciError ( 'Nonce used for credential request proof expired' )
4042 }
4143
42- const rawProof = options . vp . proof
43- const proof = ( Array . isArray ( rawProof ) ? rawProof [ 0 ] : rawProof ) as Record < string , unknown > | undefined
44-
45- if ( ! proof || typeof proof !== 'object' ) {
44+ const rawProof = ( options . vp as { proof ?: unknown } ) . proof
45+ if ( rawProof === undefined ) {
4646 throw new Openid4vciError ( `di_vp proof is missing a 'proof' entry` )
4747 }
48- if ( proof . type !== 'DataIntegrityProof' ) {
49- throw new Openid4vciError ( `di_vp proof 'proof.type' must be 'DataIntegrityProof'` )
50- }
51- if ( ! proof . cryptosuite || typeof proof . cryptosuite !== 'string' ) {
52- throw new Openid4vciError ( `di_vp proof is missing required 'proof.cryptosuite'` )
53- }
54- if ( proof . proofPurpose !== 'authentication' ) {
55- throw new Openid4vciError ( `di_vp proof 'proof.proofPurpose' must be 'authentication'` )
56- }
48+
49+ const proof = parseWithErrorHandling (
50+ zDataIntegrityProof ,
51+ Array . isArray ( rawProof ) ? rawProof [ 0 ] : rawProof ,
52+ 'di_vp proof contains an invalid proof entry'
53+ ) satisfies DataIntegrityProof ;
54+
5755 if ( proof . domain !== options . credentialIssuer ) {
5856 throw new Openid4vciError ( `di_vp proof 'proof.domain' does not match the credential issuer identifier` )
5957 }
@@ -64,9 +62,6 @@ export async function verifyCredentialRequestDiVpProof(options: VerifyCredential
6462 } else if ( proof . challenge !== undefined ) {
6563 throw new Openid4vciError ( `di_vp proof 'proof.challenge' must not be present when no nonce was issued` )
6664 }
67- if ( ! proof . verificationMethod || typeof proof . verificationMethod !== 'string' ) {
68- throw new Openid4vciError ( `di_vp proof is missing required 'proof.verificationMethod'` )
69- }
7065
7166 if ( ! options . callbacks . verifyDataIntegrityProof ) {
7267 throw new Openid4vciError ( 'Cannot verify di_vp proof: no verifyDataIntegrityProof callback configured' )
0 commit comments