From 6a6fa720911f8f8ca07d287e73aa4973108d3fae Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 12 Jun 2024 14:10:59 +0000 Subject: [PATCH] Remove klona in favor of structuredClone. --- package.json | 3 +-- tests/helpers.js | 5 ++--- tests/setup.js | 5 ++--- tests/suites/verify.js | 9 ++++----- tests/test-config.js | 9 ++++----- tests/vc-generator/contexts.js | 7 +++---- tests/vc-generator/index.js | 5 ++--- 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 53ef0e7..408a49a 100644 --- a/package.json +++ b/package.json @@ -52,9 +52,8 @@ "base64url-universal": "^2.0.0", "chai": "^4.3.7", "credentials-context": "^2.0.0", - "data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion#make-vc-gen-suite-configurable", + "data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion#add-suite-verifier-tests", "jsonld-document-loader": "^2.0.0", - "klona": "^2.0.6", "mocha": "^10.2.0", "uuid": "^9.0.0", "vc-test-suite-implementations": "github:w3c/vc-test-suite-implementations" diff --git a/tests/helpers.js b/tests/helpers.js index 7b55c8a..0e2b6b0 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -6,7 +6,6 @@ import * as bs58 from 'base58-universal'; import * as bs64 from 'base64url-universal'; import {createRequire} from 'node:module'; -import {klona} from 'klona'; import {v4 as uuidv4} from 'uuid'; // remove first element and decode @@ -57,8 +56,8 @@ export const createInitialVc = async ({ addIssuanceDate = true }) => { const {settings: {id: issuerId, options = {}}} = issuer; - const testOptions = klona(options); - const credential = klona(vc); + const testOptions = structuredClone(options); + const credential = structuredClone(vc); credential.id = `urn:uuid:${uuidv4()}`; credential.issuer = issuerId; if(addIssuanceDate) { diff --git a/tests/setup.js b/tests/setup.js index 161e0d2..9199715 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -6,7 +6,6 @@ import { deriveCredentials, issueCredentials } from './vc-generator/index.js'; -import {klona} from 'klona'; export async function verifySetup({credentials, keyTypes, suite}) { const testVectors = { @@ -40,7 +39,7 @@ export async function verifySetup({credentials, keyTypes, suite}) { // transforms the vectors const transformVectors = (obj, func) => Object.entries(obj).map(input => { const [vcVersion, vector] = input; - return [vcVersion, func(klona(vector))]; + return [vcVersion, func(structuredClone(vector))]; }); const disclosedBaseVectors = transformVectors( subjectNestedObjects, @@ -84,7 +83,7 @@ export async function verifySetup({credentials, keyTypes, suite}) { }); // select full arrays testVectors.disclosed.array.full = await deriveCredentials({ - vectors: Object.entries(klona(subjectHasArrays)), + vectors: Object.entries(structuredClone(subjectHasArrays)), suite, keyTypes }); diff --git a/tests/suites/verify.js b/tests/suites/verify.js index af366e7..9c54c18 100644 --- a/tests/suites/verify.js +++ b/tests/suites/verify.js @@ -7,7 +7,6 @@ import { verificationFail, verificationSuccess } from '../assertions.js'; -import {klona} from 'klona'; import {supportsVc} from '../helpers.js'; export function verifySuite({ @@ -70,7 +69,7 @@ export function verifySuite({ it('If the "proofValue" string does not start with "u", an ' + 'error MUST be raised.', async function() { const credential = getTestVector(disclosed?.base); - const signedCredentialCopy = klona(credential); + const signedCredentialCopy = structuredClone(credential); // intentionally modify proofValue to not start with 'u' signedCredentialCopy.proof.proofValue = 'a'; await verificationFail({ @@ -80,7 +79,7 @@ export function verifySuite({ it('If the "cryptosuite" field is not the string "bbs-2023", ' + 'an error MUST be raised.', async function() { const credential = getTestVector(disclosed?.base); - const signedCredentialCopy = klona(credential); + const signedCredentialCopy = structuredClone(credential); signedCredentialCopy.proof.cryptosuite = 'invalid-cryptosuite'; await verificationFail({ credential: signedCredentialCopy, verifier @@ -88,7 +87,7 @@ export function verifySuite({ }); it('MUST fail to verify a base proof.', async function() { const credential = getTestVector(signed); - const signedCredentialCopy = klona(credential); + const signedCredentialCopy = structuredClone(credential); await verificationFail({ credential: signedCredentialCopy, verifier }); @@ -96,7 +95,7 @@ export function verifySuite({ it('MUST fail to verify a modified disclosed credential.', async function() { const credential = getTestVector(disclosed?.base); - const signedCredentialCopy = klona(credential); + const signedCredentialCopy = structuredClone(credential); // intentionally modify `credentialSubject` ID signedCredentialCopy.credentialSubject.id = 'urn:invalid'; await verificationFail({ diff --git a/tests/test-config.js b/tests/test-config.js index 43d7f68..3c5dc33 100644 --- a/tests/test-config.js +++ b/tests/test-config.js @@ -2,7 +2,6 @@ * Copyright 2023-2024 Digital Bazaar, Inc. * SPDX-License-Identifier: BSD-3-Clause */ -import {klona} from 'klona'; import {require} from './helpers.js'; const _runner = require('../config/runner.json'); @@ -31,7 +30,7 @@ const openVectorFiles = vectorFiles => { const value = vectorFiles[property]; // assume strings are paths to be opened if(typeof value === 'string') { - vectorFiles[property] = klona(require(value)); + vectorFiles[property] = structuredClone(require(value)); continue; } // assume everything else recurs @@ -42,7 +41,7 @@ const openVectorFiles = vectorFiles => { const _createVectorConfig = suite => { // prevent mutation to require cache - const vectorConfig = klona(_vectors.suites[suite]); + const vectorConfig = structuredClone(_vectors.suites[suite]); // open test data in credentials section if(vectorConfig.credentials) { const {credentials} = vectorConfig; @@ -59,14 +58,14 @@ const _createSuiteConfig = suite => { throw new Error(`Could not find config for suite ${suite}`); } // return a deep copy to prevent test data mutation - return klona(suiteConfig); + return structuredClone(suiteConfig); }; export const getSuiteConfig = suite => { // if cached config use it if(_cache.get(suite)) { // return a deep copy to prevent test data mutation - return klona(_cache.get(suite)); + return structuredClone(_cache.get(suite)); } // create an initial config const suiteConfig = _createSuiteConfig(suite); diff --git a/tests/vc-generator/contexts.js b/tests/vc-generator/contexts.js index 93b0217..22966a6 100644 --- a/tests/vc-generator/contexts.js +++ b/tests/vc-generator/contexts.js @@ -6,22 +6,21 @@ import * as credentialsV2Ctx from '@digitalbazaar/credentials-v2-context'; import credentialsCtx from 'credentials-context'; import dataIntegrityCtx from '@digitalbazaar/data-integrity-context'; import didCtx from '@digitalcredentials/did-context'; -import {klona} from 'klona'; import multikeyCtx from '@digitalbazaar/multikey-context'; const contextMap = new Map(); const setContexts = contexts => { for(const [key, value] of contexts) { - contextMap.set(key, klona(value)); + contextMap.set(key, structuredClone(value)); } }; /* -const _dataIntegrityCtx = klona(dataIntegrityCtx.CONTEXT); +const _dataIntegrityCtx = structuredClone(dataIntegrityCtx.CONTEXT); const diCtx = _dataIntegrityCtx['@context']; // add UnknownProofType to local context for test data diCtx.UnknownProofType = - klona(_dataIntegrityCtx['@context'].DataIntegrityProof); + structuredClone(_dataIntegrityCtx['@context'].DataIntegrityProof); // add invalidPurpose to context for test data diCtx.DataIntegrityProof['@context'].proofPurpose['@context'].invalidPurpose = { '@id': 'https://w3id.org/security#invalidPurpose', diff --git a/tests/vc-generator/index.js b/tests/vc-generator/index.js index e590f1e..38ec93e 100644 --- a/tests/vc-generator/index.js +++ b/tests/vc-generator/index.js @@ -1,12 +1,11 @@ /*! - * Copyright 2023 Digital Bazaar, Inc. + * Copyright 2023-2024 Digital Bazaar, Inc. * SPDX-License-Identifier: BSD-3-Clause */ import * as vc from '@digitalbazaar/vc'; import {documentLoader as defaultLoader} from './documentLoader.js'; import {getMultikeys} from './key-gen.js'; import {getSuite} from './cryptosuites.js'; -import {klona} from 'klona'; /** * Issues test data locally and then returns a Map @@ -56,7 +55,7 @@ export async function issueCredential({ suite, mandatoryPointers = [] }) { - const _credential = klona(credential); + const _credential = structuredClone(credential); _credential.issuer = issuer; return vc.issue({ credential: _credential,