Skip to content

Commit f2563cd

Browse files
committed
Move base proof assertion to assertions and reuse.
1 parent 6424fef commit f2563cd

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

tests/assertions.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {klona} from 'klona';
1313
import varint from 'varint';
1414

1515
const should = chai.should();
16+
const {expect} = chai;
1617

1718
// RegExp with bs58 characters in it
1819
const bs58 =
@@ -182,3 +183,36 @@ export function itRejectsInvalidCryptosuite(expectedValidSuites, {
182183
await verificationFail({credential, verifier: endpoint});
183184
});
184185
}
186+
187+
export async function shouldBeBaseProofValue({proof, name}) {
188+
expect(
189+
proof,
190+
`Expected VC from issuer ${name} to have an ' +
191+
'"ecdsa-sd-2023" proof`).to.exist;
192+
expect(
193+
proof.proofValue,
194+
`Expected VC from issuer ${name} to have a ' +
195+
'"proof.proofValue"`
196+
).to.exist;
197+
expect(
198+
proof.proofValue,
199+
`Expected VC "proof.proofValue" from issuer ${name} to be ` +
200+
'a string.'
201+
).to.be.a.string;
202+
//Ensure the proofValue string starts with u, indicating that it
203+
//is a multibase-base64url-no-pad-encoded value, throwing an
204+
//error if it does not.
205+
expect(
206+
proof.proofValue.startsWith('u'),
207+
`Expected "proof.proofValue" to start with u received ` +
208+
`${proof.proofValue[0]}`).to.be.true;
209+
// now test the encoding which is bs64 url no pad for this suite
210+
expect(
211+
shouldBeBs64UrlNoPad(proof.proofValue),
212+
'Expected "proof.proofValue" to be bs64 url no pad encoded.'
213+
).to.be.true;
214+
await shouldHaveHeaderBytes(
215+
proof.proofValue,
216+
new Uint8Array([0xd9, 0x5d, 0x00])
217+
);
218+
}

tests/suites/algorithms-sd.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
issueCloned
99
} from 'data-integrity-test-suite-assertion';
1010
import {
11+
shouldBeBaseProofValue,
1112
shouldBeBs64UrlNoPad,
1213
shouldHaveHeaderBytes,
1314
} from '../assertions.js';
@@ -93,38 +94,8 @@ export function sd2023Algorithms({
9394
'specific cryptosuite proof generation algorithm.', async function() {
9495
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';
9596
assertIssuer();
96-
const _proof = proofs.find(p =>
97-
p?.cryptosuite === 'ecdsa-sd-2023');
98-
expect(
99-
_proof,
100-
`Expected VC from issuer ${name} to have an ' +
101-
'"ecdsa-sd-2023" proof`).to.exist;
102-
expect(
103-
_proof.proofValue,
104-
`Expected VC from issuer ${name} to have a ' +
105-
'"proof.proofValue"`
106-
).to.exist;
107-
expect(
108-
_proof.proofValue,
109-
`Expected VC "proof.proofValue" from issuer ${name} to be ` +
110-
'a string.'
111-
).to.be.a.string;
112-
//Ensure the proofValue string starts with u, indicating that it
113-
//is a multibase-base64url-no-pad-encoded value, throwing an
114-
//error if it does not.
115-
expect(
116-
_proof.proofValue.startsWith('u'),
117-
`Expected "proof.proofValue" to start with u received ` +
118-
`${_proof.proofValue[0]}`).to.be.true;
119-
// now test the encoding which is bs64 url no pad for this suite
120-
expect(
121-
shouldBeBs64UrlNoPad(_proof.proofValue),
122-
'Expected "proof.proofValue" to be bs64 url no pad encoded.'
123-
).to.be.true;
124-
await shouldHaveHeaderBytes(
125-
_proof.proofValue,
126-
new Uint8Array([0xd9, 0x5d, 0x00])
127-
);
97+
const proof = proofs.find(p => p?.cryptosuite === 'ecdsa-sd-2023');
98+
await shouldBeBaseProofValue({proof, name});
12899
});
129100
it('If source has an id that is not a blank node identifier, set ' +
130101
'selection.id to its value. Note: All non-blank node identifiers ' +
@@ -184,9 +155,9 @@ export function sd2023Algorithms({
184155
'raised and SHOULD convey an error type of PROOF_VERIFICATION_ERROR.',
185156
async function() {
186157
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#selective-disclosure-functions:~:text=If%20the%20decodedProofValue%20does%20not%20start%20with%20the%20ECDSA%2DSD%20base%20proof%20header%20bytes%200xd9%2C%200x5d%2C%20and%200x00%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_VERIFICATION_ERROR.';
187-
this.test.cell.skipMessage = 'Not Implemented';
188-
this.skip();
189158
assertIssuer();
159+
const proof = proofs.find(p => p?.cryptosuite === 'ecdsa-sd-2023');
160+
await shouldBeBaseProofValue({proof, name});
190161
});
191162
it('If the decodedProofValue does not start with the ECDSA-SD ' +
192163
'disclosure proof header bytes 0xd9, 0x5d, and 0x01, an error ' +

0 commit comments

Comments
 (0)