dcql 0.2.17 → 0.2.19
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/LICENSE +201 -0
- package/README.md +131 -0
- package/dist/index.d.mts +2885 -0
- package/dist/index.d.ts +2885 -0
- package/dist/index.js +1014 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +951 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -23
- package/dist/src/dcql-error/e-base.d.ts +0 -15
- package/dist/src/dcql-error/e-base.d.ts.map +0 -1
- package/dist/src/dcql-error/e-base.js +0 -78
- package/dist/src/dcql-error/e-base.js.map +0 -1
- package/dist/src/dcql-error/e-dcql.d.ts +0 -50
- package/dist/src/dcql-error/e-dcql.d.ts.map +0 -1
- package/dist/src/dcql-error/e-dcql.js +0 -53
- package/dist/src/dcql-error/e-dcql.js.map +0 -1
- package/dist/src/dcql-error/index.d.ts +0 -3
- package/dist/src/dcql-error/index.d.ts.map +0 -1
- package/dist/src/dcql-error/index.js +0 -23
- package/dist/src/dcql-error/index.js.map +0 -1
- package/dist/src/dcql-parser/claims-path.test.d.ts +0 -2
- package/dist/src/dcql-parser/claims-path.test.d.ts.map +0 -1
- package/dist/src/dcql-parser/claims-path.test.js +0 -103
- package/dist/src/dcql-parser/claims-path.test.js.map +0 -1
- package/dist/src/dcql-parser/dcql-claims-query-result.d.ts +0 -25
- package/dist/src/dcql-parser/dcql-claims-query-result.d.ts.map +0 -1
- package/dist/src/dcql-parser/dcql-claims-query-result.js +0 -178
- package/dist/src/dcql-parser/dcql-claims-query-result.js.map +0 -1
- package/dist/src/dcql-parser/dcql-credential-query-result.d.ts +0 -8
- package/dist/src/dcql-parser/dcql-credential-query-result.d.ts.map +0 -1
- package/dist/src/dcql-parser/dcql-credential-query-result.js +0 -65
- package/dist/src/dcql-parser/dcql-credential-query-result.js.map +0 -1
- package/dist/src/dcql-presentation/index.d.ts +0 -4
- package/dist/src/dcql-presentation/index.d.ts.map +0 -1
- package/dist/src/dcql-presentation/index.js +0 -13
- package/dist/src/dcql-presentation/index.js.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-credential-presentation.d.ts +0 -59
- package/dist/src/dcql-presentation/m-dcql-credential-presentation.d.ts.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-credential-presentation.js +0 -55
- package/dist/src/dcql-presentation/m-dcql-credential-presentation.js.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-presentation-result.d.ts +0 -660
- package/dist/src/dcql-presentation/m-dcql-presentation-result.d.ts.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-presentation-result.js +0 -132
- package/dist/src/dcql-presentation/m-dcql-presentation-result.js.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-presentation.d.ts +0 -14
- package/dist/src/dcql-presentation/m-dcql-presentation.d.ts.map +0 -1
- package/dist/src/dcql-presentation/m-dcql-presentation.js +0 -42
- package/dist/src/dcql-presentation/m-dcql-presentation.js.map +0 -1
- package/dist/src/dcql-query/dcql-query-complex.test.d.ts +0 -2
- package/dist/src/dcql-query/dcql-query-complex.test.d.ts.map +0 -1
- package/dist/src/dcql-query/dcql-query-complex.test.js +0 -3204
- package/dist/src/dcql-query/dcql-query-complex.test.js.map +0 -1
- package/dist/src/dcql-query/dcql-query-with-json-transform.test.d.ts +0 -2
- package/dist/src/dcql-query/dcql-query-with-json-transform.test.d.ts.map +0 -1
- package/dist/src/dcql-query/dcql-query-with-json-transform.test.js +0 -188
- package/dist/src/dcql-query/dcql-query-with-json-transform.test.js.map +0 -1
- package/dist/src/dcql-query/dcql-query.test.d.ts +0 -2
- package/dist/src/dcql-query/dcql-query.test.d.ts.map +0 -1
- package/dist/src/dcql-query/dcql-query.test.js +0 -378
- package/dist/src/dcql-query/dcql-query.test.js.map +0 -1
- package/dist/src/dcql-query/index.d.ts +0 -5
- package/dist/src/dcql-query/index.d.ts.map +0 -1
- package/dist/src/dcql-query/index.js +0 -12
- package/dist/src/dcql-query/index.js.map +0 -1
- package/dist/src/dcql-query/m-dcql-claims-query.d.ts +0 -35
- package/dist/src/dcql-query/m-dcql-claims-query.d.ts.map +0 -1
- package/dist/src/dcql-query/m-dcql-claims-query.js +0 -57
- package/dist/src/dcql-query/m-dcql-claims-query.js.map +0 -1
- package/dist/src/dcql-query/m-dcql-credential-query.d.ts +0 -186
- package/dist/src/dcql-query/m-dcql-credential-query.d.ts.map +0 -1
- package/dist/src/dcql-query/m-dcql-credential-query.js +0 -85
- package/dist/src/dcql-query/m-dcql-credential-query.js.map +0 -1
- package/dist/src/dcql-query/m-dcql-credential-set-query.d.ts +0 -18
- package/dist/src/dcql-query/m-dcql-credential-set-query.d.ts.map +0 -1
- package/dist/src/dcql-query/m-dcql-credential-set-query.js +0 -41
- package/dist/src/dcql-query/m-dcql-credential-set-query.js.map +0 -1
- package/dist/src/dcql-query/m-dcql-query.d.ts +0 -843
- package/dist/src/dcql-query/m-dcql-query.d.ts.map +0 -1
- package/dist/src/dcql-query/m-dcql-query.js +0 -89
- package/dist/src/dcql-query/m-dcql-query.js.map +0 -1
- package/dist/src/dcql-query-result/index.d.ts +0 -3
- package/dist/src/dcql-query-result/index.d.ts.map +0 -1
- package/dist/src/dcql-query-result/index.js +0 -8
- package/dist/src/dcql-query-result/index.js.map +0 -1
- package/dist/src/dcql-query-result/m-dcql-query-result.d.ts +0 -883
- package/dist/src/dcql-query-result/m-dcql-query-result.d.ts.map +0 -1
- package/dist/src/dcql-query-result/m-dcql-query-result.js +0 -69
- package/dist/src/dcql-query-result/m-dcql-query-result.js.map +0 -1
- package/dist/src/dcql-query-result/run-dcql-query.d.ts +0 -8
- package/dist/src/dcql-query-result/run-dcql-query.d.ts.map +0 -1
- package/dist/src/dcql-query-result/run-dcql-query.js +0 -56
- package/dist/src/dcql-query-result/run-dcql-query.js.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -27
- package/dist/src/index.js.map +0 -1
- package/dist/src/u-dcql-credential.d.ts +0 -104
- package/dist/src/u-dcql-credential.d.ts.map +0 -1
- package/dist/src/u-dcql-credential.js +0 -84
- package/dist/src/u-dcql-credential.js.map +0 -1
- package/dist/src/u-dcql.d.ts +0 -17
- package/dist/src/u-dcql.d.ts.map +0 -1
- package/dist/src/u-dcql.js +0 -98
- package/dist/src/u-dcql.js.map +0 -1
- package/dist/src/u-model.d.ts +0 -27
- package/dist/src/u-model.d.ts.map +0 -1
- package/dist/src/u-model.js +0 -65
- package/dist/src/u-model.js.map +0 -1
package/dist/index.mjs
ADDED
@@ -0,0 +1,951 @@
|
|
1
|
+
// src/dcql-error/e-base.ts
|
2
|
+
function isObject(value) {
|
3
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
4
|
+
}
|
5
|
+
var UnknownCauseError = class extends Error {
|
6
|
+
};
|
7
|
+
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;
|
26
|
+
}
|
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;
|
35
|
+
};
|
36
|
+
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;
|
48
|
+
}
|
49
|
+
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
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
// src/dcql-error/e-dcql.ts
|
63
|
+
var DcqlCredentialSetError = class extends DcqlError {
|
64
|
+
constructor(opts) {
|
65
|
+
super({ code: "BAD_REQUEST", ...opts });
|
66
|
+
}
|
67
|
+
};
|
68
|
+
var DcqlUndefinedClaimSetIdError = class extends DcqlError {
|
69
|
+
constructor(opts) {
|
70
|
+
super({ code: "BAD_REQUEST", ...opts });
|
71
|
+
}
|
72
|
+
};
|
73
|
+
var DcqlNonUniqueCredentialQueryIdsError = class extends DcqlError {
|
74
|
+
constructor(opts) {
|
75
|
+
super({ code: "BAD_REQUEST", ...opts });
|
76
|
+
}
|
77
|
+
};
|
78
|
+
var DcqlParseError = class extends DcqlError {
|
79
|
+
constructor(opts) {
|
80
|
+
super({ code: "PARSE_ERROR", ...opts });
|
81
|
+
}
|
82
|
+
};
|
83
|
+
var DcqlInvalidClaimsQueryIdError = class extends DcqlError {
|
84
|
+
constructor(opts) {
|
85
|
+
super({ code: "BAD_REQUEST", ...opts });
|
86
|
+
}
|
87
|
+
};
|
88
|
+
var DcqlMissingClaimSetParseError = class extends DcqlError {
|
89
|
+
constructor(opts) {
|
90
|
+
super({ code: "PARSE_ERROR", ...opts });
|
91
|
+
}
|
92
|
+
};
|
93
|
+
var DcqlInvalidPresentationRecordError = class extends DcqlError {
|
94
|
+
constructor(opts) {
|
95
|
+
super({ code: "BAD_REQUEST", ...opts });
|
96
|
+
}
|
97
|
+
};
|
98
|
+
var DcqlPresentationResultError = class extends DcqlError {
|
99
|
+
constructor(opts) {
|
100
|
+
super({ code: "BAD_REQUEST", ...opts });
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
// src/dcql-presentation/m-dcql-credential-presentation.ts
|
105
|
+
import * as v4 from "valibot";
|
106
|
+
|
107
|
+
// src/u-dcql-credential.ts
|
108
|
+
import * as v3 from "valibot";
|
109
|
+
|
110
|
+
// src/u-dcql.ts
|
111
|
+
import * as v from "valibot";
|
112
|
+
var idRegex = /^[a-zA-Z0-9_-]+$/;
|
113
|
+
var vNonEmptyArray = () => {
|
114
|
+
return v.custom((input) => input.length > 0);
|
115
|
+
};
|
116
|
+
var vIdString = v.pipe(v.string(), v.regex(idRegex));
|
117
|
+
function isToJsonable(value) {
|
118
|
+
if (value === null || typeof value !== "object") return false;
|
119
|
+
const toJsonFn = value.toJson;
|
120
|
+
return typeof toJsonFn === "function";
|
121
|
+
}
|
122
|
+
var vWithJT = (schema) => v.pipe(
|
123
|
+
v.custom(() => true),
|
124
|
+
v.rawTransform(({ dataset, addIssue, NEVER }) => {
|
125
|
+
const result = v.safeParse(schema, dataset.value);
|
126
|
+
if (result.success) return dataset.value;
|
127
|
+
if (!isToJsonable(dataset.value)) {
|
128
|
+
for (const safeParseIssue of result.issues) {
|
129
|
+
addIssue({
|
130
|
+
...safeParseIssue,
|
131
|
+
expected: safeParseIssue.expected ?? void 0
|
132
|
+
});
|
133
|
+
}
|
134
|
+
return NEVER;
|
135
|
+
}
|
136
|
+
let json;
|
137
|
+
try {
|
138
|
+
json = dataset.value.toJson();
|
139
|
+
} catch (error) {
|
140
|
+
for (const safeParseIssue of result.issues) {
|
141
|
+
addIssue({
|
142
|
+
...safeParseIssue,
|
143
|
+
expected: safeParseIssue.expected ?? void 0
|
144
|
+
});
|
145
|
+
}
|
146
|
+
addIssue({ message: "Json Transformation failed" });
|
147
|
+
return NEVER;
|
148
|
+
}
|
149
|
+
const safeParseResult = v.safeParse(schema, json);
|
150
|
+
if (safeParseResult.success) return dataset.value;
|
151
|
+
for (const safeParseIssue of safeParseResult.issues) {
|
152
|
+
addIssue({
|
153
|
+
...safeParseIssue,
|
154
|
+
expected: safeParseIssue.expected ?? void 0
|
155
|
+
});
|
156
|
+
}
|
157
|
+
return NEVER;
|
158
|
+
})
|
159
|
+
);
|
160
|
+
var vJsonLiteral = v.union([v.string(), v.number(), v.boolean(), v.null()]);
|
161
|
+
var vJson = v.lazy(
|
162
|
+
() => v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)])
|
163
|
+
);
|
164
|
+
var vJsonWithJT = v.lazy(
|
165
|
+
() => vWithJT(v.union([vJsonLiteral, v.array(vJson), v.record(v.string(), vJson)]))
|
166
|
+
);
|
167
|
+
var vJsonRecord = v.record(v.string(), vJson);
|
168
|
+
var vStringToJson = v.rawTransform(({ dataset, addIssue, NEVER }) => {
|
169
|
+
try {
|
170
|
+
return JSON.parse(dataset.value);
|
171
|
+
} catch (error) {
|
172
|
+
addIssue({ message: "Invalid JSON" });
|
173
|
+
return NEVER;
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
// src/u-model.ts
|
178
|
+
import * as v2 from "valibot";
|
179
|
+
var Model = class {
|
180
|
+
constructor(input) {
|
181
|
+
this.input = input;
|
182
|
+
}
|
183
|
+
get v() {
|
184
|
+
return this.input.vModel;
|
185
|
+
}
|
186
|
+
parse(input) {
|
187
|
+
const result = this.safeParse(input);
|
188
|
+
if (result.success) {
|
189
|
+
return result.output;
|
190
|
+
}
|
191
|
+
return new DcqlParseError({
|
192
|
+
message: JSON.stringify(result.flattened),
|
193
|
+
cause: result.error
|
194
|
+
});
|
195
|
+
}
|
196
|
+
safeParse(input) {
|
197
|
+
const res = v2.safeParse(this.input.vModel, input);
|
198
|
+
if (res.success) {
|
199
|
+
return { success: true, output: res.output };
|
200
|
+
}
|
201
|
+
return {
|
202
|
+
success: false,
|
203
|
+
error: new v2.ValiError(res.issues),
|
204
|
+
flattened: v2.flatten(res.issues)
|
205
|
+
};
|
206
|
+
}
|
207
|
+
is(input) {
|
208
|
+
return v2.is(this.v, input);
|
209
|
+
}
|
210
|
+
};
|
211
|
+
|
212
|
+
// src/u-dcql-credential.ts
|
213
|
+
var DcqlMdocCredential;
|
214
|
+
((DcqlMdocCredential2) => {
|
215
|
+
DcqlMdocCredential2.vNamespaces = v3.record(v3.string(), v3.record(v3.string(), v3.unknown()));
|
216
|
+
DcqlMdocCredential2.vModel = v3.object({
|
217
|
+
credential_format: v3.literal("mso_mdoc"),
|
218
|
+
doctype: v3.string(),
|
219
|
+
namespaces: DcqlMdocCredential2.vNamespaces
|
220
|
+
});
|
221
|
+
DcqlMdocCredential2.model = new Model({ vModel: DcqlMdocCredential2.vModel });
|
222
|
+
})(DcqlMdocCredential || (DcqlMdocCredential = {}));
|
223
|
+
var DcqlSdJwtVcCredential;
|
224
|
+
((DcqlSdJwtVcCredential2) => {
|
225
|
+
DcqlSdJwtVcCredential2.vClaims = vJsonRecord;
|
226
|
+
DcqlSdJwtVcCredential2.vModel = v3.object({
|
227
|
+
credential_format: v3.picklist(["vc+sd-jwt", "dc+sd-jwt"]),
|
228
|
+
vct: v3.string(),
|
229
|
+
claims: DcqlSdJwtVcCredential2.vClaims
|
230
|
+
});
|
231
|
+
DcqlSdJwtVcCredential2.model = new Model({ vModel: DcqlSdJwtVcCredential2.vModel });
|
232
|
+
})(DcqlSdJwtVcCredential || (DcqlSdJwtVcCredential = {}));
|
233
|
+
var DcqlW3cVcCredential;
|
234
|
+
((DcqlW3cVcCredential2) => {
|
235
|
+
DcqlW3cVcCredential2.vClaims = vJsonRecord;
|
236
|
+
DcqlW3cVcCredential2.vModel = v3.object({
|
237
|
+
credential_format: v3.picklist(["jwt_vc_json-ld", "jwt_vc_json"]),
|
238
|
+
claims: DcqlW3cVcCredential2.vClaims
|
239
|
+
});
|
240
|
+
DcqlW3cVcCredential2.model = new Model({ vModel: DcqlW3cVcCredential2.vModel });
|
241
|
+
})(DcqlW3cVcCredential || (DcqlW3cVcCredential = {}));
|
242
|
+
var DcqlCredential;
|
243
|
+
((DcqlCredential2) => {
|
244
|
+
DcqlCredential2.vModel = v3.variant("credential_format", [
|
245
|
+
DcqlMdocCredential.vModel,
|
246
|
+
DcqlSdJwtVcCredential.vModel,
|
247
|
+
DcqlW3cVcCredential.vModel
|
248
|
+
]);
|
249
|
+
DcqlCredential2.vParseSuccess = v3.object({
|
250
|
+
success: v3.literal(true),
|
251
|
+
typed: v3.literal(true),
|
252
|
+
issues: v3.optional(v3.undefined()),
|
253
|
+
input_credential_index: v3.number(),
|
254
|
+
claim_set_index: v3.union([v3.number(), v3.undefined()]),
|
255
|
+
output: DcqlCredential2.vModel
|
256
|
+
});
|
257
|
+
DcqlCredential2.vParseFailure = v3.object({
|
258
|
+
success: v3.literal(false),
|
259
|
+
typed: v3.boolean(),
|
260
|
+
output: v3.unknown(),
|
261
|
+
issues: v3.pipe(v3.array(v3.unknown()), vNonEmptyArray()),
|
262
|
+
input_credential_index: v3.number(),
|
263
|
+
claim_set_index: v3.union([v3.number(), v3.undefined()])
|
264
|
+
});
|
265
|
+
DcqlCredential2.model = new Model({ vModel: DcqlCredential2.vModel });
|
266
|
+
})(DcqlCredential || (DcqlCredential = {}));
|
267
|
+
|
268
|
+
// src/dcql-presentation/m-dcql-credential-presentation.ts
|
269
|
+
var DcqlMdocPresentation;
|
270
|
+
((DcqlMdocPresentation2) => {
|
271
|
+
DcqlMdocPresentation2.vModel = DcqlMdocCredential.vModel;
|
272
|
+
DcqlMdocPresentation2.model = new Model({ vModel: DcqlMdocPresentation2.vModel });
|
273
|
+
})(DcqlMdocPresentation || (DcqlMdocPresentation = {}));
|
274
|
+
var DcqlSdJwtVcPresentation;
|
275
|
+
((DcqlSdJwtVcPresentation2) => {
|
276
|
+
DcqlSdJwtVcPresentation2.vModel = DcqlSdJwtVcCredential.vModel;
|
277
|
+
DcqlSdJwtVcPresentation2.model = new Model({ vModel: DcqlSdJwtVcPresentation2.vModel });
|
278
|
+
})(DcqlSdJwtVcPresentation || (DcqlSdJwtVcPresentation = {}));
|
279
|
+
var DcqlW3cVcPresentation;
|
280
|
+
((DcqlW3cVcPresentation2) => {
|
281
|
+
DcqlW3cVcPresentation2.vModel = DcqlW3cVcCredential.vModel;
|
282
|
+
DcqlW3cVcPresentation2.model = new Model({ vModel: DcqlW3cVcPresentation2.vModel });
|
283
|
+
})(DcqlW3cVcPresentation || (DcqlW3cVcPresentation = {}));
|
284
|
+
var DcqlCredentialPresentation;
|
285
|
+
((DcqlCredentialPresentation2) => {
|
286
|
+
DcqlCredentialPresentation2.model = new Model({
|
287
|
+
vModel: v4.variant("credential_format", [
|
288
|
+
DcqlMdocPresentation.vModel,
|
289
|
+
DcqlSdJwtVcPresentation.vModel,
|
290
|
+
DcqlW3cVcPresentation.vModel
|
291
|
+
])
|
292
|
+
});
|
293
|
+
})(DcqlCredentialPresentation || (DcqlCredentialPresentation = {}));
|
294
|
+
|
295
|
+
// src/dcql-presentation/m-dcql-presentation-result.ts
|
296
|
+
import * as v11 from "valibot";
|
297
|
+
|
298
|
+
// src/dcql-parser/dcql-credential-query-result.ts
|
299
|
+
import * as v6 from "valibot";
|
300
|
+
|
301
|
+
// src/dcql-parser/dcql-claims-query-result.ts
|
302
|
+
import * as v5 from "valibot";
|
303
|
+
var getClaimParser = (input) => {
|
304
|
+
const { value, values } = input;
|
305
|
+
if (value) {
|
306
|
+
return vWithJT(v5.literal(value));
|
307
|
+
}
|
308
|
+
if (values) {
|
309
|
+
return vWithJT(v5.union(values.map((val) => v5.literal(val))));
|
310
|
+
}
|
311
|
+
return v5.nonNullish(v5.any());
|
312
|
+
};
|
313
|
+
var getNamespacesParser = (claimsQueries) => {
|
314
|
+
const claimsForNamespace = {};
|
315
|
+
for (const claimQuery of claimsQueries) {
|
316
|
+
if (claimsForNamespace[claimQuery.namespace]) {
|
317
|
+
claimsForNamespace[claimQuery.namespace]?.push({ ...claimQuery });
|
318
|
+
} else {
|
319
|
+
claimsForNamespace[claimQuery.namespace] = [{ ...claimQuery }];
|
320
|
+
}
|
321
|
+
}
|
322
|
+
const parsersForNamespaces = Object.entries(claimsForNamespace).map(([namespace, claims]) => {
|
323
|
+
const claimParsers = Object.fromEntries(claims.map((claim) => [claim.claim_name, getClaimParser(claim)]));
|
324
|
+
return [namespace, v5.object(claimParsers)];
|
325
|
+
});
|
326
|
+
return v5.object(Object.fromEntries(parsersForNamespaces));
|
327
|
+
};
|
328
|
+
var getClaimQueryParser = (claimQuery, ctx) => {
|
329
|
+
const { index, presentation } = ctx;
|
330
|
+
const pathElement = claimQuery.path[index];
|
331
|
+
const isLast = index === claimQuery.path.length - 1;
|
332
|
+
const vClaimParser = getClaimParser(claimQuery);
|
333
|
+
if (typeof pathElement === "number") {
|
334
|
+
const elementParser = isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 });
|
335
|
+
if (presentation) {
|
336
|
+
return v5.union([
|
337
|
+
v5.pipe(
|
338
|
+
v5.array(vJson),
|
339
|
+
v5.length(1),
|
340
|
+
v5.transform((input) => input[0]),
|
341
|
+
elementParser
|
342
|
+
),
|
343
|
+
elementParser
|
344
|
+
]);
|
345
|
+
}
|
346
|
+
return v5.pipe(
|
347
|
+
v5.array(vJson),
|
348
|
+
v5.transform((input) => input[pathElement]),
|
349
|
+
elementParser
|
350
|
+
);
|
351
|
+
}
|
352
|
+
if (typeof pathElement === "string") {
|
353
|
+
return v5.object({
|
354
|
+
[pathElement]: isLast ? vClaimParser : getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 })
|
355
|
+
});
|
356
|
+
}
|
357
|
+
return isLast ? v5.array(vClaimParser) : v5.array(getClaimQueryParser(claimQuery, { ...ctx, index: index + 1 }));
|
358
|
+
};
|
359
|
+
var getJsonClaimsParser = (claimsQueries, ctx) => {
|
360
|
+
const claimParser = v5.intersect(
|
361
|
+
claimsQueries.map(
|
362
|
+
(claimQuery) => getClaimQueryParser(claimQuery, {
|
363
|
+
...ctx,
|
364
|
+
index: 0
|
365
|
+
})
|
366
|
+
)
|
367
|
+
);
|
368
|
+
return claimParser;
|
369
|
+
};
|
370
|
+
var getMdocClaimsQueriesForClaimSet = (claimsQueries, claimSet) => {
|
371
|
+
return claimSet.map((credential_id) => {
|
372
|
+
const query = claimsQueries.find((query2) => query2.id === credential_id);
|
373
|
+
if (!query) {
|
374
|
+
throw new DcqlInvalidClaimsQueryIdError({
|
375
|
+
message: `Claims-query with id '${credential_id}' not found.`
|
376
|
+
});
|
377
|
+
}
|
378
|
+
return query;
|
379
|
+
});
|
380
|
+
};
|
381
|
+
var getJsonClaimsQueriesForClaimSet = (claimsQueries, claimSet) => {
|
382
|
+
return claimSet.map((credential_id) => {
|
383
|
+
const query = claimsQueries.find((query2) => query2.id === credential_id);
|
384
|
+
if (!query) {
|
385
|
+
throw new DcqlInvalidClaimsQueryIdError({
|
386
|
+
message: `Claims-query with id '${credential_id}' not found.`
|
387
|
+
});
|
388
|
+
}
|
389
|
+
return query;
|
390
|
+
});
|
391
|
+
};
|
392
|
+
var getMdocParser = (credentialQuery, ctx) => {
|
393
|
+
const { claimSet } = ctx;
|
394
|
+
const vDoctype = credentialQuery.meta?.doctype_value ? v5.literal(credentialQuery.meta.doctype_value) : v5.string();
|
395
|
+
const claimSetQueries = credentialQuery.claims && claimSet ? getMdocClaimsQueriesForClaimSet(credentialQuery.claims, claimSet) : credentialQuery.claims;
|
396
|
+
const credentialParser = v5.object({
|
397
|
+
credential_format: v5.literal("mso_mdoc"),
|
398
|
+
doctype: vDoctype,
|
399
|
+
namespaces: claimSetQueries ? getNamespacesParser(claimSetQueries) : v5.record(v5.string(), v5.record(v5.string(), v5.unknown()))
|
400
|
+
});
|
401
|
+
return credentialParser;
|
402
|
+
};
|
403
|
+
var getW3cVcSdJwtVcParser = (credentialQuery, ctx) => {
|
404
|
+
const { claimSet } = ctx;
|
405
|
+
const claimSetQueries = credentialQuery.claims && claimSet ? getJsonClaimsQueriesForClaimSet(credentialQuery.claims, claimSet) : credentialQuery.claims;
|
406
|
+
if (credentialQuery.format === "vc+sd-jwt" || credentialQuery.format === "dc+sd-jwt") {
|
407
|
+
return v5.object({
|
408
|
+
credential_format: v5.literal(credentialQuery.format),
|
409
|
+
vct: credentialQuery.meta?.vct_values ? v5.picklist(credentialQuery.meta.vct_values) : v5.string(),
|
410
|
+
claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord
|
411
|
+
});
|
412
|
+
}
|
413
|
+
const credentialParser = v5.object({
|
414
|
+
credential_format: v5.picklist(["jwt_vc_json", "jwt_vc_json-ld"]),
|
415
|
+
claims: claimSetQueries ? getJsonClaimsParser(claimSetQueries, ctx) : vJsonRecord
|
416
|
+
});
|
417
|
+
return credentialParser;
|
418
|
+
};
|
419
|
+
var getCredentialQueryParser = (credentialQuery, ctx) => {
|
420
|
+
if (credentialQuery.claim_sets && !ctx.claimSet) {
|
421
|
+
throw new DcqlMissingClaimSetParseError({
|
422
|
+
message: "credentialQuery specifies claim_sets but no claim_set for parsing is provided."
|
423
|
+
});
|
424
|
+
}
|
425
|
+
if (credentialQuery.format === "mso_mdoc") {
|
426
|
+
return getMdocParser(credentialQuery, ctx);
|
427
|
+
}
|
428
|
+
return getW3cVcSdJwtVcParser(credentialQuery, ctx);
|
429
|
+
};
|
430
|
+
|
431
|
+
// src/dcql-parser/dcql-credential-query-result.ts
|
432
|
+
var runCredentialQuery = (credentialQuery, ctx) => {
|
433
|
+
const { credentials, presentation } = ctx;
|
434
|
+
const claimSets = credentialQuery.claim_sets ?? [void 0];
|
435
|
+
const credentialQueryResult = new Array(
|
436
|
+
claimSets.length
|
437
|
+
).fill([]);
|
438
|
+
for (const [claimSetIndex, claim_set] of claimSets.entries()) {
|
439
|
+
const credentialParser = getCredentialQueryParser(credentialQuery, {
|
440
|
+
claimSet: claim_set,
|
441
|
+
presentation
|
442
|
+
});
|
443
|
+
for (const [credentialIndex, credential] of credentials.entries()) {
|
444
|
+
if (claimSetIndex > 0) {
|
445
|
+
const previous = credentialQueryResult[claimSetIndex - 1]?.[credentialIndex];
|
446
|
+
if (previous?.success || !previous) {
|
447
|
+
credentialQueryResult[claimSetIndex][credentialIndex] = void 0;
|
448
|
+
continue;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
const parseResult = v6.safeParse(credentialParser, credential);
|
452
|
+
credentialQueryResult[claimSetIndex]?.push({
|
453
|
+
...parseResult,
|
454
|
+
...parseResult.issues && {
|
455
|
+
flattened: v6.flatten(parseResult.issues)
|
456
|
+
},
|
457
|
+
input_credential_index: credentialIndex,
|
458
|
+
claim_set_index: credentialQuery.claim_sets ? claimSetIndex : void 0
|
459
|
+
});
|
460
|
+
}
|
461
|
+
}
|
462
|
+
return credentialQueryResult;
|
463
|
+
};
|
464
|
+
|
465
|
+
// src/dcql-query-result/m-dcql-query-result.ts
|
466
|
+
import * as v10 from "valibot";
|
467
|
+
|
468
|
+
// src/dcql-query/m-dcql-credential-query.ts
|
469
|
+
import * as v8 from "valibot";
|
470
|
+
|
471
|
+
// src/dcql-query/m-dcql-claims-query.ts
|
472
|
+
import * as v7 from "valibot";
|
473
|
+
var DcqlClaimsQuery;
|
474
|
+
((DcqlClaimsQuery2) => {
|
475
|
+
DcqlClaimsQuery2.vValue = v7.union([v7.string(), v7.pipe(v7.number(), v7.integer()), v7.boolean()]);
|
476
|
+
DcqlClaimsQuery2.vPath = v7.union([v7.string(), v7.pipe(v7.number(), v7.integer(), v7.minValue(0)), v7.null()]);
|
477
|
+
DcqlClaimsQuery2.vW3cSdJwtVc = v7.object({
|
478
|
+
id: v7.pipe(
|
479
|
+
v7.optional(v7.pipe(v7.string(), v7.regex(idRegex))),
|
480
|
+
v7.description(
|
481
|
+
"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."
|
482
|
+
)
|
483
|
+
),
|
484
|
+
path: v7.pipe(
|
485
|
+
v7.array(DcqlClaimsQuery2.vPath),
|
486
|
+
v7.description(
|
487
|
+
"A non-empty array representing a claims path pointer that specifies the path to a claim within the Verifiable Credential."
|
488
|
+
)
|
489
|
+
),
|
490
|
+
values: v7.pipe(
|
491
|
+
v7.optional(v7.array(DcqlClaimsQuery2.vValue)),
|
492
|
+
v7.description(
|
493
|
+
"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."
|
494
|
+
)
|
495
|
+
)
|
496
|
+
});
|
497
|
+
DcqlClaimsQuery2.vMdoc = v7.object({
|
498
|
+
id: v7.pipe(
|
499
|
+
v7.optional(v7.pipe(v7.string(), v7.regex(idRegex))),
|
500
|
+
v7.description(
|
501
|
+
"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."
|
502
|
+
)
|
503
|
+
),
|
504
|
+
namespace: v7.pipe(
|
505
|
+
v7.string(),
|
506
|
+
v7.description(
|
507
|
+
"A string that specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1."
|
508
|
+
)
|
509
|
+
),
|
510
|
+
claim_name: v7.pipe(
|
511
|
+
v7.string(),
|
512
|
+
v7.description(
|
513
|
+
"A string that specifies the data element identifier of the data element within the provided namespace in the mdoc, e.g., first_name."
|
514
|
+
)
|
515
|
+
),
|
516
|
+
values: v7.pipe(
|
517
|
+
v7.optional(v7.array(DcqlClaimsQuery2.vValue)),
|
518
|
+
v7.description(
|
519
|
+
"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."
|
520
|
+
)
|
521
|
+
)
|
522
|
+
});
|
523
|
+
DcqlClaimsQuery2.vModel = v7.union([DcqlClaimsQuery2.vMdoc, DcqlClaimsQuery2.vW3cSdJwtVc]);
|
524
|
+
})(DcqlClaimsQuery || (DcqlClaimsQuery = {}));
|
525
|
+
|
526
|
+
// src/dcql-query/m-dcql-credential-query.ts
|
527
|
+
var DcqlCredentialQuery;
|
528
|
+
((DcqlCredentialQuery2) => {
|
529
|
+
const vBase = v8.object({
|
530
|
+
id: v8.pipe(
|
531
|
+
v8.string(),
|
532
|
+
v8.regex(idRegex),
|
533
|
+
v8.description(
|
534
|
+
`REQUIRED. A string identifying the Credential in the response and, if provided, the constraints in 'credential_sets'.`
|
535
|
+
)
|
536
|
+
),
|
537
|
+
claim_sets: v8.pipe(
|
538
|
+
v8.optional(v8.pipe(v8.array(v8.array(v8.pipe(v8.string(), v8.regex(idRegex)))), vNonEmptyArray())),
|
539
|
+
v8.description(
|
540
|
+
`OPTIONAL. A non-empty array containing arrays of identifiers for elements in 'claims' that specifies which combinations of 'claims' for the Credential are requested.`
|
541
|
+
)
|
542
|
+
)
|
543
|
+
});
|
544
|
+
DcqlCredentialQuery2.vMdoc = v8.object({
|
545
|
+
...vBase.entries,
|
546
|
+
format: v8.pipe(
|
547
|
+
v8.literal("mso_mdoc"),
|
548
|
+
v8.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")
|
549
|
+
),
|
550
|
+
claims: v8.pipe(
|
551
|
+
v8.optional(v8.pipe(v8.array(DcqlClaimsQuery.vMdoc), vNonEmptyArray())),
|
552
|
+
v8.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")
|
553
|
+
),
|
554
|
+
meta: v8.pipe(
|
555
|
+
v8.optional(
|
556
|
+
v8.object({
|
557
|
+
doctype_value: v8.pipe(
|
558
|
+
v8.optional(v8.string()),
|
559
|
+
v8.description(
|
560
|
+
"OPTIONAL. String that specifies an allowed value for the doctype of the requested Verifiable Credential."
|
561
|
+
)
|
562
|
+
)
|
563
|
+
})
|
564
|
+
),
|
565
|
+
v8.description(
|
566
|
+
"OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."
|
567
|
+
)
|
568
|
+
)
|
569
|
+
});
|
570
|
+
DcqlCredentialQuery2.vSdJwtVc = v8.object({
|
571
|
+
...vBase.entries,
|
572
|
+
format: v8.pipe(
|
573
|
+
v8.picklist(["vc+sd-jwt", "dc+sd-jwt"]),
|
574
|
+
v8.description("REQUIRED. A string that specifies the format of the requested Verifiable Credential.")
|
575
|
+
),
|
576
|
+
claims: v8.pipe(
|
577
|
+
v8.optional(v8.pipe(v8.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray())),
|
578
|
+
v8.description("OPTIONAL. A non-empty array of objects as that specifies claims in the requested Credential.")
|
579
|
+
),
|
580
|
+
meta: v8.pipe(
|
581
|
+
v8.optional(
|
582
|
+
v8.pipe(
|
583
|
+
v8.object({
|
584
|
+
vct_values: v8.optional(v8.array(v8.string()))
|
585
|
+
}),
|
586
|
+
v8.description(
|
587
|
+
"OPTIONAL. An array of strings that specifies allowed values for the type of the requested Verifiable Credential."
|
588
|
+
)
|
589
|
+
)
|
590
|
+
),
|
591
|
+
v8.description(
|
592
|
+
"OPTIONAL. An object defining additional properties requested by the Verifier that apply to the metadata and validity data of the Credential."
|
593
|
+
)
|
594
|
+
)
|
595
|
+
});
|
596
|
+
DcqlCredentialQuery2.vW3cVc = v8.object({
|
597
|
+
...vBase.entries,
|
598
|
+
format: v8.picklist(["jwt_vc_json", "jwt_vc_json-ld"]),
|
599
|
+
claims: v8.optional(v8.pipe(v8.array(DcqlClaimsQuery.vW3cSdJwtVc), vNonEmptyArray()))
|
600
|
+
});
|
601
|
+
DcqlCredentialQuery2.vModel = v8.variant("format", [DcqlCredentialQuery2.vMdoc, DcqlCredentialQuery2.vSdJwtVc, DcqlCredentialQuery2.vW3cVc]);
|
602
|
+
DcqlCredentialQuery2.validate = (credentialQuery) => {
|
603
|
+
claimSetIdsAreDefined(credentialQuery);
|
604
|
+
};
|
605
|
+
})(DcqlCredentialQuery || (DcqlCredentialQuery = {}));
|
606
|
+
var claimSetIdsAreDefined = (credentialQuery) => {
|
607
|
+
if (!credentialQuery.claim_sets) return;
|
608
|
+
const claimIds = new Set(credentialQuery.claims?.map((claim) => claim.id));
|
609
|
+
const undefinedClaims = [];
|
610
|
+
for (const claim_set of credentialQuery.claim_sets) {
|
611
|
+
for (const claim_id of claim_set) {
|
612
|
+
if (!claimIds.has(claim_id)) {
|
613
|
+
undefinedClaims.push(claim_id);
|
614
|
+
}
|
615
|
+
}
|
616
|
+
}
|
617
|
+
if (undefinedClaims.length > 0) {
|
618
|
+
throw new DcqlUndefinedClaimSetIdError({
|
619
|
+
message: `Credential set contains undefined credential id${undefinedClaims.length === 0 ? "" : "`s"} '${undefinedClaims.join(", ")}'`
|
620
|
+
});
|
621
|
+
}
|
622
|
+
};
|
623
|
+
|
624
|
+
// src/dcql-query/m-dcql-credential-set-query.ts
|
625
|
+
import * as v9 from "valibot";
|
626
|
+
var CredentialSetQuery;
|
627
|
+
((CredentialSetQuery2) => {
|
628
|
+
CredentialSetQuery2.vModel = v9.object({
|
629
|
+
options: v9.pipe(
|
630
|
+
v9.array(v9.array(vIdString)),
|
631
|
+
vNonEmptyArray(),
|
632
|
+
v9.description(
|
633
|
+
"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."
|
634
|
+
)
|
635
|
+
),
|
636
|
+
required: v9.pipe(
|
637
|
+
v9.optional(v9.boolean(), true),
|
638
|
+
v9.description(
|
639
|
+
`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'.`
|
640
|
+
)
|
641
|
+
),
|
642
|
+
purpose: v9.pipe(
|
643
|
+
v9.optional(v9.union([v9.string(), v9.number(), v9.record(v9.string(), v9.unknown())])),
|
644
|
+
v9.description("OPTIONAL. A string, number or object specifying the purpose of the query.")
|
645
|
+
)
|
646
|
+
});
|
647
|
+
})(CredentialSetQuery || (CredentialSetQuery = {}));
|
648
|
+
|
649
|
+
// src/dcql-query-result/m-dcql-query-result.ts
|
650
|
+
var DcqlQueryResult;
|
651
|
+
((DcqlQueryResult2) => {
|
652
|
+
DcqlQueryResult2.vCredentialQueryResult = v10.pipe(
|
653
|
+
v10.array(v10.array(v10.union([v10.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure]))),
|
654
|
+
vNonEmptyArray()
|
655
|
+
);
|
656
|
+
DcqlQueryResult2.vModel = v10.object({
|
657
|
+
credentials: v10.pipe(
|
658
|
+
v10.array(DcqlCredentialQuery.vModel),
|
659
|
+
vNonEmptyArray(),
|
660
|
+
v10.description(
|
661
|
+
"REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials."
|
662
|
+
)
|
663
|
+
),
|
664
|
+
credential_matches: v10.record(
|
665
|
+
v10.pipe(v10.string(), v10.regex(idRegex)),
|
666
|
+
v10.union([
|
667
|
+
v10.object({
|
668
|
+
...DcqlCredential.vParseSuccess.entries,
|
669
|
+
all: v10.pipe(
|
670
|
+
v10.array(
|
671
|
+
v10.pipe(
|
672
|
+
v10.array(v10.union([v10.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),
|
673
|
+
vNonEmptyArray()
|
674
|
+
)
|
675
|
+
),
|
676
|
+
vNonEmptyArray()
|
677
|
+
)
|
678
|
+
}),
|
679
|
+
v10.object({
|
680
|
+
success: DcqlCredential.vParseFailure.entries.success,
|
681
|
+
all: v10.pipe(
|
682
|
+
v10.array(
|
683
|
+
v10.pipe(
|
684
|
+
v10.array(v10.union([v10.undefined(), DcqlCredential.vParseSuccess, DcqlCredential.vParseFailure])),
|
685
|
+
vNonEmptyArray()
|
686
|
+
)
|
687
|
+
),
|
688
|
+
vNonEmptyArray()
|
689
|
+
)
|
690
|
+
})
|
691
|
+
])
|
692
|
+
),
|
693
|
+
credential_sets: v10.optional(
|
694
|
+
v10.pipe(
|
695
|
+
v10.array(
|
696
|
+
v10.object({
|
697
|
+
...CredentialSetQuery.vModel.entries,
|
698
|
+
matching_options: v10.union([v10.undefined(), v10.pipe(v10.array(v10.array(v10.string())), vNonEmptyArray())])
|
699
|
+
})
|
700
|
+
),
|
701
|
+
vNonEmptyArray(),
|
702
|
+
v10.description(
|
703
|
+
"OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."
|
704
|
+
)
|
705
|
+
)
|
706
|
+
),
|
707
|
+
canBeSatisfied: v10.boolean()
|
708
|
+
});
|
709
|
+
})(DcqlQueryResult || (DcqlQueryResult = {}));
|
710
|
+
|
711
|
+
// src/dcql-presentation/m-dcql-presentation-result.ts
|
712
|
+
var DcqlPresentationResult;
|
713
|
+
((DcqlPresentationResult2) => {
|
714
|
+
DcqlPresentationResult2.vModel = v11.object({
|
715
|
+
...v11.omit(DcqlQueryResult.vModel, ["credential_matches"]).entries,
|
716
|
+
invalid_matches: v11.union([
|
717
|
+
v11.record(
|
718
|
+
v11.pipe(v11.string(), v11.regex(idRegex)),
|
719
|
+
v11.object({
|
720
|
+
...v11.omit(DcqlCredential.vParseFailure, ["input_credential_index"]).entries,
|
721
|
+
presentation_id: v11.pipe(v11.string(), v11.regex(idRegex))
|
722
|
+
})
|
723
|
+
),
|
724
|
+
v11.undefined()
|
725
|
+
]),
|
726
|
+
valid_matches: v11.record(
|
727
|
+
v11.pipe(v11.string(), v11.regex(idRegex)),
|
728
|
+
v11.object({
|
729
|
+
...v11.omit(DcqlCredential.vParseSuccess, ["issues", "input_credential_index"]).entries,
|
730
|
+
presentation_id: v11.pipe(v11.string(), v11.regex(idRegex))
|
731
|
+
})
|
732
|
+
)
|
733
|
+
});
|
734
|
+
DcqlPresentationResult2.parse = (input) => {
|
735
|
+
return v11.parse(DcqlPresentationResult2.vModel, input);
|
736
|
+
};
|
737
|
+
DcqlPresentationResult2.fromDcqlPresentation = (dcqlPresentation, ctx) => {
|
738
|
+
const { dcqlQuery } = ctx;
|
739
|
+
const presentationQueriesResults = Object.fromEntries(
|
740
|
+
Object.entries(dcqlPresentation).map(([queryId, presentation]) => {
|
741
|
+
const credentialQuery = dcqlQuery.credentials.find((c) => c.id === queryId);
|
742
|
+
if (!credentialQuery) {
|
743
|
+
throw new DcqlPresentationResultError({
|
744
|
+
message: `Query ${queryId} not found in the dcql query. Cannot validate presentation.`
|
745
|
+
});
|
746
|
+
}
|
747
|
+
return [
|
748
|
+
queryId,
|
749
|
+
runCredentialQuery(credentialQuery, {
|
750
|
+
presentation: true,
|
751
|
+
credentials: [presentation]
|
752
|
+
})
|
753
|
+
];
|
754
|
+
})
|
755
|
+
);
|
756
|
+
let invalidMatches = void 0;
|
757
|
+
const validMatches = {};
|
758
|
+
for (const [queryId, presentationQueryResult] of Object.entries(presentationQueriesResults)) {
|
759
|
+
for (const presentationQueryResultForClaimSet of presentationQueryResult) {
|
760
|
+
const result = presentationQueryResultForClaimSet[0];
|
761
|
+
if (result.success) {
|
762
|
+
const { issues, input_credential_index, ...rest } = result;
|
763
|
+
validMatches[queryId] = { ...rest, presentation_id: queryId };
|
764
|
+
} else {
|
765
|
+
if (!invalidMatches) invalidMatches = {};
|
766
|
+
const { input_credential_index, ...rest } = result;
|
767
|
+
invalidMatches[queryId] = {
|
768
|
+
...rest,
|
769
|
+
presentation_id: queryId
|
770
|
+
};
|
771
|
+
}
|
772
|
+
}
|
773
|
+
}
|
774
|
+
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
775
|
+
const matchingOptions = set.options.filter(
|
776
|
+
(option) => option.every((credentialQueryId) => validMatches[credentialQueryId]?.success)
|
777
|
+
);
|
778
|
+
return {
|
779
|
+
...set,
|
780
|
+
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
781
|
+
};
|
782
|
+
});
|
783
|
+
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : !invalidMatches;
|
784
|
+
return {
|
785
|
+
...dcqlQuery,
|
786
|
+
canBeSatisfied: dqclQueryMatched,
|
787
|
+
valid_matches: validMatches,
|
788
|
+
invalid_matches: invalidMatches,
|
789
|
+
credential_sets: credentialSetResults
|
790
|
+
};
|
791
|
+
};
|
792
|
+
DcqlPresentationResult2.validate = (dcqlQueryResult) => {
|
793
|
+
if (!dcqlQueryResult.canBeSatisfied) {
|
794
|
+
throw new DcqlInvalidPresentationRecordError({
|
795
|
+
message: "Invalid Presentation record",
|
796
|
+
cause: dcqlQueryResult
|
797
|
+
});
|
798
|
+
}
|
799
|
+
return dcqlQueryResult;
|
800
|
+
};
|
801
|
+
})(DcqlPresentationResult || (DcqlPresentationResult = {}));
|
802
|
+
|
803
|
+
// src/dcql-presentation/m-dcql-presentation.ts
|
804
|
+
import * as v12 from "valibot";
|
805
|
+
var DcqlPresentation;
|
806
|
+
((DcqlPresentation2) => {
|
807
|
+
DcqlPresentation2.vModel = v12.record(v12.pipe(v12.string(), v12.regex(idRegex)), v12.union([v12.string(), vJsonRecord]));
|
808
|
+
DcqlPresentation2.parse = (input) => {
|
809
|
+
if (typeof input === "string") {
|
810
|
+
return v12.parse(v12.pipe(v12.string(), vStringToJson, DcqlPresentation2.vModel), input);
|
811
|
+
}
|
812
|
+
return v12.parse(DcqlPresentation2.vModel, input);
|
813
|
+
};
|
814
|
+
DcqlPresentation2.encode = (input) => {
|
815
|
+
return JSON.stringify(input);
|
816
|
+
};
|
817
|
+
})(DcqlPresentation || (DcqlPresentation = {}));
|
818
|
+
|
819
|
+
// src/dcql-query-result/run-dcql-query.ts
|
820
|
+
var runDcqlQuery = (dcqlQuery, ctx) => {
|
821
|
+
const credentialQueriesResults = Object.fromEntries(
|
822
|
+
dcqlQuery.credentials.map((credentialQuery) => [credentialQuery.id, runCredentialQuery(credentialQuery, ctx)])
|
823
|
+
);
|
824
|
+
const credentialMatches = Object.fromEntries(
|
825
|
+
Object.entries(credentialQueriesResults).map(([key, credentialQueryResult]) => {
|
826
|
+
let bestMatch = void 0;
|
827
|
+
for (const credentialParseResult of credentialQueryResult) {
|
828
|
+
const bestMatchForCredential = credentialParseResult.find((result) => result?.success === true);
|
829
|
+
if (!bestMatch && bestMatchForCredential) {
|
830
|
+
const { issues, ...matchWithoutIssues } = bestMatchForCredential;
|
831
|
+
bestMatch = matchWithoutIssues;
|
832
|
+
continue;
|
833
|
+
}
|
834
|
+
if (bestMatchForCredential && bestMatchForCredential.claim_set_index < bestMatch?.claim_set_index) {
|
835
|
+
const { issues, ...matchWithoutIssues } = bestMatchForCredential;
|
836
|
+
bestMatch = matchWithoutIssues;
|
837
|
+
}
|
838
|
+
}
|
839
|
+
return [
|
840
|
+
key,
|
841
|
+
bestMatch ? { ...bestMatch, all: credentialQueryResult } : { success: false, all: credentialQueryResult }
|
842
|
+
];
|
843
|
+
})
|
844
|
+
);
|
845
|
+
const credentialSetResults = dcqlQuery.credential_sets?.map((set) => {
|
846
|
+
const matchingOptions = set.options.filter(
|
847
|
+
(option) => option.every((credentialQueryId) => credentialMatches[credentialQueryId]?.success)
|
848
|
+
);
|
849
|
+
return {
|
850
|
+
...set,
|
851
|
+
matching_options: matchingOptions.length > 0 ? matchingOptions : void 0
|
852
|
+
};
|
853
|
+
});
|
854
|
+
const dqclQueryMatched = credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : Object.values(credentialMatches).every((query) => query.success);
|
855
|
+
return {
|
856
|
+
...dcqlQuery,
|
857
|
+
canBeSatisfied: dqclQueryMatched,
|
858
|
+
credential_matches: credentialMatches,
|
859
|
+
credential_sets: credentialSetResults
|
860
|
+
};
|
861
|
+
};
|
862
|
+
|
863
|
+
// src/dcql-query/m-dcql-query.ts
|
864
|
+
import * as v13 from "valibot";
|
865
|
+
var DcqlQuery;
|
866
|
+
((DcqlQuery2) => {
|
867
|
+
DcqlQuery2.vModel = v13.object({
|
868
|
+
credentials: v13.pipe(
|
869
|
+
v13.array(DcqlCredentialQuery.vModel),
|
870
|
+
vNonEmptyArray(),
|
871
|
+
v13.description(
|
872
|
+
"REQUIRED. A non-empty array of Credential Queries that specify the requested Verifiable Credentials."
|
873
|
+
)
|
874
|
+
),
|
875
|
+
credential_sets: v13.pipe(
|
876
|
+
v13.optional(v13.pipe(v13.array(CredentialSetQuery.vModel), vNonEmptyArray())),
|
877
|
+
v13.description(
|
878
|
+
"OPTIONAL. A non-empty array of credential set queries that specifies additional constraints on which of the requested Verifiable Credentials to return."
|
879
|
+
)
|
880
|
+
)
|
881
|
+
});
|
882
|
+
DcqlQuery2.validate = (dcqlQuery) => {
|
883
|
+
validateUniqueCredentialQueryIds(dcqlQuery);
|
884
|
+
validateCredentialSets(dcqlQuery);
|
885
|
+
dcqlQuery.credentials.forEach(DcqlCredentialQuery.validate);
|
886
|
+
};
|
887
|
+
DcqlQuery2.query = (dcqlQuery, credentials) => {
|
888
|
+
return runDcqlQuery(dcqlQuery, { credentials, presentation: false });
|
889
|
+
};
|
890
|
+
DcqlQuery2.parse = (input) => {
|
891
|
+
return v13.parse(DcqlQuery2.vModel, input);
|
892
|
+
};
|
893
|
+
})(DcqlQuery || (DcqlQuery = {}));
|
894
|
+
var validateUniqueCredentialQueryIds = (query) => {
|
895
|
+
const ids = query.credentials.map((c) => c.id);
|
896
|
+
const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
|
897
|
+
if (duplicates.length > 0) {
|
898
|
+
throw new DcqlNonUniqueCredentialQueryIdsError({
|
899
|
+
message: `Duplicate credential query ids found: ${duplicates.join(", ")}`
|
900
|
+
});
|
901
|
+
}
|
902
|
+
};
|
903
|
+
var validateCredentialSets = (query) => {
|
904
|
+
if (!query.credential_sets) return;
|
905
|
+
const credentialQueryIds = new Set(query.credentials.map((c) => c.id));
|
906
|
+
const undefinedCredentialQueryIds = [];
|
907
|
+
for (const credential_set of query.credential_sets) {
|
908
|
+
for (const credentialSetOption of credential_set.options) {
|
909
|
+
for (const credentialQueryId of credentialSetOption) {
|
910
|
+
if (!credentialQueryIds.has(credentialQueryId)) {
|
911
|
+
undefinedCredentialQueryIds.push(credentialQueryId);
|
912
|
+
}
|
913
|
+
}
|
914
|
+
}
|
915
|
+
}
|
916
|
+
if (undefinedCredentialQueryIds.length > 0) {
|
917
|
+
throw new DcqlCredentialSetError({
|
918
|
+
message: `Credential set contains undefined credential id${undefinedCredentialQueryIds.length === 1 ? "" : "`s"} '${undefinedCredentialQueryIds.join(", ")}'`
|
919
|
+
});
|
920
|
+
}
|
921
|
+
};
|
922
|
+
export {
|
923
|
+
CredentialSetQuery,
|
924
|
+
DcqlClaimsQuery,
|
925
|
+
DcqlCredential,
|
926
|
+
DcqlCredentialPresentation,
|
927
|
+
DcqlCredentialQuery,
|
928
|
+
DcqlCredentialSetError,
|
929
|
+
DcqlError,
|
930
|
+
DcqlInvalidClaimsQueryIdError,
|
931
|
+
DcqlInvalidPresentationRecordError,
|
932
|
+
DcqlMdocCredential,
|
933
|
+
DcqlMdocPresentation,
|
934
|
+
DcqlMissingClaimSetParseError,
|
935
|
+
DcqlNonUniqueCredentialQueryIdsError,
|
936
|
+
DcqlParseError,
|
937
|
+
DcqlPresentation,
|
938
|
+
DcqlPresentationResult,
|
939
|
+
DcqlPresentationResultError,
|
940
|
+
DcqlQuery,
|
941
|
+
DcqlQueryResult,
|
942
|
+
DcqlSdJwtVcCredential,
|
943
|
+
DcqlSdJwtVcPresentation,
|
944
|
+
DcqlUndefinedClaimSetIdError,
|
945
|
+
DcqlW3cVcCredential,
|
946
|
+
DcqlW3cVcPresentation,
|
947
|
+
getCauseFromUnknown,
|
948
|
+
getDcqlErrorFromUnknown,
|
949
|
+
runDcqlQuery
|
950
|
+
};
|
951
|
+
//# sourceMappingURL=index.mjs.map
|