Skip to content

Commit fad0e5d

Browse files
committed
Add proofValue check to sd algorithms.
1 parent ee963ab commit fad0e5d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/suites/algorithms-sd.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
* Copyright 2024 Digital Bazaar, Inc.
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5+
import {
6+
shouldBeBs64UrlNoPad,
7+
shouldHaveHeaderBytes,
8+
} from '../assertions.js';
59
import {
610
assertions,
711
} from 'data-integrity-test-suite-assertion';
12+
import {createInitialVc} from '../helpers.js';
13+
import {expect} from 'chai';
814
import {sdVerifySetup} from '../setup.js';
915

1016
export function sd2023Algorithms({
@@ -36,12 +42,69 @@ export function sd2023Algorithms({
3642
for(const keyType of keyTypes) {
3743
this.implemented.push(`${name}: ${keyType}`);
3844
describe(`${name}: ${keyType}`, function() {
45+
let baseCredential;
46+
let proofs = [];
47+
before(async function() {
48+
// we can fairly safely assume there is an issuer
49+
// but we should check
50+
if(issuer) {
51+
baseCredential = await createInitialVc({
52+
issuer,
53+
credential,
54+
mandatoryPointers
55+
});
56+
if(baseCredential) {
57+
proofs = Array.isArray(baseCredential.proof) ?
58+
baseCredential?.proof : [baseCredential?.proof];
59+
// only test proofs that match the relevant cryptosuite
60+
proofs = proofs.filter(p => p?.cryptosuite === suiteName);
61+
}
62+
}
63+
});
3964
beforeEach(function() {
4065
this.currentTest.cell = {
4166
rowId: this.currentTest.title,
4267
columnId: this.currentTest.parent.title
4368
};
4469
});
70+
it('When generating ECDSA signatures, the signature value MUST be ' +
71+
'expressed according to section 7 of [RFC4754] (sometimes referred ' +
72+
'to as the IEEE P1363 format) and encoded according to the ' +
73+
'specific cryptosuite proof generation algorithm.', async function() {
74+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#base-proof-serialization-ecdsa-sd-2023:~:text=When%20generating%20ECDSA%20signatures%2C%20the%20signature%20value%20MUST%20be%20expressed%20according%20to%20section%207';
75+
const _proof = proofs.find(p =>
76+
p?.cryptosuite === 'ecdsa-sd-2023');
77+
expect(
78+
_proof,
79+
`Expected VC from issuer ${name} to have an ' +
80+
'"ecdsa-sd-2023" proof`).to.exist;
81+
expect(
82+
_proof.proofValue,
83+
`Expected VC from issuer ${name} to have a ' +
84+
'"proof.proofValue"`
85+
).to.exist;
86+
expect(
87+
_proof.proofValue,
88+
`Expected VC "proof.proofValue" from issuer ${name} to be ` +
89+
'a string.'
90+
).to.be.a.string;
91+
//Ensure the proofValue string starts with u, indicating that it
92+
//is a multibase-base64url-no-pad-encoded value, throwing an
93+
//error if it does not.
94+
expect(
95+
_proof.proofValue.startsWith('u'),
96+
`Expected "proof.proofValue" to start with u received ` +
97+
`${_proof.proofValue[0]}`).to.be.true;
98+
// now test the encoding which is bs64 url no pad for this suite
99+
expect(
100+
shouldBeBs64UrlNoPad(_proof.proofValue),
101+
'Expected "proof.proofValue" to be bs64 url no pad encoded.'
102+
).to.be.true;
103+
await shouldHaveHeaderBytes(
104+
_proof.proofValue,
105+
new Uint8Array([0xd9, 0x5d, 0x00])
106+
);
107+
});
45108
it('If source has an id that is not a blank node identifier, set ' +
46109
'selection.id to its value. Note: All non-blank node identifiers ' +
47110
'in the path of any JSON Pointer MUST be included in the ' +

0 commit comments

Comments
 (0)