Skip to content

Commit 5a622ee

Browse files
committed
Use verificationSucess to test common algorithm tests.
1 parent 25e2f8c commit 5a622ee

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

tests/suites/algorithms.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
* Copyright 2024 Digital Bazaar, Inc.
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5+
import {
6+
assertions,
7+
generators,
8+
issueCloned
9+
} from 'data-integrity-test-suite-assertion';
510
import {createInitialVc, endpointCheck} from '../helpers.js';
611
import {expect} from 'chai';
12+
import {localVerifier} from '../vc-verifier/index.js';
713

814
export function algorithmSuite({
915
suiteName
@@ -15,9 +21,11 @@ export function commonAlgorithms({
1521
issuers,
1622
mandatoryPointers,
1723
keyType,
24+
cryptosuite,
1825
suiteName,
1926
vcVersion
2027
}) {
28+
const verifier = localVerifier({cryptosuite});
2129
for(const [name, {endpoints}] of issuers) {
2230
const [issuer] = endpoints;
2331
// does the endpoint support this test?
@@ -26,35 +34,48 @@ export function commonAlgorithms({
2634
}
2735
describe(`${name}: ${keyType}`, function() {
2836
let securedCredential = null;
29-
let proofs = [];
3037
before(async function() {
3138
securedCredential = await createInitialVc({
3239
issuer,
3340
vcVersion,
3441
vc: credential,
3542
mandatoryPointers
3643
});
37-
if(securedCredential) {
38-
proofs = Array.isArray(securedCredential.proof) ?
39-
securedCredential?.proof : [securedCredential?.proof];
40-
// only test proofs that match the relevant cryptosuite
41-
proofs = proofs.filter(p => p?.cryptosuite === suiteName);
42-
}
4344
});
4445
it('When generating ECDSA signatures, the signature value MUST be ' +
45-
'expressed according to section 7 of [RFC4754] (sometimes referred to ' +
46-
'as the IEEE P1363 format) and encoded according to the specific ' +
46+
'expressed according to section 7 of [RFC4754] (sometimes referred ' +
47+
'to as the IEEE P1363 format) and encoded according to the specific ' +
4748
'cryptosuite proof generation algorithm.', async function() {
4849
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=When%20generating%20ECDSA%20signatures%2C%20the%20signature%20value%20MUST%20be%20expressed%20according%20to%20section%207%20of%20%5BRFC4754%5D%20(sometimes%20referred%20to%20as%20the%20IEEE%20P1363%20format)%20and%20encoded%20according%20to%20the%20specific%20cryptosuite%20proof%20generation%20algorithm';
50+
await assertions.verificationSuccess({
51+
credential: securedCredential,
52+
verifier,
53+
reason: `Should verify VC signed with ${suiteName} ${keyType}`
54+
});
4955
});
50-
it('For P-256 keys, the default hashing function, SHA-2 with 256 bits of ' +
51-
'output, MUST be used.', async function() {
52-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D256%20keys%2C%20the%20default%20hashing%20function%2C%20SHA%2D2%20with%20256%20bits%20of%20output%2C%20MUST%20be%20used.';
53-
});
54-
it('For P-384 keys, SHA-2 with 384-bits of output MUST be used, specified ' +
55-
'via the RDFC-1.0 implementation-specific parameter.', async function() {
56-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D384%20keys%2C%20SHA%2D2%20with%20384%2Dbits%20of%20output%20MUST%20be%20used%2C%20specified%20via%20the%20RDFC%2D1.0%20implementation%2Dspecific%20parameter.';
57-
});
56+
if(keyType === 'P-256') {
57+
it('For P-256 keys, the default hashing function, SHA-2 with 256 bits' +
58+
'of output, MUST be used.', async function() {
59+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D256%20keys%2C%20the%20default%20hashing%20function%2C%20SHA%2D2%20with%20256%20bits%20of%20output%2C%20MUST%20be%20used.';
60+
await assertions.verificationSuccess({
61+
credential: securedCredential,
62+
verifier,
63+
reason: `Should verify VC signed with ${suiteName} ${keyType}`
64+
});
65+
});
66+
}
67+
if(keyType === 'P-384') {
68+
it('For P-384 keys, SHA-2 with 384-bits of output MUST be used, ' +
69+
'specified via the RDFC-1.0 implementation-specific parameter.',
70+
async function() {
71+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D384%20keys%2C%20SHA%2D2%20with%20384%2Dbits%20of%20output%20MUST%20be%20used%2C%20specified%20via%20the%20RDFC%2D1.0%20implementation%2Dspecific%20parameter.';
72+
await assertions.verificationSuccess({
73+
credential: securedCredential,
74+
verifier,
75+
reason: `Should verify VC signed with ${suiteName} ${keyType}`
76+
});
77+
});
78+
}
5879
});
5980
}
6081
}

0 commit comments

Comments
 (0)