dcql 0.4.2 → 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.mjs
CHANGED
@@ -113,6 +113,12 @@ import * as v2 from "valibot";
|
|
113
113
|
// src/u-dcql.ts
|
114
114
|
import * as v from "valibot";
|
115
115
|
var idRegex = /^[a-zA-Z0-9_-]+$/;
|
116
|
+
function asNonEmptyArrayOrUndefined(array8) {
|
117
|
+
return array8.length > 0 ? array8 : void 0;
|
118
|
+
}
|
119
|
+
function isNonEmptyArray(array8) {
|
120
|
+
return array8.length > 0;
|
121
|
+
}
|
116
122
|
var vNonEmptyArray = (item) => {
|
117
123
|
return v.pipe(
|
118
124
|
v.array(item),
|
@@ -646,17 +652,17 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
646
652
|
if (!credentialQuery.claims) {
|
647
653
|
return {
|
648
654
|
success: true,
|
649
|
-
valid_claims:
|
650
|
-
failed_claims:
|
655
|
+
valid_claims: void 0,
|
656
|
+
failed_claims: void 0,
|
651
657
|
valid_claim_sets: [
|
652
658
|
{
|
653
659
|
claim_set_index: void 0,
|
654
660
|
output: {},
|
655
661
|
success: true,
|
656
|
-
valid_claim_indexes:
|
662
|
+
valid_claim_indexes: void 0
|
657
663
|
}
|
658
664
|
],
|
659
|
-
failed_claim_sets:
|
665
|
+
failed_claim_sets: void 0
|
660
666
|
};
|
661
667
|
}
|
662
668
|
const failedClaims = [];
|
@@ -708,7 +714,7 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
708
714
|
success: true,
|
709
715
|
claim_set_index: claimSetIndex,
|
710
716
|
output,
|
711
|
-
valid_claim_indexes: claims.map((claim) => claim.claim_index)
|
717
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(claims.map((claim) => claim.claim_index))
|
712
718
|
});
|
713
719
|
} else {
|
714
720
|
const issues = failedClaims.reduce((merged, claim) => deepMerge(claim.issues, merged), {});
|
@@ -717,24 +723,26 @@ var runClaimsQuery = (credentialQuery, ctx) => {
|
|
717
723
|
issues,
|
718
724
|
claim_set_index: claimSetIndex,
|
719
725
|
failed_claim_indexes: claims.filter((claim) => !claim.success).map((claim) => claim.claim_index),
|
720
|
-
valid_claim_indexes:
|
726
|
+
valid_claim_indexes: asNonEmptyArrayOrUndefined(
|
727
|
+
claims.filter((claim) => claim.success).map((claim) => claim.claim_index)
|
728
|
+
)
|
721
729
|
});
|
722
730
|
}
|
723
731
|
}
|
724
|
-
if (validClaimSets
|
732
|
+
if (isNonEmptyArray(validClaimSets)) {
|
725
733
|
return {
|
726
|
-
success:
|
727
|
-
failed_claim_sets: failedClaimSets,
|
728
|
-
|
729
|
-
valid_claims: validClaims.map(({ parser, ...rest }) => rest)
|
734
|
+
success: true,
|
735
|
+
failed_claim_sets: asNonEmptyArrayOrUndefined(failedClaimSets),
|
736
|
+
valid_claim_sets: validClaimSets,
|
737
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest)),
|
738
|
+
failed_claims: asNonEmptyArrayOrUndefined(failedClaims.map(({ parser, ...rest }) => rest))
|
730
739
|
};
|
731
740
|
}
|
732
741
|
return {
|
733
|
-
success:
|
742
|
+
success: false,
|
734
743
|
failed_claim_sets: failedClaimSets,
|
735
|
-
|
736
|
-
valid_claims: validClaims.map(({ parser, ...rest }) => rest)
|
737
|
-
failed_claims: failedClaims.map(({ parser, ...rest }) => rest)
|
744
|
+
failed_claims: failedClaims.map(({ parser, ...rest }) => rest),
|
745
|
+
valid_claims: asNonEmptyArrayOrUndefined(validClaims.map(({ parser, ...rest }) => rest))
|
738
746
|
};
|
739
747
|
};
|
740
748
|
|
@@ -839,7 +847,7 @@ var runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
|
|
839
847
|
trusted_authority_index: trustedAuthorityIndex,
|
840
848
|
output: parseResult.output
|
841
849
|
},
|
842
|
-
failed_trusted_authorities: failedTrustedAuthorities
|
850
|
+
failed_trusted_authorities: asNonEmptyArrayOrUndefined(failedTrustedAuthorities)
|
843
851
|
};
|
844
852
|
}
|
845
853
|
const issues = v9.flatten(parseResult.issues);
|
@@ -859,12 +867,6 @@ var runTrustedAuthoritiesQuery = (credentialQuery, credential) => {
|
|
859
867
|
// src/dcql-parser/dcql-credential-query-result.ts
|
860
868
|
var runCredentialQuery = (credentialQuery, ctx) => {
|
861
869
|
const { credentials, presentation } = ctx;
|
862
|
-
if (ctx.credentials.length === 0) {
|
863
|
-
throw new DcqlError({
|
864
|
-
message: "Credentials array provided to credential query has length of 0, unable to match credentials against credential query.",
|
865
|
-
code: "BAD_REQUEST"
|
866
|
-
});
|
867
|
-
}
|
868
870
|
const validCredentials = [];
|
869
871
|
const failedCredentials = [];
|
870
872
|
for (const [credentialIndex, credential] of credentials.entries()) {
|
@@ -889,21 +891,20 @@ var runCredentialQuery = (credentialQuery, ctx) => {
|
|
889
891
|
});
|
890
892
|
}
|
891
893
|
}
|
892
|
-
if (
|
894
|
+
if (isNonEmptyArray(validCredentials)) {
|
893
895
|
return {
|
894
|
-
success:
|
896
|
+
success: true,
|
895
897
|
credential_query_id: credentialQuery.id,
|
896
|
-
|
897
|
-
|
898
|
-
valid_credentials: void 0
|
898
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
899
|
+
valid_credentials: validCredentials
|
899
900
|
};
|
900
901
|
}
|
901
902
|
return {
|
902
|
-
success:
|
903
|
+
success: false,
|
903
904
|
credential_query_id: credentialQuery.id,
|
904
|
-
|
905
|
-
|
906
|
-
valid_credentials:
|
905
|
+
// Can be undefined if no credentials were provided to the query
|
906
|
+
failed_credentials: asNonEmptyArrayOrUndefined(failedCredentials),
|
907
|
+
valid_credentials: void 0
|
907
908
|
};
|
908
909
|
};
|
909
910
|
|
@@ -1094,7 +1095,7 @@ var DcqlClaimsResult;
|
|
1094
1095
|
claim_set_index: v12.union([v12.number(), v12.undefined()]),
|
1095
1096
|
// We use indexes because if there are no claim sets, the ids can be undefined
|
1096
1097
|
// Can be empty array in case there are no claims
|
1097
|
-
valid_claim_indexes: v12.
|
1098
|
+
valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
|
1098
1099
|
failed_claim_indexes: v12.optional(v12.undefined()),
|
1099
1100
|
output: vClaimsOutput
|
1100
1101
|
});
|
@@ -1103,20 +1104,20 @@ var DcqlClaimsResult;
|
|
1103
1104
|
// Undefined in case of no claim set
|
1104
1105
|
claim_set_index: v12.union([v12.number(), v12.undefined()]),
|
1105
1106
|
// We use indexes because if there are no claim sets, the ids can be undefined
|
1106
|
-
valid_claim_indexes: v12.
|
1107
|
+
valid_claim_indexes: v12.optional(vNonEmptyArray(v12.number())),
|
1107
1108
|
failed_claim_indexes: vNonEmptyArray(v12.number()),
|
1108
1109
|
issues: v12.record(v12.string(), v12.unknown())
|
1109
1110
|
});
|
1110
1111
|
DcqlClaimsResult2.vClaimsSuccessResult = v12.object({
|
1111
1112
|
success: v12.literal(true),
|
1112
|
-
valid_claims: v12.
|
1113
|
-
failed_claims: v12.
|
1113
|
+
valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
|
1114
|
+
failed_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult)),
|
1114
1115
|
valid_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetSuccessResult),
|
1115
|
-
failed_claim_sets: v12.
|
1116
|
+
failed_claim_sets: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult))
|
1116
1117
|
});
|
1117
1118
|
DcqlClaimsResult2.vClaimsFailureResult = v12.object({
|
1118
1119
|
success: v12.literal(false),
|
1119
|
-
valid_claims: v12.
|
1120
|
+
valid_claims: v12.optional(vNonEmptyArray(DcqlClaimsResult2.vClaimsEntrySuccessResult)),
|
1120
1121
|
failed_claims: vNonEmptyArray(DcqlClaimsResult2.vClaimsEntryFailureResult),
|
1121
1122
|
valid_claim_sets: v12.optional(v12.undefined()),
|
1122
1123
|
failed_claim_sets: vNonEmptyArray(DcqlClaimsResult2.vClaimSetFailureResult)
|
@@ -1169,7 +1170,7 @@ var DcqlTrustedAuthoritiesResult;
|
|
1169
1170
|
v14.object({
|
1170
1171
|
success: v14.literal(true),
|
1171
1172
|
valid_trusted_authority: DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntrySuccessResult,
|
1172
|
-
failed_trusted_authorities: v14.
|
1173
|
+
failed_trusted_authorities: v14.optional(vNonEmptyArray(DcqlTrustedAuthoritiesResult2.vTrustedAuthorityEntryFailureResult))
|
1173
1174
|
})
|
1174
1175
|
]);
|
1175
1176
|
DcqlTrustedAuthoritiesResult2.vTrustedAuthorityFailureResult = v14.object({
|
@@ -1203,13 +1204,13 @@ var DcqlQueryResult;
|
|
1203
1204
|
success: v15.literal(true),
|
1204
1205
|
credential_query_id: vIdString,
|
1205
1206
|
valid_credentials: vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialSuccessResult),
|
1206
|
-
failed_credentials: v15.
|
1207
|
+
failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
|
1207
1208
|
}),
|
1208
1209
|
v15.object({
|
1209
1210
|
success: v15.literal(false),
|
1210
1211
|
credential_query_id: vIdString,
|
1211
1212
|
valid_credentials: v15.optional(v15.undefined()),
|
1212
|
-
failed_credentials: vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult)
|
1213
|
+
failed_credentials: v15.optional(vNonEmptyArray(DcqlQueryResult2.vCredentialQueryItemCredentialFailureResult))
|
1213
1214
|
})
|
1214
1215
|
]);
|
1215
1216
|
DcqlQueryResult2.vCredentialQueryResult = v15.record(vIdString, DcqlQueryResult2.vCredentialQueryItemResult);
|
@@ -1285,7 +1286,7 @@ var DcqlPresentationResult;
|
|
1285
1286
|
const dqclQueryMatched = (
|
1286
1287
|
// We require that all the submitted presentations match with the queries
|
1287
1288
|
// So we must have success for all queries, and we don't allow failed_credentials
|
1288
|
-
queriesResults.every((result) => result.success && result.failed_credentials
|
1289
|
+
queriesResults.every((result) => result.success && !result.failed_credentials) && (credentialSetResults ? credentialSetResults.every((set) => !set.required || set.matching_options) : (
|
1289
1290
|
// If not credential_sets are used, we require that at least every credential has a match
|
1290
1291
|
dcqlQuery.credentials.every(
|
1291
1292
|
(credentialQuery) => queriesResults.find((result) => result.credential_query_id === credentialQuery.id)?.success
|