Skip to content

Commit 4819cec

Browse files
committed
Fix pex required attributes filter.
1 parent 577b611 commit 4819cec

File tree

3 files changed

+119
-66
lines changed

3 files changed

+119
-66
lines changed

integration-tests/verification-flow/vpi-verification.test.ts

Lines changed: 117 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,62 @@ const testAPIURL = process.env.TESTING_API_URL || null;
1111
const testCredsURL = testAPIURL.replace('api-', 'creds-');
1212

1313
const credential = {
14-
"@context": [
15-
"https://www.w3.org/2018/credentials/v1",
16-
"https://ld.dock.io/security/bbdt16/v1",
17-
{
18-
"BasicCredential": "dk:BasicCredential",
19-
"address": "dk:address",
20-
"city": "dk:city",
21-
"dk": "https://ld.dock.io/credentials#",
22-
"name": "dk:name",
23-
"street": "dk:street",
24-
"zipCode": "dk:zipCode"
25-
}
26-
],
27-
"id": `${testCredsURL}/4d007f22b2677d542e18962cc88ba74c2e6e97482f57c9b205f99bf644aa9254`,
28-
"type": [
29-
"VerifiableCredential",
30-
"BasicCredential"
31-
],
32-
"credentialSubject": {
33-
"id": "did:key:z6MkoWAL66HUG7SHmJpwisjbUrjgaUZZnesNXp5m2CDmrFkT",
34-
"name": "Nested Attributes",
35-
"address": {
36-
"street": "Soem street name",
37-
"city": "City name",
38-
"zipCode": "12345"
39-
}
40-
},
41-
"issuanceDate": "2024-04-09T15:43:59.361Z",
42-
"issuer": {
43-
"name": "profile bbs+",
44-
"id": "did:dock:5GJeBeStWSxqyPGUJnERMFhm3wKcfCZP6nhqtoKyRAmq9FeU"
45-
},
46-
"credentialSchema": {
47-
"id": "https://schema.dock.io/BasicCredential-V2-1703777584571.json",
48-
"type": "JsonSchemaValidator2018",
49-
"details": "{\"jsonSchema\":{\"$id\":\"https://schema.dock.io/BasicCredential-V2-1703777584571.json\",\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"additionalProperties\":true,\"description\":\"A representation of a very basic example credential\",\"name\":\"Basic Credential\",\"properties\":{\"@context\":{\"type\":\"string\"},\"credentialSchema\":{\"properties\":{\"details\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}},\"type\":\"object\"},\"credentialSubject\":{\"properties\":{\"address\":{\"properties\":{\"city\":{\"type\":\"string\"},\"street\":{\"type\":\"string\"},\"zipCode\":{\"type\":\"string\"}},\"type\":\"object\"},\"id\":{\"description\":\"A unique identifier of the recipient. Example: DID, email address, national ID number, employee ID, student ID etc. If you enter the recipient's DID, the person will automatically receive the credential in their Dock wallet.\",\"title\":\"Subject ID\",\"type\":\"string\"},\"name\":{\"description\":\"The name of the credential holder.\",\"title\":\"Subject Name\",\"type\":\"string\"}},\"required\":[\"name\"],\"type\":\"object\"},\"cryptoVersion\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"issuanceDate\":{\"format\":\"date-time\",\"type\":\"string\"},\"issuer\":{\"properties\":{\"id\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"}},\"type\":\"object\"},\"name\":{\"type\":\"string\"},\"proof\":{\"properties\":{\"@context\":{\"items\":[{\"properties\":{\"proof\":{\"properties\":{\"@container\":{\"type\":\"string\"},\"@id\":{\"type\":\"string\"},\"@type\":{\"type\":\"string\"}},\"type\":\"object\"},\"sec\":{\"type\":\"string\"}},\"type\":\"object\"},{\"type\":\"string\"}],\"type\":\"array\"},\"created\":{\"format\":\"date-time\",\"type\":\"string\"},\"proofPurpose\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"},\"verificationMethod\":{\"type\":\"string\"}},\"type\":\"object\"},\"type\":{\"type\":\"string\"}},\"type\":\"object\"},\"parsingOptions\":{\"defaultDecimalPlaces\":4,\"defaultMinimumDate\":-17592186044415,\"defaultMinimumInteger\":-4294967295,\"useDefaults\":true}}",
50-
"version": "0.4.0"
51-
},
52-
"name": "Nested Attributes",
53-
"cryptoVersion": "0.6.0",
54-
"proof": {
55-
"@context": [
56-
{
57-
"sec": "https://w3id.org/security#",
58-
"proof": {
59-
"@id": "sec:proof",
60-
"@type": "@id",
61-
"@container": "@graph"
62-
}
63-
},
64-
"https://ld.dock.io/security/bbdt16/v1"
65-
],
66-
"type": "Bls12381BBDT16MACDock2024",
67-
"created": "2024-07-03T17:38:33Z",
68-
"verificationMethod": "did:dock:5GJeBeStWSxqyPGUJnERMFhm3wKcfCZP6nhqtoKyRAmq9FeU#73UFp7oRA5TcjuRLyAy7D2z7szZPjEZs1S8uVP8pvVJL9rm7xW2TBPcQShwLz813pT",
69-
"proofPurpose": "assertionMethod",
70-
"proofValue": "zYtFbq55ZsfiK7wLB8AKfdyBriaMCg5CDNgoeKbJphiCGnE3JHG5PNZJV2scJAnaAT1StakGswamqoLAVjfTDTyz78KSqVmRNB4JuPDGFi4umBRc4wCFQvQjGwgzm812bqmtzkJWijrvFVaiFnoKDNRUZU"
71-
}
14+
"@context": [
15+
"https://www.w3.org/2018/credentials/v1",
16+
"https://ld.truvera.io/credentials/extensions-v1",
17+
"https://ld.truvera.io/security/bbdt16/v1",
18+
{
19+
"dk": "https://ld.truvera.io/credentials#",
20+
"fieldOfStudy": "dk:fieldOfStudy",
21+
"fullName": "dk:fullName",
22+
"grade": "dk:grade",
23+
"universityName": "dk:universityName"
24+
}
25+
],
26+
"id": "http://127.0.0.1:3001/4449fe773d1b0c478ecd9544265421a5cd48908e118d950dacc8570991068404",
27+
"type": [
28+
"VerifiableCredential"
29+
],
30+
"credentialSubject": {
31+
"grade": "A",
32+
"universityName": "Vilnius",
33+
"fieldOfStudy": "Psychology",
34+
"fullName": "Agne Caunt"
35+
},
36+
"issuanceDate": "2019-12-03T12:19:52Z",
37+
"expirationDate": "2029-12-03T12:19:52Z",
38+
"issuer": {
39+
"name": "My Issuer",
40+
"logo": "https://dock.io/issuer.png",
41+
"description": "An issuer",
42+
"id": "did:dock:5DWQSynyrP2DU3YpJayctaNy5jYJAiy3BXWnDD6r1DH69mR1"
43+
},
44+
"credentialSchema": {
45+
"id": "https://schema.dock.io/BachelorOfIndustrialDesign-V2-1717755908049.json",
46+
"type": "JsonSchemaValidator2018",
47+
"details": "{\"jsonSchema\":{\"$id\":\"https://schema.dock.io/BachelorOfIndustrialDesign-V2-1717755908049.json\",\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"additionalProperties\":true,\"description\":\"\",\"name\":\"Bachelor of Industrial Design\",\"properties\":{\"@context\":{\"type\":\"string\"},\"credentialSchema\":{\"properties\":{\"details\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}},\"type\":\"object\"},\"credentialSubject\":{\"properties\":{\"fieldOfStudy\":{\"title\":\"Field of Study\",\"type\":\"string\"},\"fullName\":{\"title\":\"Full Name\",\"type\":\"string\"},\"grade\":{\"title\":\"Grade\",\"type\":\"string\"},\"universityName\":{\"description\":\"\",\"title\":\"University Name\",\"type\":\"string\"}},\"required\":[\"grade\",\"fieldOfStudy\",\"fullName\",\"universityName\"],\"type\":\"object\"},\"cryptoVersion\":{\"type\":\"string\"},\"expirationDate\":{\"format\":\"date-time\",\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"issuanceDate\":{\"format\":\"date-time\",\"type\":\"string\"},\"issuer\":{\"properties\":{\"description\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"logo\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"}},\"type\":\"object\"},\"name\":{\"type\":\"string\"},\"proof\":{\"properties\":{\"@context\":{\"items\":[{\"properties\":{\"proof\":{\"properties\":{\"@container\":{\"type\":\"string\"},\"@id\":{\"type\":\"string\"},\"@type\":{\"type\":\"string\"}},\"type\":\"object\"},\"sec\":{\"type\":\"string\"}},\"type\":\"object\"},{\"type\":\"string\"}],\"type\":\"array\"},\"created\":{\"format\":\"date-time\",\"type\":\"string\"},\"proofPurpose\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"},\"verificationMethod\":{\"type\":\"string\"}},\"type\":\"object\"},\"type\":{\"type\":\"string\"}},\"type\":\"object\"},\"parsingOptions\":{\"defaultDecimalPlaces\":4,\"defaultMinimumDate\":-17592186044415,\"defaultMinimumInteger\":-4294967295,\"useDefaults\":true}}",
48+
"version": "0.4.0"
49+
},
50+
"name": "Bachelor of Industrial Design",
51+
"cryptoVersion": "0.6.0",
52+
"proof": {
53+
"@context": [
54+
{
55+
"sec": "https://w3id.org/security#",
56+
"proof": {
57+
"@id": "sec:proof",
58+
"@type": "@id",
59+
"@container": "@graph"
60+
}
61+
},
62+
"https://ld.truvera.io/security/bbdt16/v1"
63+
],
64+
"type": "Bls12381BBDT16MACDock2024",
65+
"created": "2025-04-08T14:45:17Z",
66+
"verificationMethod": "did:dock:5DWQSynyrP2DU3YpJayctaNy5jYJAiy3BXWnDD6r1DH69mR1#7c4TNuBRW826sJhe72T3vRGQnRCQJ7vinazMeix7RFSc7NVPpE1S2vWebt6SnCVRhm",
67+
"proofPurpose": "assertionMethod",
68+
"proofValue": "zVrcXRAUuJo8ztNYS6pppBwJuSQR7CzmcG75onGwKi7A71RxPjj2ynjMNEceSVx2JPPEfHroQ2KVy25D3uhyn5y3LqsmrR96uEkcZ3RNeBVMWQy56g5KzA5fiDpaW8Nh2kLDsphKYJEU8ciJn2r9nytKes"
69+
}
7270
}
7371

7472
describe('VPI verification', () => {
@@ -77,10 +75,6 @@ describe('VPI verification', () => {
7775

7876
getCredentialProvider().addCredential(credential);
7977

80-
const proofRequest = await createProofRequest(
81-
ProofTemplateIds.ANY_CREDENTIAL,
82-
);
83-
8478
const result: any = await getCredentialProvider().isValid(credential);
8579

8680
expect(result.status).toBe('verified');
@@ -90,10 +84,69 @@ describe('VPI verification', () => {
9084
});
9185

9286
await controller.start({
93-
template: proofRequest,
87+
template: {
88+
"id": "f2ca747d-1176-4db8-8406-7e5ef75ee253",
89+
"name": "Proof request",
90+
"nonce": "c00bcff2d1841effc6cc235605e26648",
91+
"did": "did:cheqd:testnet:d1c05a89-954d-4b71-b225-01d02c90a4d7",
92+
"verified": false,
93+
"expired": false,
94+
"created": "2025-04-09T13:44:55.717Z",
95+
"updated": "2025-04-09T13:44:55.717Z",
96+
"signature": "7HwwhaOq-nwMVTmbB8ofgIh8CjfUcguTp_Uwb_1DhKJUAwqy3K-l8j1raDqVf6DKnTUyhNoHP1cbyHPcVCkMCQ",
97+
"presentation": {},
98+
"response_url": "http://127.0.0.1:8000/proof-requests/f2ca747d-1176-4db8-8406-7e5ef75ee253/send-presentation",
99+
"type": "proof-request",
100+
"qr": "http://127.0.0.1:3001/proof/f2ca747d-1176-4db8-8406-7e5ef75ee253",
101+
"expirationTime": {
102+
"amount": 999,
103+
"unit": "years"
104+
},
105+
"request": {
106+
"id": "f2ca747d-1176-4db8-8406-7e5ef75ee253",
107+
"name": "test request",
108+
"purpose": "my purpose",
109+
"input_descriptors": [
110+
{
111+
"id": "Credential 1",
112+
"name": "test request",
113+
"purpose": "my purpose",
114+
"constraints": {
115+
"fields": [
116+
{
117+
"path": [
118+
"$.issuanceDate"
119+
],
120+
"optional": true
121+
},
122+
{
123+
"path": [
124+
"$.credentialSchema.id"
125+
],
126+
"filter": {
127+
"const": "https://schema.dock.io/BachelorOfIndustrialDesign-V2-1717755908049.json"
128+
}
129+
},
130+
{
131+
"path": [
132+
"$.credentialSchema.id"
133+
],
134+
"filter": {
135+
"const": "https://schema.dock.io/BachelorOfIndustrialDesign-V2-1717755908049.json"
136+
}
137+
}
138+
]
139+
}
140+
}
141+
]
142+
},
143+
"types": [
144+
"jsonld"
145+
]
146+
},
94147
});
95148

96-
let attributesToReveal = ['credentialSubject.name'];
149+
let attributesToReveal = ['credentialSubject.grade', 'credentialSubject.universityName', 'credentialSubject.fieldOfStudy', 'credentialSubject.fullName'];
97150

98151
controller.selectedCredentials.set(credential.id, {
99152
credential: credential,

packages/core/src/verification-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function createVerificationController({
195195
? keyDoc.id
196196
: `${keyDoc.controller}#keys-1`,
197197
domain: 'dock.io',
198-
...(isRangeProofTemplate(templateJSON) ? { pexForBounds: templateJSON } : {}),
198+
pexForBounds: templateJSON,
199199
});
200200

201201
return presentation;

packages/wasm/src/services/credential/pex-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export function getPexRequiredAttributes(pexRequest, selectedCredentials = []) {
268268
.map((inputDescriptor, index) => {
269269
return inputDescriptor.constraints.fields
270270
.filter(field => {
271-
if (field.filter) {
271+
if (field.filter || field.optional) {
272272
return false;
273273
}
274274

0 commit comments

Comments
 (0)