|
2 | 2 | * Copyright 2024 Digital Bazaar, Inc. |
3 | 3 | * SPDX-License-Identifier: BSD-3-Clause |
4 | 4 | */ |
| 5 | +import { |
| 6 | + shouldBeBs64UrlNoPad, |
| 7 | + shouldHaveHeaderBytes, |
| 8 | +} from '../assertions.js'; |
5 | 9 | import { |
6 | 10 | assertions, |
7 | 11 | } from 'data-integrity-test-suite-assertion'; |
| 12 | +import {createInitialVc} from '../helpers.js'; |
| 13 | +import {expect} from 'chai'; |
8 | 14 | import {sdVerifySetup} from '../setup.js'; |
9 | 15 |
|
10 | 16 | export function sd2023Algorithms({ |
@@ -36,12 +42,69 @@ export function sd2023Algorithms({ |
36 | 42 | for(const keyType of keyTypes) { |
37 | 43 | this.implemented.push(`${name}: ${keyType}`); |
38 | 44 | 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 | + }); |
39 | 64 | beforeEach(function() { |
40 | 65 | this.currentTest.cell = { |
41 | 66 | rowId: this.currentTest.title, |
42 | 67 | columnId: this.currentTest.parent.title |
43 | 68 | }; |
44 | 69 | }); |
| 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 | + }); |
45 | 108 | it('If source has an id that is not a blank node identifier, set ' + |
46 | 109 | 'selection.id to its value. Note: All non-blank node identifiers ' + |
47 | 110 | 'in the path of any JSON Pointer MUST be included in the ' + |
|
0 commit comments