|
| 1 | +/*! |
| 2 | + * Copyright 2023-2024 Digital Bazaar, Inc. |
| 3 | + * SPDX-License-Identifier: BSD-3-Clause |
| 4 | + */ |
| 5 | +import {createInitialVc, endpointCheck} from './helpers.js'; |
| 6 | +import { |
| 7 | + shouldBeBs58, |
| 8 | + shouldBeMulticodecEncoded, |
| 9 | + shouldHaveByteLength, |
| 10 | + verificationSuccess |
| 11 | +} from './assertions.js'; |
| 12 | +import {cryptosuite} from '@digitalbazaar/ecdsa-rdfc-2019-cryptosuite'; |
| 13 | +import {documentLoader} from './documentLoader.js'; |
| 14 | +import {endpoints} from 'vc-test-suite-implementations'; |
| 15 | +import {expect} from 'chai'; |
| 16 | +import {getSuiteConfig} from './test-config.js'; |
| 17 | +import {localVerifier} from './vc-verifier/index.js'; |
| 18 | + |
| 19 | +const { |
| 20 | + tags, |
| 21 | + credentials, |
| 22 | + vectors, |
| 23 | + proofLengths |
| 24 | +} = getSuiteConfig('ecdsa-rdfc-2019'); |
| 25 | +const {match} = endpoints.filterByTag({ |
| 26 | + tags: [...tags], |
| 27 | + property: 'issuers' |
| 28 | +}); |
| 29 | + |
| 30 | +const verifier = localVerifier({cryptosuite}); |
| 31 | + |
| 32 | +describe('ecdsa-rdfc-2019 (create)', function() { |
| 33 | + for(const vcVersion of vectors.vcTypes) { |
| 34 | + describe(`ecdsa-rdfc-2019 (issuers) VC ${vcVersion}`, function() { |
| 35 | + this.matrix = true; |
| 36 | + this.report = true; |
| 37 | + this.implemented = []; |
| 38 | + this.rowLabel = 'Test Name'; |
| 39 | + this.columnLabel = 'Implementation'; |
| 40 | + for(const [name, {endpoints: issuers}] of match) { |
| 41 | + // test for each support key type |
| 42 | + for(const keyType of vectors.keyTypes) { |
| 43 | + // loop through each issuer in suite |
| 44 | + for(const issuer of issuers) { |
| 45 | + // does the endpoint support this test? |
| 46 | + if(!endpointCheck({endpoint: issuer, keyType, vcVersion})) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + // add implementer name and keyType to test report |
| 50 | + this.implemented.push(`${name}: ${keyType}`); |
| 51 | + describe(`${name}: ${keyType}`, function() { |
| 52 | + let issuedVc; |
| 53 | + let proofs; |
| 54 | + const verificationMethodDocuments = []; |
| 55 | + before(async function() { |
| 56 | + issuedVc = await createInitialVc({ |
| 57 | + issuer, |
| 58 | + vc: credentials.create[vcVersion].document, |
| 59 | + vcVersion |
| 60 | + }); |
| 61 | + // VCs can have multiple proofs so account for that |
| 62 | + proofs = Array.isArray(issuedVc?.proof) ? issuedVc.proof : |
| 63 | + [issuedVc?.proof]; |
| 64 | + const verificationMethods = proofs.map( |
| 65 | + proof => proof.verificationMethod); |
| 66 | + for(const verificationMethod of verificationMethods) { |
| 67 | + const verificationMethodDocument = await documentLoader({ |
| 68 | + url: verificationMethod |
| 69 | + }); |
| 70 | + verificationMethodDocuments.push(verificationMethodDocument); |
| 71 | + } |
| 72 | + }); |
| 73 | + /* |
| 74 | + @link https://w3c.github.io/vc-di-ecdsa/ |
| 75 | + #verify-derived-proof-ecdsa-sd-2023:~:text= |
| 76 | + The%20type%20property%20MUST%20be%20DataIntegrityProof |
| 77 | + */ |
| 78 | + it('The (proof) type property MUST be DataIntegrityProof.', |
| 79 | + function() { |
| 80 | + this.test.cell = { |
| 81 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 82 | + }; |
| 83 | + proofs.map(p => p?.type).should.contain( |
| 84 | + 'DataIntegrityProof', |
| 85 | + 'Expected at least one proof to have type ' + |
| 86 | + 'DataIntegrityProof'); |
| 87 | + }); |
| 88 | + /* |
| 89 | + @link https://w3c.github.io/vc-di-ecdsa/ |
| 90 | + #verify-derived-proof-ecdsa-sd-2023:~:text= |
| 91 | + The%20cryptosuite%20property%20MUST%20be%20ecdsa%2Drdfc%2D2019% |
| 92 | + 2C%20ecdsa%2Djcs%2D2019%2C%20or%20ecdsa%2Dsd%2D2023. |
| 93 | + */ |
| 94 | + it('The cryptosuite property of the proof MUST be ' + |
| 95 | + 'ecdsa-rdfc-2019 or ecdsa-jcs-2019.', function() { |
| 96 | + this.test.cell = { |
| 97 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 98 | + }; |
| 99 | + const cryptosuite = ['ecdsa-rdfc-2019', 'ecdsa-jcs-2019']; |
| 100 | + expect( |
| 101 | + proofs.map(proof => proof?.cryptosuite), |
| 102 | + 'Expected at least one proof to have ' + |
| 103 | + '"cryptosuite" property "ecdsa-rdfc-2019" or "ecdsa-jcs-2019".') |
| 104 | + .to.contain.oneOf(cryptosuite); |
| 105 | + }); |
| 106 | + it('the signature value (proofValue) MUST be expressed ' + |
| 107 | + 'according to section 7 of [RFC4754] (sometimes referred to ' + |
| 108 | + 'as the IEEE P1363 format) and encoded according to the ' + |
| 109 | + 'specific cryptosuite proof generation algorithm.', |
| 110 | + async function() { |
| 111 | + this.test.cell = { |
| 112 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 113 | + }; |
| 114 | + const _proof = proofs.find(p => |
| 115 | + p?.cryptosuite === 'ecdsa-rdfc-2019'); |
| 116 | + expect( |
| 117 | + _proof, |
| 118 | + `Expected VC from issuer ${name} to have an ' + |
| 119 | + '"ecdsa-rdfc-2019" proof`).to.exist; |
| 120 | + expect( |
| 121 | + _proof.proofValue, |
| 122 | + `Expected VC from issuer ${name} to have a ' + |
| 123 | + '"proof.proofValue"` |
| 124 | + ).to.exist; |
| 125 | + expect( |
| 126 | + _proof.proofValue, |
| 127 | + `Expected VC "proof.proofValue" from issuer ${name} to be ` + |
| 128 | + 'a string.' |
| 129 | + ).to.be.a.string; |
| 130 | + // now test the encoding which is bs58 for this suite |
| 131 | + expect( |
| 132 | + shouldBeBs58(_proof.proofValue), |
| 133 | + 'Expected "proof.proofValue" to be bs58 encoded.' |
| 134 | + ).to.be.true; |
| 135 | + // proofBytes will be exactly 64 bytes in size for a P-256 key, |
| 136 | + // and 96 bytes in size for a P-384 key. |
| 137 | + const expectedLength = proofLengths[keyType]; |
| 138 | + await shouldHaveByteLength(_proof.proofValue, expectedLength); |
| 139 | + }); |
| 140 | + it('The "proof" MUST verify with a conformant verifier.', |
| 141 | + async function() { |
| 142 | + this.test.cell = { |
| 143 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 144 | + }; |
| 145 | + await verificationSuccess({ |
| 146 | + credential: issuedVc, |
| 147 | + verifier |
| 148 | + }); |
| 149 | + }); |
| 150 | + it('The "proof.proofPurpose" field MUST match the verification ' + |
| 151 | + 'relationship expressed by the verification method controller.', |
| 152 | + async function() { |
| 153 | + this.test.cell = { |
| 154 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 155 | + }; |
| 156 | + verificationMethodDocuments.should.not.eql([], 'Expected ' + |
| 157 | + 'at least one "verificationMethodDocument".'); |
| 158 | + verificationMethodDocuments.some( |
| 159 | + verificationMethodDocument => |
| 160 | + verificationMethodDocument?.type === 'Multikey' |
| 161 | + ).should.equal(true, 'Expected at least one proof to have ' + |
| 162 | + '"type" property value "Multikey".' |
| 163 | + ); |
| 164 | + const controllerDocuments = []; |
| 165 | + for(const verificationMethodDocument of |
| 166 | + verificationMethodDocuments) { |
| 167 | + const controllerDocument = await documentLoader({ |
| 168 | + url: verificationMethodDocument.controller |
| 169 | + }); |
| 170 | + controllerDocuments.push(controllerDocument); |
| 171 | + } |
| 172 | + proofs.some( |
| 173 | + proof => controllerDocuments.some(controllerDocument => |
| 174 | + controllerDocument.hasOwnProperty(proof.proofPurpose)) |
| 175 | + ).should.equal(true, 'Expected "proof.proofPurpose" field ' + |
| 176 | + 'to match the verification method controller.' |
| 177 | + ); |
| 178 | + }); |
| 179 | + it('Dereferencing "verificationMethod" MUST result in an ' + |
| 180 | + 'object containing a type property with "Multikey" value.', |
| 181 | + async function() { |
| 182 | + this.test.cell = { |
| 183 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 184 | + }; |
| 185 | + verificationMethodDocuments.should.not.eql([], 'Expected ' + |
| 186 | + 'at least one "verificationMethodDocument".'); |
| 187 | + verificationMethodDocuments.some( |
| 188 | + verificationMethodDocument => |
| 189 | + verificationMethodDocument?.type === 'Multikey' |
| 190 | + ).should.equal(true, 'Expected at least one proof to have ' + |
| 191 | + '"type" property value "Multikey".' |
| 192 | + ); |
| 193 | + }); |
| 194 | + it('The "publicKeyMultibase" property of the verification ' + |
| 195 | + 'method MUST be public key encoded according to MULTICODEC ' + |
| 196 | + 'and formatted according to MULTIBASE.', async function() { |
| 197 | + this.test.cell = { |
| 198 | + columnId: `${name}: ${keyType}`, rowId: this.test.title |
| 199 | + }; |
| 200 | + verificationMethodDocuments.should.not.eql([], 'Expected ' + |
| 201 | + '"verificationMethodDocuments" to not be empty.'); |
| 202 | + verificationMethodDocuments.some( |
| 203 | + verificationMethodDocument => { |
| 204 | + const multibase = 'z'; |
| 205 | + const {publicKeyMultibase} = verificationMethodDocument; |
| 206 | + return publicKeyMultibase.startsWith(multibase) && |
| 207 | + shouldBeBs58(publicKeyMultibase) && |
| 208 | + shouldBeMulticodecEncoded(publicKeyMultibase); |
| 209 | + } |
| 210 | + ).should.equal(true, 'Expected at "publicKeyMultibase" to ' + |
| 211 | + 'be MULTIBASE formatted and MULTICODEC encoded.'); |
| 212 | + }); |
| 213 | + }); |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | + }); |
| 218 | + } |
| 219 | +}); |
0 commit comments