dcql 2.0.0-alpha-20250916080434 → 2.0.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/dist/index.cjs +1177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12749 -0
- package/dist/index.d.mts +12428 -12412
- package/dist/index.mjs +944 -1398
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/index.d.ts +0 -12733
- package/dist/index.js +0 -1559
- package/dist/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,1494 +1,1040 @@
|
|
|
1
|
-
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/dcql-error/e-base.ts
|
|
2
4
|
function isObject(value) {
|
|
3
|
-
|
|
5
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
4
6
|
}
|
|
5
|
-
var UnknownCauseError = class extends Error {
|
|
6
|
-
};
|
|
7
|
+
var UnknownCauseError = class extends Error {};
|
|
7
8
|
function getCauseFromUnknown(cause) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (isObject(cause)) {
|
|
19
|
-
const err = new UnknownCauseError();
|
|
20
|
-
for (const key in cause) {
|
|
21
|
-
err[key] = cause[key];
|
|
22
|
-
}
|
|
23
|
-
return err;
|
|
24
|
-
}
|
|
25
|
-
return void 0;
|
|
9
|
+
if (cause instanceof Error) return cause;
|
|
10
|
+
const type = typeof cause;
|
|
11
|
+
if (type === "undefined" || type === "function" || cause === null) return;
|
|
12
|
+
if (type !== "object") return new Error(String(cause));
|
|
13
|
+
if (isObject(cause)) {
|
|
14
|
+
const err = new UnknownCauseError();
|
|
15
|
+
for (const key in cause) err[key] = cause[key];
|
|
16
|
+
return err;
|
|
17
|
+
}
|
|
26
18
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (cause instanceof Error && cause.name === "DcqlError") {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
19
|
+
const isDcqlError = (cause) => {
|
|
20
|
+
if (cause instanceof DcqlError) return true;
|
|
21
|
+
if (cause instanceof Error && cause.name === "DcqlError") return true;
|
|
22
|
+
return false;
|
|
35
23
|
};
|
|
36
24
|
function getDcqlErrorFromUnknown(cause) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (cause instanceof Error && cause.stack) {
|
|
45
|
-
dcqlError.stack = cause.stack;
|
|
46
|
-
}
|
|
47
|
-
return dcqlError;
|
|
25
|
+
if (isDcqlError(cause)) return cause;
|
|
26
|
+
const dcqlError = new DcqlError({
|
|
27
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
28
|
+
cause
|
|
29
|
+
});
|
|
30
|
+
if (cause instanceof Error && cause.stack) dcqlError.stack = cause.stack;
|
|
31
|
+
return dcqlError;
|
|
48
32
|
}
|
|
49
33
|
var DcqlError = class extends Error {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
34
|
+
constructor(opts) {
|
|
35
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
36
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
37
|
+
super(message, { cause });
|
|
38
|
+
this.code = opts.code;
|
|
39
|
+
this.name = "DcqlError";
|
|
40
|
+
if (!this.cause) this.cause = cause;
|
|
41
|
+
}
|
|
60
42
|
};
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/dcql-error/e-dcql.ts
|
|
63
46
|
var DcqlCredentialSetError = class extends DcqlError {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
constructor(opts) {
|
|
48
|
+
super({
|
|
49
|
+
code: "BAD_REQUEST",
|
|
50
|
+
...opts
|
|
51
|
+
});
|
|
52
|
+
}
|
|
67
53
|
};
|
|
68
54
|
var DcqlUndefinedClaimSetIdError = class extends DcqlError {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
constructor(opts) {
|
|
56
|
+
super({
|
|
57
|
+
code: "BAD_REQUEST",
|
|
58
|
+
...opts
|
|
59
|
+
});
|
|
60
|
+
}
|
|
72
61
|
};
|
|
73
62
|
var DcqlNonUniqueCredentialQueryIdsError = class extends DcqlError {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
constructor(opts) {
|
|
64
|
+
super({
|
|
65
|
+
code: "BAD_REQUEST",
|
|
66
|
+
...opts
|
|
67
|
+
});
|
|
68
|
+
}
|
|
77
69
|
};
|
|
78
70
|
var DcqlParseError = class extends DcqlError {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
constructor(opts) {
|
|
72
|
+
super({
|
|
73
|
+
code: "PARSE_ERROR",
|
|
74
|
+
...opts
|
|
75
|
+
});
|
|
76
|
+
}
|
|
82
77
|
};
|
|
83
78
|
var DcqlInvalidClaimsQueryIdError = class extends DcqlError {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
constructor(opts) {
|
|
80
|
+
super({
|
|
81
|
+
code: "BAD_REQUEST",
|
|
82
|
+
...opts
|
|
83
|
+
});
|
|
84
|
+
}
|
|
87
85
|
};
|
|
88
86
|
var DcqlMissingClaimSetParseError = class extends DcqlError {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
constructor(opts) {
|
|
88
|
+
super({
|
|
89
|
+
code: "PARSE_ERROR",
|
|
90
|
+
...opts
|
|
91
|
+
});
|
|
92
|
+
}
|
|
92
93
|
};
|
|
93
94
|
var DcqlInvalidPresentationRecordError = class extends DcqlError {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
constructor(opts) {
|
|
96
|
+
super({
|
|
97
|
+
code: "BAD_REQUEST",
|
|
98
|
+
...opts
|
|
99
|
+
});
|
|
100
|
+
}
|
|
97
101
|
};
|
|
98
102
|
var DcqlPresentationResultError = class extends DcqlError {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
constructor(opts) {
|
|
104
|
+
super({
|
|
105
|
+
code: "BAD_REQUEST",
|
|
106
|
+
...opts
|
|
107
|
+
});
|
|
108
|
+
}
|
|
102
109
|
};
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// src/dcql-query/m-dcql-trusted-authorities.ts
|
|
111
|
-
import * as v2 from "valibot";
|
|
112
|
-
|
|
113
|
-
// src/u-dcql.ts
|
|
114
|
-
import * as v from "valibot";
|
|
115
|
-
var idRegex = /^[a-zA-Z0-9_-]+$/;
|
|
116
|
-
function asNonEmptyArrayOrUndefined(array8) {
|
|
117
|
-
return array8.length > 0 ? array8 : void 0;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/u-dcql.ts
|
|
113
|
+
const idRegex = /^[a-zA-Z0-9_-]+$/;
|
|
114
|
+
function asNonEmptyArrayOrUndefined(array) {
|
|
115
|
+
return array.length > 0 ? array : void 0;
|
|
118
116
|
}
|
|
119
|
-
function isNonEmptyArray(
|
|
120
|
-
|
|
117
|
+
function isNonEmptyArray(array) {
|
|
118
|
+
return array.length > 0;
|
|
121
119
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
v.array(item, (i) => `Expected input to be an array, but received '${i.received}'`),
|
|
125
|
-
v.custom(
|
|
126
|
-
(input) => input.length > 0,
|
|
127
|
-
"Array must be non-empty and have length of at least 1"
|
|
128
|
-
)
|
|
129
|
-
);
|
|
120
|
+
const vNonEmptyArray = (item) => {
|
|
121
|
+
return v.pipe(v.array(item, (i) => `Expected input to be an array, but received '${i.received}'`), v.custom((input) => input.length > 0, "Array must be non-empty and have length of at least 1"));
|
|
130
122
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
`Value must include all of: ${subset.join(", ")}`
|
|
138
|
-
);
|
|
123
|
+
const vIncludesAll = (subset) => {
|
|
124
|
+
return v.custom((value) => {
|
|
125
|
+
if (!Array.isArray(value)) return false;
|
|
126
|
+
return subset.every((item) => value.includes(item));
|
|
127
|
+
}, `Value must include all of: ${subset.join(", ")}`);
|
|
139
128
|
};
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
const vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty());
|
|
130
|
+
const vBase64url = v.regex(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==)?|[\w-]{3}=?)?$/iu, "must be base64url");
|
|
142
131
|
function isToJsonable(value) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return typeof toJsonFn === "function";
|
|
132
|
+
if (value === null || typeof value !== "object") return false;
|
|
133
|
+
return typeof value.toJson === "function";
|
|
146
134
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
135
|
+
const vWithJT = (schema) => v.pipe(v.custom(() => true), v.rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
136
|
+
const result = v.safeParse(schema, dataset.value);
|
|
137
|
+
if (result.success) return dataset.value;
|
|
138
|
+
if (!isToJsonable(dataset.value)) {
|
|
139
|
+
for (const safeParseIssue of result.issues) addIssue({
|
|
140
|
+
...safeParseIssue,
|
|
141
|
+
expected: safeParseIssue.expected ?? void 0
|
|
142
|
+
});
|
|
143
|
+
return NEVER;
|
|
144
|
+
}
|
|
145
|
+
let json;
|
|
146
|
+
try {
|
|
147
|
+
json = dataset.value.toJson();
|
|
148
|
+
} catch {
|
|
149
|
+
for (const safeParseIssue of result.issues) addIssue({
|
|
150
|
+
...safeParseIssue,
|
|
151
|
+
expected: safeParseIssue.expected ?? void 0
|
|
152
|
+
});
|
|
153
|
+
addIssue({ message: "Json Transformation failed" });
|
|
154
|
+
return NEVER;
|
|
155
|
+
}
|
|
156
|
+
const safeParseResult = v.safeParse(schema, json);
|
|
157
|
+
if (safeParseResult.success) return dataset.value;
|
|
158
|
+
for (const safeParseIssue of safeParseResult.issues) addIssue({
|
|
159
|
+
...safeParseIssue,
|
|
160
|
+
expected: safeParseIssue.expected ?? void 0
|
|
161
|
+
});
|
|
162
|
+
return NEVER;
|
|
163
|
+
}));
|
|
164
|
+
const vJsonLiteral = v.union([
|
|
165
|
+
v.string(),
|
|
166
|
+
v.number(),
|
|
167
|
+
v.boolean(),
|
|
168
|
+
v.null()
|
|
169
|
+
]);
|
|
170
|
+
const vJson = v.lazy(() => v.union([
|
|
171
|
+
vJsonLiteral,
|
|
172
|
+
v.array(vJson),
|
|
173
|
+
v.record(v.string(), vJson)
|
|
174
|
+
]));
|
|
175
|
+
const vJsonWithJT = v.lazy(() => vWithJT(v.union([
|
|
176
|
+
vJsonLiteral,
|
|
177
|
+
v.array(vJson),
|
|
178
|
+
v.record(v.string(), vJson)
|
|
179
|
+
])));
|
|
180
|
+
const vJsonRecord = v.record(v.string(), vJson);
|
|
181
|
+
const vStringToJson = v.rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
182
|
+
try {
|
|
183
|
+
return JSON.parse(dataset.value);
|
|
184
|
+
} catch {
|
|
185
|
+
addIssue({ message: "Invalid JSON" });
|
|
186
|
+
return NEVER;
|
|
187
|
+
}
|
|
200
188
|
});
|
|
189
|
+
/**
|
|
190
|
+
* Helper function to provide a custom required message for an object property.
|
|
191
|
+
*
|
|
192
|
+
* The behavior was changed in newer valibot versions.
|
|
193
|
+
*
|
|
194
|
+
* @see https://github.com/fabian-hiller/valibot/issues/1034
|
|
195
|
+
*/
|
|
196
|
+
function vCustomRequiredMessage(schema, message) {
|
|
197
|
+
const outputSchema = v.pipe(v.optional(schema, () => void 0), schema);
|
|
198
|
+
if (message) return v.message(outputSchema, message);
|
|
199
|
+
return outputSchema;
|
|
200
|
+
}
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
v2.description(
|
|
233
|
-
"Contains a list of KeyIdentifier entries of the AuthorityKeyIdentifier as defined in Section 4.2.1.1 of [RFC5280], encoded as base64url. The raw byte representation of one of the elements MUST match with the AuthorityKeyIdentifier element of an X.509 certificate in the certificate chain present in the credential (e.g., in the header of an mdoc or SD-JWT). Note that the chain can consist of a single certificate and the credential can include the entire X.509 chain or parts of it."
|
|
234
|
-
)
|
|
235
|
-
)
|
|
236
|
-
)
|
|
237
|
-
});
|
|
238
|
-
var vEtsiTrustedList = v2.object({
|
|
239
|
-
type: v2.literal("etsi_tl"),
|
|
240
|
-
values: vNonEmptyArray(
|
|
241
|
-
v2.pipe(
|
|
242
|
-
v2.string("etsi_tl trusted authority value must be a string"),
|
|
243
|
-
v2.url("etsi_tl trusted authority value must be a valid https url"),
|
|
244
|
-
v2.check(
|
|
245
|
-
(url2) => url2.startsWith("http://") || url2.startsWith("https://"),
|
|
246
|
-
"etsi_tl trusted authority value must be a valid https url"
|
|
247
|
-
),
|
|
248
|
-
v2.description(
|
|
249
|
-
"The identifier of a Trusted List as specified in ETSI TS 119 612 [ETSI.TL]. An ETSI Trusted List contains references to other Trusted Lists, creating a list of trusted lists, or entries for Trust Service Providers with corresponding service description and X.509 Certificates. The trust chain of a matching Credential MUST contain at least one X.509 Certificate that matches one of the entries of the Trusted List or its cascading Trusted Lists."
|
|
250
|
-
)
|
|
251
|
-
)
|
|
252
|
-
)
|
|
253
|
-
});
|
|
254
|
-
var vOpenidFederation = v2.object({
|
|
255
|
-
type: v2.literal("openid_federation"),
|
|
256
|
-
values: vNonEmptyArray(
|
|
257
|
-
v2.pipe(
|
|
258
|
-
v2.string("openid_federation trusted authority value must be a string"),
|
|
259
|
-
v2.url("openid_federation trusted authority value must be a valid https url"),
|
|
260
|
-
// TODO: should we have a config similar to oid4vc-ts to support http for development?
|
|
261
|
-
v2.check(
|
|
262
|
-
(url2) => url2.startsWith("http://") || url2.startsWith("https://"),
|
|
263
|
-
"openid_federation trusted authority value must be a valid https url"
|
|
264
|
-
),
|
|
265
|
-
v2.description(
|
|
266
|
-
"The Entity Identifier as defined in Section 1 of [OpenID.Federation] that is bound to an entity in a federation. While this Entity Identifier could be any entity in that ecosystem, this entity would usually have the Entity Configuration of a Trust Anchor. A valid trust path, including the given Entity Identifier, must be constructible from a matching credential."
|
|
267
|
-
)
|
|
268
|
-
)
|
|
269
|
-
)
|
|
270
|
-
});
|
|
271
|
-
var vTrustedAuthorities = [vAuthorityKeyIdentifier, vEtsiTrustedList, vOpenidFederation];
|
|
272
|
-
var DcqlTrustedAuthoritiesQuery;
|
|
273
|
-
((DcqlTrustedAuthoritiesQuery2) => {
|
|
274
|
-
const vTrustedAuthoritiesQuery = vTrustedAuthorities.map(
|
|
275
|
-
(authority) => v2.object({
|
|
276
|
-
type: v2.pipe(
|
|
277
|
-
authority.entries.type,
|
|
278
|
-
v2.description(
|
|
279
|
-
"REQUIRED. A string uniquely identifying the type of information about the issuer trust framework."
|
|
280
|
-
)
|
|
281
|
-
),
|
|
282
|
-
values: v2.pipe(
|
|
283
|
-
vNonEmptyArray(authority.entries.values.item),
|
|
284
|
-
v2.description(
|
|
285
|
-
"REQUIRED. An array of strings, where each string (value) contains information specific to the used Trusted Authorities Query type that allows to identify an issuer, trust framework, or a federation that an issuer belongs to."
|
|
286
|
-
)
|
|
287
|
-
)
|
|
288
|
-
})
|
|
289
|
-
);
|
|
290
|
-
DcqlTrustedAuthoritiesQuery2.vModel = v2.variant("type", vTrustedAuthoritiesQuery);
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/dcql-query/m-dcql-trusted-authorities.ts
|
|
204
|
+
const getTrustedAuthorityParser = (trustedAuthority) => v.pipe(v.object({
|
|
205
|
+
type: v.literal(trustedAuthority.type, (i) => `Expected trusted authority type to be '${trustedAuthority.type}' but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`),
|
|
206
|
+
values: v.pipe(vNonEmptyArray(v.string()), v.someItem((item) => trustedAuthority.values.includes(item), (i) => `Expected one of the trusted authority values to be '${trustedAuthority.values.join("' | '")}' but received '${i.input.join("' , '")}'`))
|
|
207
|
+
}, `Expected trusted authority object with type '${trustedAuthority.type}' to be defined, but received undefined`), v.transform(({ values,...rest }) => ({
|
|
208
|
+
...rest,
|
|
209
|
+
value: values.find((value) => trustedAuthority.values.includes(value))
|
|
210
|
+
})));
|
|
211
|
+
const vTrustedAuthorities = [
|
|
212
|
+
v.object({
|
|
213
|
+
type: v.literal("aki"),
|
|
214
|
+
values: vNonEmptyArray(v.pipe(v.string("aki trusted authority value must be a string"), vBase64url, v.description("Contains a list of KeyIdentifier entries of the AuthorityKeyIdentifier as defined in Section 4.2.1.1 of [RFC5280], encoded as base64url. The raw byte representation of one of the elements MUST match with the AuthorityKeyIdentifier element of an X.509 certificate in the certificate chain present in the credential (e.g., in the header of an mdoc or SD-JWT). Note that the chain can consist of a single certificate and the credential can include the entire X.509 chain or parts of it.")))
|
|
215
|
+
}),
|
|
216
|
+
v.object({
|
|
217
|
+
type: v.literal("etsi_tl"),
|
|
218
|
+
values: vNonEmptyArray(v.pipe(v.string("etsi_tl trusted authority value must be a string"), v.url("etsi_tl trusted authority value must be a valid https url"), v.check((url) => url.startsWith("http://") || url.startsWith("https://"), "etsi_tl trusted authority value must be a valid https url"), v.description("The identifier of a Trusted List as specified in ETSI TS 119 612 [ETSI.TL]. An ETSI Trusted List contains references to other Trusted Lists, creating a list of trusted lists, or entries for Trust Service Providers with corresponding service description and X.509 Certificates. The trust chain of a matching Credential MUST contain at least one X.509 Certificate that matches one of the entries of the Trusted List or its cascading Trusted Lists.")))
|
|
219
|
+
}),
|
|
220
|
+
v.object({
|
|
221
|
+
type: v.literal("openid_federation"),
|
|
222
|
+
values: vNonEmptyArray(v.pipe(v.string("openid_federation trusted authority value must be a string"), v.url("openid_federation trusted authority value must be a valid https url"), v.check((url) => url.startsWith("http://") || url.startsWith("https://"), "openid_federation trusted authority value must be a valid https url"), v.description("The Entity Identifier as defined in Section 1 of [OpenID.Federation] that is bound to an entity in a federation. While this Entity Identifier could be any entity in that ecosystem, this entity would usually have the Entity Configuration of a Trust Anchor. A valid trust path, including the given Entity Identifier, must be constructible from a matching credential.")))
|
|
223
|
+
})
|
|
224
|
+
];
|
|
225
|
+
let DcqlTrustedAuthoritiesQuery;
|
|
226
|
+
(function(_DcqlTrustedAuthoritiesQuery) {
|
|
227
|
+
const vTrustedAuthoritiesQuery = vTrustedAuthorities.map((authority) => v.object({
|
|
228
|
+
type: v.pipe(authority.entries.type, v.description("REQUIRED. A string uniquely identifying the type of information about the issuer trust framework.")),
|
|
229
|
+
values: v.pipe(vNonEmptyArray(authority.entries.values.item), v.description("REQUIRED. An array of strings, where each string (value) contains information specific to the used Trusted Authorities Query type that allows to identify an issuer, trust framework, or a federation that an issuer belongs to."))
|
|
230
|
+
}));
|
|
231
|
+
_DcqlTrustedAuthoritiesQuery.vModel = v.variant("type", vTrustedAuthoritiesQuery);
|
|
291
232
|
})(DcqlTrustedAuthoritiesQuery || (DcqlTrustedAuthoritiesQuery = {}));
|
|
292
|
-
|
|
293
|
-
((
|
|
294
|
-
|
|
233
|
+
let DcqlCredentialTrustedAuthority;
|
|
234
|
+
(function(_DcqlCredentialTrustedAuthority) {
|
|
235
|
+
_DcqlCredentialTrustedAuthority.vModel = v.variant("type", vTrustedAuthorities);
|
|
295
236
|
})(DcqlCredentialTrustedAuthority || (DcqlCredentialTrustedAuthority = {}));
|
|
296
237
|
|
|
297
|
-
|
|
298
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/u-model.ts
|
|
299
240
|
var ModelDefinition = class {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
241
|
+
constructor(input) {
|
|
242
|
+
this.input = input;
|
|
243
|
+
}
|
|
244
|
+
get v() {
|
|
245
|
+
return this.input.vModel;
|
|
246
|
+
}
|
|
247
|
+
parse(input) {
|
|
248
|
+
const result = this.safeParse(input);
|
|
249
|
+
if (result.success) return result.output;
|
|
250
|
+
return new DcqlParseError({
|
|
251
|
+
message: JSON.stringify(result.flattened),
|
|
252
|
+
cause: result.error
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
safeParse(input) {
|
|
256
|
+
const res = v.safeParse(this.input.vModel, input);
|
|
257
|
+
if (res.success) return {
|
|
258
|
+
success: true,
|
|
259
|
+
output: res.output
|
|
260
|
+
};
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
error: new v.ValiError(res.issues),
|
|
264
|
+
flattened: v.flatten(res.issues)
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
is(input) {
|
|
268
|
+
return v.is(this.v, input);
|
|
269
|
+
}
|
|
330
270
|
};
|
|
331
271
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
* the `require_cryptographic_holder_binding` property from the query.
|
|
338
|
-
*
|
|
339
|
-
* In the context of a presentation this value means whether the presentation is created
|
|
340
|
-
* with cryptographic holder binding. In the context of a credential query this means whether
|
|
341
|
-
* the credential supports cryptographic holder binding.
|
|
342
|
-
*/
|
|
343
|
-
cryptographic_holder_binding: v4.pipe(
|
|
344
|
-
v4.boolean(),
|
|
345
|
-
v4.description(
|
|
346
|
-
"Indicates support/inclusion of cryptographic holder binding. This will be checked against the `require_cryptographic_holder_binding` property from the query."
|
|
347
|
-
)
|
|
348
|
-
)
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/u-dcql-credential.ts
|
|
274
|
+
const vCredentialModelBase = v.object({
|
|
275
|
+
authority: v.optional(DcqlCredentialTrustedAuthority.vModel),
|
|
276
|
+
cryptographic_holder_binding: v.pipe(v.boolean(), v.description("Indicates support/inclusion of cryptographic holder binding. This will be checked against the `require_cryptographic_holder_binding` property from the query."))
|
|
349
277
|
});
|
|
350
|
-
|
|
351
|
-
((
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
DcqlMdocCredential2.model = new ModelDefinition({ vModel: DcqlMdocCredential2.vModel });
|
|
278
|
+
let DcqlMdocCredential;
|
|
279
|
+
(function(_DcqlMdocCredential) {
|
|
280
|
+
const vNamespaces = _DcqlMdocCredential.vNamespaces = v.record(v.string(), v.record(v.string(), v.unknown()));
|
|
281
|
+
_DcqlMdocCredential.model = new ModelDefinition({ vModel: _DcqlMdocCredential.vModel = v.object({
|
|
282
|
+
...vCredentialModelBase.entries,
|
|
283
|
+
credential_format: v.literal("mso_mdoc"),
|
|
284
|
+
doctype: v.string(),
|
|
285
|
+
namespaces: vNamespaces
|
|
286
|
+
}) });
|
|
360
287
|
})(DcqlMdocCredential || (DcqlMdocCredential = {}));
|
|
361
|
-
|
|
362
|
-
((
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
DcqlSdJwtVcCredential2.model = new ModelDefinition({ vModel: DcqlSdJwtVcCredential2.vModel });
|
|
288
|
+
let DcqlSdJwtVcCredential;
|
|
289
|
+
(function(_DcqlSdJwtVcCredential) {
|
|
290
|
+
const vClaims = _DcqlSdJwtVcCredential.vClaims = vJsonRecord;
|
|
291
|
+
_DcqlSdJwtVcCredential.model = new ModelDefinition({ vModel: _DcqlSdJwtVcCredential.vModel = v.object({
|
|
292
|
+
...vCredentialModelBase.entries,
|
|
293
|
+
credential_format: v.picklist(["vc+sd-jwt", "dc+sd-jwt"]),
|
|
294
|
+
vct: v.string(),
|
|
295
|
+
claims: vClaims
|
|
296
|
+
}) });
|
|
371
297
|
})(DcqlSdJwtVcCredential || (DcqlSdJwtVcCredential = {}));
|
|
372
|
-
|
|
373
|
-
((
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
298
|
+
let DcqlW3cVcCredential;
|
|
299
|
+
(function(_DcqlW3cVcCredential) {
|
|
300
|
+
const vClaims = _DcqlW3cVcCredential.vClaims = vJsonRecord;
|
|
301
|
+
_DcqlW3cVcCredential.model = new ModelDefinition({ vModel: _DcqlW3cVcCredential.vModel = v.object({
|
|
302
|
+
...vCredentialModelBase.entries,
|
|
303
|
+
credential_format: v.picklist([
|
|
304
|
+
"ldp_vc",
|
|
305
|
+
"jwt_vc_json",
|
|
306
|
+
"vc+sd-jwt"
|
|
307
|
+
]),
|
|
308
|
+
claims: vClaims,
|
|
309
|
+
type: v.array(v.string())
|
|
310
|
+
}) });
|
|
382
311
|
})(DcqlW3cVcCredential || (DcqlW3cVcCredential = {}));
|
|
383
|
-
|
|
384
|
-
((
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
DcqlCredential2.model = new ModelDefinition({ vModel: DcqlCredential2.vModel });
|
|
312
|
+
let DcqlCredential;
|
|
313
|
+
(function(_DcqlCredential) {
|
|
314
|
+
_DcqlCredential.model = new ModelDefinition({ vModel: _DcqlCredential.vModel = v.variant("credential_format", [
|
|
315
|
+
DcqlMdocCredential.vModel,
|
|
316
|
+
DcqlSdJwtVcCredential.vModel,
|
|
317
|
+
DcqlW3cVcCredential.vModel
|
|
318
|
+
]) });
|
|
391
319
|
})(DcqlCredential || (DcqlCredential = {}));
|
|
392
320
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/dcql-presentation/m-dcql-credential-presentation.ts
|
|
323
|
+
let DcqlMdocPresentation;
|
|
324
|
+
(function(_DcqlMdocPresentation) {
|
|
325
|
+
_DcqlMdocPresentation.model = new ModelDefinition({ vModel: _DcqlMdocPresentation.vModel = DcqlMdocCredential.vModel });
|
|
398
326
|
})(DcqlMdocPresentation || (DcqlMdocPresentation = {}));
|
|
399
|
-
|
|
400
|
-
((
|
|
401
|
-
|
|
402
|
-
DcqlSdJwtVcPresentation2.model = new ModelDefinition({ vModel: DcqlSdJwtVcPresentation2.vModel });
|
|
327
|
+
let DcqlSdJwtVcPresentation;
|
|
328
|
+
(function(_DcqlSdJwtVcPresentation) {
|
|
329
|
+
_DcqlSdJwtVcPresentation.model = new ModelDefinition({ vModel: _DcqlSdJwtVcPresentation.vModel = DcqlSdJwtVcCredential.vModel });
|
|
403
330
|
})(DcqlSdJwtVcPresentation || (DcqlSdJwtVcPresentation = {}));
|
|
404
|
-
|
|
405
|
-
((
|
|
406
|
-
|
|
407
|
-
DcqlW3cVcPresentation2.model = new ModelDefinition({ vModel: DcqlW3cVcPresentation2.vModel });
|
|
331
|
+
let DcqlW3cVcPresentation;
|
|
332
|
+
(function(_DcqlW3cVcPresentation) {
|
|
333
|
+
_DcqlW3cVcPresentation.model = new ModelDefinition({ vModel: _DcqlW3cVcPresentation.vModel = DcqlW3cVcCredential.vModel });
|
|
408
334
|
})(DcqlW3cVcPresentation || (DcqlW3cVcPresentation = {}));
|
|
409
|
-
|
|
410
|
-
((
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
])
|
|
417
|
-
});
|
|
335
|
+
let DcqlCredentialPresentation;
|
|
336
|
+
(function(_DcqlCredentialPresentation) {
|
|
337
|
+
_DcqlCredentialPresentation.model = new ModelDefinition({ vModel: v.variant("credential_format", [
|
|
338
|
+
DcqlMdocPresentation.vModel,
|
|
339
|
+
DcqlSdJwtVcPresentation.vModel,
|
|
340
|
+
DcqlW3cVcPresentation.vModel
|
|
341
|
+
]) });
|
|
418
342
|
})(DcqlCredentialPresentation || (DcqlCredentialPresentation = {}));
|
|
419
343
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/dcql-presentation/m-dcql-presentation.ts
|
|
346
|
+
let DcqlPresentation;
|
|
347
|
+
(function(_DcqlPresentation) {
|
|
348
|
+
const vPresentationEntry = v.union([v.string(), vJsonRecord]);
|
|
349
|
+
const vModel = _DcqlPresentation.vModel = v.pipe(v.union([v.record(vIdString, vNonEmptyArray(vPresentationEntry)), v.record(vIdString, vPresentationEntry)]), v.description("REQUIRED. This is a JSON-encoded object containing entries where the key is the id value used for a Credential Query in the DCQL query and the value is an array of one or more Presentations that match the respective Credential Query. When multiple is omitted, or set to false, the array MUST contain only one Presentation. There MUST NOT be any entry in the JSON-encoded object for optional Credential Queries when there are no matching Credentials for the respective Credential Query. Each Presentation is represented as a string or object, depending on the format as defined in Appendix B. The same rules as above apply for encoding the Presentations."));
|
|
350
|
+
_DcqlPresentation.parse = (input) => {
|
|
351
|
+
if (typeof input === "string") return v.parse(v.pipe(v.string(), vStringToJson, vModel), input);
|
|
352
|
+
return v.parse(vModel, input);
|
|
353
|
+
};
|
|
354
|
+
_DcqlPresentation.encode = (input) => {
|
|
355
|
+
return JSON.stringify(input);
|
|
356
|
+
};
|
|
357
|
+
})(DcqlPresentation || (DcqlPresentation = {}));
|
|
425
358
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
((
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
v6.description(
|
|
462
|
-
"An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array."
|
|
463
|
-
)
|
|
464
|
-
)
|
|
465
|
-
});
|
|
466
|
-
DcqlClaimsQuery2.vMdocNamespace = v6.object({
|
|
467
|
-
...vMdocBase.entries,
|
|
468
|
-
namespace: v6.pipe(
|
|
469
|
-
v6.string(),
|
|
470
|
-
v6.description(
|
|
471
|
-
"A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1."
|
|
472
|
-
)
|
|
473
|
-
),
|
|
474
|
-
claim_name: v6.pipe(
|
|
475
|
-
v6.string(),
|
|
476
|
-
v6.description(
|
|
477
|
-
"A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name."
|
|
478
|
-
)
|
|
479
|
-
)
|
|
480
|
-
});
|
|
481
|
-
DcqlClaimsQuery2.vMdocPath = v6.object({
|
|
482
|
-
...vMdocBase.entries,
|
|
483
|
-
intent_to_retain: v6.pipe(
|
|
484
|
-
v6.optional(v6.boolean()),
|
|
485
|
-
v6.description(
|
|
486
|
-
"A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5]."
|
|
487
|
-
)
|
|
488
|
-
),
|
|
489
|
-
path: v6.pipe(
|
|
490
|
-
v6.tuple([
|
|
491
|
-
v6.pipe(
|
|
492
|
-
v6.string(),
|
|
493
|
-
v6.description(
|
|
494
|
-
"A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1."
|
|
495
|
-
)
|
|
496
|
-
),
|
|
497
|
-
v6.pipe(
|
|
498
|
-
v6.string(),
|
|
499
|
-
v6.description(
|
|
500
|
-
"A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name."
|
|
501
|
-
)
|
|
502
|
-
)
|
|
503
|
-
]),
|
|
504
|
-
v6.description(
|
|
505
|
-
"An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier."
|
|
506
|
-
)
|
|
507
|
-
)
|
|
508
|
-
});
|
|
509
|
-
DcqlClaimsQuery2.vMdoc = v6.union([DcqlClaimsQuery2.vMdocNamespace, DcqlClaimsQuery2.vMdocPath]);
|
|
510
|
-
DcqlClaimsQuery2.vModel = v6.union([DcqlClaimsQuery2.vMdoc, DcqlClaimsQuery2.vW3cSdJwtVc]);
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/dcql-query/m-dcql-claims-query.ts
|
|
361
|
+
let DcqlClaimsQuery;
|
|
362
|
+
(function(_DcqlClaimsQuery) {
|
|
363
|
+
const vValue = _DcqlClaimsQuery.vValue = v.union([
|
|
364
|
+
v.string(),
|
|
365
|
+
v.pipe(v.number(), v.integer()),
|
|
366
|
+
v.boolean()
|
|
367
|
+
]);
|
|
368
|
+
const vPath = _DcqlClaimsQuery.vPath = v.union([
|
|
369
|
+
v.string(),
|
|
370
|
+
v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
371
|
+
v.null()
|
|
372
|
+
]);
|
|
373
|
+
const vW3cSdJwtVc = _DcqlClaimsQuery.vW3cSdJwtVc = v.object({
|
|
374
|
+
id: v.pipe(v.optional(vIdString), v.description("A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.")),
|
|
375
|
+
path: v.pipe(vNonEmptyArray(vPath), v.description("A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential.")),
|
|
376
|
+
values: v.pipe(v.optional(v.array(vValue)), v.description("An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array."))
|
|
377
|
+
});
|
|
378
|
+
const vMdocBase = v.object({
|
|
379
|
+
id: v.pipe(v.optional(vIdString), v.description("A string identifying the particular claim. The value MUST be a non-empty string consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular claims array, the same id MUST NOT be present more than once.")),
|
|
380
|
+
values: v.pipe(v.optional(v.array(vValue)), v.description("An array of strings, integers or boolean values that specifies the expected values of the claim. If the values property is present, the Wallet SHOULD return the claim only if the type and value of the claim both match for at least one of the elements in the array."))
|
|
381
|
+
});
|
|
382
|
+
const vMdocNamespace = _DcqlClaimsQuery.vMdocNamespace = v.object({
|
|
383
|
+
...vMdocBase.entries,
|
|
384
|
+
namespace: v.pipe(v.string(), v.description("A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.")),
|
|
385
|
+
claim_name: v.pipe(v.string(), v.description("A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name."))
|
|
386
|
+
});
|
|
387
|
+
const vMdocPath = _DcqlClaimsQuery.vMdocPath = v.object({
|
|
388
|
+
...vMdocBase.entries,
|
|
389
|
+
intent_to_retain: v.pipe(v.optional(v.boolean()), v.description("A boolean that is equivalent to `IntentToRetain` variable defined in Section 8.3.2.1.2.1 of [@ISO.18013-5].")),
|
|
390
|
+
path: v.pipe(v.tuple([v.pipe(v.string(), v.description("A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1.")), v.pipe(v.string(), v.description("A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name."))]), v.description("An array defining a claims path pointer into an mdoc. It must contain two elements of type string. The first element refers to a namespace and the second element refers to a data element identifier."))
|
|
391
|
+
});
|
|
392
|
+
const vMdoc = _DcqlClaimsQuery.vMdoc = v.union([vMdocNamespace, vMdocPath]);
|
|
393
|
+
_DcqlClaimsQuery.vModel = v.union([vMdoc, vW3cSdJwtVc]);
|
|
511
394
|
})(DcqlClaimsQuery || (DcqlClaimsQuery = {}));
|
|
512
395
|
|
|
513
|
-
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/util/deep-merge.ts
|
|
398
|
+
/**
|
|
399
|
+
* Deep merge two objects. Null values will be overriden if there is a value in one
|
|
400
|
+
* of the two objects. Objects can also be arrays, but otherwise only primitive types
|
|
401
|
+
* are allowed
|
|
402
|
+
*/
|
|
514
403
|
function deepMerge(source, target) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
if (val !== null && typeof val === "object" && (Object.getPrototypeOf(val) === Object.prototype || Array.isArray(val))) {
|
|
530
|
-
const newValue = deepMerge(
|
|
531
|
-
val,
|
|
532
|
-
newTarget[key] ?? new (Object.getPrototypeOf(val)).constructor()
|
|
533
|
-
);
|
|
534
|
-
newTarget = setValue(newTarget, key, newValue);
|
|
535
|
-
} else if (val != null) {
|
|
536
|
-
newTarget = setValue(newTarget, key, val);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
return newTarget;
|
|
404
|
+
let newTarget = target;
|
|
405
|
+
if (Object.getPrototypeOf(source) !== Object.prototype && !Array.isArray(source)) throw new DcqlError({
|
|
406
|
+
message: "source value provided to deepMerge is neither an array or object.",
|
|
407
|
+
code: "PARSE_ERROR"
|
|
408
|
+
});
|
|
409
|
+
if (Object.getPrototypeOf(target) !== Object.prototype && !Array.isArray(target)) throw new DcqlError({
|
|
410
|
+
message: "target value provided to deepMerge is neither an array or object.",
|
|
411
|
+
code: "PARSE_ERROR"
|
|
412
|
+
});
|
|
413
|
+
for (const [key, val] of Object.entries(source)) if (val !== null && typeof val === "object" && (Object.getPrototypeOf(val) === Object.prototype || Array.isArray(val))) {
|
|
414
|
+
const newValue = deepMerge(val, newTarget[key] ?? new (Object.getPrototypeOf(val)).constructor());
|
|
415
|
+
newTarget = setValue(newTarget, key, newValue);
|
|
416
|
+
} else if (val != null) newTarget = setValue(newTarget, key, val);
|
|
417
|
+
return newTarget;
|
|
540
418
|
}
|
|
541
419
|
function setValue(target, key, value) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
420
|
+
let newTarget = target;
|
|
421
|
+
if (Array.isArray(newTarget)) {
|
|
422
|
+
newTarget = [...newTarget];
|
|
423
|
+
newTarget[key] = value;
|
|
424
|
+
} else if (Object.getPrototypeOf(newTarget) === Object.prototype) newTarget = {
|
|
425
|
+
...newTarget,
|
|
426
|
+
[key]: value
|
|
427
|
+
};
|
|
428
|
+
else throw new DcqlError({
|
|
429
|
+
message: "Unsupported type for deep merge. Only primitive types or Array and Object are supported",
|
|
430
|
+
code: "INTERNAL_SERVER_ERROR"
|
|
431
|
+
});
|
|
432
|
+
return newTarget;
|
|
555
433
|
}
|
|
556
434
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
(val) => v7.literal(
|
|
564
|
-
val,
|
|
565
|
-
(i) => `Expected claim ${pathToString(path)} to be ${typeof val === "string" ? `'${val}'` : val} but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`
|
|
566
|
-
)
|
|
567
|
-
),
|
|
568
|
-
(i) => `Expected claim ${pathToString(path)} to be ${values.map((v19) => typeof v19 === "string" ? `'${v19}'` : v19).join(" | ")} but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
return v7.pipe(
|
|
572
|
-
v7.unknown(),
|
|
573
|
-
v7.check((value) => value !== null && value !== void 0, `Expected claim '${path.join("'.'")}' to be defined`)
|
|
574
|
-
);
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/dcql-parser/dcql-claims-query-result.ts
|
|
437
|
+
const pathToString = (path) => path.map((item) => typeof item === "string" ? `'${item}'` : `${item}`).join(".");
|
|
438
|
+
const getClaimParser = (path, values) => {
|
|
439
|
+
if (values) return v.union(values.map((val) => v.literal(val, (i) => `Expected claim ${pathToString(path)} to be ${typeof val === "string" ? `'${val}'` : val} but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`)), (i) => `Expected claim ${pathToString(path)} to be ${values.map((v$1) => typeof v$1 === "string" ? `'${v$1}'` : v$1).join(" | ")} but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`);
|
|
440
|
+
return v.pipe(v.unknown(), v.check((value) => value !== null && value !== void 0, `Expected claim '${path.join("'.'")}' to be defined`));
|
|
575
441
|
};
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
{
|
|
586
|
-
[namespace]: v7.object(
|
|
587
|
-
{
|
|
588
|
-
[field]: getClaimParser(mdocPathQuery.path, claimQuery.values)
|
|
589
|
-
},
|
|
590
|
-
`Expected claim ${pathToString(mdocPathQuery.path)} to be defined`
|
|
591
|
-
)
|
|
592
|
-
},
|
|
593
|
-
`Expected claim ${pathToString(mdocPathQuery.path)} to be defined`
|
|
594
|
-
);
|
|
442
|
+
const getMdocClaimParser = (claimQuery) => {
|
|
443
|
+
const mdocPathQuery = v.is(DcqlClaimsQuery.vMdocNamespace, claimQuery) ? {
|
|
444
|
+
id: claimQuery.id,
|
|
445
|
+
path: [claimQuery.namespace, claimQuery.claim_name],
|
|
446
|
+
values: claimQuery.values
|
|
447
|
+
} : claimQuery;
|
|
448
|
+
const namespace = mdocPathQuery.path[0];
|
|
449
|
+
const field = mdocPathQuery.path[1];
|
|
450
|
+
return v.object({ [namespace]: v.object({ [field]: getClaimParser(mdocPathQuery.path, claimQuery.values) }, `Expected claim ${pathToString(mdocPathQuery.path)} to be defined`) }, `Expected claim ${pathToString(mdocPathQuery.path)} to be defined`);
|
|
595
451
|
};
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
v7.rawTransform(({ addIssue, dataset, NEVER }) => {
|
|
646
|
-
const mapped = dataset.value.map((item) => {
|
|
647
|
-
const parsed = v7.safeParse(
|
|
648
|
-
isLast ? vClaimParser : getJsonClaimParser(claimQuery, { ...ctx, index: index + 1 }),
|
|
649
|
-
item
|
|
650
|
-
);
|
|
651
|
-
return parsed;
|
|
652
|
-
});
|
|
653
|
-
if (mapped.every((parsed) => !parsed.success)) {
|
|
654
|
-
for (const parsed of mapped) {
|
|
655
|
-
for (const issue of parsed.issues) {
|
|
656
|
-
addIssue(issue);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
return NEVER;
|
|
660
|
-
}
|
|
661
|
-
return mapped.map((parsed) => parsed.success ? parsed.output : null);
|
|
662
|
-
})
|
|
663
|
-
);
|
|
452
|
+
const getJsonClaimParser = (claimQuery, ctx) => {
|
|
453
|
+
const { index, presentation } = ctx;
|
|
454
|
+
const pathElement = claimQuery.path[index];
|
|
455
|
+
const isLast = index === claimQuery.path.length - 1;
|
|
456
|
+
const vClaimParser = getClaimParser(claimQuery.path, claimQuery.values);
|
|
457
|
+
if (typeof pathElement === "number") {
|
|
458
|
+
const elementParser = isLast ? vClaimParser : getJsonClaimParser(claimQuery, {
|
|
459
|
+
...ctx,
|
|
460
|
+
index: index + 1
|
|
461
|
+
});
|
|
462
|
+
if (presentation) return v.pipe(v.array(v.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`), v.rawTransform(({ dataset, addIssue }) => {
|
|
463
|
+
const issues = [];
|
|
464
|
+
for (const item of dataset.value) {
|
|
465
|
+
const itemResult = v.safeParse(elementParser, item);
|
|
466
|
+
if (itemResult.success) return dataset.value;
|
|
467
|
+
issues.push(itemResult.issues[0]);
|
|
468
|
+
}
|
|
469
|
+
addIssue({
|
|
470
|
+
...issues[0],
|
|
471
|
+
message: isLast ? issues[0].message : `Expected any element in array ${pathToString(claimQuery.path.slice(0, index + 1))} to match sub requirement but none matched: ${issues[0].message}`
|
|
472
|
+
});
|
|
473
|
+
return dataset.value;
|
|
474
|
+
}));
|
|
475
|
+
return v.pipe(v.array(v.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`), v.rawTransform(({ addIssue, dataset, NEVER }) => {
|
|
476
|
+
const result = v.safeParse(elementParser, dataset.value[pathElement]);
|
|
477
|
+
if (!result.success) {
|
|
478
|
+
addIssue(result.issues[0]);
|
|
479
|
+
return NEVER;
|
|
480
|
+
}
|
|
481
|
+
return [...dataset.value.slice(0, pathElement).map(() => null), result.output];
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
if (typeof pathElement === "string") return v.object({ [pathElement]: isLast ? vClaimParser : getJsonClaimParser(claimQuery, {
|
|
485
|
+
...ctx,
|
|
486
|
+
index: index + 1
|
|
487
|
+
}) }, `Expected claim ${pathToString(claimQuery.path)} to be defined`);
|
|
488
|
+
return v.pipe(v.array(v.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`), v.rawTransform(({ addIssue, dataset, NEVER }) => {
|
|
489
|
+
const mapped = dataset.value.map((item) => {
|
|
490
|
+
return v.safeParse(isLast ? vClaimParser : getJsonClaimParser(claimQuery, {
|
|
491
|
+
...ctx,
|
|
492
|
+
index: index + 1
|
|
493
|
+
}), item);
|
|
494
|
+
});
|
|
495
|
+
if (mapped.every((parsed) => !parsed.success)) {
|
|
496
|
+
for (const parsed of mapped) for (const issue of parsed.issues) addIssue(issue);
|
|
497
|
+
return NEVER;
|
|
498
|
+
}
|
|
499
|
+
return mapped.map((parsed) => parsed.success ? parsed.output : null);
|
|
500
|
+
}));
|
|
664
501
|
};
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}
|
|
746
|
-
if (isNonEmptyArray(validClaimSets)) {
|
|
747
|
-
return {
|
|
748
|
-
success: true,
|
|
749
|
-
failed_claim_sets: asNonEmptyArrayOrUndefined(failedClaimSets),
|
|
750
|
-
valid_claim_sets: validClaimSets,
|
|
751
|
-
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest)),
|
|
752
|
-
failed_claims: asNonEmptyArrayOrUndefined(failedClaims.map(({ parser, ...rest }) => rest))
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
return {
|
|
756
|
-
success: false,
|
|
757
|
-
failed_claim_sets: failedClaimSets,
|
|
758
|
-
failed_claims: failedClaims.map(({ parser, ...rest }) => rest),
|
|
759
|
-
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest))
|
|
760
|
-
};
|
|
502
|
+
const runClaimsQuery = (credentialQuery, ctx) => {
|
|
503
|
+
if (!credentialQuery.claims) return {
|
|
504
|
+
success: true,
|
|
505
|
+
valid_claims: void 0,
|
|
506
|
+
failed_claims: void 0,
|
|
507
|
+
valid_claim_sets: [{
|
|
508
|
+
claim_set_index: void 0,
|
|
509
|
+
output: {},
|
|
510
|
+
success: true,
|
|
511
|
+
valid_claim_indexes: void 0
|
|
512
|
+
}],
|
|
513
|
+
failed_claim_sets: void 0
|
|
514
|
+
};
|
|
515
|
+
const failedClaims = [];
|
|
516
|
+
const validClaims = [];
|
|
517
|
+
for (const [claimIndex, claimQuery] of credentialQuery.claims.entries()) {
|
|
518
|
+
const parser = credentialQuery.format === "mso_mdoc" ? getMdocClaimParser(claimQuery) : getJsonClaimParser(claimQuery, {
|
|
519
|
+
index: 0,
|
|
520
|
+
presentation: ctx.presentation
|
|
521
|
+
});
|
|
522
|
+
const parseResult = v.safeParse(parser, ctx.credential.credential_format === "mso_mdoc" ? ctx.credential.namespaces : ctx.credential.claims);
|
|
523
|
+
if (parseResult.success) validClaims.push({
|
|
524
|
+
success: true,
|
|
525
|
+
claim_index: claimIndex,
|
|
526
|
+
claim_id: claimQuery.id,
|
|
527
|
+
output: parseResult.output,
|
|
528
|
+
parser
|
|
529
|
+
});
|
|
530
|
+
else {
|
|
531
|
+
const flattened = v.flatten(parseResult.issues);
|
|
532
|
+
failedClaims.push({
|
|
533
|
+
success: false,
|
|
534
|
+
issues: flattened.nested ?? flattened,
|
|
535
|
+
claim_index: claimIndex,
|
|
536
|
+
claim_id: claimQuery.id,
|
|
537
|
+
output: parseResult.output,
|
|
538
|
+
parser
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const failedClaimSets = [];
|
|
543
|
+
const validClaimSets = [];
|
|
544
|
+
for (const [claimSetIndex, claimSet] of credentialQuery.claim_sets?.entries() ?? [[void 0, void 0]]) {
|
|
545
|
+
const claims = claimSet?.map((id) => {
|
|
546
|
+
const claim = validClaims.find((claim$1) => claim$1.claim_id === id) ?? failedClaims.find((claim$1) => claim$1.claim_id === id);
|
|
547
|
+
if (!claim) throw new DcqlParseError({ message: `Claim with id '${id}' in query '${credentialQuery.id}' from claim set with index '${claimSetIndex}' not found in claims of claim` });
|
|
548
|
+
return claim;
|
|
549
|
+
}) ?? [...validClaims, ...failedClaims];
|
|
550
|
+
if (claims.every((claim) => claim.success)) {
|
|
551
|
+
const output = claims.reduce((merged, claim) => deepMerge(claim.output, merged), {});
|
|
552
|
+
validClaimSets.push({
|
|
553
|
+
success: true,
|
|
554
|
+
claim_set_index: claimSetIndex,
|
|
555
|
+
output,
|
|
556
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(claims.map((claim) => claim.claim_index))
|
|
557
|
+
});
|
|
558
|
+
} else {
|
|
559
|
+
const issues = failedClaims.reduce((merged, claim) => deepMerge(claim.issues, merged), {});
|
|
560
|
+
failedClaimSets.push({
|
|
561
|
+
success: false,
|
|
562
|
+
issues,
|
|
563
|
+
claim_set_index: claimSetIndex,
|
|
564
|
+
failed_claim_indexes: claims.filter((claim) => !claim.success).map((claim) => claim.claim_index),
|
|
565
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(claims.filter((claim) => claim.success).map((claim) => claim.claim_index))
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (isNonEmptyArray(validClaimSets)) return {
|
|
570
|
+
success: true,
|
|
571
|
+
failed_claim_sets: asNonEmptyArrayOrUndefined(failedClaimSets),
|
|
572
|
+
valid_claim_sets: validClaimSets,
|
|
573
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser,...rest }) => rest)),
|
|
574
|
+
failed_claims: asNonEmptyArrayOrUndefined(failedClaims.map(({ parser,...rest }) => rest))
|
|
575
|
+
};
|
|
576
|
+
return {
|
|
577
|
+
success: false,
|
|
578
|
+
failed_claim_sets: failedClaimSets,
|
|
579
|
+
failed_claims: failedClaims.map(({ parser,...rest }) => rest),
|
|
580
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser,...rest }) => rest))
|
|
581
|
+
};
|
|
761
582
|
};
|
|
762
583
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
credentialQuery.meta.doctype_value,
|
|
774
|
-
(i) => `Expected doctype to be '${credentialQuery.meta?.doctype_value}' but received '${i.input}'`
|
|
775
|
-
) : v8.string("Expected doctype to be defined");
|
|
776
|
-
const credentialParser = v8.object({
|
|
777
|
-
credential_format: v8.literal(
|
|
778
|
-
"mso_mdoc",
|
|
779
|
-
(i) => `Expected credential format to be 'mso_mdoc' but received '${i.input}'`
|
|
780
|
-
),
|
|
781
|
-
doctype: vDoctype,
|
|
782
|
-
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
783
|
-
});
|
|
784
|
-
return credentialParser;
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/dcql-parser/dcql-meta-query-result.ts
|
|
586
|
+
const getCryptographicHolderBindingValue = (credentialQuery) => v.object({ cryptographic_holder_binding: credentialQuery.require_cryptographic_holder_binding ? v.literal(true, (i) => `Expected cryptographic_holder_binding to be true (because credential query '${credentialQuery.id}' requires cryptographic holder binding), but received ${i.input}`) : v.boolean() });
|
|
587
|
+
const getMdocMetaParser = (credentialQuery) => {
|
|
588
|
+
const vDoctype = credentialQuery.meta?.doctype_value ? v.literal(credentialQuery.meta.doctype_value, (i) => `Expected doctype to be '${credentialQuery.meta?.doctype_value}' but received '${i.input}'`) : v.string("Expected doctype to be defined");
|
|
589
|
+
return v.object({
|
|
590
|
+
credential_format: v.literal("mso_mdoc", (i) => `Expected credential format to be 'mso_mdoc' but received '${i.input}'`),
|
|
591
|
+
doctype: vDoctype,
|
|
592
|
+
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
593
|
+
});
|
|
785
594
|
};
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
vct: credentialQuery.meta?.vct_values ? v8.picklist(
|
|
793
|
-
credentialQuery.meta.vct_values,
|
|
794
|
-
(i) => `Expected vct to be '${credentialQuery.meta?.vct_values?.join("' | '")}' but received '${i.input}'`
|
|
795
|
-
) : v8.string("Expected vct to be defined"),
|
|
796
|
-
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
797
|
-
});
|
|
595
|
+
const getSdJwtVcMetaParser = (credentialQuery) => {
|
|
596
|
+
return v.object({
|
|
597
|
+
credential_format: v.literal(credentialQuery.format, (i) => `Expected credential format to be '${credentialQuery.format}' but received '${i.input}'`),
|
|
598
|
+
vct: credentialQuery.meta?.vct_values ? vCustomRequiredMessage(v.picklist(credentialQuery.meta.vct_values, (i) => `Expected vct to be '${credentialQuery.meta?.vct_values?.join("' | '")}' but received '${i.input}'`), (i) => `Expected vct to be '${credentialQuery.meta?.vct_values?.join("' | '")}' but received '${i.input}'`) : vCustomRequiredMessage(v.string("Expected vct to be a string"), "Expected vct to be defined"),
|
|
599
|
+
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
600
|
+
});
|
|
798
601
|
};
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
type: credentialQuery.meta?.type_values ? v8.union(
|
|
806
|
-
credentialQuery.meta.type_values.map((values) => vIncludesAll(values)),
|
|
807
|
-
`Expected type to include all values from one of the following subsets: ${credentialQuery.meta.type_values.map((values) => `[${values.join(", ")}]`).join(" | ")}`
|
|
808
|
-
) : vNonEmptyArray(v8.string()),
|
|
809
|
-
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
810
|
-
});
|
|
602
|
+
const getW3cVcMetaParser = (credentialQuery) => {
|
|
603
|
+
return v.object({
|
|
604
|
+
credential_format: v.literal(credentialQuery.format, (i) => `Expected credential format to be '${credentialQuery.format}' but received '${i.input}'`),
|
|
605
|
+
type: credentialQuery.meta?.type_values ? v.union(credentialQuery.meta.type_values.map((values) => vIncludesAll(values)), `Expected type to include all values from one of the following subsets: ${credentialQuery.meta.type_values.map((values) => `[${values.join(", ")}]`).join(" | ")}`) : vNonEmptyArray(v.string()),
|
|
606
|
+
...getCryptographicHolderBindingValue(credentialQuery).entries
|
|
607
|
+
});
|
|
811
608
|
};
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
if (credentialQuery.format === "ldp_vc" || credentialQuery.format === "jwt_vc_json") {
|
|
826
|
-
return getW3cVcMetaParser(credentialQuery);
|
|
827
|
-
}
|
|
828
|
-
throw new DcqlError({
|
|
829
|
-
code: "NOT_IMPLEMENTED",
|
|
830
|
-
message: `Unsupported format '${credentialQuery.format}'`
|
|
831
|
-
});
|
|
609
|
+
const getMetaParser = (credentialQuery) => {
|
|
610
|
+
if (credentialQuery.format === "mso_mdoc") return getMdocMetaParser(credentialQuery);
|
|
611
|
+
if (credentialQuery.format === "dc+sd-jwt") return getSdJwtVcMetaParser(credentialQuery);
|
|
612
|
+
if (credentialQuery.format === "vc+sd-jwt") {
|
|
613
|
+
if (credentialQuery.meta && "type_values" in credentialQuery.meta) return getW3cVcMetaParser(credentialQuery);
|
|
614
|
+
return getSdJwtVcMetaParser(credentialQuery);
|
|
615
|
+
}
|
|
616
|
+
if (credentialQuery.format === "ldp_vc" || credentialQuery.format === "jwt_vc_json") return getW3cVcMetaParser(credentialQuery);
|
|
617
|
+
throw new DcqlError({
|
|
618
|
+
code: "NOT_IMPLEMENTED",
|
|
619
|
+
message: `Unsupported format '${credentialQuery.format}'`
|
|
620
|
+
});
|
|
832
621
|
};
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
622
|
+
const runMetaQuery = (credentialQuery, credential) => {
|
|
623
|
+
const metaParser = getMetaParser(credentialQuery);
|
|
624
|
+
const parseResult = v.safeParse(metaParser, credential);
|
|
625
|
+
if (!parseResult.success) {
|
|
626
|
+
const issues = v.flatten(parseResult.issues);
|
|
627
|
+
return {
|
|
628
|
+
success: false,
|
|
629
|
+
issues: issues.nested ?? issues,
|
|
630
|
+
output: parseResult.output
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
success: true,
|
|
635
|
+
output: parseResult.output
|
|
636
|
+
};
|
|
848
637
|
};
|
|
849
638
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
return {
|
|
882
|
-
success: false,
|
|
883
|
-
failed_trusted_authorities: failedTrustedAuthorities
|
|
884
|
-
};
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/dcql-parser/dcql-trusted-authorities-result.ts
|
|
641
|
+
const runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
|
|
642
|
+
if (!credentialQuery.trusted_authorities) return { success: true };
|
|
643
|
+
const failedTrustedAuthorities = [];
|
|
644
|
+
for (const [trustedAuthorityIndex, trustedAuthority] of credentialQuery.trusted_authorities.entries()) {
|
|
645
|
+
const trustedAuthorityParser = getTrustedAuthorityParser(trustedAuthority);
|
|
646
|
+
const parseResult = v.safeParse(trustedAuthorityParser, credential.authority);
|
|
647
|
+
if (parseResult.success) return {
|
|
648
|
+
success: true,
|
|
649
|
+
valid_trusted_authority: {
|
|
650
|
+
success: true,
|
|
651
|
+
trusted_authority_index: trustedAuthorityIndex,
|
|
652
|
+
output: parseResult.output
|
|
653
|
+
},
|
|
654
|
+
failed_trusted_authorities: asNonEmptyArrayOrUndefined(failedTrustedAuthorities)
|
|
655
|
+
};
|
|
656
|
+
const issues = v.flatten(parseResult.issues);
|
|
657
|
+
failedTrustedAuthorities.push({
|
|
658
|
+
success: false,
|
|
659
|
+
trusted_authority_index: trustedAuthorityIndex,
|
|
660
|
+
issues: issues.nested ?? issues,
|
|
661
|
+
output: parseResult.output
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
return {
|
|
665
|
+
success: false,
|
|
666
|
+
failed_trusted_authorities: failedTrustedAuthorities
|
|
667
|
+
};
|
|
885
668
|
};
|
|
886
669
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
valid_credentials: void 0
|
|
928
|
-
};
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/dcql-parser/dcql-credential-query-result.ts
|
|
672
|
+
const runCredentialQuery = (credentialQuery, ctx) => {
|
|
673
|
+
const { credentials, presentation } = ctx;
|
|
674
|
+
const validCredentials = [];
|
|
675
|
+
const failedCredentials = [];
|
|
676
|
+
for (const [credentialIndex, credential] of credentials.entries()) {
|
|
677
|
+
const trustedAuthorityResult = runTrustedAuthoritiesQuery(credentialQuery, credential);
|
|
678
|
+
const claimsResult = runClaimsQuery(credentialQuery, {
|
|
679
|
+
credential,
|
|
680
|
+
presentation
|
|
681
|
+
});
|
|
682
|
+
const metaResult = runMetaQuery(credentialQuery, credential);
|
|
683
|
+
if (claimsResult.success && trustedAuthorityResult.success && metaResult.success) validCredentials.push({
|
|
684
|
+
success: true,
|
|
685
|
+
input_credential_index: credentialIndex,
|
|
686
|
+
trusted_authorities: trustedAuthorityResult,
|
|
687
|
+
meta: metaResult,
|
|
688
|
+
claims: claimsResult
|
|
689
|
+
});
|
|
690
|
+
else failedCredentials.push({
|
|
691
|
+
success: false,
|
|
692
|
+
input_credential_index: credentialIndex,
|
|
693
|
+
trusted_authorities: trustedAuthorityResult,
|
|
694
|
+
meta: metaResult,
|
|
695
|
+
claims: claimsResult
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
if (isNonEmptyArray(validCredentials)) return {
|
|
699
|
+
success: true,
|
|
700
|
+
credential_query_id: credentialQuery.id,
|
|
701
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
|
702
|
+
valid_credentials: validCredentials
|
|
703
|
+
};
|
|
704
|
+
return {
|
|
705
|
+
success: false,
|
|
706
|
+
credential_query_id: credentialQuery.id,
|
|
707
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
|
708
|
+
valid_credentials: void 0
|
|
709
|
+
};
|
|
929
710
|
};
|
|
930
711
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
((
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
...vBase.entries,
|
|
973
|
-
format: v10.pipe(
|
|
974
|
-
v10.literal("mso_mdoc"),
|
|
975
|
-
v10.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")
|
|
976
|
-
),
|
|
977
|
-
claims: v10.pipe(
|
|
978
|
-
v10.optional(vNonEmptyArray(DcqlClaimsQuery.vMdoc)),
|
|
979
|
-
v10.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")
|
|
980
|
-
),
|
|
981
|
-
meta: v10.pipe(
|
|
982
|
-
v10.optional(
|
|
983
|
-
v10.object({
|
|
984
|
-
doctype_value: v10.pipe(
|
|
985
|
-
v10.optional(v10.string()),
|
|
986
|
-
v10.description(
|
|
987
|
-
"OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential."
|
|
988
|
-
)
|
|
989
|
-
)
|
|
990
|
-
})
|
|
991
|
-
),
|
|
992
|
-
v10.description(
|
|
993
|
-
"OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."
|
|
994
|
-
)
|
|
995
|
-
)
|
|
996
|
-
});
|
|
997
|
-
DcqlCredentialQuery2.vSdJwtVc = v10.object({
|
|
998
|
-
...vBase.entries,
|
|
999
|
-
format: v10.pipe(
|
|
1000
|
-
v10.picklist(["vc+sd-jwt", "dc+sd-jwt"]),
|
|
1001
|
-
v10.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")
|
|
1002
|
-
),
|
|
1003
|
-
claims: v10.pipe(
|
|
1004
|
-
v10.optional(vNonEmptyArray(DcqlClaimsQuery.vW3cSdJwtVc)),
|
|
1005
|
-
v10.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")
|
|
1006
|
-
),
|
|
1007
|
-
meta: v10.pipe(
|
|
1008
|
-
v10.optional(
|
|
1009
|
-
v10.pipe(
|
|
1010
|
-
v10.object({
|
|
1011
|
-
vct_values: v10.optional(v10.array(v10.string()))
|
|
1012
|
-
}),
|
|
1013
|
-
v10.description(
|
|
1014
|
-
"OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential."
|
|
1015
|
-
)
|
|
1016
|
-
)
|
|
1017
|
-
),
|
|
1018
|
-
v10.description(
|
|
1019
|
-
"OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."
|
|
1020
|
-
)
|
|
1021
|
-
)
|
|
1022
|
-
});
|
|
1023
|
-
DcqlCredentialQuery2.vW3cVc = v10.object({
|
|
1024
|
-
...vBase.entries,
|
|
1025
|
-
format: v10.pipe(
|
|
1026
|
-
v10.picklist(["jwt_vc_json", "ldp_vc", "vc+sd-jwt"]),
|
|
1027
|
-
v10.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")
|
|
1028
|
-
),
|
|
1029
|
-
claims: v10.pipe(
|
|
1030
|
-
v10.optional(vNonEmptyArray(DcqlClaimsQuery.vW3cSdJwtVc)),
|
|
1031
|
-
v10.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")
|
|
1032
|
-
),
|
|
1033
|
-
meta: v10.pipe(
|
|
1034
|
-
v10.pipe(
|
|
1035
|
-
v10.object({
|
|
1036
|
-
type_values: v10.pipe(
|
|
1037
|
-
vNonEmptyArray(vNonEmptyArray(v10.string())),
|
|
1038
|
-
v10.description(
|
|
1039
|
-
"REQUIRED. An array of string arrays that specifies the fully expanded types (IRIs) after the @context was applied that the Verifier accepts to be presented in the Presentation. Each of the top-level arrays specifies one alternative to match the type values of the Verifiable Credential against. Each inner array specifies a set of fully expanded types that MUST be present in the type property of the Verifiable Credential, regardless of order or the presence of additional types."
|
|
1040
|
-
)
|
|
1041
|
-
)
|
|
1042
|
-
})
|
|
1043
|
-
),
|
|
1044
|
-
v10.description(
|
|
1045
|
-
"REQUIRED. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."
|
|
1046
|
-
)
|
|
1047
|
-
)
|
|
1048
|
-
});
|
|
1049
|
-
DcqlCredentialQuery2.vModel = v10.variant("format", [DcqlCredentialQuery2.vMdoc, DcqlCredentialQuery2.vW3cVc, DcqlCredentialQuery2.vSdJwtVc]);
|
|
1050
|
-
DcqlCredentialQuery2.validate = (credentialQuery) => {
|
|
1051
|
-
claimSetIdsAreDefined(credentialQuery);
|
|
1052
|
-
};
|
|
712
|
+
//#endregion
|
|
713
|
+
//#region src/dcql-query/m-dcql-credential-query.ts
|
|
714
|
+
let DcqlCredentialQuery;
|
|
715
|
+
(function(_DcqlCredentialQuery) {
|
|
716
|
+
const vBase = v.object({
|
|
717
|
+
id: v.pipe(v.string(), v.regex(idRegex), v.description(`REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`)),
|
|
718
|
+
require_cryptographic_holder_binding: v.pipe(v.optional(v.boolean(), true), v.description("OPTIONAL. A boolean which indicates whether the Verifier requires a Cryptographic Holder Binding proof. The default value is true, i.e., a Verifiable Presentation with Cryptographic Holder Binding is required. If set to false, the Verifier accepts a Credential without Cryptographic Holder Binding proof.")),
|
|
719
|
+
multiple: v.pipe(v.optional(v.boolean(), false), v.description("OPTIONAL. A boolean which indicates whether multiple Credentials can be returned for this Credential Query. If omitted, the default value is false.")),
|
|
720
|
+
claim_sets: v.pipe(v.optional(vNonEmptyArray(vNonEmptyArray(vIdString))), v.description(`OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`)),
|
|
721
|
+
trusted_authorities: v.pipe(v.optional(vNonEmptyArray(DcqlTrustedAuthoritiesQuery.vModel)), v.description("OPTIONAL. A non-empty array of objects as defined in Section 6.1.1 that specifies expected authorities or trust frameworks that certify Issuers, that the Verifier will accept. Every Credential returned by the Wallet SHOULD match at least one of the conditions present in the corresponding trusted_authorities array if present."))
|
|
722
|
+
});
|
|
723
|
+
const vMdoc = _DcqlCredentialQuery.vMdoc = v.object({
|
|
724
|
+
...vBase.entries,
|
|
725
|
+
format: v.pipe(v.literal("mso_mdoc"), v.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")),
|
|
726
|
+
claims: v.pipe(v.optional(vNonEmptyArray(DcqlClaimsQuery.vMdoc)), v.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")),
|
|
727
|
+
meta: v.pipe(v.optional(v.object({ doctype_value: v.pipe(v.optional(v.string()), v.description("OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential.")) })), v.description("OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."))
|
|
728
|
+
});
|
|
729
|
+
const vSdJwtVc = _DcqlCredentialQuery.vSdJwtVc = v.object({
|
|
730
|
+
...vBase.entries,
|
|
731
|
+
format: v.pipe(v.picklist(["vc+sd-jwt", "dc+sd-jwt"]), v.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")),
|
|
732
|
+
claims: v.pipe(v.optional(vNonEmptyArray(DcqlClaimsQuery.vW3cSdJwtVc)), v.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")),
|
|
733
|
+
meta: v.pipe(v.optional(v.pipe(v.object({ vct_values: v.optional(v.array(v.string())) }), v.description("OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential."))), v.description("OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."))
|
|
734
|
+
});
|
|
735
|
+
const vW3cVc = _DcqlCredentialQuery.vW3cVc = v.object({
|
|
736
|
+
...vBase.entries,
|
|
737
|
+
format: v.pipe(v.picklist([
|
|
738
|
+
"jwt_vc_json",
|
|
739
|
+
"ldp_vc",
|
|
740
|
+
"vc+sd-jwt"
|
|
741
|
+
]), v.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")),
|
|
742
|
+
claims: v.pipe(v.optional(vNonEmptyArray(DcqlClaimsQuery.vW3cSdJwtVc)), v.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")),
|
|
743
|
+
meta: v.pipe(v.pipe(v.object({ type_values: v.pipe(vNonEmptyArray(vNonEmptyArray(v.string())), v.description("REQUIRED. An array of string arrays that specifies the fully expanded types (IRIs) after the @context was applied that the Verifier accepts to be presented in the Presentation. Each of the top-level arrays specifies one alternative to match the type values of the Verifiable Credential against. Each inner array specifies a set of fully expanded types that MUST be present in the type property of the Verifiable Credential, regardless of order or the presence of additional types.")) })), v.description("REQUIRED. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."))
|
|
744
|
+
});
|
|
745
|
+
_DcqlCredentialQuery.vModel = v.variant("format", [
|
|
746
|
+
vMdoc,
|
|
747
|
+
vW3cVc,
|
|
748
|
+
vSdJwtVc
|
|
749
|
+
]);
|
|
750
|
+
_DcqlCredentialQuery.validate = (credentialQuery) => {
|
|
751
|
+
claimSetIdsAreDefined(credentialQuery);
|
|
752
|
+
};
|
|
1053
753
|
})(DcqlCredentialQuery || (DcqlCredentialQuery = {}));
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
if (!claimIds.has(claim_id)) {
|
|
1061
|
-
undefinedClaims.push(claim_id);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
if (undefinedClaims.length > 0) {
|
|
1066
|
-
throw new DcqlUndefinedClaimSetIdError({
|
|
1067
|
-
message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? "" : "`s"} '${undefinedClaims.join(", ")}'`
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
754
|
+
const claimSetIdsAreDefined = (credentialQuery) => {
|
|
755
|
+
if (!credentialQuery.claim_sets) return;
|
|
756
|
+
const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id));
|
|
757
|
+
const undefinedClaims = [];
|
|
758
|
+
for (const claim_set of credentialQuery.claim_sets) for (const claim_id of claim_set) if (!claimIds.has(claim_id)) undefinedClaims.push(claim_id);
|
|
759
|
+
if (undefinedClaims.length > 0) throw new DcqlUndefinedClaimSetIdError({ message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? "" : "`s"} '${undefinedClaims.join(", ")}'` });
|
|
1070
760
|
};
|
|
1071
761
|
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
((
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
v11.description(
|
|
1086
|
-
`OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`
|
|
1087
|
-
)
|
|
1088
|
-
),
|
|
1089
|
-
purpose: v11.pipe(
|
|
1090
|
-
v11.optional(v11.union([v11.string(), v11.number(), v11.record(v11.string(), v11.unknown())])),
|
|
1091
|
-
v11.description("OPTIONAL. A string, number or object specifying the purpose of the query.")
|
|
1092
|
-
)
|
|
1093
|
-
});
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/dcql-query/m-dcql-credential-set-query.ts
|
|
764
|
+
let CredentialSetQuery;
|
|
765
|
+
(function(_CredentialSetQuery) {
|
|
766
|
+
_CredentialSetQuery.vModel = v.object({
|
|
767
|
+
options: v.pipe(vNonEmptyArray(v.array(vIdString)), v.description("REQUIRED. A non-empty array, where each value in the array is a list of Credential Query identifiers representing one set of Credentials that satisfies the use case.")),
|
|
768
|
+
required: v.pipe(v.optional(v.boolean(), true), v.description(`OPTIONAL. Boolean which indicates whether this set of Credentials is required to satisfy the particular use case at the Verifier. If omitted, the default value is 'true'.`)),
|
|
769
|
+
purpose: v.pipe(v.optional(v.union([
|
|
770
|
+
v.string(),
|
|
771
|
+
v.number(),
|
|
772
|
+
v.record(v.string(), v.unknown())
|
|
773
|
+
])), v.description("OPTIONAL. A string, number or object specifying the purpose of the query."))
|
|
774
|
+
});
|
|
1094
775
|
})(CredentialSetQuery || (CredentialSetQuery = {}));
|
|
1095
776
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
((
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
failed_claims: vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult),
|
|
1148
|
-
valid_claim_sets: v12.optional(v12.undefined()),
|
|
1149
|
-
failed_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult)
|
|
1150
|
-
});
|
|
1151
|
-
DcqlClaimsResult2.vModel = v12.union([DcqlClaimsResult2.vClaimsSuccessResult, DcqlClaimsResult2.vClaimsFailureResult]);
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/dcql-query-result/m-claims-result.ts
|
|
779
|
+
let DcqlClaimsResult;
|
|
780
|
+
(function(_DcqlClaimsResult) {
|
|
781
|
+
const vClaimsOutput = v.union([
|
|
782
|
+
DcqlMdocCredential.vModel.entries.namespaces,
|
|
783
|
+
DcqlSdJwtVcCredential.vModel.entries.claims,
|
|
784
|
+
DcqlW3cVcCredential.vModel.entries.claims
|
|
785
|
+
]);
|
|
786
|
+
const vClaimsEntrySuccessResult = _DcqlClaimsResult.vClaimsEntrySuccessResult = v.object({
|
|
787
|
+
success: v.literal(true),
|
|
788
|
+
claim_index: v.number(),
|
|
789
|
+
claim_id: v.optional(vIdString),
|
|
790
|
+
output: vClaimsOutput
|
|
791
|
+
});
|
|
792
|
+
const vClaimsEntryFailureResult = _DcqlClaimsResult.vClaimsEntryFailureResult = v.object({
|
|
793
|
+
success: v.literal(false),
|
|
794
|
+
claim_index: v.number(),
|
|
795
|
+
claim_id: v.optional(vIdString),
|
|
796
|
+
issues: v.record(v.string(), v.unknown()),
|
|
797
|
+
output: v.unknown()
|
|
798
|
+
});
|
|
799
|
+
const vClaimSetSuccessResult = _DcqlClaimsResult.vClaimSetSuccessResult = v.object({
|
|
800
|
+
success: v.literal(true),
|
|
801
|
+
claim_set_index: v.union([v.number(), v.undefined()]),
|
|
802
|
+
valid_claim_indexes: v.optional(vNonEmptyArray(v.number())),
|
|
803
|
+
failed_claim_indexes: v.optional(v.undefined()),
|
|
804
|
+
output: vClaimsOutput
|
|
805
|
+
});
|
|
806
|
+
const vClaimSetFailureResult = _DcqlClaimsResult.vClaimSetFailureResult = v.object({
|
|
807
|
+
success: v.literal(false),
|
|
808
|
+
claim_set_index: v.union([v.number(), v.undefined()]),
|
|
809
|
+
valid_claim_indexes: v.optional(vNonEmptyArray(v.number())),
|
|
810
|
+
failed_claim_indexes: vNonEmptyArray(v.number()),
|
|
811
|
+
issues: v.record(v.string(), v.unknown())
|
|
812
|
+
});
|
|
813
|
+
const vClaimsSuccessResult = _DcqlClaimsResult.vClaimsSuccessResult = v.object({
|
|
814
|
+
success: v.literal(true),
|
|
815
|
+
valid_claims: v.optional(vNonEmptyArray(vClaimsEntrySuccessResult)),
|
|
816
|
+
failed_claims: v.optional(vNonEmptyArray(vClaimsEntryFailureResult)),
|
|
817
|
+
valid_claim_sets: vNonEmptyArray(vClaimSetSuccessResult),
|
|
818
|
+
failed_claim_sets: v.optional(vNonEmptyArray(vClaimSetFailureResult))
|
|
819
|
+
});
|
|
820
|
+
const vClaimsFailureResult = _DcqlClaimsResult.vClaimsFailureResult = v.object({
|
|
821
|
+
success: v.literal(false),
|
|
822
|
+
valid_claims: v.optional(vNonEmptyArray(vClaimsEntrySuccessResult)),
|
|
823
|
+
failed_claims: vNonEmptyArray(vClaimsEntryFailureResult),
|
|
824
|
+
valid_claim_sets: v.optional(v.undefined()),
|
|
825
|
+
failed_claim_sets: vNonEmptyArray(vClaimSetFailureResult)
|
|
826
|
+
});
|
|
827
|
+
_DcqlClaimsResult.vModel = v.union([vClaimsSuccessResult, vClaimsFailureResult]);
|
|
1152
828
|
})(DcqlClaimsResult || (DcqlClaimsResult = {}));
|
|
1153
829
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
((
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/dcql-query-result/m-meta-result.ts
|
|
832
|
+
let DcqlMetaResult;
|
|
833
|
+
(function(_DcqlMetaResult) {
|
|
834
|
+
const vMetaSuccessResult = _DcqlMetaResult.vMetaSuccessResult = v.object({
|
|
835
|
+
success: v.literal(true),
|
|
836
|
+
output: v.variant("credential_format", [
|
|
837
|
+
v.pick(DcqlSdJwtVcCredential.vModel, [
|
|
838
|
+
"credential_format",
|
|
839
|
+
"cryptographic_holder_binding",
|
|
840
|
+
"vct"
|
|
841
|
+
]),
|
|
842
|
+
v.pick(DcqlMdocCredential.vModel, [
|
|
843
|
+
"credential_format",
|
|
844
|
+
"cryptographic_holder_binding",
|
|
845
|
+
"doctype"
|
|
846
|
+
]),
|
|
847
|
+
v.pick(DcqlW3cVcCredential.vModel, [
|
|
848
|
+
"credential_format",
|
|
849
|
+
"cryptographic_holder_binding",
|
|
850
|
+
"type"
|
|
851
|
+
])
|
|
852
|
+
])
|
|
853
|
+
});
|
|
854
|
+
const vMetaFailureResult = _DcqlMetaResult.vMetaFailureResult = v.object({
|
|
855
|
+
success: v.literal(false),
|
|
856
|
+
issues: v.record(v.string(), v.unknown()),
|
|
857
|
+
output: v.unknown()
|
|
858
|
+
});
|
|
859
|
+
_DcqlMetaResult.vModel = v.union([vMetaSuccessResult, vMetaFailureResult]);
|
|
1172
860
|
})(DcqlMetaResult || (DcqlMetaResult = {}));
|
|
1173
861
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
((
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
valid_trusted_authority: DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntrySuccessResult,
|
|
1208
|
-
failed_trusted_authorities: v14.optional(vNonEmptyArray(DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntryFailureResult))
|
|
1209
|
-
})
|
|
1210
|
-
]);
|
|
1211
|
-
DcqlTrustedAuthoritiesResult2.vTrustedAuthorityFailureResult = v14.object({
|
|
1212
|
-
success: v14.literal(false),
|
|
1213
|
-
valid_trusted_authority: v14.optional(v14.undefined()),
|
|
1214
|
-
failed_trusted_authorities: vNonEmptyArray(DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntryFailureResult)
|
|
1215
|
-
});
|
|
1216
|
-
DcqlTrustedAuthoritiesResult2.vModel = v14.union([...DcqlTrustedAuthoritiesResult2.vTrustedAuthoritySuccessResult.options, DcqlTrustedAuthoritiesResult2.vTrustedAuthorityFailureResult]);
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/dcql-query-result/m-trusted-authorities-result.ts
|
|
864
|
+
let DcqlTrustedAuthoritiesResult;
|
|
865
|
+
(function(_DcqlTrustedAuthoritiesResult) {
|
|
866
|
+
const vTrustedAuthorityEntrySuccessResult = _DcqlTrustedAuthoritiesResult.vTrustedAuthorityEntrySuccessResult = v.object({
|
|
867
|
+
success: v.literal(true),
|
|
868
|
+
trusted_authority_index: v.number(),
|
|
869
|
+
output: v.variant("type", DcqlCredentialTrustedAuthority.vModel.options.map((o) => v.object({
|
|
870
|
+
type: o.entries.type,
|
|
871
|
+
value: o.entries.values.item
|
|
872
|
+
})))
|
|
873
|
+
});
|
|
874
|
+
const vTrustedAuthorityEntryFailureResult = _DcqlTrustedAuthoritiesResult.vTrustedAuthorityEntryFailureResult = v.object({
|
|
875
|
+
success: v.literal(false),
|
|
876
|
+
trusted_authority_index: v.number(),
|
|
877
|
+
issues: v.record(v.string(), v.unknown()),
|
|
878
|
+
output: v.unknown()
|
|
879
|
+
});
|
|
880
|
+
const vTrustedAuthoritySuccessResult = _DcqlTrustedAuthoritiesResult.vTrustedAuthoritySuccessResult = v.union([v.object({
|
|
881
|
+
success: v.literal(true),
|
|
882
|
+
valid_trusted_authority: v.optional(v.undefined()),
|
|
883
|
+
failed_trusted_authorities: v.optional(v.undefined())
|
|
884
|
+
}), v.object({
|
|
885
|
+
success: v.literal(true),
|
|
886
|
+
valid_trusted_authority: vTrustedAuthorityEntrySuccessResult,
|
|
887
|
+
failed_trusted_authorities: v.optional(vNonEmptyArray(vTrustedAuthorityEntryFailureResult))
|
|
888
|
+
})]);
|
|
889
|
+
const vTrustedAuthorityFailureResult = _DcqlTrustedAuthoritiesResult.vTrustedAuthorityFailureResult = v.object({
|
|
890
|
+
success: v.literal(false),
|
|
891
|
+
valid_trusted_authority: v.optional(v.undefined()),
|
|
892
|
+
failed_trusted_authorities: vNonEmptyArray(vTrustedAuthorityEntryFailureResult)
|
|
893
|
+
});
|
|
894
|
+
_DcqlTrustedAuthoritiesResult.vModel = v.union([...vTrustedAuthoritySuccessResult.options, vTrustedAuthorityFailureResult]);
|
|
1217
895
|
})(DcqlTrustedAuthoritiesResult || (DcqlTrustedAuthoritiesResult = {}));
|
|
1218
896
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
),
|
|
1259
|
-
credential_matches: DcqlQueryResult2.vCredentialQueryResult,
|
|
1260
|
-
credential_sets: v15.optional(
|
|
1261
|
-
v15.pipe(
|
|
1262
|
-
vNonEmptyArray(
|
|
1263
|
-
v15.object({
|
|
1264
|
-
...CredentialSetQuery.vModel.entries,
|
|
1265
|
-
matching_options: v15.union([v15.undefined(), vNonEmptyArray(v15.array(v15.string()))])
|
|
1266
|
-
})
|
|
1267
|
-
),
|
|
1268
|
-
v15.description(
|
|
1269
|
-
"OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."
|
|
1270
|
-
)
|
|
1271
|
-
)
|
|
1272
|
-
),
|
|
1273
|
-
can_be_satisfied: v15.boolean()
|
|
1274
|
-
});
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/dcql-query-result/m-dcql-query-result.ts
|
|
899
|
+
let DcqlQueryResult;
|
|
900
|
+
(function(_DcqlQueryResult) {
|
|
901
|
+
const vCredentialQueryItemCredentialSuccessResult = _DcqlQueryResult.vCredentialQueryItemCredentialSuccessResult = v.object({
|
|
902
|
+
success: v.literal(true),
|
|
903
|
+
input_credential_index: v.number(),
|
|
904
|
+
trusted_authorities: DcqlTrustedAuthoritiesResult.vTrustedAuthoritySuccessResult,
|
|
905
|
+
claims: DcqlClaimsResult.vClaimsSuccessResult,
|
|
906
|
+
meta: DcqlMetaResult.vMetaSuccessResult
|
|
907
|
+
});
|
|
908
|
+
const vCredentialQueryItemCredentialFailureResult = _DcqlQueryResult.vCredentialQueryItemCredentialFailureResult = v.object({
|
|
909
|
+
success: v.literal(false),
|
|
910
|
+
input_credential_index: v.number(),
|
|
911
|
+
trusted_authorities: DcqlTrustedAuthoritiesResult.vModel,
|
|
912
|
+
claims: DcqlClaimsResult.vModel,
|
|
913
|
+
meta: DcqlMetaResult.vModel
|
|
914
|
+
});
|
|
915
|
+
const vCredentialQueryItemResult = _DcqlQueryResult.vCredentialQueryItemResult = v.union([v.object({
|
|
916
|
+
success: v.literal(true),
|
|
917
|
+
credential_query_id: vIdString,
|
|
918
|
+
valid_credentials: vNonEmptyArray(vCredentialQueryItemCredentialSuccessResult),
|
|
919
|
+
failed_credentials: v.optional(vNonEmptyArray(vCredentialQueryItemCredentialFailureResult))
|
|
920
|
+
}), v.object({
|
|
921
|
+
success: v.literal(false),
|
|
922
|
+
credential_query_id: vIdString,
|
|
923
|
+
valid_credentials: v.optional(v.undefined()),
|
|
924
|
+
failed_credentials: v.optional(vNonEmptyArray(vCredentialQueryItemCredentialFailureResult))
|
|
925
|
+
})]);
|
|
926
|
+
const vCredentialQueryResult = _DcqlQueryResult.vCredentialQueryResult = v.record(vIdString, vCredentialQueryItemResult);
|
|
927
|
+
_DcqlQueryResult.vModel = v.object({
|
|
928
|
+
credentials: v.pipe(vNonEmptyArray(DcqlCredentialQuery.vModel), v.description("REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.")),
|
|
929
|
+
credential_matches: vCredentialQueryResult,
|
|
930
|
+
credential_sets: v.optional(v.pipe(vNonEmptyArray(v.object({
|
|
931
|
+
...CredentialSetQuery.vModel.entries,
|
|
932
|
+
matching_options: v.union([v.undefined(), vNonEmptyArray(v.array(v.string()))])
|
|
933
|
+
})), v.description("OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."))),
|
|
934
|
+
can_be_satisfied: v.boolean()
|
|
935
|
+
});
|
|
1275
936
|
})(DcqlQueryResult || (DcqlQueryResult = {}));
|
|
1276
937
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
};
|
|
1320
|
-
});
|
|
1321
|
-
const dqclQueryMatched = (
|
|
1322
|
-
// We require that all the submitted presentations match with the queries
|
|
1323
|
-
// So we must have success for all queries, and we don't allow failed_credentials
|
|
1324
|
-
queriesResults.every((result) => result.success && !result.failed_credentials) && (credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : (
|
|
1325
|
-
// If not credential_sets are used, we require that at least every credential has a match
|
|
1326
|
-
dcqlQuery.credentials.every(
|
|
1327
|
-
(credentialQuery) => queriesResults.find((result) => result.credential_query_id === credentialQuery.id)?.success
|
|
1328
|
-
)
|
|
1329
|
-
))
|
|
1330
|
-
);
|
|
1331
|
-
return {
|
|
1332
|
-
// NOTE: can_be_satisfied is maybe not the best term, because we return false if it can be
|
|
1333
|
-
// satisfied, but one of the provided presentations did not match
|
|
1334
|
-
can_be_satisfied: dqclQueryMatched,
|
|
1335
|
-
credential_sets: credentialSetResults,
|
|
1336
|
-
credential_matches: Object.fromEntries(queriesResults.map((result) => [result.credential_query_id, result]))
|
|
1337
|
-
};
|
|
1338
|
-
};
|
|
1339
|
-
DcqlPresentationResult2.validate = (dcqlQueryResult) => {
|
|
1340
|
-
if (!dcqlQueryResult.can_be_satisfied) {
|
|
1341
|
-
throw new DcqlInvalidPresentationRecordError({
|
|
1342
|
-
message: "Invalid Presentation record",
|
|
1343
|
-
cause: dcqlQueryResult
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
return dcqlQueryResult;
|
|
1347
|
-
};
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region src/dcql-presentation/m-dcql-presentation-result.ts
|
|
940
|
+
let DcqlPresentationResult;
|
|
941
|
+
(function(_DcqlPresentationResult) {
|
|
942
|
+
const vModel = _DcqlPresentationResult.vModel = v.omit(DcqlQueryResult.vModel, ["credentials"]);
|
|
943
|
+
_DcqlPresentationResult.parse = (input) => {
|
|
944
|
+
return v.parse(vModel, input);
|
|
945
|
+
};
|
|
946
|
+
_DcqlPresentationResult.fromDcqlPresentation = (dcqlPresentation, ctx) => {
|
|
947
|
+
const { dcqlQuery } = ctx;
|
|
948
|
+
const queriesResults = Object.entries(dcqlPresentation).map(([credentialQueryId, presentations]) => {
|
|
949
|
+
const credentialQuery = dcqlQuery.credentials.find((c) => c.id === credentialQueryId);
|
|
950
|
+
if (!credentialQuery) throw new DcqlPresentationResultError({ message: `Query ${credentialQueryId} not found in the dcql query. Cannot validate presentation.` });
|
|
951
|
+
if (Array.isArray(presentations)) {
|
|
952
|
+
if (presentations.length === 0) throw new DcqlPresentationResultError({ message: `Query credential '${credentialQueryId}' is present in the presentations but the value is an empty array. Each entry must at least provide one presentation.` });
|
|
953
|
+
if (!credentialQuery.multiple && presentations.length > 1) throw new DcqlPresentationResultError({ message: `Query credential '${credentialQueryId}' has not enabled 'multiple', but multiple presentations were provided. Only a single presentation is allowed for each query credential when 'multiple' is not enabled on the query.` });
|
|
954
|
+
}
|
|
955
|
+
return runCredentialQuery(credentialQuery, {
|
|
956
|
+
presentation: true,
|
|
957
|
+
credentials: presentations ? Array.isArray(presentations) ? presentations : [presentations] : []
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
|
961
|
+
const matchingOptions = set.options.filter((option) => option.every((credentialQueryId) => queriesResults.find((result) => result.credential_query_id === credentialQueryId)?.success));
|
|
962
|
+
return {
|
|
963
|
+
...set,
|
|
964
|
+
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
|
965
|
+
};
|
|
966
|
+
});
|
|
967
|
+
return {
|
|
968
|
+
can_be_satisfied: queriesResults.every((result) => result.success && !result.failed_credentials) && (credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : dcqlQuery.credentials.every((credentialQuery) => queriesResults.find((result) => result.credential_query_id === credentialQuery.id)?.success)),
|
|
969
|
+
credential_sets: credentialSetResults,
|
|
970
|
+
credential_matches: Object.fromEntries(queriesResults.map((result) => [result.credential_query_id, result]))
|
|
971
|
+
};
|
|
972
|
+
};
|
|
973
|
+
_DcqlPresentationResult.validate = (dcqlQueryResult) => {
|
|
974
|
+
if (!dcqlQueryResult.can_be_satisfied) throw new DcqlInvalidPresentationRecordError({
|
|
975
|
+
message: "Invalid Presentation record",
|
|
976
|
+
cause: dcqlQueryResult
|
|
977
|
+
});
|
|
978
|
+
return dcqlQueryResult;
|
|
979
|
+
};
|
|
1348
980
|
})(DcqlPresentationResult || (DcqlPresentationResult = {}));
|
|
1349
981
|
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
((
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
DcqlPresentation2.parse = (input) => {
|
|
1369
|
-
if (typeof input === "string") {
|
|
1370
|
-
return v17.parse(v17.pipe(v17.string(), vStringToJson, DcqlPresentation2.vModel), input);
|
|
1371
|
-
}
|
|
1372
|
-
return v17.parse(DcqlPresentation2.vModel, input);
|
|
1373
|
-
};
|
|
1374
|
-
DcqlPresentation2.encode = (input) => {
|
|
1375
|
-
return JSON.stringify(input);
|
|
1376
|
-
};
|
|
1377
|
-
})(DcqlPresentation || (DcqlPresentation = {}));
|
|
1378
|
-
|
|
1379
|
-
// src/dcql-query-result/run-dcql-query.ts
|
|
1380
|
-
var runDcqlQuery = (dcqlQuery, ctx) => {
|
|
1381
|
-
const credentialQueriesResults = Object.fromEntries(
|
|
1382
|
-
dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])
|
|
1383
|
-
);
|
|
1384
|
-
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
|
1385
|
-
const matchingOptions = set.options.filter(
|
|
1386
|
-
(option) => option.every((credentialQueryId) => credentialQueriesResults[credentialQueryId].success)
|
|
1387
|
-
);
|
|
1388
|
-
return {
|
|
1389
|
-
...set,
|
|
1390
|
-
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
|
1391
|
-
};
|
|
1392
|
-
});
|
|
1393
|
-
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : (
|
|
1394
|
-
// If not credential_sets are used, we require that at least every credential has a match
|
|
1395
|
-
dcqlQuery.credentials.every(({ id }) => credentialQueriesResults[id].success === true)
|
|
1396
|
-
);
|
|
1397
|
-
return {
|
|
1398
|
-
...dcqlQuery,
|
|
1399
|
-
can_be_satisfied: dqclQueryMatched,
|
|
1400
|
-
credential_matches: credentialQueriesResults,
|
|
1401
|
-
credential_sets: credentialSetResults
|
|
1402
|
-
};
|
|
982
|
+
//#endregion
|
|
983
|
+
//#region src/dcql-query-result/run-dcql-query.ts
|
|
984
|
+
const runDcqlQuery = (dcqlQuery, ctx) => {
|
|
985
|
+
const credentialQueriesResults = Object.fromEntries(dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)]));
|
|
986
|
+
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
|
987
|
+
const matchingOptions = set.options.filter((option) => option.every((credentialQueryId) => credentialQueriesResults[credentialQueryId].success));
|
|
988
|
+
return {
|
|
989
|
+
...set,
|
|
990
|
+
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
|
991
|
+
};
|
|
992
|
+
});
|
|
993
|
+
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : dcqlQuery.credentials.every(({ id }) => credentialQueriesResults[id].success === true);
|
|
994
|
+
return {
|
|
995
|
+
...dcqlQuery,
|
|
996
|
+
can_be_satisfied: dqclQueryMatched,
|
|
997
|
+
credential_matches: credentialQueriesResults,
|
|
998
|
+
credential_sets: credentialSetResults
|
|
999
|
+
};
|
|
1403
1000
|
};
|
|
1404
1001
|
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
((
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
};
|
|
1428
|
-
DcqlQuery2.query = (dcqlQuery, credentials) => {
|
|
1429
|
-
return runDcqlQuery(dcqlQuery, { credentials, presentation: false });
|
|
1430
|
-
};
|
|
1431
|
-
DcqlQuery2.parse = (input) => {
|
|
1432
|
-
return v18.parse(DcqlQuery2.vModel, input);
|
|
1433
|
-
};
|
|
1002
|
+
//#endregion
|
|
1003
|
+
//#region src/dcql-query/m-dcql-query.ts
|
|
1004
|
+
let DcqlQuery;
|
|
1005
|
+
(function(_DcqlQuery) {
|
|
1006
|
+
const vModel = _DcqlQuery.vModel = v.object({
|
|
1007
|
+
credentials: v.pipe(vNonEmptyArray(DcqlCredentialQuery.vModel), v.description("REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials.")),
|
|
1008
|
+
credential_sets: v.pipe(v.optional(vNonEmptyArray(CredentialSetQuery.vModel)), v.description("OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."))
|
|
1009
|
+
});
|
|
1010
|
+
_DcqlQuery.validate = (dcqlQuery) => {
|
|
1011
|
+
validateUniqueCredentialQueryIds(dcqlQuery);
|
|
1012
|
+
validateCredentialSets(dcqlQuery);
|
|
1013
|
+
dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate);
|
|
1014
|
+
};
|
|
1015
|
+
_DcqlQuery.query = (dcqlQuery, credentials) => {
|
|
1016
|
+
return runDcqlQuery(dcqlQuery, {
|
|
1017
|
+
credentials,
|
|
1018
|
+
presentation: false
|
|
1019
|
+
});
|
|
1020
|
+
};
|
|
1021
|
+
_DcqlQuery.parse = (input) => {
|
|
1022
|
+
return v.parse(vModel, input);
|
|
1023
|
+
};
|
|
1434
1024
|
})(DcqlQuery || (DcqlQuery = {}));
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
throw new DcqlNonUniqueCredentialQueryIdsError({
|
|
1440
|
-
message: `Duplicate credential query ids found: ${duplicates.join(", ")}`
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1025
|
+
const validateUniqueCredentialQueryIds = (query) => {
|
|
1026
|
+
const ids = query.credentials.map((c) => c.id);
|
|
1027
|
+
const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
1028
|
+
if (duplicates.length > 0) throw new DcqlNonUniqueCredentialQueryIdsError({ message: `Duplicate credential query ids found: ${duplicates.join(", ")}` });
|
|
1443
1029
|
};
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
for (const credentialQueryId of credentialSetOption) {
|
|
1451
|
-
if (!credentialQueryIds.has(credentialQueryId)) {
|
|
1452
|
-
undefinedCredentialQueryIds.push(credentialQueryId);
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
if (undefinedCredentialQueryIds.length > 0) {
|
|
1458
|
-
throw new DcqlCredentialSetError({
|
|
1459
|
-
message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? "" : "`s"} '${undefinedCredentialQueryIds.join(", ")}'`
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
export {
|
|
1464
|
-
CredentialSetQuery,
|
|
1465
|
-
DcqlClaimsQuery,
|
|
1466
|
-
DcqlCredential,
|
|
1467
|
-
DcqlCredentialPresentation,
|
|
1468
|
-
DcqlCredentialQuery,
|
|
1469
|
-
DcqlCredentialSetError,
|
|
1470
|
-
DcqlCredentialTrustedAuthority,
|
|
1471
|
-
DcqlError,
|
|
1472
|
-
DcqlInvalidClaimsQueryIdError,
|
|
1473
|
-
DcqlInvalidPresentationRecordError,
|
|
1474
|
-
DcqlMdocCredential,
|
|
1475
|
-
DcqlMdocPresentation,
|
|
1476
|
-
DcqlMissingClaimSetParseError,
|
|
1477
|
-
DcqlNonUniqueCredentialQueryIdsError,
|
|
1478
|
-
DcqlParseError,
|
|
1479
|
-
DcqlPresentation,
|
|
1480
|
-
DcqlPresentationResult,
|
|
1481
|
-
DcqlPresentationResultError,
|
|
1482
|
-
DcqlQuery,
|
|
1483
|
-
DcqlQueryResult,
|
|
1484
|
-
DcqlSdJwtVcCredential,
|
|
1485
|
-
DcqlSdJwtVcPresentation,
|
|
1486
|
-
DcqlTrustedAuthoritiesQuery,
|
|
1487
|
-
DcqlUndefinedClaimSetIdError,
|
|
1488
|
-
DcqlW3cVcCredential,
|
|
1489
|
-
DcqlW3cVcPresentation,
|
|
1490
|
-
getCauseFromUnknown,
|
|
1491
|
-
getDcqlErrorFromUnknown,
|
|
1492
|
-
runDcqlQuery
|
|
1030
|
+
const validateCredentialSets = (query) => {
|
|
1031
|
+
if (!query.credential_sets) return;
|
|
1032
|
+
const credentialQueryIds = new Set(query.credentials.map((c) => c.id));
|
|
1033
|
+
const undefinedCredentialQueryIds = [];
|
|
1034
|
+
for (const credential_set of query.credential_sets) for (const credentialSetOption of credential_set.options) for (const credentialQueryId of credentialSetOption) if (!credentialQueryIds.has(credentialQueryId)) undefinedCredentialQueryIds.push(credentialQueryId);
|
|
1035
|
+
if (undefinedCredentialQueryIds.length > 0) throw new DcqlCredentialSetError({ message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? "" : "`s"} '${undefinedCredentialQueryIds.join(", ")}'` });
|
|
1493
1036
|
};
|
|
1037
|
+
|
|
1038
|
+
//#endregion
|
|
1039
|
+
export { CredentialSetQuery, DcqlClaimsQuery, DcqlCredential, DcqlCredentialPresentation, DcqlCredentialQuery, DcqlCredentialSetError, DcqlCredentialTrustedAuthority, DcqlError, DcqlInvalidClaimsQueryIdError, DcqlInvalidPresentationRecordError, DcqlMdocCredential, DcqlMdocPresentation, DcqlMissingClaimSetParseError, DcqlNonUniqueCredentialQueryIdsError, DcqlParseError, DcqlPresentation, DcqlPresentationResult, DcqlPresentationResultError, DcqlQuery, DcqlQueryResult, DcqlSdJwtVcCredential, DcqlSdJwtVcPresentation, DcqlTrustedAuthoritiesQuery, DcqlUndefinedClaimSetIdError, DcqlW3cVcCredential, DcqlW3cVcPresentation, getCauseFromUnknown, getDcqlErrorFromUnknown, runDcqlQuery };
|
|
1494
1040
|
//# sourceMappingURL=index.mjs.map
|