Skip to content

Commit

Permalink
Use structuredClone over klona.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Nov 3, 2024
1 parent 82da910 commit 1b9a7b7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"chai": "^4.3.6",
"data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion",
"jsonld-document-loader": "^2.0.0",
"klona": "^2.0.5",
"mocha": "^10.0.0",
"uuid": "^9.0.0",
"varint": "^6.0.0",
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';
import {IdDecoder, IdEncoder} from 'bnid';
import {documentLoader} from './documentLoader.js';
import {isUtf8} from 'node:buffer';
import {klona} from 'klona';
import {readFileSync} from 'fs';
import {v4 as uuidv4} from 'uuid';
import varint from 'varint';
Expand Down Expand Up @@ -69,7 +68,7 @@ export async function getVerificationMethodDocuments(proofs) {

export const createInitialVc = async ({issuer, vc}) => {
const {settings: {id: issuerId, options}} = issuer;
const credential = klona(vc);
const credential = structuredClone(vc);
credential.id = `urn:uuid:${uuidv4()}`;
credential.issuer = issuerId;
const body = {credential, options};
Expand Down
5 changes: 2 additions & 3 deletions tests/vc-generator/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import {
} from '@digitalbazaar/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(credentialsContexts);

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',
Expand Down
3 changes: 1 addition & 2 deletions tests/vc-generator/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
cryptosuite as eddsaRdfc2022CryptoSuite
} from '@digitalbazaar/eddsa-rdfc-2022-cryptosuite';
import jcsCanonicalize from 'canonicalize';
import {klona} from 'klona';

export const vcGenerators = new Map([
['issuedVc', _issuedVc],
Expand Down Expand Up @@ -122,7 +121,7 @@ function _createEddsa2022Suite({signer}) {

async function _issueCloned({suite, credential, loader = documentLoader}) {
return vc.issue({
credential: klona(credential),
credential: structuredClone(credential),
suite,
documentLoader: loader
});
Expand Down
7 changes: 3 additions & 4 deletions tests/vc-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
import {getMultikey} from './helpers.js';
import {klona} from 'klona';
import {validVc} from './validVc.js';
import {vcGenerators} from './generators.js';

// cache test data for a single run
const vcCache = new Map([
['validVc', klona(validVc)]
['validVc', structuredClone(validVc)]
]);

/**
Expand All @@ -23,7 +22,7 @@ export async function generateTestData() {
seedMultibase: (process.env?.KEY_SEED_DB ||
process.env?.CLIENT_SECRET_DB)
});
const credential = klona(validVc);
const credential = structuredClone(validVc);
credential.issuer = issuer;
for(const [id, generator] of vcGenerators) {
if(vcCache.get(id)) {
Expand All @@ -34,7 +33,7 @@ export async function generateTestData() {
}
return {
clone(key) {
return klona(vcCache.get(key));
return structuredClone(vcCache.get(key));
}
};
}

0 comments on commit 1b9a7b7

Please sign in to comment.