dcql 0.2.2 → 0.2.4
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/src/dcql-query/claims-path.d.ts +14 -0
- package/dist/src/dcql-query/claims-path.d.ts.map +1 -0
- package/dist/src/dcql-query/claims-path.js +23 -0
- package/dist/src/dcql-query/claims-path.js.map +1 -0
- package/dist/src/dcql-query/claims-path.test.d.ts +2 -0
- package/dist/src/dcql-query/claims-path.test.d.ts.map +1 -0
- package/dist/src/dcql-query/claims-path.test.js +97 -0
- package/dist/src/dcql-query/claims-path.test.js.map +1 -0
- package/dist/src/dcql-query/dcql-query.d.ts +5 -0
- package/dist/src/dcql-query/dcql-query.d.ts.map +1 -0
- package/dist/src/dcql-query/dcql-query.js +53 -0
- package/dist/src/dcql-query/dcql-query.js.map +1 -0
- package/dist/src/dcql-query/dcql-query.test.d.ts +2 -0
- package/dist/src/dcql-query/dcql-query.test.d.ts.map +1 -0
- package/dist/src/dcql-query/dcql-query.test.js +165 -0
- package/dist/src/dcql-query/dcql-query.test.js.map +1 -0
- package/dist/src/dcql-query/m-dcql-claims-query.d.ts +37 -0
- package/dist/src/dcql-query/m-dcql-claims-query.d.ts.map +1 -0
- package/dist/src/dcql-query/m-dcql-claims-query.js +57 -0
- package/dist/src/dcql-query/m-dcql-claims-query.js.map +1 -0
- package/dist/src/dcql-query/m-dcql-credential-query.d.ts +186 -0
- package/dist/src/dcql-query/m-dcql-credential-query.d.ts.map +1 -0
- package/dist/src/dcql-query/m-dcql-credential-query.js +85 -0
- package/dist/src/dcql-query/m-dcql-credential-query.js.map +1 -0
- package/dist/src/dcql-query/m-dcql-credential-set-query.d.ts +18 -0
- package/dist/src/dcql-query/m-dcql-credential-set-query.d.ts.map +1 -0
- package/dist/src/dcql-query/m-dcql-credential-set-query.js +41 -0
- package/dist/src/dcql-query/m-dcql-credential-set-query.js.map +1 -0
- package/dist/src/dcql-query/m-dcql-query.d.ts +433 -0
- package/dist/src/dcql-query/m-dcql-query.d.ts.map +1 -0
- package/dist/src/dcql-query/m-dcql-query.js +89 -0
- package/dist/src/dcql-query/m-dcql-query.js.map +1 -0
- package/dist/src/dcql-query-result/dcql-claims-query-result.d.ts +81 -0
- package/dist/src/dcql-query-result/dcql-claims-query-result.d.ts.map +1 -0
- package/dist/src/dcql-query-result/dcql-claims-query-result.js +158 -0
- package/dist/src/dcql-query-result/dcql-claims-query-result.js.map +1 -0
- package/dist/src/dcql-query-result/dcql-credential-query-result.d.ts +38 -0
- package/dist/src/dcql-query-result/dcql-credential-query-result.d.ts.map +1 -0
- package/dist/src/dcql-query-result/dcql-credential-query-result.js +61 -0
- package/dist/src/dcql-query-result/dcql-credential-query-result.js.map +1 -0
- package/dist/src/dcql-query-result/m-dcql-query-result.d.ts +730 -0
- package/dist/src/dcql-query-result/m-dcql-query-result.d.ts.map +1 -0
- package/dist/src/dcql-query-result/m-dcql-query-result.js +78 -0
- package/dist/src/dcql-query-result/m-dcql-query-result.js.map +1 -0
- package/dist/src/dcql-query-vp-token/m-dcql-query-vp-token.d.ts +65 -0
- package/dist/src/dcql-query-vp-token/m-dcql-query-vp-token.d.ts.map +1 -0
- package/dist/src/dcql-query-vp-token/m-dcql-query-vp-token.js +50 -0
- package/dist/src/dcql-query-vp-token/m-dcql-query-vp-token.js.map +1 -0
- package/dist/src/e-base.d.ts +15 -0
- package/dist/src/e-base.d.ts.map +1 -0
- package/dist/{esm/src → src}/e-base.js +18 -23
- package/dist/src/e-base.js.map +1 -0
- package/dist/src/e-dcql.d.ts +32 -0
- package/dist/src/e-dcql.d.ts.map +1 -0
- package/dist/src/e-dcql.js +35 -0
- package/dist/src/e-dcql.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +30 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/u-dcql-credential-representation.d.ts +28 -0
- package/dist/src/u-dcql-credential-representation.d.ts.map +1 -0
- package/dist/src/u-dcql-credential-representation.js +32 -0
- package/dist/src/u-dcql-credential-representation.js.map +1 -0
- package/dist/src/u-dcql.d.ts +49 -0
- package/dist/src/u-dcql.d.ts.map +1 -0
- package/dist/src/u-dcql.js +76 -0
- package/dist/src/u-dcql.js.map +1 -0
- package/package.json +14 -9
- package/.cache/tsbuildinfo.json +0 -1
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -7
- package/dist/esm/src/claims-query/claims-query-result.d.ts +0 -24
- package/dist/esm/src/claims-query/claims-query-result.d.ts.map +0 -1
- package/dist/esm/src/claims-query/claims-query-result.js +0 -67
- package/dist/esm/src/claims-query/claims-query-result.js.map +0 -1
- package/dist/esm/src/claims-query/v-claims-query-result.d.ts +0 -82
- package/dist/esm/src/claims-query/v-claims-query-result.d.ts.map +0 -1
- package/dist/esm/src/claims-query/v-claims-query-result.js +0 -30
- package/dist/esm/src/claims-query/v-claims-query-result.js.map +0 -1
- package/dist/esm/src/claims-query/v-claims-query.d.ts +0 -34
- package/dist/esm/src/claims-query/v-claims-query.d.ts.map +0 -1
- package/dist/esm/src/claims-query/v-claims-query.js +0 -24
- package/dist/esm/src/claims-query/v-claims-query.js.map +0 -1
- package/dist/esm/src/credential-query/credential-query-result.d.ts +0 -101
- package/dist/esm/src/credential-query/credential-query-result.d.ts.map +0 -1
- package/dist/esm/src/credential-query/credential-query-result.js +0 -91
- package/dist/esm/src/credential-query/credential-query-result.js.map +0 -1
- package/dist/esm/src/credential-query/v-credential-query-result.d.ts +0 -696
- package/dist/esm/src/credential-query/v-credential-query-result.d.ts.map +0 -1
- package/dist/esm/src/credential-query/v-credential-query-result.js +0 -44
- package/dist/esm/src/credential-query/v-credential-query-result.js.map +0 -1
- package/dist/esm/src/credential-query/v-credential-query.d.ts +0 -109
- package/dist/esm/src/credential-query/v-credential-query.d.ts.map +0 -1
- package/dist/esm/src/credential-query/v-credential-query.js +0 -57
- package/dist/esm/src/credential-query/v-credential-query.js.map +0 -1
- package/dist/esm/src/e-base.d.ts +0 -25
- package/dist/esm/src/e-base.d.ts.map +0 -1
- package/dist/esm/src/e-base.js.map +0 -1
- package/dist/esm/src/e-vp-query.d.ts +0 -32
- package/dist/esm/src/e-vp-query.d.ts.map +0 -1
- package/dist/esm/src/e-vp-query.js +0 -27
- package/dist/esm/src/e-vp-query.js.map +0 -1
- package/dist/esm/src/index.d.ts +0 -7
- package/dist/esm/src/index.d.ts.map +0 -1
- package/dist/esm/src/index.js +0 -7
- package/dist/esm/src/index.js.map +0 -1
- package/dist/esm/src/u-query.d.ts +0 -20
- package/dist/esm/src/u-query.d.ts.map +0 -1
- package/dist/esm/src/u-query.js +0 -25
- package/dist/esm/src/u-query.js.map +0 -1
- package/dist/esm/src/vp-query/v-vp-query-result.d.ts +0 -767
- package/dist/esm/src/vp-query/v-vp-query-result.d.ts.map +0 -1
- package/dist/esm/src/vp-query/v-vp-query-result.js +0 -18
- package/dist/esm/src/vp-query/v-vp-query-result.js.map +0 -1
- package/dist/esm/src/vp-query/v-vp-query.d.ts +0 -94
- package/dist/esm/src/vp-query/v-vp-query.d.ts.map +0 -1
- package/dist/esm/src/vp-query/v-vp-query.js +0 -52
- package/dist/esm/src/vp-query/v-vp-query.js.map +0 -1
- package/dist/esm/src/vp-query/vp-query.d.ts +0 -5
- package/dist/esm/src/vp-query/vp-query.d.ts.map +0 -1
- package/dist/esm/src/vp-query/vp-query.fixtures.d.ts +0 -7
- package/dist/esm/src/vp-query/vp-query.fixtures.d.ts.map +0 -1
- package/dist/esm/src/vp-query/vp-query.fixtures.js +0 -172
- package/dist/esm/src/vp-query/vp-query.fixtures.js.map +0 -1
- package/dist/esm/src/vp-query/vp-query.js +0 -21
- package/dist/esm/src/vp-query/vp-query.js.map +0 -1
- package/dist/esm/src/vp-query/vp-query.test.d.ts +0 -31
- package/dist/esm/src/vp-query/vp-query.test.d.ts.map +0 -1
- package/dist/esm/src/vp-query/vp-query.test.js +0 -130
- package/dist/esm/src/vp-query/vp-query.test.js.map +0 -1
- package/eslint.config.js +0 -10
- package/src/claims-query/claims-query-result.ts +0 -104
- package/src/claims-query/v-claims-query-result.ts +0 -42
- package/src/claims-query/v-claims-query.ts +0 -34
- package/src/credential-query/credential-query-result.ts +0 -130
- package/src/credential-query/v-credential-query-result.ts +0 -71
- package/src/credential-query/v-credential-query.ts +0 -85
- package/src/e-base.ts +0 -116
- package/src/e-vp-query.ts +0 -31
- package/src/index.ts +0 -6
- package/src/u-query.ts +0 -39
- package/src/vp-query/v-vp-query-result.ts +0 -23
- package/src/vp-query/v-vp-query.ts +0 -71
- package/src/vp-query/vp-query.fixtures.ts +0 -178
- package/src/vp-query/vp-query.test.ts +0 -156
- package/src/vp-query/vp-query.ts +0 -44
- package/tsconfig.json +0 -5
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { CredentialQuery } from '../credential-query/v-credential-query.js';
|
|
3
|
-
import {
|
|
4
|
-
InvalidCredentialQueryIdError,
|
|
5
|
-
VpQueryCredentialSetError,
|
|
6
|
-
VpQueryNonUniqueCredentialQueryIdsError,
|
|
7
|
-
} from '../e-vp-query.js';
|
|
8
|
-
import { credentialSetIdRegex, getIdMetadata } from '../u-query.js';
|
|
9
|
-
import { queryVerifiablePresentation } from './vp-query.js';
|
|
10
|
-
|
|
11
|
-
export namespace VpQuery {
|
|
12
|
-
export const vModel = v.object({
|
|
13
|
-
credentials: v.pipe(v.array(CredentialQuery.vModel), v.nonEmpty()),
|
|
14
|
-
credential_sets: v.optional(
|
|
15
|
-
v.pipe(
|
|
16
|
-
v.array(v.array(v.pipe(v.string(), v.regex(credentialSetIdRegex)))),
|
|
17
|
-
v.nonEmpty()
|
|
18
|
-
)
|
|
19
|
-
),
|
|
20
|
-
});
|
|
21
|
-
export type Input = v.InferInput<typeof vModel>;
|
|
22
|
-
export type Out = v.InferOutput<typeof vModel>;
|
|
23
|
-
export const validate = (vpQuery: Out) => {
|
|
24
|
-
validateUniqueCredentialQueryIds(vpQuery);
|
|
25
|
-
validateCredentialSets(vpQuery);
|
|
26
|
-
};
|
|
27
|
-
export const query = queryVerifiablePresentation;
|
|
28
|
-
}
|
|
29
|
-
export type VpQuery = VpQuery.Out;
|
|
30
|
-
|
|
31
|
-
// --- validations --- //
|
|
32
|
-
|
|
33
|
-
const validateUniqueCredentialQueryIds = (query: VpQuery.Out) => {
|
|
34
|
-
const ids = query.credentials.map(c => c.id);
|
|
35
|
-
const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
36
|
-
|
|
37
|
-
if (duplicates.length > 0) {
|
|
38
|
-
throw new VpQueryNonUniqueCredentialQueryIdsError({
|
|
39
|
-
message: `Duplicate credential query ids found: ${duplicates.join(', ')}`,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const validateCredentialSets = (query: VpQuery.Out) => {
|
|
45
|
-
if (!query.credential_sets) return;
|
|
46
|
-
|
|
47
|
-
const credentialIds = new Set(query.credentials.map(c => c.id));
|
|
48
|
-
const undefinedCredentials: string[] = [];
|
|
49
|
-
for (const credential_set of query.credential_sets) {
|
|
50
|
-
for (const credential_id of credential_set) {
|
|
51
|
-
const { baseId, isRequiredIfPresent } = getIdMetadata(credential_id);
|
|
52
|
-
|
|
53
|
-
if (isRequiredIfPresent) {
|
|
54
|
-
throw new InvalidCredentialQueryIdError({
|
|
55
|
-
message:
|
|
56
|
-
'Invalid credential-query id. Required if present operator can only be applied to credential queries.',
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!credentialIds.has(baseId)) {
|
|
61
|
-
undefinedCredentials.push(credential_id);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (undefinedCredentials.length > 1) {
|
|
67
|
-
throw new VpQueryCredentialSetError({
|
|
68
|
-
message: `Credential set contains undefined credential id${undefinedCredentials.length === 1 ? '' : '`s'} '${undefinedCredentials.join(', ')}'`,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import type { VpQuery } from './v-vp-query.js';
|
|
2
|
-
|
|
3
|
-
export const simple: VpQuery = {
|
|
4
|
-
credentials: [
|
|
5
|
-
{
|
|
6
|
-
id: 'my_credential',
|
|
7
|
-
format: 'vc+sd-jwt',
|
|
8
|
-
meta: {
|
|
9
|
-
vct_values: ['https://credentials.example.com/identity_credential'],
|
|
10
|
-
},
|
|
11
|
-
claims: [
|
|
12
|
-
{ path: ['last_name'] },
|
|
13
|
-
{ path: ['first_name'] },
|
|
14
|
-
{ path: ['address', 'street_address'] },
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const matchingSimple: VpQuery = {
|
|
21
|
-
credentials: [
|
|
22
|
-
{
|
|
23
|
-
id: 'my_credential',
|
|
24
|
-
format: 'vc+sd-jwt',
|
|
25
|
-
meta: {
|
|
26
|
-
vct_values: ['https://credentials.example.com/identity_credential'],
|
|
27
|
-
},
|
|
28
|
-
claims: [
|
|
29
|
-
{
|
|
30
|
-
path: ['last_name'],
|
|
31
|
-
values: ['Doe'],
|
|
32
|
-
},
|
|
33
|
-
{ path: ['first_name'] },
|
|
34
|
-
{ path: ['address', 'street_address'] },
|
|
35
|
-
{
|
|
36
|
-
path: ['postal_code'],
|
|
37
|
-
values: ['90210', '90211'],
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const multiCredentials: VpQuery = {
|
|
45
|
-
credentials: [
|
|
46
|
-
{
|
|
47
|
-
id: 'pid',
|
|
48
|
-
format: 'vc+sd-jwt',
|
|
49
|
-
meta: {
|
|
50
|
-
vct_values: ['https://credentials.example.com/identity_credential'],
|
|
51
|
-
},
|
|
52
|
-
claims: [
|
|
53
|
-
{ path: ['given_name'] },
|
|
54
|
-
{ path: ['family_name'] },
|
|
55
|
-
{ path: ['address', 'street_address'] },
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: 'mdl',
|
|
60
|
-
format: 'mso_mdoc',
|
|
61
|
-
meta: {
|
|
62
|
-
doctype_values: ['org.iso.7367.1.mVR'],
|
|
63
|
-
},
|
|
64
|
-
claims: [
|
|
65
|
-
{
|
|
66
|
-
namespace: 'org.iso.7367.1',
|
|
67
|
-
claim_name: 'vehicle_holder',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
namespace: 'org.iso.18013.5.1',
|
|
71
|
-
claim_name: 'first_name',
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const credentialAlternatives: VpQuery = {
|
|
79
|
-
credentials: [
|
|
80
|
-
{
|
|
81
|
-
id: 'pid',
|
|
82
|
-
format: 'vc+sd-jwt',
|
|
83
|
-
meta: {
|
|
84
|
-
vct_values: ['https://credentials.example.com/identity_credential'],
|
|
85
|
-
},
|
|
86
|
-
claims: [
|
|
87
|
-
{ path: ['given_name'] },
|
|
88
|
-
{ path: ['family_name'] },
|
|
89
|
-
{ path: ['address', 'street_address'] },
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
id: 'other_pid',
|
|
94
|
-
format: 'vc+sd-jwt',
|
|
95
|
-
meta: {
|
|
96
|
-
vct_values: ['https://othercredentials.example/pid'],
|
|
97
|
-
},
|
|
98
|
-
claims: [
|
|
99
|
-
{ path: ['given_name'] },
|
|
100
|
-
{ path: ['family_name'] },
|
|
101
|
-
{ path: ['address', 'street_address'] },
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
id: 'pid_reduced_cred_1',
|
|
106
|
-
format: 'vc+sd-jwt',
|
|
107
|
-
meta: {
|
|
108
|
-
vct_values: [
|
|
109
|
-
'https://credentials.example.com/reduced_identity_credential',
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
claims: [{ path: ['family_name'] }, { path: ['given_name'] }],
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
id: 'pid_reduced_cred_2',
|
|
116
|
-
format: 'vc+sd-jwt',
|
|
117
|
-
meta: {
|
|
118
|
-
vct_values: ['https://cred.example/residence_credential'],
|
|
119
|
-
},
|
|
120
|
-
claims: [
|
|
121
|
-
{ path: ['postal_code'] },
|
|
122
|
-
{ path: ['locality'] },
|
|
123
|
-
{ path: ['region'] },
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
id: 'nice_to_have',
|
|
128
|
-
format: 'vc+sd-jwt',
|
|
129
|
-
meta: {
|
|
130
|
-
vct_values: ['https://company.example/company_rewards'],
|
|
131
|
-
},
|
|
132
|
-
claims: [
|
|
133
|
-
{ id: 'current', path: ['rewards_number'] },
|
|
134
|
-
{ id: 'legacy', path: ['legacy_system_rewards_number'] },
|
|
135
|
-
],
|
|
136
|
-
claim_sets: [['current', 'legacy?']],
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
credential_sets: [
|
|
140
|
-
// deliver the pid, or the other_pid, or both pid_reduced_cred1 + 2; nice_to_have is optional in all cases
|
|
141
|
-
['pid', 'nice_to_have?'],
|
|
142
|
-
['other_pid', 'nice_to_have?'],
|
|
143
|
-
['pid_reduced_cred_1', 'pid_reduced_cred_2', 'nice_to_have?'],
|
|
144
|
-
],
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const claimAlternatives: VpQuery = {
|
|
148
|
-
credentials: [
|
|
149
|
-
{
|
|
150
|
-
id: 'pid',
|
|
151
|
-
format: 'vc+sd-jwt',
|
|
152
|
-
meta: {
|
|
153
|
-
vct_values: ['https://credentials.example.com/identity_credential'],
|
|
154
|
-
},
|
|
155
|
-
// Comments in JSON to be removed before merging PR, they are just here to make Brian less sad
|
|
156
|
-
claims: [
|
|
157
|
-
// define claims, may add other properties like a purpose to each claims
|
|
158
|
-
{
|
|
159
|
-
id: 'a', // required for use in claim_sets below; if that is omitted, the id is optional
|
|
160
|
-
path: ['last_name'],
|
|
161
|
-
},
|
|
162
|
-
{ id: 'b', path: ['postal_code'] },
|
|
163
|
-
{ id: 'c', path: ['locality'] },
|
|
164
|
-
{ id: 'd', path: ['region'] },
|
|
165
|
-
{ id: 'e', path: ['date_of_birth'] },
|
|
166
|
-
{ id: 'f', path: ['email'] },
|
|
167
|
-
],
|
|
168
|
-
claim_sets: [
|
|
169
|
-
// defines the rules
|
|
170
|
-
// postal code or (locality and region), last_name, and date_of_birth are mandatory; email is optional
|
|
171
|
-
['a', 'b', 'e', 'f?'],
|
|
172
|
-
['a', 'c', 'd', 'e', 'f?'],
|
|
173
|
-
|
|
174
|
-
// Note: the ? to mark a claim as optional is syntactical sugar; the rules could be rewritten without it, but that would require a lot of repetition
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import * as v from 'valibot';
|
|
3
|
-
import type { VpQueryResult } from './v-vp-query-result.js';
|
|
4
|
-
import { VpQuery } from './v-vp-query.js';
|
|
5
|
-
|
|
6
|
-
export class ResultBuilder {
|
|
7
|
-
private autoComplete: boolean;
|
|
8
|
-
constructor(private vpQueryResult: VpQueryResult) {
|
|
9
|
-
this.autoComplete = false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
disableAutoComplete(disabled?: boolean) {
|
|
13
|
-
this.autoComplete = !(disabled ?? true);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getSolutionSpace() {
|
|
17
|
-
const solutionSpace: {
|
|
18
|
-
credentialSetIndex: number;
|
|
19
|
-
claimSets: {
|
|
20
|
-
claimSetIndex: number;
|
|
21
|
-
credentialIndices: number[];
|
|
22
|
-
}[];
|
|
23
|
-
}[] = [];
|
|
24
|
-
|
|
25
|
-
for (const [
|
|
26
|
-
credentialSetIndex,
|
|
27
|
-
credentialSetResults,
|
|
28
|
-
] of this.vpQueryResult.credential_sets_results.entries()) {
|
|
29
|
-
if (!credentialSetResults.areRequiredCredentialsPresent) continue;
|
|
30
|
-
|
|
31
|
-
const claimSets = credentialSetResults.credential_set_result.flatMap(
|
|
32
|
-
credentialSetResultsForCredential => {
|
|
33
|
-
return credentialSetResultsForCredential.claim_sets_results.flatMap(
|
|
34
|
-
(claimSetResults, claimSetIndex) => {
|
|
35
|
-
const credentialIndices = claimSetResults
|
|
36
|
-
.map((claimSetResultForCredential, credentialIndex) =>
|
|
37
|
-
claimSetResultForCredential.areRequiredClaimsPresent
|
|
38
|
-
? credentialIndex
|
|
39
|
-
: -1
|
|
40
|
-
)
|
|
41
|
-
.filter(index => index !== -1);
|
|
42
|
-
|
|
43
|
-
return credentialIndices.length > 0
|
|
44
|
-
? [{ claimSetIndex, credentialIndices }]
|
|
45
|
-
: [];
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (claimSets.length > 0) {
|
|
52
|
-
solutionSpace.push({ credentialSetIndex, claimSets });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return solutionSpace;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const simpleMdoc = {
|
|
61
|
-
credentials: [
|
|
62
|
-
{
|
|
63
|
-
id: 'my_credential',
|
|
64
|
-
format: 'mso_mdoc',
|
|
65
|
-
meta: {
|
|
66
|
-
doctype_values: ['org.iso.7367.1.mVR'],
|
|
67
|
-
},
|
|
68
|
-
claims: [
|
|
69
|
-
{
|
|
70
|
-
id: 'a',
|
|
71
|
-
namespace: 'org.iso.7367.1',
|
|
72
|
-
claim_name: 'vehicle_holder',
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
id: 'b',
|
|
76
|
-
namespace: 'org.iso.18013.5.1',
|
|
77
|
-
claim_name: 'first_name',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
id: 'c',
|
|
81
|
-
namespace: 'org.iso.18013.5.1',
|
|
82
|
-
claim_name: 'invalid',
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
claim_sets: [['a'], ['b'], ['c'], ['a', 'b?!']],
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
id: 'my_credential2',
|
|
89
|
-
format: 'mso_mdoc',
|
|
90
|
-
meta: {
|
|
91
|
-
doctype_values: ['org.iso.7367.1.mVR'],
|
|
92
|
-
},
|
|
93
|
-
claims: [
|
|
94
|
-
{
|
|
95
|
-
id: 'a',
|
|
96
|
-
namespace: 'org.iso.7367.1',
|
|
97
|
-
claim_name: 'vehicle_holder',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: 'b',
|
|
101
|
-
namespace: 'org.iso.18013.5.1',
|
|
102
|
-
claim_name: 'first_name',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
id: 'c',
|
|
106
|
-
namespace: 'org.iso.18013.5.1',
|
|
107
|
-
claim_name: 'invalid',
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
claim_sets: [['a'], ['b'], ['c'], ['a', 'b?!']],
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
credential_sets: [['my_credential?'], ['my_credential']],
|
|
114
|
-
} satisfies VpQuery;
|
|
115
|
-
|
|
116
|
-
const validMdoc = {
|
|
117
|
-
docType: 'org.iso.7367.1.mVR',
|
|
118
|
-
namespaces: {
|
|
119
|
-
'org.iso.7367.1': {
|
|
120
|
-
vehicle_holder: 'Martin Auer',
|
|
121
|
-
non_disclosed: 'secret',
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
'org.iso.18013.5.1': {
|
|
125
|
-
first_name: 'Martin Auer',
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
await describe('credential-parser', async () => {
|
|
131
|
-
await it('mdoc-credential-parser', _t => {
|
|
132
|
-
const query = v.parse(VpQuery.vModel, simpleMdoc);
|
|
133
|
-
VpQuery.validate(query);
|
|
134
|
-
const res = VpQuery.query(query, [
|
|
135
|
-
validMdoc,
|
|
136
|
-
{
|
|
137
|
-
docType: 'org.iso.7367.1.mVR',
|
|
138
|
-
namespaces: {
|
|
139
|
-
'org.iso.7367.1': {
|
|
140
|
-
non_disclosed: 'secret',
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
'org.iso.18013.5.1': {
|
|
144
|
-
first_name: 'Martin Auer',
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
{ docType: 'some', namespaces: {} },
|
|
149
|
-
]);
|
|
150
|
-
|
|
151
|
-
console.log(res);
|
|
152
|
-
const builder = new ResultBuilder(res);
|
|
153
|
-
const solutionSpace = builder.getSolutionSpace();
|
|
154
|
-
console.log(solutionSpace);
|
|
155
|
-
});
|
|
156
|
-
});
|
package/src/vp-query/vp-query.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { queryCredentialSet } from '../credential-query/credential-query-result.js';
|
|
2
|
-
import type { Mdoc } from '../u-query.js';
|
|
3
|
-
import type { VpQueryResult } from './v-vp-query-result.js';
|
|
4
|
-
import type { VpQuery } from './v-vp-query.js';
|
|
5
|
-
|
|
6
|
-
export const queryVerifiablePresentation = (
|
|
7
|
-
vpQuery: VpQuery,
|
|
8
|
-
credentials: Mdoc[]
|
|
9
|
-
): VpQueryResult => {
|
|
10
|
-
const credential_sets_results = (vpQuery.credential_sets ?? [undefined]).map(
|
|
11
|
-
credential_set => {
|
|
12
|
-
// TODO: SHOULD WE THROW IN CASE AN EMPTY CREDENTIAL_SET IS PASSED?
|
|
13
|
-
if (credential_set?.length === 0) {
|
|
14
|
-
return {
|
|
15
|
-
areRequiredCredentialsPresent: true,
|
|
16
|
-
credential_set_result: [],
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const credentialSetQueryResult = queryCredentialSet(
|
|
21
|
-
vpQuery.credentials,
|
|
22
|
-
credentials,
|
|
23
|
-
credential_set as [string, ...string[]] | undefined
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const areRequiredCredentialsPresent = credentialSetQueryResult.every(
|
|
27
|
-
credentialQueryResult =>
|
|
28
|
-
credentialQueryResult.isOptional ||
|
|
29
|
-
credentialQueryResult.claim_sets_results.some(claimSetResult =>
|
|
30
|
-
claimSetResult.some(
|
|
31
|
-
claimQueryResult => claimQueryResult.areRequiredClaimsPresent
|
|
32
|
-
)
|
|
33
|
-
)
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
areRequiredCredentialsPresent,
|
|
38
|
-
credential_set_result: credentialSetQueryResult,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return { ...vpQuery, credential_sets_results };
|
|
44
|
-
};
|