@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.
- package/lib/convert/index.js +27 -12
- package/lib/query/presentationExchange.js +29 -12
- package/lib/query/util.js +1 -1
- package/package.json +1 -1
package/lib/convert/index.js
CHANGED
|
@@ -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
|
|
88
|
-
(
|
|
89
|
-
query.acceptedEnvelopes
|
|
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
|
|
282
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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(
|
|
310
|
-
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
124
|
+
if(envelopes?.includes('application/jwt')) {
|
|
121
125
|
acceptsVpJwt = true;
|
|
122
126
|
}
|
|
123
|
-
if(
|
|
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
|
-
|
|
237
|
-
(
|
|
238
|
-
|
|
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