Skip to content

Commit 265e798

Browse files
committed
improve proof handling when asserting a secured credential
Signed-off-by: PatStLouis <[email protected]>
1 parent df248bf commit 265e798

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

tests/90-algorithms-jcs.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
generateCredential,
1212
getProofs,
1313
isValidDatetime,
14+
proofExists,
1415
secureCredential,
1516
setupReportableTestSuite,
1617
setupRow,
@@ -46,17 +47,18 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
4647
describe(columnId, function() {
4748
const [issuer] = endpoints;
4849
let securedCredential;
49-
let proof;
50+
let proofs;
5051
before(async function() {
5152
securedCredential = await secureCredential(
5253
{issuer, vc: generateCredential()});
53-
proof = getProofs(securedCredential)[0];
54+
proofs = getProofs(securedCredential);
5455
});
5556
beforeEach(setupRow);
5657
it('A data integrity proof (map), or an error, is produced as output.',
5758
async function() {
5859
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
5960
assertSecuredCredential(securedCredential);
61+
const proof = proofExists(proofs);
6062
assertDataIntegrityProof(proof, 'ecdsa-jcs-2019');
6163
// Since we are not sending proof options, we only do a positive test
6264
});
@@ -67,6 +69,7 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
6769
// NOTE, for backwards compatibility reason, this step is not mandatory
6870
// This feature is designed to be used with proof sets/chains,
6971
// when adding new context in subsequent proofs
72+
const proof = proofExists(proofs);
7073
should.exist(proof['@context'],
7174
'Expected proof to have context.');
7275
canonicalize(proof['@context']).should.equal(
@@ -80,6 +83,7 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
8083
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
8184
// Shallow multibase test
8285
// TODO try decoding
86+
const proof = proofExists(proofs);
8387
should.exist(proof.proofValue,
8488
'Expected proof to have proofValue.');
8589
expect(proof.proofValue.startsWith('z')).to.be.true;
@@ -124,18 +128,19 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
124128
describe(columnId, function() {
125129
const [issuer] = endpoints;
126130
let securedCredential;
127-
let proof;
131+
let proofs;
128132
before(async function() {
129133
securedCredential = await secureCredential(
130134
{issuer, vc: generateCredential()});
131-
proof = getProofs(securedCredential)[0];
135+
proofs = getProofs(securedCredential);
132136
});
133137
beforeEach(setupRow);
134138
it('The transformation options MUST contain a type identifier ' +
135139
'for the cryptographic suite (type) and a cryptosuite identifier ' +
136140
'(cryptosuite).',
137141
async function() {
138142
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
143+
const proof = proofExists(proofs);
139144
should.exist(proof.type,
140145
'Expected a type identifier on the proof.');
141146
should.exist(proof.cryptosuite,
@@ -145,6 +150,7 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
145150
'it MUST use UTF-8 encoding.',
146151
async function() {
147152
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
153+
const proof = proofExists(proofs);
148154
assertAllUtf8(proof);
149155
});
150156
it('If options.type is not set to the string DataIntegrityProof or ' +
@@ -153,6 +159,7 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
153159
'of PROOF_TRANSFORMATION_ERROR.',
154160
async function() {
155161
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
162+
const proof = proofExists(proofs);
156163
should.exist(proof.type,
157164
'Expected a type identifier on the proof.');
158165
should.exist(proof.cryptosuite,
@@ -173,18 +180,19 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
173180
describe(columnId, function() {
174181
const [issuer] = endpoints;
175182
let securedCredential;
176-
let proof;
183+
let proofs;
177184
before(async function() {
178185
securedCredential = await secureCredential(
179186
{issuer, vc: generateCredential()});
180-
proof = getProofs(securedCredential)[0];
187+
proofs = getProofs(securedCredential);
181188
});
182189
beforeEach(setupRow);
183190
it('The proof options MUST contain a type identifier for the ' +
184191
'cryptographic suite (type) and MUST contain a cryptosuite ' +
185192
'identifier (cryptosuite).',
186193
async function() {
187194
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
195+
const proof = proofExists(proofs);
188196
should.exist(proof.type,
189197
'Expected a type identifier on the proof.');
190198
should.exist(proof.cryptosuite,
@@ -196,6 +204,7 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
196204
'of PROOF_GENERATION_ERROR.',
197205
async function() {
198206
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
207+
const proof = proofExists(proofs);
199208
should.exist(proof.type,
200209
'Expected a type identifier on the proof.');
201210
should.exist(proof.cryptosuite,
@@ -210,6 +219,7 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
210219
'SHOULD convey an error type of PROOF_GENERATION_ERROR.',
211220
async function() {
212221
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
222+
const proof = proofExists(proofs);
213223
if(proof?.created) {
214224
isValidDatetime(proof.created).should.equal(
215225
true,
@@ -228,18 +238,19 @@ describe('Algorithms - Proof Serialization (ecdsa-jcs-2019)', function() {
228238
describe(columnId, function() {
229239
const [issuer] = endpoints;
230240
let securedCredential;
231-
let proof;
241+
let proofs;
232242
before(async function() {
233243
securedCredential = await secureCredential(
234244
{issuer, vc: generateCredential()});
235-
proof = getProofs(securedCredential)[0];
245+
proofs = getProofs(securedCredential);
236246
});
237247
beforeEach(setupRow);
238248
it('The proof options MUST contain a type identifier for the ' +
239249
'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
240250
'(cryptosuite).',
241251
async function() {
242252
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019';
253+
const proof = proofExists(proofs);
243254
should.exist(proof.type,
244255
'Expected a type identifier on the proof.');
245256
});

tests/90-algorithms-rdfc.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
generateCredential,
77
getProofs,
88
isValidDatetime,
9+
proofExists,
910
secureCredential,
1011
setupReportableTestSuite,
1112
setupRow
@@ -34,18 +35,19 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
3435
describe(columnId, function() {
3536
const [issuer] = endpoints;
3637
let securedCredential;
37-
let proof;
38+
let proofs;
3839
before(async function() {
3940
securedCredential = await secureCredential(
4041
{issuer, vc: generateCredential()});
41-
proof = getProofs(securedCredential)[0];
42+
proofs = getProofs(securedCredential);
4243
});
4344
beforeEach(setupRow);
4445
it('The transformation options MUST contain a type identifier ' +
4546
'for the cryptographic suite (type) and a cryptosuite identifier ' +
4647
'(cryptosuite).',
4748
async function() {
4849
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
50+
const proof = proofExists(proofs);
4951
should.exist(proof.type,
5052
'Expected a type identifier on the proof.');
5153
should.exist(proof.cryptosuite,
@@ -55,6 +57,7 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
5557
'it MUST use UTF-8 encoding.',
5658
async function() {
5759
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
60+
const proof = proofExists(proofs);
5861
assertAllUtf8(proof);
5962
});
6063
it('If options.type is not set to the string DataIntegrityProof or ' +
@@ -63,6 +66,7 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
6366
'of PROOF_TRANSFORMATION_ERROR.',
6467
async function() {
6568
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
69+
const proof = proofExists(proofs);
6670
should.exist(proof.type,
6771
'Expected a type identifier on the proof.');
6872
should.exist(proof.cryptosuite,
@@ -83,18 +87,19 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
8387
describe(columnId, function() {
8488
const [issuer] = endpoints;
8589
let securedCredential;
86-
let proof;
90+
let proofs;
8791
before(async function() {
8892
securedCredential = await secureCredential(
8993
{issuer, vc: generateCredential()});
90-
proof = getProofs(securedCredential)[0];
94+
proofs = getProofs(securedCredential);
9195
});
9296
beforeEach(setupRow);
9397
it('The proof options MUST contain a type identifier for the ' +
9498
'cryptographic suite (type) and MUST contain a cryptosuite ' +
9599
'identifier (cryptosuite).',
96100
async function() {
97101
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
102+
const proof = proofExists(proofs);
98103
should.exist(proof.type,
99104
'Expected a type identifier on the proof.');
100105
should.exist(proof.cryptosuite,
@@ -106,6 +111,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
106111
'of PROOF_GENERATION_ERROR.',
107112
async function() {
108113
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
114+
const proof = proofExists(proofs);
109115
should.exist(proof.type,
110116
'Expected a type identifier on the proof.');
111117
should.exist(proof.cryptosuite,
@@ -120,6 +126,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
120126
'SHOULD convey an error type of PROOF_GENERATION_ERROR.',
121127
async function() {
122128
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
129+
const proof = proofExists(proofs);
123130
if(proof?.created) {
124131
isValidDatetime(proof.created).should.equal(
125132
true,
@@ -138,18 +145,19 @@ describe('Algorithms - Proof Serialization (ecdsa-rdfc-2019)', function() {
138145
describe(columnId, function() {
139146
const [issuer] = endpoints;
140147
let securedCredential;
141-
let proof;
148+
let proofs;
142149
before(async function() {
143150
securedCredential = await secureCredential(
144151
{issuer, vc: generateCredential()});
145-
proof = getProofs(securedCredential)[0];
152+
proofs = getProofs(securedCredential);
146153
});
147154
beforeEach(setupRow);
148155
it('The proof options MUST contain a type identifier for the ' +
149156
'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
150157
'(cryptosuite).',
151158
async function() {
152159
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-rdfc-2019';
160+
const proof = proofExists(proofs);
153161
should.exist(proof.type,
154162
'Expected a type identifier on the proof.');
155163
});

tests/helpers.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,19 @@ export function setupRow() {
287287
};
288288
}
289289

290+
export function proofExists(proofs) {
291+
should.exist(proofs,
292+
'Expected credential to have a proof.');
293+
proofs.length.should.be.gte(1,
294+
'Expected credential to have at least one proof.');
295+
return proofs[0];
296+
}
297+
290298
export function assertSecuredCredential(securedCredential) {
291299
should.exist(securedCredential,
292300
'Expected issuer to have issued a credential.');
293301
const proofs = getProofs(securedCredential);
294-
should.exist(proofs,
295-
'Expected credential to have a proof.');
296-
proofs.length.should.equal(1,
297-
'Expected credential to have a single proof.');
302+
proofExists(proofs);
298303
}
299304

300305
export async function verifySuccess(verifier, securedCredential) {

0 commit comments

Comments
 (0)