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.mjs CHANGED
@@ -1,1494 +1,1040 @@
1
- // src/dcql-error/e-base.ts
1
+ import * as v from "valibot";
2
+
3
+ //#region src/dcql-error/e-base.ts
2
4
  function isObject(value) {
3
- return !!value && !Array.isArray(value) && typeof value === "object";
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
- if (cause instanceof Error) {
9
- return cause;
10
- }
11
- const type = typeof cause;
12
- if (type === "undefined" || type === "function" || cause === null) {
13
- return void 0;
14
- }
15
- if (type !== "object") {
16
- return new Error(String(cause));
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
- var isDcqlError = (cause) => {
28
- if (cause instanceof DcqlError) {
29
- return true;
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
- if (isDcqlError(cause)) {
38
- return cause;
39
- }
40
- const dcqlError = new DcqlError({
41
- code: "INTERNAL_SERVER_ERROR",
42
- cause
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
- constructor(opts) {
51
- const cause = getCauseFromUnknown(opts.cause);
52
- const message = opts.message ?? cause?.message ?? opts.code;
53
- super(message, { cause });
54
- this.code = opts.code;
55
- this.name = "DcqlError";
56
- if (!this.cause) {
57
- this.cause = cause;
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
- // src/dcql-error/e-dcql.ts
44
+ //#endregion
45
+ //#region src/dcql-error/e-dcql.ts
63
46
  var DcqlCredentialSetError = class extends DcqlError {
64
- constructor(opts) {
65
- super({ code: "BAD_REQUEST", ...opts });
66
- }
47
+ constructor(opts) {
48
+ super({
49
+ code: "BAD_REQUEST",
50
+ ...opts
51
+ });
52
+ }
67
53
  };
68
54
  var DcqlUndefinedClaimSetIdError = class extends DcqlError {
69
- constructor(opts) {
70
- super({ code: "BAD_REQUEST", ...opts });
71
- }
55
+ constructor(opts) {
56
+ super({
57
+ code: "BAD_REQUEST",
58
+ ...opts
59
+ });
60
+ }
72
61
  };
73
62
  var DcqlNonUniqueCredentialQueryIdsError = class extends DcqlError {
74
- constructor(opts) {
75
- super({ code: "BAD_REQUEST", ...opts });
76
- }
63
+ constructor(opts) {
64
+ super({
65
+ code: "BAD_REQUEST",
66
+ ...opts
67
+ });
68
+ }
77
69
  };
78
70
  var DcqlParseError = class extends DcqlError {
79
- constructor(opts) {
80
- super({ code: "PARSE_ERROR", ...opts });
81
- }
71
+ constructor(opts) {
72
+ super({
73
+ code: "PARSE_ERROR",
74
+ ...opts
75
+ });
76
+ }
82
77
  };
83
78
  var DcqlInvalidClaimsQueryIdError = class extends DcqlError {
84
- constructor(opts) {
85
- super({ code: "BAD_REQUEST", ...opts });
86
- }
79
+ constructor(opts) {
80
+ super({
81
+ code: "BAD_REQUEST",
82
+ ...opts
83
+ });
84
+ }
87
85
  };
88
86
  var DcqlMissingClaimSetParseError = class extends DcqlError {
89
- constructor(opts) {
90
- super({ code: "PARSE_ERROR", ...opts });
91
- }
87
+ constructor(opts) {
88
+ super({
89
+ code: "PARSE_ERROR",
90
+ ...opts
91
+ });
92
+ }
92
93
  };
93
94
  var DcqlInvalidPresentationRecordError = class extends DcqlError {
94
- constructor(opts) {
95
- super({ code: "BAD_REQUEST", ...opts });
96
- }
95
+ constructor(opts) {
96
+ super({
97
+ code: "BAD_REQUEST",
98
+ ...opts
99
+ });
100
+ }
97
101
  };
98
102
  var DcqlPresentationResultError = class extends DcqlError {
99
- constructor(opts) {
100
- super({ code: "BAD_REQUEST", ...opts });
101
- }
103
+ constructor(opts) {
104
+ super({
105
+ code: "BAD_REQUEST",
106
+ ...opts
107
+ });
108
+ }
102
109
  };
103
110
 
104
- // src/dcql-presentation/m-dcql-credential-presentation.ts
105
- import * as v5 from "valibot";
106
-
107
- // src/u-dcql-credential.ts
108
- import * as v4 from "valibot";
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(array8) {
120
- return array8.length > 0;
117
+ function isNonEmptyArray(array) {
118
+ return array.length > 0;
121
119
  }
122
- var vNonEmptyArray = (item) => {
123
- return v.pipe(
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
- var vIncludesAll = (subset) => {
132
- return v.custom(
133
- (value) => {
134
- if (!Array.isArray(value)) return false;
135
- return subset.every((item) => value.includes(item));
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
- var vIdString = v.pipe(v.string(), v.regex(idRegex), v.nonEmpty());
141
- var vBase64url = v.regex(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==)?|[\w-]{3}=?)?$/iu, "must be base64url");
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
- if (value === null || typeof value !== "object") return false;
144
- const toJsonFn = value.toJson;
145
- return typeof toJsonFn === "function";
132
+ if (value === null || typeof value !== "object") return false;
133
+ return typeof value.toJson === "function";
146
134
  }
147
- var vWithJT = (schema) => v.pipe(
148
- v.custom(() => true),
149
- v.rawTransform(({ dataset, addIssue, NEVER }) => {
150
- const result = v.safeParse(schema, dataset.value);
151
- if (result.success) return dataset.value;
152
- if (!isToJsonable(dataset.value)) {
153
- for (const safeParseIssue of result.issues) {
154
- addIssue({
155
- ...safeParseIssue,
156
- expected: safeParseIssue.expected ?? void 0
157
- });
158
- }
159
- return NEVER;
160
- }
161
- let json;
162
- try {
163
- json = dataset.value.toJson();
164
- } catch (error) {
165
- for (const safeParseIssue of result.issues) {
166
- addIssue({
167
- ...safeParseIssue,
168
- expected: safeParseIssue.expected ?? void 0
169
- });
170
- }
171
- addIssue({ message: "Json Transformation failed" });
172
- return NEVER;
173
- }
174
- const safeParseResult = v.safeParse(schema, json);
175
- if (safeParseResult.success) return dataset.value;
176
- for (const safeParseIssue of safeParseResult.issues) {
177
- addIssue({
178
- ...safeParseIssue,
179
- expected: safeParseIssue.expected ?? void 0
180
- });
181
- }
182
- return NEVER;
183
- })
184
- );
185
- var vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()]);
186
- var vJson = v.lazy(
187
- () => v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])
188
- );
189
- var vJsonWithJT = v.lazy(
190
- () => vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))
191
- );
192
- var vJsonRecord = v.record(v.string(), vJson);
193
- var vStringToJson = v.rawTransform(({ dataset, addIssue, NEVER }) => {
194
- try {
195
- return JSON.parse(dataset.value);
196
- } catch (error) {
197
- addIssue({ message: "Invalid JSON" });
198
- return NEVER;
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
- // src/dcql-query/m-dcql-trusted-authorities.ts
203
- var getTrustedAuthorityParser = (trustedAuthority) => v2.pipe(
204
- v2.object(
205
- {
206
- type: v2.literal(
207
- trustedAuthority.type,
208
- (i) => `Expected trusted authority type to be '${trustedAuthority.type}' but received ${typeof i.input === "string" ? `'${i.input}'` : i.input}`
209
- ),
210
- // Some trusted authorities support an array as input type
211
- values: v2.pipe(
212
- vNonEmptyArray(v2.string()),
213
- v2.someItem(
214
- (item) => trustedAuthority.values.includes(item),
215
- (i) => `Expected one of the trusted authority values to be '${trustedAuthority.values.join("' | '")}' but received '${i.input.join("' , '")}'`
216
- )
217
- )
218
- },
219
- `Expected trusted authority object with type '${trustedAuthority.type}' to be defined, but received undefined`
220
- ),
221
- v2.transform(({ values, ...rest }) => ({
222
- ...rest,
223
- value: values.find((value) => trustedAuthority.values.includes(value))
224
- }))
225
- );
226
- var vAuthorityKeyIdentifier = v2.object({
227
- type: v2.literal("aki"),
228
- values: vNonEmptyArray(
229
- v2.pipe(
230
- v2.string("aki trusted authority value must be a string"),
231
- vBase64url,
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
- var DcqlCredentialTrustedAuthority;
293
- ((DcqlCredentialTrustedAuthority2) => {
294
- DcqlCredentialTrustedAuthority2.vModel = v2.variant("type", vTrustedAuthorities);
233
+ let DcqlCredentialTrustedAuthority;
234
+ (function(_DcqlCredentialTrustedAuthority) {
235
+ _DcqlCredentialTrustedAuthority.vModel = v.variant("type", vTrustedAuthorities);
295
236
  })(DcqlCredentialTrustedAuthority || (DcqlCredentialTrustedAuthority = {}));
296
237
 
297
- // src/u-model.ts
298
- import * as v3 from "valibot";
238
+ //#endregion
239
+ //#region src/u-model.ts
299
240
  var ModelDefinition = class {
300
- constructor(input) {
301
- this.input = input;
302
- }
303
- get v() {
304
- return this.input.vModel;
305
- }
306
- parse(input) {
307
- const result = this.safeParse(input);
308
- if (result.success) {
309
- return result.output;
310
- }
311
- return new DcqlParseError({
312
- message: JSON.stringify(result.flattened),
313
- cause: result.error
314
- });
315
- }
316
- safeParse(input) {
317
- const res = v3.safeParse(this.input.vModel, input);
318
- if (res.success) {
319
- return { success: true, output: res.output };
320
- }
321
- return {
322
- success: false,
323
- error: new v3.ValiError(res.issues),
324
- flattened: v3.flatten(res.issues)
325
- };
326
- }
327
- is(input) {
328
- return v3.is(this.v, input);
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
- // src/u-dcql-credential.ts
333
- var vCredentialModelBase = v4.object({
334
- authority: v4.optional(DcqlCredentialTrustedAuthority.vModel),
335
- /**
336
- * Indicates support/inclusion of cryptographic holder binding. This will be checked against
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
- var DcqlMdocCredential;
351
- ((DcqlMdocCredential2) => {
352
- DcqlMdocCredential2.vNamespaces = v4.record(v4.string(), v4.record(v4.string(), v4.unknown()));
353
- DcqlMdocCredential2.vModel = v4.object({
354
- ...vCredentialModelBase.entries,
355
- credential_format: v4.literal("mso_mdoc"),
356
- doctype: v4.string(),
357
- namespaces: DcqlMdocCredential2.vNamespaces
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
- var DcqlSdJwtVcCredential;
362
- ((DcqlSdJwtVcCredential2) => {
363
- DcqlSdJwtVcCredential2.vClaims = vJsonRecord;
364
- DcqlSdJwtVcCredential2.vModel = v4.object({
365
- ...vCredentialModelBase.entries,
366
- credential_format: v4.picklist(["vc+sd-jwt", "dc+sd-jwt"]),
367
- vct: v4.string(),
368
- claims: DcqlSdJwtVcCredential2.vClaims
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
- var DcqlW3cVcCredential;
373
- ((DcqlW3cVcCredential2) => {
374
- DcqlW3cVcCredential2.vClaims = vJsonRecord;
375
- DcqlW3cVcCredential2.vModel = v4.object({
376
- ...vCredentialModelBase.entries,
377
- credential_format: v4.picklist(["ldp_vc", "jwt_vc_json", "vc+sd-jwt"]),
378
- claims: DcqlW3cVcCredential2.vClaims,
379
- type: v4.array(v4.string())
380
- });
381
- DcqlW3cVcCredential2.model = new ModelDefinition({ vModel: DcqlW3cVcCredential2.vModel });
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
- var DcqlCredential;
384
- ((DcqlCredential2) => {
385
- DcqlCredential2.vModel = v4.variant("credential_format", [
386
- DcqlMdocCredential.vModel,
387
- DcqlSdJwtVcCredential.vModel,
388
- DcqlW3cVcCredential.vModel
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
- // src/dcql-presentation/m-dcql-credential-presentation.ts
394
- var DcqlMdocPresentation;
395
- ((DcqlMdocPresentation2) => {
396
- DcqlMdocPresentation2.vModel = DcqlMdocCredential.vModel;
397
- DcqlMdocPresentation2.model = new ModelDefinition({ vModel: DcqlMdocPresentation2.vModel });
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
- var DcqlSdJwtVcPresentation;
400
- ((DcqlSdJwtVcPresentation2) => {
401
- DcqlSdJwtVcPresentation2.vModel = DcqlSdJwtVcCredential.vModel;
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
- var DcqlW3cVcPresentation;
405
- ((DcqlW3cVcPresentation2) => {
406
- DcqlW3cVcPresentation2.vModel = DcqlW3cVcCredential.vModel;
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
- var DcqlCredentialPresentation;
410
- ((DcqlCredentialPresentation2) => {
411
- DcqlCredentialPresentation2.model = new ModelDefinition({
412
- vModel: v5.variant("credential_format", [
413
- DcqlMdocPresentation.vModel,
414
- DcqlSdJwtVcPresentation.vModel,
415
- DcqlW3cVcPresentation.vModel
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
- // src/dcql-presentation/m-dcql-presentation-result.ts
421
- import * as v16 from "valibot";
422
-
423
- // src/dcql-parser/dcql-claims-query-result.ts
424
- import * as v7 from "valibot";
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
- // src/dcql-query/m-dcql-claims-query.ts
427
- import * as v6 from "valibot";
428
- var DcqlClaimsQuery;
429
- ((DcqlClaimsQuery2) => {
430
- DcqlClaimsQuery2.vValue = v6.union([v6.string(), v6.pipe(v6.number(), v6.integer()), v6.boolean()]);
431
- DcqlClaimsQuery2.vPath = v6.union([v6.string(), v6.pipe(v6.number(), v6.integer(), v6.minValue(0)), v6.null()]);
432
- DcqlClaimsQuery2.vW3cSdJwtVc = v6.object({
433
- id: v6.pipe(
434
- v6.optional(vIdString),
435
- v6.description(
436
- "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."
437
- )
438
- ),
439
- path: v6.pipe(
440
- vNonEmptyArray(DcqlClaimsQuery2.vPath),
441
- v6.description(
442
- "A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential."
443
- )
444
- ),
445
- values: v6.pipe(
446
- v6.optional(v6.array(DcqlClaimsQuery2.vValue)),
447
- v6.description(
448
- "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."
449
- )
450
- )
451
- });
452
- const vMdocBase = v6.object({
453
- id: v6.pipe(
454
- v6.optional(vIdString),
455
- v6.description(
456
- "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."
457
- )
458
- ),
459
- values: v6.pipe(
460
- v6.optional(v6.array(DcqlClaimsQuery2.vValue)),
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
- // src/util/deep-merge.ts
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
- let newTarget = target;
516
- if (Object.getPrototypeOf(source) !== Object.prototype && !Array.isArray(source)) {
517
- throw new DcqlError({
518
- message: "source value provided to deepMerge is neither an array or object.",
519
- code: "PARSE_ERROR"
520
- });
521
- }
522
- if (Object.getPrototypeOf(target) !== Object.prototype && !Array.isArray(target)) {
523
- throw new DcqlError({
524
- message: "target value provided to deepMerge is neither an array or object.",
525
- code: "PARSE_ERROR"
526
- });
527
- }
528
- for (const [key, val] of Object.entries(source)) {
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
- let newTarget = target;
543
- if (Array.isArray(newTarget)) {
544
- newTarget = [...newTarget];
545
- newTarget[key] = value;
546
- } else if (Object.getPrototypeOf(newTarget) === Object.prototype) {
547
- newTarget = { ...newTarget, [key]: value };
548
- } else {
549
- throw new DcqlError({
550
- message: "Unsupported type for deep merge. Only primitive types or Array and Object are supported",
551
- code: "INTERNAL_SERVER_ERROR"
552
- });
553
- }
554
- return newTarget;
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
- // src/dcql-parser/dcql-claims-query-result.ts
558
- var pathToString = (path) => path.map((item) => typeof item === "string" ? `'${item}'` : `${item}`).join(".");
559
- var getClaimParser = (path, values) => {
560
- if (values) {
561
- return v7.union(
562
- values.map(
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
- var getMdocClaimParser = (claimQuery) => {
577
- const mdocPathQuery = v7.is(DcqlClaimsQuery.vMdocNamespace, claimQuery) ? {
578
- id: claimQuery.id,
579
- path: [claimQuery.namespace, claimQuery.claim_name],
580
- values: claimQuery.values
581
- } : claimQuery;
582
- const namespace = mdocPathQuery.path[0];
583
- const field = mdocPathQuery.path[1];
584
- return v7.object(
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
- var getJsonClaimParser = (claimQuery, ctx) => {
597
- const { index, presentation } = ctx;
598
- const pathElement = claimQuery.path[index];
599
- const isLast = index === claimQuery.path.length - 1;
600
- const vClaimParser = getClaimParser(claimQuery.path, claimQuery.values);
601
- if (typeof pathElement === "number") {
602
- const elementParser = isLast ? vClaimParser : getJsonClaimParser(claimQuery, { ...ctx, index: index + 1 });
603
- if (presentation) {
604
- return v7.pipe(
605
- v7.array(v7.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`),
606
- v7.rawTransform(({ dataset, addIssue }) => {
607
- const issues = [];
608
- for (const item of dataset.value) {
609
- const itemResult = v7.safeParse(elementParser, item);
610
- if (itemResult.success) {
611
- return dataset.value;
612
- }
613
- issues.push(itemResult.issues[0]);
614
- }
615
- addIssue({
616
- ...issues[0],
617
- 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}`
618
- });
619
- return dataset.value;
620
- })
621
- );
622
- }
623
- return v7.pipe(
624
- v7.array(v7.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`),
625
- v7.rawTransform(({ addIssue, dataset, NEVER }) => {
626
- const result = v7.safeParse(elementParser, dataset.value[pathElement]);
627
- if (!result.success) {
628
- addIssue(result.issues[0]);
629
- return NEVER;
630
- }
631
- return [...dataset.value.slice(0, pathElement).map(() => null), result.output];
632
- })
633
- );
634
- }
635
- if (typeof pathElement === "string") {
636
- return v7.object(
637
- {
638
- [pathElement]: isLast ? vClaimParser : getJsonClaimParser(claimQuery, { ...ctx, index: index + 1 })
639
- },
640
- `Expected claim ${pathToString(claimQuery.path)} to be defined`
641
- );
642
- }
643
- return v7.pipe(
644
- v7.array(v7.any(), `Expected path ${pathToString(claimQuery.path.slice(0, index + 1))} to be an array`),
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
- var runClaimsQuery = (credentialQuery, ctx) => {
666
- if (!credentialQuery.claims) {
667
- return {
668
- success: true,
669
- valid_claims: void 0,
670
- failed_claims: void 0,
671
- valid_claim_sets: [
672
- {
673
- claim_set_index: void 0,
674
- output: {},
675
- success: true,
676
- valid_claim_indexes: void 0
677
- }
678
- ],
679
- failed_claim_sets: void 0
680
- };
681
- }
682
- const failedClaims = [];
683
- const validClaims = [];
684
- for (const [claimIndex, claimQuery] of credentialQuery.claims.entries()) {
685
- const parser = credentialQuery.format === "mso_mdoc" ? getMdocClaimParser(claimQuery) : getJsonClaimParser(claimQuery, {
686
- index: 0,
687
- presentation: ctx.presentation
688
- });
689
- const parseResult = v7.safeParse(
690
- parser,
691
- ctx.credential.credential_format === "mso_mdoc" ? ctx.credential.namespaces : ctx.credential.claims
692
- );
693
- if (parseResult.success) {
694
- validClaims.push({
695
- success: true,
696
- claim_index: claimIndex,
697
- claim_id: claimQuery.id,
698
- output: parseResult.output,
699
- parser
700
- });
701
- } else {
702
- const flattened = v7.flatten(parseResult.issues);
703
- failedClaims.push({
704
- success: false,
705
- issues: flattened.nested ?? flattened,
706
- claim_index: claimIndex,
707
- claim_id: claimQuery.id,
708
- output: parseResult.output,
709
- parser
710
- });
711
- }
712
- }
713
- const failedClaimSets = [];
714
- const validClaimSets = [];
715
- for (const [claimSetIndex, claimSet] of credentialQuery.claim_sets?.entries() ?? [[void 0, void 0]]) {
716
- const claims = claimSet?.map((id) => {
717
- const claim = validClaims.find((claim2) => claim2.claim_id === id) ?? failedClaims.find((claim2) => claim2.claim_id === id);
718
- if (!claim) {
719
- throw new DcqlParseError({
720
- message: `Claim with id '${id}' in query '${credentialQuery.id}' from claim set with index '${claimSetIndex}' not found in claims of claim`
721
- });
722
- }
723
- return claim;
724
- }) ?? [...validClaims, ...failedClaims];
725
- if (claims.every((claim) => claim.success)) {
726
- const output = claims.reduce((merged, claim) => deepMerge(claim.output, merged), {});
727
- validClaimSets.push({
728
- success: true,
729
- claim_set_index: claimSetIndex,
730
- output,
731
- valid_claim_indexes: asNonEmptyArrayOrUndefined(claims.map((claim) => claim.claim_index))
732
- });
733
- } else {
734
- const issues = failedClaims.reduce((merged, claim) => deepMerge(claim.issues, merged), {});
735
- failedClaimSets.push({
736
- success: false,
737
- issues,
738
- claim_set_index: claimSetIndex,
739
- failed_claim_indexes: claims.filter((claim) => !claim.success).map((claim) => claim.claim_index),
740
- valid_claim_indexes: asNonEmptyArrayOrUndefined(
741
- claims.filter((claim) => claim.success).map((claim) => claim.claim_index)
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
- // src/dcql-parser/dcql-meta-query-result.ts
764
- import * as v8 from "valibot";
765
- var getCryptographicHolderBindingValue = (credentialQuery) => v8.object({
766
- cryptographic_holder_binding: credentialQuery.require_cryptographic_holder_binding ? v8.literal(
767
- true,
768
- (i) => `Expected cryptographic_holder_binding to be true (because credential query '${credentialQuery.id}' requires cryptographic holder binding), but received ${i.input}`
769
- ) : v8.boolean()
770
- });
771
- var getMdocMetaParser = (credentialQuery) => {
772
- const vDoctype = credentialQuery.meta?.doctype_value ? v8.literal(
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
- var getSdJwtVcMetaParser = (credentialQuery) => {
787
- return v8.object({
788
- credential_format: v8.literal(
789
- credentialQuery.format,
790
- (i) => `Expected credential format to be '${credentialQuery.format}' but received '${i.input}'`
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
- var getW3cVcMetaParser = (credentialQuery) => {
800
- return v8.object({
801
- credential_format: v8.literal(
802
- credentialQuery.format,
803
- (i) => `Expected credential format to be '${credentialQuery.format}' but received '${i.input}'`
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
- var getMetaParser = (credentialQuery) => {
813
- if (credentialQuery.format === "mso_mdoc") {
814
- return getMdocMetaParser(credentialQuery);
815
- }
816
- if (credentialQuery.format === "dc+sd-jwt") {
817
- return getSdJwtVcMetaParser(credentialQuery);
818
- }
819
- if (credentialQuery.format === "vc+sd-jwt") {
820
- if (credentialQuery.meta && "type_values" in credentialQuery.meta) {
821
- return getW3cVcMetaParser(credentialQuery);
822
- }
823
- return getSdJwtVcMetaParser(credentialQuery);
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
- var runMetaQuery = (credentialQuery, credential) => {
834
- const metaParser = getMetaParser(credentialQuery);
835
- const parseResult = v8.safeParse(metaParser, credential);
836
- if (!parseResult.success) {
837
- const issues = v8.flatten(parseResult.issues);
838
- return {
839
- success: false,
840
- issues: issues.nested ?? issues,
841
- output: parseResult.output
842
- };
843
- }
844
- return {
845
- success: true,
846
- output: parseResult.output
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
- // src/dcql-parser/dcql-trusted-authorities-result.ts
851
- import * as v9 from "valibot";
852
- var runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
853
- if (!credentialQuery.trusted_authorities) {
854
- return {
855
- success: true
856
- };
857
- }
858
- const failedTrustedAuthorities = [];
859
- for (const [trustedAuthorityIndex, trustedAuthority] of credentialQuery.trusted_authorities.entries()) {
860
- const trustedAuthorityParser = getTrustedAuthorityParser(trustedAuthority);
861
- const parseResult = v9.safeParse(trustedAuthorityParser, credential.authority);
862
- if (parseResult.success) {
863
- return {
864
- success: true,
865
- valid_trusted_authority: {
866
- success: true,
867
- trusted_authority_index: trustedAuthorityIndex,
868
- output: parseResult.output
869
- },
870
- failed_trusted_authorities: asNonEmptyArrayOrUndefined(failedTrustedAuthorities)
871
- };
872
- }
873
- const issues = v9.flatten(parseResult.issues);
874
- failedTrustedAuthorities.push({
875
- success: false,
876
- trusted_authority_index: trustedAuthorityIndex,
877
- issues: issues.nested ?? issues,
878
- output: parseResult.output
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
- // src/dcql-parser/dcql-credential-query-result.ts
888
- var runCredentialQuery = (credentialQuery, ctx) => {
889
- const { credentials, presentation } = ctx;
890
- const validCredentials = [];
891
- const failedCredentials = [];
892
- for (const [credentialIndex, credential] of credentials.entries()) {
893
- const trustedAuthorityResult = runTrustedAuthoritiesQuery(credentialQuery, credential);
894
- const claimsResult = runClaimsQuery(credentialQuery, { credential, presentation });
895
- const metaResult = runMetaQuery(credentialQuery, credential);
896
- if (claimsResult.success && trustedAuthorityResult.success && metaResult.success) {
897
- validCredentials.push({
898
- success: true,
899
- input_credential_index: credentialIndex,
900
- trusted_authorities: trustedAuthorityResult,
901
- meta: metaResult,
902
- claims: claimsResult
903
- });
904
- } else {
905
- failedCredentials.push({
906
- success: false,
907
- input_credential_index: credentialIndex,
908
- trusted_authorities: trustedAuthorityResult,
909
- meta: metaResult,
910
- claims: claimsResult
911
- });
912
- }
913
- }
914
- if (isNonEmptyArray(validCredentials)) {
915
- return {
916
- success: true,
917
- credential_query_id: credentialQuery.id,
918
- failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
919
- valid_credentials: validCredentials
920
- };
921
- }
922
- return {
923
- success: false,
924
- credential_query_id: credentialQuery.id,
925
- // Can be undefined if no credentials were provided to the query
926
- failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
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
- // src/dcql-query-result/m-dcql-query-result.ts
932
- import * as v15 from "valibot";
933
-
934
- // src/dcql-query/m-dcql-credential-query.ts
935
- import * as v10 from "valibot";
936
- var DcqlCredentialQuery;
937
- ((DcqlCredentialQuery2) => {
938
- const vBase = v10.object({
939
- id: v10.pipe(
940
- v10.string(),
941
- v10.regex(idRegex),
942
- v10.description(
943
- `REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`
944
- )
945
- ),
946
- require_cryptographic_holder_binding: v10.pipe(
947
- v10.optional(v10.boolean(), true),
948
- v10.description(
949
- "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."
950
- )
951
- ),
952
- multiple: v10.pipe(
953
- v10.optional(v10.boolean(), false),
954
- v10.description(
955
- "OPTIONAL. A boolean which indicates whether multiple Credentials can be returned for this Credential Query. If omitted, the default value is false."
956
- )
957
- ),
958
- claim_sets: v10.pipe(
959
- v10.optional(vNonEmptyArray(vNonEmptyArray(vIdString))),
960
- v10.description(
961
- `OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`
962
- )
963
- ),
964
- trusted_authorities: v10.pipe(
965
- v10.optional(vNonEmptyArray(DcqlTrustedAuthoritiesQuery.vModel)),
966
- v10.description(
967
- "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."
968
- )
969
- )
970
- });
971
- DcqlCredentialQuery2.vMdoc = v10.object({
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
- var claimSetIdsAreDefined = (credentialQuery) => {
1055
- if (!credentialQuery.claim_sets) return;
1056
- const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id));
1057
- const undefinedClaims = [];
1058
- for (const claim_set of credentialQuery.claim_sets) {
1059
- for (const claim_id of claim_set) {
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
- // src/dcql-query/m-dcql-credential-set-query.ts
1073
- import * as v11 from "valibot";
1074
- var CredentialSetQuery;
1075
- ((CredentialSetQuery2) => {
1076
- CredentialSetQuery2.vModel = v11.object({
1077
- options: v11.pipe(
1078
- vNonEmptyArray(v11.array(vIdString)),
1079
- v11.description(
1080
- "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."
1081
- )
1082
- ),
1083
- required: v11.pipe(
1084
- v11.optional(v11.boolean(), true),
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
- // src/dcql-query-result/m-claims-result.ts
1097
- import * as v12 from "valibot";
1098
- var DcqlClaimsResult;
1099
- ((DcqlClaimsResult2) => {
1100
- const vClaimsOutput = v12.union([
1101
- DcqlMdocCredential.vModel.entries.namespaces,
1102
- DcqlSdJwtVcCredential.vModel.entries.claims,
1103
- DcqlW3cVcCredential.vModel.entries.claims
1104
- ]);
1105
- DcqlClaimsResult2.vClaimsEntrySuccessResult = v12.object({
1106
- success: v12.literal(true),
1107
- claim_index: v12.number(),
1108
- claim_id: v12.optional(vIdString),
1109
- output: vClaimsOutput
1110
- });
1111
- DcqlClaimsResult2.vClaimsEntryFailureResult = v12.object({
1112
- success: v12.literal(false),
1113
- claim_index: v12.number(),
1114
- claim_id: v12.optional(vIdString),
1115
- issues: v12.record(v12.string(), v12.unknown()),
1116
- output: v12.unknown()
1117
- });
1118
- DcqlClaimsResult2.vClaimSetSuccessResult = v12.object({
1119
- success: v12.literal(true),
1120
- // Undefined in case of no claim set
1121
- claim_set_index: v12.union([v12.number(), v12.undefined()]),
1122
- // We use indexes because if there are no claim sets, the ids can be undefined
1123
- // Can be empty array in case there are no claims
1124
- valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
1125
- failed_claim_indexes: v12.optional(v12.undefined()),
1126
- output: vClaimsOutput
1127
- });
1128
- DcqlClaimsResult2.vClaimSetFailureResult = v12.object({
1129
- success: v12.literal(false),
1130
- // Undefined in case of no claim set
1131
- claim_set_index: v12.union([v12.number(), v12.undefined()]),
1132
- // We use indexes because if there are no claim sets, the ids can be undefined
1133
- valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
1134
- failed_claim_indexes: vNonEmptyArray(v12.number()),
1135
- issues: v12.record(v12.string(), v12.unknown())
1136
- });
1137
- DcqlClaimsResult2.vClaimsSuccessResult = v12.object({
1138
- success: v12.literal(true),
1139
- valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
1140
- failed_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult)),
1141
- valid_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetSuccessResult),
1142
- failed_claim_sets: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult))
1143
- });
1144
- DcqlClaimsResult2.vClaimsFailureResult = v12.object({
1145
- success: v12.literal(false),
1146
- valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
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
- // src/dcql-query-result/m-meta-result.ts
1155
- import * as v13 from "valibot";
1156
- var DcqlMetaResult;
1157
- ((DcqlMetaResult2) => {
1158
- DcqlMetaResult2.vMetaSuccessResult = v13.object({
1159
- success: v13.literal(true),
1160
- output: v13.variant("credential_format", [
1161
- v13.pick(DcqlSdJwtVcCredential.vModel, ["credential_format", "cryptographic_holder_binding", "vct"]),
1162
- v13.pick(DcqlMdocCredential.vModel, ["credential_format", "cryptographic_holder_binding", "doctype"]),
1163
- v13.pick(DcqlW3cVcCredential.vModel, ["credential_format", "cryptographic_holder_binding", "type"])
1164
- ])
1165
- });
1166
- DcqlMetaResult2.vMetaFailureResult = v13.object({
1167
- success: v13.literal(false),
1168
- issues: v13.record(v13.string(), v13.unknown()),
1169
- output: v13.unknown()
1170
- });
1171
- DcqlMetaResult2.vModel = v13.union([DcqlMetaResult2.vMetaSuccessResult, DcqlMetaResult2.vMetaFailureResult]);
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
- // src/dcql-query-result/m-trusted-authorities-result.ts
1175
- import * as v14 from "valibot";
1176
- var DcqlTrustedAuthoritiesResult;
1177
- ((DcqlTrustedAuthoritiesResult2) => {
1178
- DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntrySuccessResult = v14.object({
1179
- success: v14.literal(true),
1180
- trusted_authority_index: v14.number(),
1181
- // We map from values (multiple options for a credential/query) to value (the matching option)
1182
- output: v14.variant(
1183
- "type",
1184
- DcqlCredentialTrustedAuthority.vModel.options.map(
1185
- (o) => v14.object({
1186
- type: o.entries.type,
1187
- value: o.entries.values.item
1188
- })
1189
- )
1190
- )
1191
- });
1192
- DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntryFailureResult = v14.object({
1193
- success: v14.literal(false),
1194
- trusted_authority_index: v14.number(),
1195
- issues: v14.record(v14.string(), v14.unknown()),
1196
- output: v14.unknown()
1197
- });
1198
- DcqlTrustedAuthoritiesResult2.vTrustedAuthoritySuccessResult = v14.union([
1199
- // In this case there is no trusted authority on the query
1200
- v14.object({
1201
- success: v14.literal(true),
1202
- valid_trusted_authority: v14.optional(v14.undefined()),
1203
- failed_trusted_authorities: v14.optional(v14.undefined())
1204
- }),
1205
- v14.object({
1206
- success: v14.literal(true),
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
- // src/dcql-query-result/m-dcql-query-result.ts
1220
- var DcqlQueryResult;
1221
- ((DcqlQueryResult2) => {
1222
- DcqlQueryResult2.vCredentialQueryItemCredentialSuccessResult = v15.object({
1223
- success: v15.literal(true),
1224
- input_credential_index: v15.number(),
1225
- trusted_authorities: DcqlTrustedAuthoritiesResult.vTrustedAuthoritySuccessResult,
1226
- // TODO: format specific (we should probably add format to this object, to differentiate?)
1227
- claims: DcqlClaimsResult.vClaimsSuccessResult,
1228
- meta: DcqlMetaResult.vMetaSuccessResult
1229
- });
1230
- DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult = v15.object({
1231
- success: v15.literal(false),
1232
- input_credential_index: v15.number(),
1233
- trusted_authorities: DcqlTrustedAuthoritiesResult.vModel,
1234
- claims: DcqlClaimsResult.vModel,
1235
- meta: DcqlMetaResult.vModel
1236
- });
1237
- DcqlQueryResult2.vCredentialQueryItemResult = v15.union([
1238
- v15.object({
1239
- success: v15.literal(true),
1240
- credential_query_id: vIdString,
1241
- valid_credentials: vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialSuccessResult),
1242
- failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
1243
- }),
1244
- v15.object({
1245
- success: v15.literal(false),
1246
- credential_query_id: vIdString,
1247
- valid_credentials: v15.optional(v15.undefined()),
1248
- failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
1249
- })
1250
- ]);
1251
- DcqlQueryResult2.vCredentialQueryResult = v15.record(vIdString, DcqlQueryResult2.vCredentialQueryItemResult);
1252
- DcqlQueryResult2.vModel = v15.object({
1253
- credentials: v15.pipe(
1254
- vNonEmptyArray(DcqlCredentialQuery.vModel),
1255
- v15.description(
1256
- "REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials."
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
- // src/dcql-presentation/m-dcql-presentation-result.ts
1278
- var DcqlPresentationResult;
1279
- ((DcqlPresentationResult2) => {
1280
- DcqlPresentationResult2.vModel = v16.omit(DcqlQueryResult.vModel, ["credentials"]);
1281
- DcqlPresentationResult2.parse = (input) => {
1282
- return v16.parse(DcqlPresentationResult2.vModel, input);
1283
- };
1284
- DcqlPresentationResult2.fromDcqlPresentation = (dcqlPresentation, ctx) => {
1285
- const { dcqlQuery } = ctx;
1286
- const queriesResults = Object.entries(dcqlPresentation).map(([credentialQueryId, presentations]) => {
1287
- const credentialQuery = dcqlQuery.credentials.find((c) => c.id === credentialQueryId);
1288
- if (!credentialQuery) {
1289
- throw new DcqlPresentationResultError({
1290
- message: `Query ${credentialQueryId} not found in the dcql query. Cannot validate presentation.`
1291
- });
1292
- }
1293
- if (Array.isArray(presentations)) {
1294
- if (presentations.length === 0) {
1295
- throw new DcqlPresentationResultError({
1296
- message: `Query credential '${credentialQueryId}' is present in the presentations but the value is an empty array. Each entry must at least provide one presentation.`
1297
- });
1298
- }
1299
- if (!credentialQuery.multiple && presentations.length > 1) {
1300
- throw new DcqlPresentationResultError({
1301
- 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.`
1302
- });
1303
- }
1304
- }
1305
- return runCredentialQuery(credentialQuery, {
1306
- presentation: true,
1307
- credentials: presentations ? Array.isArray(presentations) ? presentations : [presentations] : []
1308
- });
1309
- });
1310
- const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
1311
- const matchingOptions = set.options.filter(
1312
- (option) => option.every(
1313
- (credentialQueryId) => queriesResults.find((result) => result.credential_query_id === credentialQueryId)?.success
1314
- )
1315
- );
1316
- return {
1317
- ...set,
1318
- matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
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
- // src/dcql-presentation/m-dcql-presentation.ts
1351
- import * as v17 from "valibot";
1352
- var DcqlPresentation;
1353
- ((DcqlPresentation2) => {
1354
- const vPresentationEntry = v17.union([v17.string(), vJsonRecord]);
1355
- DcqlPresentation2.vModel = v17.pipe(
1356
- v17.union([
1357
- v17.record(vIdString, vNonEmptyArray(vPresentationEntry)),
1358
- v17.record(
1359
- vIdString,
1360
- // We support presentation entry directly (not as array) to support older draft of DCQL
1361
- vPresentationEntry
1362
- )
1363
- ]),
1364
- v17.description(
1365
- "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."
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
- // src/dcql-query/m-dcql-query.ts
1406
- import * as v18 from "valibot";
1407
- var DcqlQuery;
1408
- ((DcqlQuery2) => {
1409
- DcqlQuery2.vModel = v18.object({
1410
- credentials: v18.pipe(
1411
- vNonEmptyArray(DcqlCredentialQuery.vModel),
1412
- v18.description(
1413
- "REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials."
1414
- )
1415
- ),
1416
- credential_sets: v18.pipe(
1417
- v18.optional(vNonEmptyArray(CredentialSetQuery.vModel)),
1418
- v18.description(
1419
- "OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."
1420
- )
1421
- )
1422
- });
1423
- DcqlQuery2.validate = (dcqlQuery) => {
1424
- validateUniqueCredentialQueryIds(dcqlQuery);
1425
- validateCredentialSets(dcqlQuery);
1426
- dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate);
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
- var validateUniqueCredentialQueryIds = (query) => {
1436
- const ids = query.credentials.map((c) => c.id);
1437
- const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
1438
- if (duplicates.length > 0) {
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
- var validateCredentialSets = (query) => {
1445
- if (!query.credential_sets) return;
1446
- const credentialQueryIds = new Set(query.credentials.map((c) => c.id));
1447
- const undefinedCredentialQueryIds = [];
1448
- for (const credential_set of query.credential_sets) {
1449
- for (const credentialSetOption of credential_set.options) {
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