@digitalbazaar/oid4-client 5.6.3 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,9 +84,10 @@ export function fromVpr({
84
84
  const cryptosuites = new Set();
85
85
  const envelopes = new Set();
86
86
  for(const query of didAuthnQuery) {
87
- query.acceptedCryptosuites?.forEach(
88
- ({cryptosuite}) => cryptosuites.add(cryptosuite));
89
- query.acceptedEnvelopes?.forEach(envelope => envelopes.add(envelope));
87
+ _getCryptosuites(query.acceptedCryptosuites)
88
+ .forEach(cryptosuites.add, cryptosuites);
89
+ _getEnvelopes(query.acceptedEnvelopes)
90
+ .forEach(envelopes.add, envelopes);
90
91
  }
91
92
  // convert last DID authn query w/merged cryptosuites and envelopes
92
93
  const query = structuredClone(didAuthnQuery.at(-1));
@@ -269,6 +270,20 @@ function _strictCheckVprGroups({groupMap, queryFormats}) {
269
270
  }
270
271
  }
271
272
 
273
+ function _getCryptosuites(acceptedCryptosuites) {
274
+ // array elements can be '<cryptosuite>' or {cryptosuite: '<cryptosuite>'}
275
+ return acceptedCryptosuites
276
+ ?.filter(e => e && (typeof e === 'string' || e.cryptosuite))
277
+ ?.map(e => typeof e === 'string' ? e : e.cryptosuite) ?? [];
278
+ }
279
+
280
+ function _getEnvelopes(acceptedEnvelopes) {
281
+ // array elements can be '<mediaType>' or {mediaType: '<mediaType>'}
282
+ return acceptedEnvelopes
283
+ ?.filter(e => e && (typeof e === 'string' || e.mediaType))
284
+ ?.map(e => typeof e === 'string' ? e : e.mediaType) ?? [];
285
+ }
286
+
272
287
  function _fromDIDAuthenticationQuery({query, strict = false}) {
273
288
  const vp_formats = {};
274
289
  const vp_formats_supported = {};
@@ -278,9 +293,8 @@ function _fromDIDAuthenticationQuery({query, strict = false}) {
278
293
  vp_formats_supported
279
294
  };
280
295
 
281
- const cryptosuites = query.acceptedCryptosuites?.map(
282
- ({cryptosuite}) => cryptosuite);
283
- if(cryptosuites?.length > 0) {
296
+ const cryptosuites = _getCryptosuites(query.acceptedCryptosuites);
297
+ if(cryptosuites.length > 0) {
284
298
  // legacy (before OID4VP 1.0)
285
299
  client_metadata.vp_formats.ldp_vp = {
286
300
  proof_type: cryptosuites
@@ -297,24 +311,25 @@ function _fromDIDAuthenticationQuery({query, strict = false}) {
297
311
  }
298
312
  }
299
313
 
300
- if(query.acceptedEnvelopes?.length > 0) {
301
- for(const envelope of query.acceptedEnvelopes) {
302
- if(envelope === 'application/jwt') {
314
+ const envelopes = _getEnvelopes(query.acceptedEnvelopes);
315
+ if(envelopes.length > 0) {
316
+ for(const mediaType of envelopes) {
317
+ if(mediaType === 'application/jwt') {
303
318
  // legacy (before OID4VP 1.0)
304
319
  vp_formats.jwt_vp = vp_formats.jwt_vp_json = {
305
320
  alg: ['EdDSA', 'Ed25519', 'ES256', 'ES384']
306
321
  };
307
322
  // OID4VP 1.0+
308
323
  vp_formats_supported.jwt_vc_json = {};
309
- } else if(envelope === 'application/mdl' ||
310
- envelope === 'application/mdoc') {
324
+ } else if(mediaType === 'application/mdl' ||
325
+ mediaType === 'application/mdoc') {
311
326
  // legacy (before OID4VP 1.0)
312
327
  vp_formats.mso_mdoc = {
313
328
  alg: ['EdDSA', 'ES256']
314
329
  };
315
330
  // OID4VP 1.0+
316
331
  vp_formats_supported.mso_mdoc = {};
317
- } else if(envelope === 'application/dc+sd-jwt') {
332
+ } else if(mediaType === 'application/dc+sd-jwt') {
318
333
  // legacy (before OID4VP 1.0)
319
334
  vp_formats['dc+sd-jwt'] = {};
320
335
  // OID4VP 1.0+
@@ -84,19 +84,21 @@ export function vprGroupsToPresentationDefinition({
84
84
  });
85
85
 
86
86
  const {acceptedEnvelopes, acceptedCryptosuites} = credentialQuery;
87
- const shouldAddFormat = acceptedEnvelopes || acceptedCryptosuites;
87
+ const envelopes = _getEnvelopes(acceptedEnvelopes);
88
+ const cryptosuites = _getCryptosuites(acceptedCryptosuites);
89
+
90
+ const shouldAddFormat =
91
+ envelopes?.length > 0 || cryptosuites?.length > 0;
88
92
  if(shouldAddFormat && !inputDescriptor.format) {
89
93
  inputDescriptor.format = {};
90
94
  }
91
- if(acceptedEnvelopes?.includes('application/jwt')) {
95
+ if(envelopes?.includes('application/jwt')) {
92
96
  inputDescriptor.format.jwt_vc_json = {
93
97
  alg: SUPPORTED_JWT_ALGS
94
98
  };
95
99
  acceptsVcJwt = true;
96
100
  }
97
- if(acceptedCryptosuites) {
98
- const cryptosuites = acceptedCryptosuites
99
- .map(({cryptosuite}) => cryptosuite);
101
+ if(cryptosuites?.length > 0) {
100
102
  inputDescriptor.format.ldp_vc = {
101
103
  proof_type: cryptosuites
102
104
  };
@@ -116,13 +118,13 @@ export function vprGroupsToPresentationDefinition({
116
118
  const didAuthentications = queries.get('DIDAuthentication') ?? [];
117
119
  for(const didAuthentication of didAuthentications) {
118
120
  const {acceptedEnvelopes, acceptedCryptosuites} = didAuthentication;
121
+ const envelopes = _getEnvelopes(acceptedEnvelopes);
122
+ const cryptosuites = _getCryptosuites(acceptedCryptosuites);
119
123
 
120
- if(acceptedEnvelopes?.includes('application/jwt')) {
124
+ if(envelopes?.includes('application/jwt')) {
121
125
  acceptsVpJwt = true;
122
126
  }
123
- if(acceptedCryptosuites) {
124
- const cryptosuites = acceptedCryptosuites
125
- .map(({cryptosuite}) => cryptosuite);
127
+ if(cryptosuites?.length > 0) {
126
128
  for(const cryptosuite of cryptosuites) {
127
129
  ldpVpProofTypes.add(cryptosuite);
128
130
  }
@@ -233,9 +235,10 @@ export function _fromQueryByExampleQuery({credentialQuery, prefixJwtVcPath}) {
233
235
  // determine `prefixJwtVcPath` default:
234
236
  // if `credentialQuery` specifies `acceptedEnvelopes: ['application/jwt']`,
235
237
  // then default `prefixJwtVcPath` to `true`
236
- if(prefixJwtVcPath === undefined &&
237
- (Array.isArray(credentialQuery.acceptedEnvelopes) &&
238
- credentialQuery.acceptedEnvelopes.includes?.('application/jwt'))) {
238
+ const envelopes = credentialQuery.acceptedEnvelopes
239
+ ?.filter(e => e && (typeof e === 'string' || e.mediaType))
240
+ .map(e => typeof e === 'string' ? e : e.mediaType);
241
+ if(prefixJwtVcPath === undefined && envelopes?.includes('application/jwt')) {
239
242
  prefixJwtVcPath = true;
240
243
  }
241
244
 
@@ -408,3 +411,17 @@ function _primitiveValueToFilter(value) {
408
411
  }
409
412
  return filter;
410
413
  }
414
+
415
+ function _getCryptosuites(acceptedCryptosuites) {
416
+ // array elements can be '<cryptosuite>' or {cryptosuite: '<cryptosuite>'}
417
+ return acceptedCryptosuites
418
+ ?.filter(e => e && (typeof e === 'string' || e.cryptosuite))
419
+ ?.map(e => typeof e === 'string' ? e : e.cryptosuite) ?? [];
420
+ }
421
+
422
+ function _getEnvelopes(acceptedEnvelopes) {
423
+ // array elements can be '<mediaType>' or {mediaType: '<mediaType>'}
424
+ return acceptedEnvelopes
425
+ ?.filter(e => e && (typeof e === 'string' || e.mediaType))
426
+ ?.map(e => typeof e === 'string' ? e : e.mediaType) ?? [];
427
+ }
package/lib/query/util.js CHANGED
@@ -48,7 +48,7 @@ export function toNumberIfNumber(x) {
48
48
  return x;
49
49
  }
50
50
 
51
- export function _fromPointers({map} = {}) {
51
+ function _fromPointers({map} = {}) {
52
52
  const result = {};
53
53
 
54
54
  for(const [pointer, value] of map) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/oid4-client",
3
- "version": "5.6.3",
3
+ "version": "5.7.0",
4
4
  "description": "An OID4 (VC + VP) client",
5
5
  "homepage": "https://github.com/digitalbazaar/oid4-client",
6
6
  "author": {