Skip to content

Commit 462ef2c

Browse files
committed
improve proof selection when asserting issued credentials
Signed-off-by: PatStLouis <[email protected]>
1 parent 265e798 commit 462ef2c

File tree

3 files changed

+22
-44
lines changed

3 files changed

+22
-44
lines changed

tests/90-algorithms-jcs.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
*/
55
import {
66
assertAllUtf8,
7-
assertDataIntegrityProof,
8-
assertSecuredCredential
7+
assertDataIntegrityProof
98
} from './assertions.js';
109
import {
1110
generateCredential,
12-
getProofs,
1311
isValidDatetime,
1412
proofExists,
1513
secureCredential,
@@ -47,18 +45,15 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
4745
describe(columnId, function() {
4846
const [issuer] = endpoints;
4947
let securedCredential;
50-
let proofs;
5148
before(async function() {
5249
securedCredential = await secureCredential(
5350
{issuer, vc: generateCredential()});
54-
proofs = getProofs(securedCredential);
5551
});
5652
beforeEach(setupRow);
5753
it('A data integrity proof (map), or an error, is produced as output.',
5854
async function() {
5955
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
60-
assertSecuredCredential(securedCredential);
61-
const proof = proofExists(proofs);
56+
const proof = proofExists(securedCredential);
6257
assertDataIntegrityProof(proof, 'ecdsa-jcs-2019');
6358
// Since we are not sending proof options, we only do a positive test
6459
});
@@ -69,7 +64,7 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
6964
// NOTE, for backwards compatibility reason, this step is not mandatory
7065
// This feature is designed to be used with proof sets/chains,
7166
// when adding new context in subsequent proofs
72-
const proof = proofExists(proofs);
67+
const proof = proofExists(securedCredential);
7368
should.exist(proof['@context'],
7469
'Expected proof to have context.');
7570
canonicalize(proof['@context']).should.equal(
@@ -83,7 +78,7 @@ describe('Algorithms - Create Proof (ecdsa-jcs-2019)', function() {
8378
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
8479
// Shallow multibase test
8580
// TODO try decoding
86-
const proof = proofExists(proofs);
81+
const proof = proofExists(securedCredential);
8782
should.exist(proof.proofValue,
8883
'Expected proof to have proofValue.');
8984
expect(proof.proofValue.startsWith('z')).to.be.true;
@@ -128,19 +123,17 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
128123
describe(columnId, function() {
129124
const [issuer] = endpoints;
130125
let securedCredential;
131-
let proofs;
132126
before(async function() {
133127
securedCredential = await secureCredential(
134128
{issuer, vc: generateCredential()});
135-
proofs = getProofs(securedCredential);
136129
});
137130
beforeEach(setupRow);
138131
it('The transformation options MUST contain a type identifier ' +
139132
'for the cryptographic suite (type) and a cryptosuite identifier ' +
140133
'(cryptosuite).',
141134
async function() {
142135
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
143-
const proof = proofExists(proofs);
136+
const proof = proofExists(securedCredential);
144137
should.exist(proof.type,
145138
'Expected a type identifier on the proof.');
146139
should.exist(proof.cryptosuite,
@@ -150,7 +143,7 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
150143
'it MUST use UTF-8 encoding.',
151144
async function() {
152145
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
153-
const proof = proofExists(proofs);
146+
const proof = proofExists(securedCredential);
154147
assertAllUtf8(proof);
155148
});
156149
it('If options.type is not set to the string DataIntegrityProof or ' +
@@ -159,7 +152,7 @@ describe('Algorithms - Transformation (ecdsa-jcs-2019)', function() {
159152
'of PROOF_TRANSFORMATION_ERROR.',
160153
async function() {
161154
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
162-
const proof = proofExists(proofs);
155+
const proof = proofExists(securedCredential);
163156
should.exist(proof.type,
164157
'Expected a type identifier on the proof.');
165158
should.exist(proof.cryptosuite,
@@ -180,19 +173,17 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
180173
describe(columnId, function() {
181174
const [issuer] = endpoints;
182175
let securedCredential;
183-
let proofs;
184176
before(async function() {
185177
securedCredential = await secureCredential(
186178
{issuer, vc: generateCredential()});
187-
proofs = getProofs(securedCredential);
188179
});
189180
beforeEach(setupRow);
190181
it('The proof options MUST contain a type identifier for the ' +
191182
'cryptographic suite (type) and MUST contain a cryptosuite ' +
192183
'identifier (cryptosuite).',
193184
async function() {
194185
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
195-
const proof = proofExists(proofs);
186+
const proof = proofExists(securedCredential);
196187
should.exist(proof.type,
197188
'Expected a type identifier on the proof.');
198189
should.exist(proof.cryptosuite,
@@ -204,7 +195,7 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
204195
'of PROOF_GENERATION_ERROR.',
205196
async function() {
206197
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
207-
const proof = proofExists(proofs);
198+
const proof = proofExists(securedCredential);
208199
should.exist(proof.type,
209200
'Expected a type identifier on the proof.');
210201
should.exist(proof.cryptosuite,
@@ -219,7 +210,7 @@ describe('Algorithms - Proof Configuration (ecdsa-jcs-2019)', function() {
219210
'SHOULD convey an error type of PROOF_GENERATION_ERROR.',
220211
async function() {
221212
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
222-
const proof = proofExists(proofs);
213+
const proof = proofExists(securedCredential);
223214
if(proof?.created) {
224215
isValidDatetime(proof.created).should.equal(
225216
true,
@@ -238,19 +229,17 @@ describe('Algorithms - Proof Serialization (ecdsa-jcs-2019)', function() {
238229
describe(columnId, function() {
239230
const [issuer] = endpoints;
240231
let securedCredential;
241-
let proofs;
242232
before(async function() {
243233
securedCredential = await secureCredential(
244234
{issuer, vc: generateCredential()});
245-
proofs = getProofs(securedCredential);
246235
});
247236
beforeEach(setupRow);
248237
it('The proof options MUST contain a type identifier for the ' +
249238
'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
250239
'(cryptosuite).',
251240
async function() {
252241
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019';
253-
const proof = proofExists(proofs);
242+
const proof = proofExists(securedCredential);
254243
should.exist(proof.type,
255244
'Expected a type identifier on the proof.');
256245
});

tests/90-algorithms-rdfc.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
import {
66
generateCredential,
7-
getProofs,
87
isValidDatetime,
98
proofExists,
109
secureCredential,
@@ -35,19 +34,17 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
3534
describe(columnId, function() {
3635
const [issuer] = endpoints;
3736
let securedCredential;
38-
let proofs;
3937
before(async function() {
4038
securedCredential = await secureCredential(
4139
{issuer, vc: generateCredential()});
42-
proofs = getProofs(securedCredential);
4340
});
4441
beforeEach(setupRow);
4542
it('The transformation options MUST contain a type identifier ' +
4643
'for the cryptographic suite (type) and a cryptosuite identifier ' +
4744
'(cryptosuite).',
4845
async function() {
4946
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
50-
const proof = proofExists(proofs);
47+
const proof = proofExists(securedCredential);
5148
should.exist(proof.type,
5249
'Expected a type identifier on the proof.');
5350
should.exist(proof.cryptosuite,
@@ -57,7 +54,7 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
5754
'it MUST use UTF-8 encoding.',
5855
async function() {
5956
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
60-
const proof = proofExists(proofs);
57+
const proof = proofExists(securedCredential);
6158
assertAllUtf8(proof);
6259
});
6360
it('If options.type is not set to the string DataIntegrityProof or ' +
@@ -66,7 +63,7 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
6663
'of PROOF_TRANSFORMATION_ERROR.',
6764
async function() {
6865
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019';
69-
const proof = proofExists(proofs);
66+
const proof = proofExists(securedCredential);
7067
should.exist(proof.type,
7168
'Expected a type identifier on the proof.');
7269
should.exist(proof.cryptosuite,
@@ -87,19 +84,17 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
8784
describe(columnId, function() {
8885
const [issuer] = endpoints;
8986
let securedCredential;
90-
let proofs;
9187
before(async function() {
9288
securedCredential = await secureCredential(
9389
{issuer, vc: generateCredential()});
94-
proofs = getProofs(securedCredential);
9590
});
9691
beforeEach(setupRow);
9792
it('The proof options MUST contain a type identifier for the ' +
9893
'cryptographic suite (type) and MUST contain a cryptosuite ' +
9994
'identifier (cryptosuite).',
10095
async function() {
10196
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
102-
const proof = proofExists(proofs);
97+
const proof = proofExists(securedCredential);
10398
should.exist(proof.type,
10499
'Expected a type identifier on the proof.');
105100
should.exist(proof.cryptosuite,
@@ -111,7 +106,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
111106
'of PROOF_GENERATION_ERROR.',
112107
async function() {
113108
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
114-
const proof = proofExists(proofs);
109+
const proof = proofExists(securedCredential);
115110
should.exist(proof.type,
116111
'Expected a type identifier on the proof.');
117112
should.exist(proof.cryptosuite,
@@ -126,7 +121,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
126121
'SHOULD convey an error type of PROOF_GENERATION_ERROR.',
127122
async function() {
128123
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019';
129-
const proof = proofExists(proofs);
124+
const proof = proofExists(securedCredential);
130125
if(proof?.created) {
131126
isValidDatetime(proof.created).should.equal(
132127
true,
@@ -145,19 +140,17 @@ describe('Algorithms - Proof Serialization (ecdsa-rdfc-2019)', function() {
145140
describe(columnId, function() {
146141
const [issuer] = endpoints;
147142
let securedCredential;
148-
let proofs;
149143
before(async function() {
150144
securedCredential = await secureCredential(
151145
{issuer, vc: generateCredential()});
152-
proofs = getProofs(securedCredential);
153146
});
154147
beforeEach(setupRow);
155148
it('The proof options MUST contain a type identifier for the ' +
156149
'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
157150
'(cryptosuite).',
158151
async function() {
159152
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-rdfc-2019';
160-
const proof = proofExists(proofs);
153+
const proof = proofExists(securedCredential);
161154
should.exist(proof.type,
162155
'Expected a type identifier on the proof.');
163156
});

tests/helpers.js

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

290-
export function proofExists(proofs) {
290+
export function proofExists(securedCredential) {
291+
should.exist(securedCredential,
292+
'Expected issuer to have issued a credential.');
293+
const proofs = getProofs(securedCredential);
291294
should.exist(proofs,
292295
'Expected credential to have a proof.');
293296
proofs.length.should.be.gte(1,
294297
'Expected credential to have at least one proof.');
295298
return proofs[0];
296299
}
297300

298-
export function assertSecuredCredential(securedCredential) {
299-
should.exist(securedCredential,
300-
'Expected issuer to have issued a credential.');
301-
const proofs = getProofs(securedCredential);
302-
proofExists(proofs);
303-
}
304-
305301
export async function verifySuccess(verifier, securedCredential) {
306302
const body = {
307303
verifiableCredential: securedCredential

0 commit comments

Comments
 (0)