From 6adc7c3568c04233b01a05d855de5b178a6557b1 Mon Sep 17 00:00:00 2001 From: PatStLouis Date: Mon, 11 Nov 2024 21:01:34 +0000 Subject: [PATCH 01/12] ecdsa-jcs algorithms and helpers Signed-off-by: PatStLouis --- tests/90-algorithms-jcs.js | 7 + tests/helpers.js | 75 +++++++++++ tests/suites/algorithms-jcs.js | 228 +++++++++++++++++++++++++++++++++ 3 files changed, 310 insertions(+) create mode 100644 tests/90-algorithms-jcs.js create mode 100644 tests/suites/algorithms-jcs.js diff --git a/tests/90-algorithms-jcs.js b/tests/90-algorithms-jcs.js new file mode 100644 index 00000000..6fe2c455 --- /dev/null +++ b/tests/90-algorithms-jcs.js @@ -0,0 +1,7 @@ +/*! + * Copyright 2024 Digital Bazaar, Inc. + * SPDX-License-Identifier: BSD-3-Clause + */ +import {ecdsaJcs2019Algorithms} from './suites/algorithms-jcs.js'; + +ecdsaJcs2019Algorithms(); diff --git a/tests/helpers.js b/tests/helpers.js index 5dc06626..39c2aefc 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -5,7 +5,9 @@ import * as bs58 from 'base58-universal'; import * as bs64 from 'base64url-universal'; import {createRequire} from 'node:module'; +import {isUtf8} from 'node:buffer'; import {klona} from 'klona'; +import {readFileSync} from 'fs'; import {v4 as uuidv4} from 'uuid'; export const require = createRequire(import.meta.url); @@ -216,3 +218,76 @@ export function setupReportableTestSuite(runnerContext, name) { runnerContext.implemented = []; } + +export function isValidUtf8(string) { + const textEncoder = new TextEncoder(); + const uint8Array = textEncoder.encode(string); + if(!isUtf8(uint8Array)) { + return false; + } else { + return true; + } +} + +export function isValidDatetime(dateString) { + return !isNaN(Date.parse(dateString)); +} + +export function setupMatrix(match) { + // this will tell the report + // to make an interop matrix with this suite + this.matrix = true; + this.report = true; + this.implemented = [...match.keys()]; + this.rowLabel = 'Test Name'; + this.columnLabel = 'Implementer'; +} + +export const config = JSON.parse(readFileSync('./config/runner.json')); + +export function createValidCredential(version = 2) { + let credential = { + type: ['VerifiableCredential'], + id: `urn:uuid:${uuidv4()}`, + credentialSubject: {id: 'did:example:alice'} + }; + if(version === 1) { + // add v1.1 context and issuanceDate + credential = Object.assign({}, { + '@context': [ + 'https://www.w3.org/2018/credentials/v1', + 'https://w3id.org/security/data-integrity/v2' + ], + issuanceDate: ISOTimeStamp() + }, credential); + } else if(version === 2) { + // add v2 context + credential = Object.assign({}, { + '@context': [ + 'https://www.w3.org/ns/credentials/v2' + ] + }, credential); + } else { + return null; + } + return credential; +} + +export function setupRow() { + // append test meta data to the it/test this. + this.currentTest.cell = { + columnId: this.currentTest.parent.title, + rowId: this.currentTest.title + }; +} + +export function getProofs(issuedVc) { + // if the implementation failed to issue a VC or to sign the VC, return + // an empty array + if(!issuedVc?.proof) { + return []; + } + const proofs = Array.isArray(issuedVc?.proof) ? + issuedVc.proof : [issuedVc?.proof]; + return proofs; +} diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js new file mode 100644 index 00000000..4fa29ebc --- /dev/null +++ b/tests/suites/algorithms-jcs.js @@ -0,0 +1,228 @@ +/*! + * Copyright 2024 Digital Bazaar, Inc. + * SPDX-License-Identifier: BSD-3-Clause + */ +import { + config, + createInitialVc, + createValidCredential, + getProofs, + setupMatrix, + setupRow +} from '../helpers.js'; +import {isValidDatetime, isValidUtf8} from './helpers.js'; +import chai from 'chai'; +import {endpoints} from 'vc-test-suite-implementations'; + +export function ecdsaJcs2019Algorithms() { + const cryptosuite = 'ecdsa-jcs-2022'; + const {tags} = config.suites[ + cryptosuite + ]; + const {issuerMatch} = endpoints.filterByTag({ + tags: [...tags], + property: 'issuers' + }); + // const {verifierMatch} = endpoints.filterByTag({ + // tags: [...tags], + // property: 'verifiers' + // }); + const should = chai.should(); + + describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { + setupMatrix.call(this, issuerMatch); + let validCredential; + before(async function() { + validCredential = await createValidCredential(); + }); + for(const [columnId, {endpoints}] of issuerMatch) { + describe(columnId, function() { + const [issuer] = endpoints; + let issuedVc; + let proofs; + let ecdsa2022Proofs = []; + before(async function() { + issuedVc = await createInitialVc({issuer, vc: validCredential}); + proofs = getProofs(issuedVc); + if(proofs?.length) { + ecdsa2022Proofs = proofs.filter( + proof => proof?.cryptosuite === cryptosuite); + } + }); + beforeEach(setupRow); + const assertBefore = () => { + should.exist(issuedVc, 'Expected issuer to have issued a ' + + 'credential.'); + should.exist(proofs, 'Expected credential to have a proof.'); + ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + 'ecdsa-jcs-2019 cryptosuite.'); + }; + it('The transformation options MUST contain a type identifier ' + + 'for the cryptographic suite (type) and a cryptosuite identifier ' + + '(cryptosuite).', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof.type, 'Expected a type identifier on ' + + 'the proof.'); + should.exist(proof.cryptosuite, + 'Expected a cryptosuite identifier on the proof.'); + } + }); + it('Whenever this algorithm encodes strings, ' + + 'it MUST use UTF-8 encoding.', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof?.proofValue, + 'Expected proofValue to exist.'); + isValidUtf8(proof.proofValue).should.equal( + true, + 'Expected proofValue value to be a valid UTF-8 encoded string.' + ); + } + }); + it('If options.type is not set to the string DataIntegrityProof or ' + + 'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' + + 'an error MUST be raised and SHOULD convey an error type ' + + 'of PROOF_TRANSFORMATION_ERROR.', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof.type, + 'Expected a type identifier on the proof.'); + should.exist(proof.cryptosuite, + 'Expected a cryptosuite identifier on the proof.'); + proof.type.should.equal('DataIntegrityProof', + 'Expected DataIntegrityProof type.'); + proof.cryptosuite.should.equal('ecdsa-jcs-2022', + 'Expected ecdsa-jcs-2022 cryptosuite.'); + } + }); + }); + } + }); + + describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() { + setupMatrix.call(this, issuerMatch); + let validCredential; + before(async function() { + validCredential = await createValidCredential(); + }); + for(const [columnId, {endpoints}] of issuerMatch) { + describe(columnId, function() { + const [issuer] = endpoints; + let issuedVc; + let proofs; + let ecdsa2022Proofs = []; + before(async function() { + issuedVc = await createInitialVc({issuer, vc: validCredential}); + proofs = getProofs(issuedVc); + if(proofs?.length) { + ecdsa2022Proofs = proofs.filter( + proof => proof?.cryptosuite === cryptosuite); + } + }); + beforeEach(setupRow); + const assertBefore = () => { + should.exist(issuedVc, 'Expected issuer to have issued a ' + + 'credential.'); + should.exist(proofs, 'Expected credential to have a proof.'); + ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + 'ecdsa-jcs-2019 cryptosuite.'); + }; + it('The proof options MUST contain a type identifier for the ' + + 'cryptographic suite (type) and MUST contain a cryptosuite ' + + 'identifier (cryptosuite).', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof.type, + 'Expected a type identifier on the proof.'); + should.exist(proof.cryptosuite, + 'Expected a cryptosuite identifier on the proof.'); + } + }); + it('If proofConfig.type is not set to DataIntegrityProof ' + + 'and/or proofConfig.cryptosuite is not set to ecdsa-jcs-2019, ' + + 'an error MUST be raised and SHOULD convey an error type ' + + 'of PROOF_GENERATION_ERROR.', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof.type, + 'Expected a type identifier on the proof.'); + should.exist(proof.cryptosuite, + 'Expected a cryptosuite identifier on the proof.'); + proof.type.should.equal('DataIntegrityProof', + 'Expected DataIntegrityProof type.'); + proof.cryptosuite.should.equal('ecdsa-jcs-2022', + 'Expected ecdsa-jcs-2022 cryptosuite.'); + } + }); + it('If proofConfig.created is set and if the value is not a ' + + 'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' + + 'SHOULD convey an error type of PROOF_GENERATION_ERROR.', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; + for(const proof of ecdsa2022Proofs) { + if(proof?.created) { + isValidDatetime(proof.created).should.equal( + true, + 'Expected created value to be a valid datetime string.' + ); + } + } + }); + }); + } + }); + + describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { + setupMatrix.call(this, issuerMatch); + let validCredential; + before(async function() { + validCredential = await createValidCredential(); + }); + for(const [columnId, {endpoints}] of issuerMatch) { + describe(columnId, function() { + const [issuer] = endpoints; + let issuedVc; + let proofs; + let ecdsa2022Proofs = []; + before(async function() { + issuedVc = await createInitialVc({issuer, vc: validCredential}); + proofs = getProofs(issuedVc); + if(proofs?.length) { + ecdsa2022Proofs = proofs.filter( + proof => proof?.cryptosuite === cryptosuite); + } + }); + beforeEach(setupRow); + const assertBefore = () => { + should.exist(issuedVc, 'Expected issuer to have issued a ' + + 'credential.'); + should.exist(proofs, 'Expected credential to have a proof.'); + ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + 'ecdsa-jcs-2019 cryptosuite.'); + }; + it('The proof options MUST contain a type identifier for the ' + + 'cryptographic suite (type) and MAY contain a cryptosuite ' + + 'identifier (cryptosuite).', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of ecdsa2022Proofs) { + should.exist(proof.type, + 'Expected a type identifier on the proof.'); + } + }); + }); + } + }); +} From 61eee843ec77d43124e879f4044c306d5ebe2967 Mon Sep 17 00:00:00 2001 From: Patrick St-Louis <43082425+PatStLouis@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:00:17 -0500 Subject: [PATCH 02/12] Apply text suggestion Co-authored-by: Ted Thibodeau Jr --- tests/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/helpers.js b/tests/helpers.js index 39c2aefc..ede9c5aa 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -282,8 +282,8 @@ export function setupRow() { } export function getProofs(issuedVc) { - // if the implementation failed to issue a VC or to sign the VC, return - // an empty array + // if the implementation failed to issue a VC or to sign the VC, + // return an empty array if(!issuedVc?.proof) { return []; } From 274e80b5eaadf10cd0623721845b4aa37cc17ab7 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 17:02:27 +0000 Subject: [PATCH 03/12] Use test helpers not suite helpers. --- tests/suites/algorithms-jcs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index 4fa29ebc..b9f5fd8e 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -10,7 +10,7 @@ import { setupMatrix, setupRow } from '../helpers.js'; -import {isValidDatetime, isValidUtf8} from './helpers.js'; +import {isValidDatetime, isValidUtf8} from '../helpers.js'; import chai from 'chai'; import {endpoints} from 'vc-test-suite-implementations'; From dd48a981b07b266997c5b793ce3c84f923d0ac57 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 17:05:05 +0000 Subject: [PATCH 04/12] Switch default interop vc version to 2.0 for rdfc-2019. --- config/runner.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/runner.json b/config/runner.json index d3dc716e..4cbf752a 100644 --- a/config/runner.json +++ b/config/runner.json @@ -8,7 +8,7 @@ "P-384": 96 }, "interop": { - "vcVersion": "1.1" + "vcVersion": "2.0" } }, "ecdsa-sd-2023": { From f36026e28fc7206fcda5a81d2be6e9f61a0aa0e9 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 17:05:24 +0000 Subject: [PATCH 05/12] Merge isValid utils into common helpers import. --- tests/suites/algorithms-jcs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index b9f5fd8e..200a26a3 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -7,10 +7,11 @@ import { createInitialVc, createValidCredential, getProofs, + isValidDatetime, + isValidUtf8, setupMatrix, setupRow } from '../helpers.js'; -import {isValidDatetime, isValidUtf8} from '../helpers.js'; import chai from 'chai'; import {endpoints} from 'vc-test-suite-implementations'; From 7b4034e7999c9c363bb02961fd5df3b47be01bdc Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 17:08:13 +0000 Subject: [PATCH 06/12] Add initial jcs 2019 config and update cryptosuite name. --- config/runner.json | 10 ++++++++++ tests/suites/algorithms-jcs.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/runner.json b/config/runner.json index 4cbf752a..52f24956 100644 --- a/config/runner.json +++ b/config/runner.json @@ -11,6 +11,16 @@ "vcVersion": "2.0" } }, + "ecdsa-jcs-2019": { + "tags": ["ecdsa-jcs-2019"], + "proofLengths": { + "P-256": 64, + "P-384": 96 + }, + "interop": { + "vcVersion": "2.0" + } + }, "ecdsa-sd-2023": { "tags": ["ecdsa-sd-2023"], "interop": { diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index 200a26a3..a3bd7c21 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -16,7 +16,7 @@ import chai from 'chai'; import {endpoints} from 'vc-test-suite-implementations'; export function ecdsaJcs2019Algorithms() { - const cryptosuite = 'ecdsa-jcs-2022'; + const cryptosuite = 'ecdsa-jcs-2019'; const {tags} = config.suites[ cryptosuite ]; From 8cdd7d4510c3a43e7361e0a3e0d2e05e8ccf48e5 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 18:35:45 +0000 Subject: [PATCH 07/12] Change default supported vc type to 2.0. --- tests/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/helpers.js b/tests/helpers.js index ede9c5aa..7440e596 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -92,7 +92,7 @@ export const endpointCheck = ({endpoint, vcVersion, keyType}) => { const { supportedEcdsaKeyTypes, // assume support for vc 1.1 - supports = {vc: ['1.1']} + supports = {vc: ['2.0']} } = endpoint.settings; // if an issuer does not support the current keyType skip it const keyTypes = supportedEcdsaKeyTypes || supports?.keyTypes; From 1771eba62886ec785263a3f1fc7b7331bdc40e3b Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 18:41:54 +0000 Subject: [PATCH 08/12] Minor corrections to jcs suite. --- tests/helpers.js | 16 ++++------------ tests/suites/algorithms-jcs.js | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/tests/helpers.js b/tests/helpers.js index 7440e596..f896e331 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -210,12 +210,14 @@ export function getColumnNameForTestCategory(testCategory) { } } -export function setupReportableTestSuite(runnerContext, name) { +export function setupReportableTestSuite( + runnerContext, + name = 'Implementation' +) { runnerContext.matrix = true; runnerContext.report = true; runnerContext.rowLabel = 'Test Name'; runnerContext.columnLabel = name; - runnerContext.implemented = []; } @@ -233,16 +235,6 @@ export function isValidDatetime(dateString) { return !isNaN(Date.parse(dateString)); } -export function setupMatrix(match) { - // this will tell the report - // to make an interop matrix with this suite - this.matrix = true; - this.report = true; - this.implemented = [...match.keys()]; - this.rowLabel = 'Test Name'; - this.columnLabel = 'Implementer'; -} - export const config = JSON.parse(readFileSync('./config/runner.json')); export function createValidCredential(version = 2) { diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index a3bd7c21..283cb17f 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -9,7 +9,7 @@ import { getProofs, isValidDatetime, isValidUtf8, - setupMatrix, + setupReportableTestSuite, setupRow } from '../helpers.js'; import chai from 'chai'; @@ -20,7 +20,7 @@ export function ecdsaJcs2019Algorithms() { const {tags} = config.suites[ cryptosuite ]; - const {issuerMatch} = endpoints.filterByTag({ + const {match: issuers} = endpoints.filterByTag({ tags: [...tags], property: 'issuers' }); @@ -31,12 +31,12 @@ export function ecdsaJcs2019Algorithms() { const should = chai.should(); describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { - setupMatrix.call(this, issuerMatch); + setupReportableTestSuite(this); let validCredential; before(async function() { validCredential = await createValidCredential(); }); - for(const [columnId, {endpoints}] of issuerMatch) { + for(const [columnId, {endpoints}] of issuers) { describe(columnId, function() { const [issuer] = endpoints; let issuedVc; @@ -99,8 +99,8 @@ export function ecdsaJcs2019Algorithms() { 'Expected a cryptosuite identifier on the proof.'); proof.type.should.equal('DataIntegrityProof', 'Expected DataIntegrityProof type.'); - proof.cryptosuite.should.equal('ecdsa-jcs-2022', - 'Expected ecdsa-jcs-2022 cryptosuite.'); + proof.cryptosuite.should.equal('ecdsa-jcs-2019', + 'Expected ecdsa-jcs-2019 cryptosuite.'); } }); }); @@ -108,12 +108,12 @@ export function ecdsaJcs2019Algorithms() { }); describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() { - setupMatrix.call(this, issuerMatch); + setupReportableTestSuite(this); let validCredential; before(async function() { validCredential = await createValidCredential(); }); - for(const [columnId, {endpoints}] of issuerMatch) { + for(const [columnId, {endpoints}] of issuers) { describe(columnId, function() { const [issuer] = endpoints; let issuedVc; @@ -162,8 +162,8 @@ export function ecdsaJcs2019Algorithms() { 'Expected a cryptosuite identifier on the proof.'); proof.type.should.equal('DataIntegrityProof', 'Expected DataIntegrityProof type.'); - proof.cryptosuite.should.equal('ecdsa-jcs-2022', - 'Expected ecdsa-jcs-2022 cryptosuite.'); + proof.cryptosuite.should.equal('ecdsa-jcs-2019', + 'Expected ecdsa-jcs-2019 cryptosuite.'); } }); it('If proofConfig.created is set and if the value is not a ' + @@ -185,12 +185,12 @@ export function ecdsaJcs2019Algorithms() { }); describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { - setupMatrix.call(this, issuerMatch); + setupReportableTestSuite(this); let validCredential; before(async function() { validCredential = await createValidCredential(); }); - for(const [columnId, {endpoints}] of issuerMatch) { + for(const [columnId, {endpoints}] of issuers) { describe(columnId, function() { const [issuer] = endpoints; let issuedVc; From 9b8bbcaab6c1b33b69ba793c6eb4960655331ca9 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 18:53:03 +0000 Subject: [PATCH 09/12] Add implemented to suites. --- tests/suites/algorithms-jcs.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index 283cb17f..f660c573 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -24,14 +24,11 @@ export function ecdsaJcs2019Algorithms() { tags: [...tags], property: 'issuers' }); - // const {verifierMatch} = endpoints.filterByTag({ - // tags: [...tags], - // property: 'verifiers' - // }); const should = chai.should(); describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { setupReportableTestSuite(this); + this.implemented = [...issuers.keys()]; let validCredential; before(async function() { validCredential = await createValidCredential(); @@ -109,6 +106,7 @@ export function ecdsaJcs2019Algorithms() { describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() { setupReportableTestSuite(this); + this.implemented = [...issuers.keys()]; let validCredential; before(async function() { validCredential = await createValidCredential(); @@ -186,6 +184,7 @@ export function ecdsaJcs2019Algorithms() { describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { setupReportableTestSuite(this); + this.implemented = [...issuers.keys()]; let validCredential; before(async function() { validCredential = await createValidCredential(); From 565007be9927fe5dcef5656842ff95614de9ede2 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 19:00:10 +0000 Subject: [PATCH 10/12] Replace ecdsa2022 w/ jcs2019Proofs. --- tests/suites/algorithms-jcs.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index f660c573..3543f9bc 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -38,12 +38,12 @@ export function ecdsaJcs2019Algorithms() { const [issuer] = endpoints; let issuedVc; let proofs; - let ecdsa2022Proofs = []; + let jcs2019Proofs = []; before(async function() { issuedVc = await createInitialVc({issuer, vc: validCredential}); proofs = getProofs(issuedVc); if(proofs?.length) { - ecdsa2022Proofs = proofs.filter( + jcs2019Proofs = proofs.filter( proof => proof?.cryptosuite === cryptosuite); } }); @@ -52,7 +52,7 @@ export function ecdsaJcs2019Algorithms() { should.exist(issuedVc, 'Expected issuer to have issued a ' + 'credential.'); should.exist(proofs, 'Expected credential to have a proof.'); - ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + jcs2019Proofs.length.should.be.gte(1, 'Expected at least one ' + 'ecdsa-jcs-2019 cryptosuite.'); }; it('The transformation options MUST contain a type identifier ' + @@ -61,7 +61,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof.type, 'Expected a type identifier on ' + 'the proof.'); should.exist(proof.cryptosuite, @@ -73,7 +73,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof?.proofValue, 'Expected proofValue to exist.'); isValidUtf8(proof.proofValue).should.equal( @@ -89,7 +89,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof.type, 'Expected a type identifier on the proof.'); should.exist(proof.cryptosuite, @@ -116,12 +116,12 @@ export function ecdsaJcs2019Algorithms() { const [issuer] = endpoints; let issuedVc; let proofs; - let ecdsa2022Proofs = []; + let jcs2019Proofs = []; before(async function() { issuedVc = await createInitialVc({issuer, vc: validCredential}); proofs = getProofs(issuedVc); if(proofs?.length) { - ecdsa2022Proofs = proofs.filter( + jcs2019Proofs = proofs.filter( proof => proof?.cryptosuite === cryptosuite); } }); @@ -130,7 +130,7 @@ export function ecdsaJcs2019Algorithms() { should.exist(issuedVc, 'Expected issuer to have issued a ' + 'credential.'); should.exist(proofs, 'Expected credential to have a proof.'); - ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + jcs2019Proofs.length.should.be.gte(1, 'Expected at least one ' + 'ecdsa-jcs-2019 cryptosuite.'); }; it('The proof options MUST contain a type identifier for the ' + @@ -139,7 +139,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof.type, 'Expected a type identifier on the proof.'); should.exist(proof.cryptosuite, @@ -153,7 +153,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof.type, 'Expected a type identifier on the proof.'); should.exist(proof.cryptosuite, @@ -169,7 +169,7 @@ export function ecdsaJcs2019Algorithms() { 'SHOULD convey an error type of PROOF_GENERATION_ERROR.', async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019'; - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { if(proof?.created) { isValidDatetime(proof.created).should.equal( true, @@ -194,12 +194,12 @@ export function ecdsaJcs2019Algorithms() { const [issuer] = endpoints; let issuedVc; let proofs; - let ecdsa2022Proofs = []; + let jcs2019Proofs = []; before(async function() { issuedVc = await createInitialVc({issuer, vc: validCredential}); proofs = getProofs(issuedVc); if(proofs?.length) { - ecdsa2022Proofs = proofs.filter( + jcs2019Proofs = proofs.filter( proof => proof?.cryptosuite === cryptosuite); } }); @@ -208,7 +208,7 @@ export function ecdsaJcs2019Algorithms() { should.exist(issuedVc, 'Expected issuer to have issued a ' + 'credential.'); should.exist(proofs, 'Expected credential to have a proof.'); - ecdsa2022Proofs.length.should.be.gte(1, 'Expected at least one ' + + jcs2019Proofs.length.should.be.gte(1, 'Expected at least one ' + 'ecdsa-jcs-2019 cryptosuite.'); }; it('The proof options MUST contain a type identifier for the ' + @@ -217,7 +217,7 @@ export function ecdsaJcs2019Algorithms() { async function() { this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019'; assertBefore(); - for(const proof of ecdsa2022Proofs) { + for(const proof of jcs2019Proofs) { should.exist(proof.type, 'Expected a type identifier on the proof.'); } From f044d3cc765c3fabef5cd512a338129838783390 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 19:12:25 +0000 Subject: [PATCH 11/12] Move lone transformation test to main area. --- tests/suites/algorithms-jcs.js | 58 ++++++++-------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/tests/suites/algorithms-jcs.js b/tests/suites/algorithms-jcs.js index 3543f9bc..5c55a95a 100644 --- a/tests/suites/algorithms-jcs.js +++ b/tests/suites/algorithms-jcs.js @@ -15,6 +15,8 @@ import { import chai from 'chai'; import {endpoints} from 'vc-test-suite-implementations'; +const should = chai.should(); + export function ecdsaJcs2019Algorithms() { const cryptosuite = 'ecdsa-jcs-2019'; const {tags} = config.suites[ @@ -24,7 +26,6 @@ export function ecdsaJcs2019Algorithms() { tags: [...tags], property: 'issuers' }); - const should = chai.should(); describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { setupReportableTestSuite(this); @@ -55,6 +56,17 @@ export function ecdsaJcs2019Algorithms() { jcs2019Proofs.length.should.be.gte(1, 'Expected at least one ' + 'ecdsa-jcs-2019 cryptosuite.'); }; + it('The proof options MUST contain a type identifier for the ' + + 'cryptographic suite (type) and MAY contain a cryptosuite ' + + 'identifier (cryptosuite).', + async function() { + this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019'; + assertBefore(); + for(const proof of jcs2019Proofs) { + should.exist(proof.type, + 'Expected a type identifier on the proof.'); + } + }); it('The transformation options MUST contain a type identifier ' + 'for the cryptographic suite (type) and a cryptosuite identifier ' + '(cryptosuite).', @@ -181,48 +193,4 @@ export function ecdsaJcs2019Algorithms() { }); } }); - - describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() { - setupReportableTestSuite(this); - this.implemented = [...issuers.keys()]; - let validCredential; - before(async function() { - validCredential = await createValidCredential(); - }); - for(const [columnId, {endpoints}] of issuers) { - describe(columnId, function() { - const [issuer] = endpoints; - let issuedVc; - let proofs; - let jcs2019Proofs = []; - before(async function() { - issuedVc = await createInitialVc({issuer, vc: validCredential}); - proofs = getProofs(issuedVc); - if(proofs?.length) { - jcs2019Proofs = proofs.filter( - proof => proof?.cryptosuite === cryptosuite); - } - }); - beforeEach(setupRow); - const assertBefore = () => { - should.exist(issuedVc, 'Expected issuer to have issued a ' + - 'credential.'); - should.exist(proofs, 'Expected credential to have a proof.'); - jcs2019Proofs.length.should.be.gte(1, 'Expected at least one ' + - 'ecdsa-jcs-2019 cryptosuite.'); - }; - it('The proof options MUST contain a type identifier for the ' + - 'cryptographic suite (type) and MAY contain a cryptosuite ' + - 'identifier (cryptosuite).', - async function() { - this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019'; - assertBefore(); - for(const proof of jcs2019Proofs) { - should.exist(proof.type, - 'Expected a type identifier on the proof.'); - } - }); - }); - } - }); } From 5e8c1d5d386e373fdb9578c5a4794b9f9943c9d2 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 Nov 2024 20:18:35 +0000 Subject: [PATCH 12/12] Update tests/helpers.js comment about test version support. Co-authored-by: BigBlueHat --- tests/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/helpers.js b/tests/helpers.js index f896e331..04d907dd 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -91,7 +91,7 @@ export const createDisclosedVc = async ({ export const endpointCheck = ({endpoint, vcVersion, keyType}) => { const { supportedEcdsaKeyTypes, - // assume support for vc 1.1 + // assume support for vc 2.0 supports = {vc: ['2.0']} } = endpoint.settings; // if an issuer does not support the current keyType skip it