44import {
55 createAuthorizationDetailsFromOffer , createCredentialRequestsFromOffer
66} from './oid4vci/credentialOffer.js' ;
7+ import { generateDIDProofDIVP , generateDIDProofJWT } from './oid4vci/proofs.js' ;
78import { createNamedError } from './util.js' ;
8- import { generateDIDProofJWT } from './oid4vci/proofs.js' ;
99import { httpClient } from '@digitalbazaar/http-client' ;
1010import { robustDiscoverIssuer } from './oid4vci/discovery.js' ;
1111
@@ -231,6 +231,46 @@ export class OID4Client {
231231 }
232232}
233233
234+ async function _addDIDProof ( {
235+ issuerConfig, json, nonce, did, didProofSigner
236+ } ) {
237+ // FIXME: allow these to combine; and choose just one based on
238+ // `proof_types_supported`, defaulting to `jwt` if nothing is specified
239+ await _addDIDProofDIVP ( { issuerConfig, json, nonce, did, didProofSigner} ) ;
240+ // add DID proof `jwt` to json
241+ await _addDIDProofJWT ( { issuerConfig, json, nonce, did, didProofSigner} ) ;
242+ }
243+
244+ async function _addDIDProofDIVP ( {
245+ issuerConfig, json, nonce, did, didProofSigner
246+ } ) {
247+ // generate a DID proof DI VP
248+ const { issuer : domain } = issuerConfig ;
249+ const di_vp = [ await generateDIDProofDIVP ( {
250+ did,
251+ signer : didProofSigner ,
252+ domain,
253+ challenge : nonce
254+ } ) ] ;
255+
256+ // add proof to body to be posted and loop to retry
257+ const proof = { proof_type : 'di_vp' , di_vp} ;
258+ if ( json . credential_requests ) {
259+ // OID4VCI Draft 13 only
260+ json . credential_requests = json . credential_requests . map (
261+ cr => ( { ...cr , proof} ) ) ;
262+ } else if ( json . credential_definition ) {
263+ // OID4VCI Draft 13 only
264+ json . proof = proof ;
265+ } else {
266+ // OID4VCI 1.0+
267+ json . proofs = {
268+ ...proof ,
269+ di_vp : [ proof . di_vp ]
270+ } ;
271+ }
272+ }
273+
234274async function _addDIDProofJWT ( {
235275 issuerConfig, json, nonce, did, didProofSigner
236276} ) {
@@ -278,6 +318,12 @@ async function _requestCredential({
278318 "format": "ldp_vc",
279319 "credential_definition": {...},
280320 // only present on retry after server requests it or if nonce is given
321+ // v1.0 format:
322+ "proofs": {
323+ "di_vp": [VP1, VP2, ...],
324+ "jwt": [JWT1, JWT2, ...]
325+ }
326+ // draft 13 format:
281327 "proof": {
282328 "proof_type": "jwt",
283329 "jwt": "eyJraW..."
@@ -306,6 +352,12 @@ async function _requestCredential({
306352 "format": "ldp_vc",
307353 "credential_definition": {...},
308354 // only present on retry after server requests it
355+ // v1.0 format:
356+ "proofs": {
357+ "di_vp": [VP1, VP2, ...],
358+ "jwt": [JWT1, JWT2, ...]
359+ }
360+ // draft 13 format:
309361 "proof": {
310362 "proof_type": "jwt",
311363 "jwt": "eyJraW..."
@@ -320,8 +372,8 @@ async function _requestCredential({
320372
321373 */
322374 if ( nonce !== undefined ) {
323- // add DID proof JWT to json
324- await _addDIDProofJWT ( { issuerConfig, json, nonce, did, didProofSigner} ) ;
375+ // add DID proof to json
376+ await _addDIDProof ( { issuerConfig, json, nonce, did, didProofSigner} ) ;
325377 }
326378
327379 let result ;
@@ -373,10 +425,8 @@ async function _requestCredential({
373425 ( { nonce} = await this . getNonce ( { agent} ) ) ;
374426 }
375427
376- // add DID proof JWT to json
377- await _addDIDProofJWT ( {
378- issuerConfig, json, nonce, did, didProofSigner
379- } ) ;
428+ // add DID proof to json
429+ await _addDIDProof ( { issuerConfig, json, nonce, did, didProofSigner} ) ;
380430 }
381431 }
382432
0 commit comments