Skip to content

Commit 18dc497

Browse files
committed
add rdfc vectors and base sd algorithms file
Signed-off-by: PatStLouis <[email protected]>
1 parent 1aff5d5 commit 18dc497

File tree

5 files changed

+264
-210
lines changed

5 files changed

+264
-210
lines changed

tests/90-algorithms-jcs.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import {
66
assertAllUtf8,
7+
assertCryptosuiteProof,
78
assertDataIntegrityProof
89
} from './assertions.js';
910
import {
@@ -98,7 +99,7 @@ describe('Algorithms - Verify Proof (ecdsa-jcs-2019)', function() {
9899
'Required inputs are an secured data document (map securedDocument). ' +
99100
'This algorithm returns a verification result.',
100101
async function() {
101-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019';
102+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-jcs-2019';
102103
for(const curve of verifier.settings.supportedEcdsaKeyTypes) {
103104
// Send a valid VC and an invalid VC to the verifier
104105
// Check for success/error on response
@@ -139,28 +140,20 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
139140
should.exist(proof.cryptosuite,
140141
'Expected a cryptosuite identifier on the proof.');
141142
});
142-
it('Whenever this algorithm encodes strings, ' +
143-
'it MUST use UTF-8 encoding.',
144-
async function() {
145-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
146-
const proof = proofExists(securedCredential);
147-
assertAllUtf8(proof);
148-
});
143+
it('Whenever this algorithm encodes strings, it MUST use UTF-8 encoding.',
144+
async function() {
145+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
146+
const proof = proofExists(securedCredential);
147+
assertAllUtf8(proof);
148+
});
149149
it('If options.type is not set to the string DataIntegrityProof or ' +
150150
'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' +
151151
'an error MUST be raised and SHOULD convey an error type ' +
152152
'of PROOF_TRANSFORMATION_ERROR.',
153153
async function() {
154154
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
155155
const proof = proofExists(securedCredential);
156-
should.exist(proof.type,
157-
'Expected a type identifier on the proof.');
158-
should.exist(proof.cryptosuite,
159-
'Expected a cryptosuite identifier on the proof.');
160-
proof.type.should.equal('DataIntegrityProof',
161-
'Expected DataIntegrityProof type.');
162-
proof.cryptosuite.should.equal('ecdsa-jcs-2019',
163-
'Expected ecdsa-jcs-2019 cryptosuite.');
156+
assertCryptosuiteProof(proof, 'ecdsa-jcs-2019');
164157
});
165158
});
166159
}
@@ -196,14 +189,7 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
196189
async function() {
197190
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
198191
const proof = proofExists(securedCredential);
199-
should.exist(proof.type,
200-
'Expected a type identifier on the proof.');
201-
should.exist(proof.cryptosuite,
202-
'Expected a cryptosuite identifier on the proof.');
203-
proof.type.should.equal('DataIntegrityProof',
204-
'Expected DataIntegrityProof type.');
205-
proof.cryptosuite.should.equal('ecdsa-jcs-2019',
206-
'Expected ecdsa-jcs-2019 cryptosuite.');
192+
assertCryptosuiteProof(proof, 'ecdsa-jcs-2019');
207193
});
208194
it('If proofConfig.created is set and if the value is not a ' +
209195
'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' +

tests/90-algorithms-rdfc.js

Lines changed: 88 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
* Copyright 2024 Digital Bazaar, Inc.
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5+
import {
6+
assertAllUtf8,
7+
assertCryptosuiteProof,
8+
assertDataIntegrityProof
9+
} from './assertions.js';
510
import {
611
generateCredential,
712
isValidDatetime,
813
proofExists,
914
secureCredential,
1015
setupReportableTestSuite,
11-
setupRow
16+
setupRow,
17+
verifyError,
18+
verifySuccess
1219
} from './helpers.js';
13-
import {
14-
assertAllUtf8
15-
} from './assertions.js';
1620
import chai from 'chai';
21+
import {ecdsaRdfcVectors} from './vectors.js';
1722
import {endpoints} from 'vc-test-suite-implementations';
23+
import {expect} from 'chai';
1824

1925
const should = chai.should();
2026

@@ -27,6 +33,74 @@ const {match: issuers} = endpoints.filterByTag({
2733
property: 'issuers'
2834
});
2935

36+
const {match: verifiers} = endpoints.filterByTag({
37+
tags: cryptosuites,
38+
property: 'verifiers'
39+
});
40+
41+
describe('Algorithms - Create Proof (ecdsa-rdfc-2019)', function() {
42+
setupReportableTestSuite(this);
43+
this.implemented = [...issuers.keys()];
44+
for(const [columnId, {endpoints}] of issuers) {
45+
describe(columnId, function() {
46+
const [issuer] = endpoints;
47+
let securedCredential;
48+
before(async function() {
49+
securedCredential = await secureCredential(
50+
{issuer, vc: generateCredential()});
51+
});
52+
beforeEach(setupRow);
53+
it('A data integrity proof (map), or an error, is produced as output.',
54+
async function() {
55+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-rdfc-2019';
56+
const proof = proofExists(securedCredential);
57+
assertDataIntegrityProof(proof, 'ecdsa-rdfc-2019');
58+
// Since we are not sending proof options, we only do a positive test
59+
});
60+
it('Let proof.proofValue be a base58-btc-encoded ' +
61+
'Multibase value of the proofBytes.',
62+
async function() {
63+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-rdfc-2019';
64+
// Shallow multibase test
65+
// TODO try decoding
66+
const proof = proofExists(securedCredential);
67+
should.exist(proof.proofValue,
68+
'Expected proof to have proofValue.');
69+
expect(proof.proofValue.startsWith('z')).to.be.true;
70+
});
71+
});
72+
}
73+
});
74+
75+
describe('Algorithms - Verify Proof (ecdsa-rdfc-2019)', function() {
76+
setupReportableTestSuite(this);
77+
for(const [columnId, {endpoints}] of verifiers) {
78+
describe(columnId, function() {
79+
const [verifier] = endpoints;
80+
beforeEach(setupRow);
81+
it('The following algorithm specifies how to verify a ' +
82+
'data integrity proof given an secured data document. ' +
83+
'Required inputs are an secured data document (map securedDocument). ' +
84+
'This algorithm returns a verification result.',
85+
async function() {
86+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019';
87+
for(const curve of verifier.settings.supportedEcdsaKeyTypes) {
88+
// Send a valid VC and an invalid VC to the verifier
89+
// Check for success/error on response
90+
const testVector = structuredClone(ecdsaRdfcVectors[curve]);
91+
await verifySuccess(verifier, testVector);
92+
93+
// Slice the proof
94+
testVector.proof.proofValue =
95+
testVector.proof.proofValue.slice(0, -1);
96+
await verifyError(verifier, testVector);
97+
// TODO, create a verifyProblemDetails function
98+
}
99+
});
100+
});
101+
}
102+
});
103+
30104
describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
31105
setupReportableTestSuite(this);
32106
this.implemented = [...issuers.keys()];
@@ -40,8 +114,8 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
40114
});
41115
beforeEach(setupRow);
42116
it('The transformation options MUST contain a type identifier ' +
43-
'for the cryptographic suite (type) and a cryptosuite identifier ' +
44-
'(cryptosuite).',
117+
'for the cryptographic suite (type) and a cryptosuite identifier ' +
118+
'(cryptosuite).',
45119
async function() {
46120
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
47121
const proof = proofExists(securedCredential);
@@ -50,28 +124,20 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
50124
should.exist(proof.cryptosuite,
51125
'Expected a cryptosuite identifier on the proof.');
52126
});
53-
it('Whenever this algorithm encodes strings, ' +
54-
'it MUST use UTF-8 encoding.',
55-
async function() {
56-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
57-
const proof = proofExists(securedCredential);
58-
assertAllUtf8(proof);
59-
});
127+
it('Whenever this algorithm encodes strings, it MUST use UTF-8 encoding.',
128+
async function() {
129+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
130+
const proof = proofExists(securedCredential);
131+
assertAllUtf8(proof);
132+
});
60133
it('If options.type is not set to the string DataIntegrityProof or ' +
61134
'options.cryptosuite is not set to the string ecdsa-rdfc-2019, ' +
62135
'an error MUST be raised and SHOULD convey an error type ' +
63136
'of PROOF_TRANSFORMATION_ERROR.',
64137
async function() {
65138
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
66139
const proof = proofExists(securedCredential);
67-
should.exist(proof.type,
68-
'Expected a type identifier on the proof.');
69-
should.exist(proof.cryptosuite,
70-
'Expected a cryptosuite identifier on the proof.');
71-
proof.type.should.equal('DataIntegrityProof',
72-
'Expected DataIntegrityProof type.');
73-
proof.cryptosuite.should.equal('ecdsa-rdfc-2019',
74-
'Expected ecdsa-rdfc-2019 cryptosuite.');
140+
assertCryptosuiteProof(proof, 'ecdsa-rdfc-2019');
75141
});
76142
});
77143
}
@@ -107,14 +173,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
107173
async function() {
108174
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
109175
const proof = proofExists(securedCredential);
110-
should.exist(proof.type,
111-
'Expected a type identifier on the proof.');
112-
should.exist(proof.cryptosuite,
113-
'Expected a cryptosuite identifier on the proof.');
114-
proof.type.should.equal('DataIntegrityProof',
115-
'Expected DataIntegrityProof type.');
116-
proof.cryptosuite.should.equal('ecdsa-rdfc-2019',
117-
'Expected ecdsa-rdfc-2019 cryptosuite.');
176+
assertCryptosuiteProof(proof, 'ecdsa-rdfc-2019');
118177
});
119178
it('If proofConfig.created is set and if the value is not a ' +
120179
'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' +

0 commit comments

Comments
 (0)