dcql 0.4.3-alpha-20250706143223 → 0.5.0-alpha-20250718124032
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.d.mts +2813 -1394
- package/dist/index.d.ts +2813 -1394
- package/dist/index.js +42 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -177,6 +177,12 @@ var v2 = __toESM(require("valibot"));
|
|
177
177
|
// src/u-dcql.ts
|
178
178
|
var v = __toESM(require("valibot"));
|
179
179
|
var idRegex = /^[a-zA-Z0-9_-]+$/;
|
180
|
+
function asNonEmptyArrayOrUndefined(array8) {
|
181
|
+
return array8.length > 0 ? array8 : void 0;
|
182
|
+
}
|
183
|
+
function isNonEmptyArray(array8) {
|
184
|
+
return array8.length > 0;
|
185
|
+
}
|
180
186
|
var vNonEmptyArray = (item) => {
|
181
187
|
return v.pipe(
|
182
188
|
v.array(item),
|
@@ -710,17 +716,17 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
710
716
|
if (!credentialQuery.claims) {
|
711
717
|
return {
|
712
718
|
success: true,
|
713
|
-
valid_claims:
|
714
|
-
failed_claims:
|
719
|
+
valid_claims: void 0,
|
720
|
+
failed_claims: void 0,
|
715
721
|
valid_claim_sets: [
|
716
722
|
{
|
717
723
|
claim_set_index: void 0,
|
718
724
|
output: {},
|
719
725
|
success: true,
|
720
|
-
valid_claim_indexes:
|
726
|
+
valid_claim_indexes: void 0
|
721
727
|
}
|
722
728
|
],
|
723
|
-
failed_claim_sets:
|
729
|
+
failed_claim_sets: void 0
|
724
730
|
};
|
725
731
|
}
|
726
732
|
const failedClaims = [];
|
@@ -772,7 +778,7 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
772
778
|
success: true,
|
773
779
|
claim_set_index: claimSetIndex,
|
774
780
|
output,
|
775
|
-
valid_claim_indexes: claims.map((claim) => claim.claim_index)
|
781
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(claims.map((claim) => claim.claim_index))
|
776
782
|
});
|
777
783
|
} else {
|
778
784
|
const issues = failedClaims.reduce((merged, claim) => deepMerge(claim.issues, merged), {});
|
@@ -781,24 +787,26 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
781
787
|
issues,
|
782
788
|
claim_set_index: claimSetIndex,
|
783
789
|
failed_claim_indexes: claims.filter((claim) => !claim.success).map((claim) => claim.claim_index),
|
784
|
-
valid_claim_indexes:
|
790
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(
|
791
|
+
claims.filter((claim) => claim.success).map((claim) => claim.claim_index)
|
792
|
+
)
|
785
793
|
});
|
786
794
|
}
|
787
795
|
}
|
788
|
-
if (validClaimSets
|
796
|
+
if (isNonEmptyArray(validClaimSets)) {
|
789
797
|
return {
|
790
|
-
success:
|
791
|
-
failed_claim_sets: failedClaimSets,
|
792
|
-
|
793
|
-
valid_claims: validClaims.map(({ parser, ...rest }) => rest)
|
798
|
+
success: true,
|
799
|
+
failed_claim_sets: asNonEmptyArrayOrUndefined(failedClaimSets),
|
800
|
+
valid_claim_sets: validClaimSets,
|
801
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest)),
|
802
|
+
failed_claims: asNonEmptyArrayOrUndefined(failedClaims.map(({ parser, ...rest }) => rest))
|
794
803
|
};
|
795
804
|
}
|
796
805
|
return {
|
797
|
-
success:
|
806
|
+
success: false,
|
798
807
|
failed_claim_sets: failedClaimSets,
|
799
|
-
|
800
|
-
valid_claims: validClaims.map(({ parser, ...rest }) => rest)
|
801
|
-
failed_claims: failedClaims.map(({ parser, ...rest }) => rest)
|
808
|
+
failed_claims: failedClaims.map(({ parser, ...rest }) => rest),
|
809
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest))
|
802
810
|
};
|
803
811
|
};
|
804
812
|
|
@@ -903,7 +911,7 @@ var runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
|
|
903
911
|
trusted_authority_index: trustedAuthorityIndex,
|
904
912
|
output: parseResult.output
|
905
913
|
},
|
906
|
-
failed_trusted_authorities: failedTrustedAuthorities
|
914
|
+
failed_trusted_authorities: asNonEmptyArrayOrUndefined(failedTrustedAuthorities)
|
907
915
|
};
|
908
916
|
}
|
909
917
|
const issues = v9.flatten(parseResult.issues);
|
@@ -923,12 +931,6 @@ var runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
|
|
923
931
|
// src/dcql-parser/dcql-credential-query-result.ts
|
924
932
|
var runCredentialQuery = (credentialQuery, ctx) => {
|
925
933
|
const { credentials, presentation } = ctx;
|
926
|
-
if (ctx.credentials.length === 0) {
|
927
|
-
throw new DcqlError({
|
928
|
-
message: "Credentials array provided to credential query has length of 0, unable to match credentials against credential query.",
|
929
|
-
code: "BAD_REQUEST"
|
930
|
-
});
|
931
|
-
}
|
932
934
|
const validCredentials = [];
|
933
935
|
const failedCredentials = [];
|
934
936
|
for (const [credentialIndex, credential] of credentials.entries()) {
|
@@ -953,21 +955,20 @@ var runCredentialQuery = (credentialQuery, ctx) => {
|
|
953
955
|
});
|
954
956
|
}
|
955
957
|
}
|
956
|
-
if (
|
958
|
+
if (isNonEmptyArray(validCredentials)) {
|
957
959
|
return {
|
958
|
-
success:
|
960
|
+
success: true,
|
959
961
|
credential_query_id: credentialQuery.id,
|
960
|
-
|
961
|
-
|
962
|
-
valid_credentials: void 0
|
962
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
963
|
+
valid_credentials: validCredentials
|
963
964
|
};
|
964
965
|
}
|
965
966
|
return {
|
966
|
-
success:
|
967
|
+
success: false,
|
967
968
|
credential_query_id: credentialQuery.id,
|
968
|
-
|
969
|
-
|
970
|
-
valid_credentials:
|
969
|
+
// Can be undefined if no credentials were provided to the query
|
970
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
971
|
+
valid_credentials: void 0
|
971
972
|
};
|
972
973
|
};
|
973
974
|
|
@@ -1158,7 +1159,7 @@ var DcqlClaimsResult;
|
|
1158
1159
|
claim_set_index: v12.union([v12.number(), v12.undefined()]),
|
1159
1160
|
// We use indexes because if there are no claim sets, the ids can be undefined
|
1160
1161
|
// Can be empty array in case there are no claims
|
1161
|
-
valid_claim_indexes: v12.
|
1162
|
+
valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
|
1162
1163
|
failed_claim_indexes: v12.optional(v12.undefined()),
|
1163
1164
|
output: vClaimsOutput
|
1164
1165
|
});
|
@@ -1167,20 +1168,20 @@ var DcqlClaimsResult;
|
|
1167
1168
|
// Undefined in case of no claim set
|
1168
1169
|
claim_set_index: v12.union([v12.number(), v12.undefined()]),
|
1169
1170
|
// We use indexes because if there are no claim sets, the ids can be undefined
|
1170
|
-
valid_claim_indexes: v12.
|
1171
|
+
valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
|
1171
1172
|
failed_claim_indexes: vNonEmptyArray(v12.number()),
|
1172
1173
|
issues: v12.record(v12.string(), v12.unknown())
|
1173
1174
|
});
|
1174
1175
|
DcqlClaimsResult2.vClaimsSuccessResult = v12.object({
|
1175
1176
|
success: v12.literal(true),
|
1176
|
-
valid_claims: v12.
|
1177
|
-
failed_claims: v12.
|
1177
|
+
valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
|
1178
|
+
failed_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult)),
|
1178
1179
|
valid_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetSuccessResult),
|
1179
|
-
failed_claim_sets: v12.
|
1180
|
+
failed_claim_sets: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult))
|
1180
1181
|
});
|
1181
1182
|
DcqlClaimsResult2.vClaimsFailureResult = v12.object({
|
1182
1183
|
success: v12.literal(false),
|
1183
|
-
valid_claims: v12.
|
1184
|
+
valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
|
1184
1185
|
failed_claims: vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult),
|
1185
1186
|
valid_claim_sets: v12.optional(v12.undefined()),
|
1186
1187
|
failed_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult)
|
@@ -1233,7 +1234,7 @@ var DcqlTrustedAuthoritiesResult;
|
|
1233
1234
|
v14.object({
|
1234
1235
|
success: v14.literal(true),
|
1235
1236
|
valid_trusted_authority: DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntrySuccessResult,
|
1236
|
-
failed_trusted_authorities: v14.
|
1237
|
+
failed_trusted_authorities: v14.optional(vNonEmptyArray(DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntryFailureResult))
|
1237
1238
|
})
|
1238
1239
|
]);
|
1239
1240
|
DcqlTrustedAuthoritiesResult2.vTrustedAuthorityFailureResult = v14.object({
|
@@ -1267,13 +1268,13 @@ var DcqlQueryResult;
|
|
1267
1268
|
success: v15.literal(true),
|
1268
1269
|
credential_query_id: vIdString,
|
1269
1270
|
valid_credentials: vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialSuccessResult),
|
1270
|
-
failed_credentials: v15.
|
1271
|
+
failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
|
1271
1272
|
}),
|
1272
1273
|
v15.object({
|
1273
1274
|
success: v15.literal(false),
|
1274
1275
|
credential_query_id: vIdString,
|
1275
1276
|
valid_credentials: v15.optional(v15.undefined()),
|
1276
|
-
failed_credentials: vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult)
|
1277
|
+
failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
|
1277
1278
|
})
|
1278
1279
|
]);
|
1279
1280
|
DcqlQueryResult2.vCredentialQueryResult = v15.record(vIdString, DcqlQueryResult2.vCredentialQueryItemResult);
|
@@ -1349,7 +1350,7 @@ var DcqlPresentationResult;
|
|
1349
1350
|
const dqclQueryMatched = (
|
1350
1351
|
// We require that all the submitted presentations match with the queries
|
1351
1352
|
// So we must have success for all queries, and we don't allow failed_credentials
|
1352
|
-
queriesResults.every((result) => result.success && result.failed_credentials
|
1353
|
+
queriesResults.every((result) => result.success && !result.failed_credentials) && (credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : (
|
1353
1354
|
// If not credential_sets are used, we require that at least every credential has a match
|
1354
1355
|
dcqlQuery.credentials.every(
|
1355
1356
|
(credentialQuery) => queriesResults.find((result) => result.credential_query_id === credentialQuery.id)?.success
|