@digitalbazaar/oid4-client 5.4.1 → 5.6.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/query/dcql.js
CHANGED
|
@@ -112,7 +112,9 @@ export function _fromQueryByExampleQuery({
|
|
|
112
112
|
id: crypto.randomUUID(),
|
|
113
113
|
format: 'ldp_vc',
|
|
114
114
|
meta: {
|
|
115
|
-
type_values: [
|
|
115
|
+
type_values: [
|
|
116
|
+
['https://www.w3.org/2018/credentials#VerifiableCredential']
|
|
117
|
+
]
|
|
116
118
|
}
|
|
117
119
|
};
|
|
118
120
|
if(credentialQuery?.reason) {
|
|
@@ -7,6 +7,7 @@ import {JSONPath} from 'jsonpath-plus';
|
|
|
7
7
|
import jsonpointer from 'json-pointer';
|
|
8
8
|
|
|
9
9
|
const VALUE_TYPES = new Set(['string', 'number', 'boolean']);
|
|
10
|
+
const SUPPORTED_JWT_ALGS = ['EdDSA', 'Ed25519', 'ES256', 'ES384'];
|
|
10
11
|
|
|
11
12
|
export function presentationDefinitionToVprGroups({
|
|
12
13
|
presentation_definition, strict = false
|
|
@@ -42,14 +43,15 @@ export function vprGroupsToPresentationDefinition({
|
|
|
42
43
|
input_descriptors
|
|
43
44
|
};
|
|
44
45
|
|
|
46
|
+
let acceptsVpJwt = false;
|
|
47
|
+
let acceptsVcJwt = false;
|
|
48
|
+
|
|
49
|
+
const ldpVpProofTypes = new Set();
|
|
50
|
+
const ldpVcProofTypes = new Set();
|
|
45
51
|
// note: same group ID is logical "AND" and different group ID is "OR"
|
|
46
52
|
const groups = [...groupMap.values()];
|
|
47
53
|
for(const queries of groups) {
|
|
48
|
-
// only `QueryByExample` is convertible
|
|
49
54
|
const queryByExamples = queries.get('QueryByExample');
|
|
50
|
-
if(!queryByExamples) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
55
|
|
|
54
56
|
// for each `QueryByExample`, add another input descriptor (for every
|
|
55
57
|
// "credentialQuery" within it
|
|
@@ -59,11 +61,74 @@ export function vprGroupsToPresentationDefinition({
|
|
|
59
61
|
const all = Array.isArray(queryByExample.credentialQuery) ?
|
|
60
62
|
queryByExample.credentialQuery : [queryByExample.credentialQuery];
|
|
61
63
|
for(const credentialQuery of all) {
|
|
62
|
-
|
|
64
|
+
const inputDescriptor = _fromQueryByExampleQuery({
|
|
63
65
|
credentialQuery, prefixJwtVcPath
|
|
64
|
-
})
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const {acceptedEnvelopes, acceptedCryptosuites} = credentialQuery;
|
|
69
|
+
const shouldAddFormat = acceptedEnvelopes || acceptedCryptosuites;
|
|
70
|
+
if(shouldAddFormat && !inputDescriptor.format) {
|
|
71
|
+
inputDescriptor.format = {};
|
|
72
|
+
}
|
|
73
|
+
if(acceptedEnvelopes?.includes('application/jwt')) {
|
|
74
|
+
inputDescriptor.format.jwt_vc_json = {
|
|
75
|
+
alg: SUPPORTED_JWT_ALGS
|
|
76
|
+
};
|
|
77
|
+
acceptsVcJwt = true;
|
|
78
|
+
}
|
|
79
|
+
if(acceptedCryptosuites) {
|
|
80
|
+
const cryptosuites = acceptedCryptosuites
|
|
81
|
+
.map(({cryptosuite}) => cryptosuite);
|
|
82
|
+
inputDescriptor.format.ldp_vc = {
|
|
83
|
+
proof_type: cryptosuites
|
|
84
|
+
};
|
|
85
|
+
for(const cryptosuite of cryptosuites) {
|
|
86
|
+
ldpVcProofTypes.add(cryptosuite);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
input_descriptors.push(inputDescriptor);
|
|
65
91
|
}
|
|
66
92
|
}
|
|
93
|
+
|
|
94
|
+
const didAuthentications = queries.get('DIDAuthentication');
|
|
95
|
+
for(const didAuthentication of didAuthentications) {
|
|
96
|
+
const {acceptedEnvelopes, acceptedCryptosuites} = didAuthentication;
|
|
97
|
+
|
|
98
|
+
if(acceptedEnvelopes?.includes('application/jwt')) {
|
|
99
|
+
acceptsVpJwt = true;
|
|
100
|
+
}
|
|
101
|
+
if(acceptedCryptosuites) {
|
|
102
|
+
const cryptosuites = acceptedCryptosuites
|
|
103
|
+
.map(({cryptosuite}) => cryptosuite);
|
|
104
|
+
for(const cryptosuite of cryptosuites) {
|
|
105
|
+
ldpVpProofTypes.add(cryptosuite);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const shouldAddFormat = acceptsVcJwt || acceptsVpJwt ||
|
|
112
|
+
ldpVcProofTypes.size > 0 || ldpVpProofTypes.size > 0;
|
|
113
|
+
if(shouldAddFormat && !presentationDefinition.format) {
|
|
114
|
+
presentationDefinition.format = {};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if(acceptsVcJwt) {
|
|
118
|
+
presentationDefinition.format.jwt_vc_json = {alg: SUPPORTED_JWT_ALGS};
|
|
119
|
+
}
|
|
120
|
+
if(acceptsVpJwt) {
|
|
121
|
+
presentationDefinition.format.jwt_vp = {alg: SUPPORTED_JWT_ALGS};
|
|
122
|
+
presentationDefinition.format.jwt_vp_json = {alg: SUPPORTED_JWT_ALGS};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if(ldpVcProofTypes.size > 0) {
|
|
126
|
+
const proof_type = [...ldpVcProofTypes];
|
|
127
|
+
presentationDefinition.format.ldp_vc = {proof_type};
|
|
128
|
+
}
|
|
129
|
+
if(ldpVpProofTypes.size > 0) {
|
|
130
|
+
const proof_type = [...ldpVpProofTypes];
|
|
131
|
+
presentationDefinition.format.ldp_vp = {proof_type};
|
|
67
132
|
}
|
|
68
133
|
|
|
69
134
|
return presentationDefinition;
|