diff --git a/packages/data-store-json/src/identifier/did-store.ts b/packages/data-store-json/src/identifier/did-store.ts index 28a6407c4..a049b3e59 100644 --- a/packages/data-store-json/src/identifier/did-store.ts +++ b/packages/data-store-json/src/identifier/did-store.ts @@ -3,7 +3,7 @@ import { AbstractDIDStore } from '@veramo/did-manager' import Debug from 'debug' import { DiffCallback, VeramoJsonCache, VeramoJsonStore } from '../types' -import structuredClone from '@ungap/structured-clone' +import { serialize, deserialize } from '@ungap/structured-clone' const debug = Debug('veramo:data-store-json:did-store') @@ -66,12 +66,12 @@ export class DIDStoreJson extends AbstractDIDStore { if (!identifier) throw Error('Identifier not found') - return structuredClone(identifier) + return deserialize(serialize(identifier)) } async delete({ did }: { did: string }) { if (this.cacheTree.dids[did]) { - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) delete this.cacheTree.dids[did] // FIXME: delete key associations? await this.notifyUpdate(oldTree, this.cacheTree) @@ -81,7 +81,7 @@ export class DIDStoreJson extends AbstractDIDStore { } async import(args: IIdentifier) { - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) this.cacheTree.dids[args.did] = args args.keys.forEach((key) => { this.cacheTree.keys[key.kid] = { @@ -101,6 +101,6 @@ export class DIDStoreJson extends AbstractDIDStore { (!args.provider || (args.provider && iid.provider === args.provider)) && (!args.alias || (args.alias && iid.alias === args.alias)), ) - return structuredClone(result) + return deserialize(serialize(result)) } } diff --git a/packages/data-store-json/src/identifier/key-store.ts b/packages/data-store-json/src/identifier/key-store.ts index 13ed244c1..90738e624 100644 --- a/packages/data-store-json/src/identifier/key-store.ts +++ b/packages/data-store-json/src/identifier/key-store.ts @@ -3,7 +3,7 @@ import { AbstractKeyStore } from '@veramo/key-manager' import Debug from 'debug' import { DiffCallback, VeramoJsonCache, VeramoJsonStore } from '../types' -import structuredClone from '@ungap/structured-clone' +import { serialize, deserialize } from '@ungap/structured-clone' const debug = Debug('veramo:data-store-json:key-store') @@ -41,7 +41,7 @@ export class KeyStoreJson extends AbstractKeyStore { async get({ kid }: { kid: string }): Promise { if (this.cacheTree.keys[kid]) { - return structuredClone(this.cacheTree.keys[kid]) + return deserialize(serialize(this.cacheTree.keys[kid])) } else { throw Error('not_found: Key not found') } @@ -49,7 +49,7 @@ export class KeyStoreJson extends AbstractKeyStore { async delete({ kid }: { kid: string }) { if (this.cacheTree.keys[kid]) { - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) delete this.cacheTree.keys[kid] await this.notifyUpdate(oldTree, this.cacheTree) return true @@ -59,7 +59,7 @@ export class KeyStoreJson extends AbstractKeyStore { } async import(args: IKey) { - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) this.cacheTree.keys[args.kid] = args await this.notifyUpdate(oldTree, this.cacheTree) return true @@ -68,7 +68,7 @@ export class KeyStoreJson extends AbstractKeyStore { async list(args: {} = {}): Promise { const keys = Object.values(this.cacheTree.keys).map((key: IKey) => { const { kid, publicKeyHex, type, meta, kms } = key - return { kid, publicKeyHex, type, meta: structuredClone(meta), kms } as ManagedKeyInfo + return { kid, publicKeyHex, type, meta: deserialize(serialize(meta)), kms } as ManagedKeyInfo }) return keys } diff --git a/packages/data-store-json/src/identifier/private-key-store.ts b/packages/data-store-json/src/identifier/private-key-store.ts index 6ae5676a6..b237cfbf1 100644 --- a/packages/data-store-json/src/identifier/private-key-store.ts +++ b/packages/data-store-json/src/identifier/private-key-store.ts @@ -3,7 +3,7 @@ import { ImportablePrivateKey, ManagedPrivateKey } from '@veramo/key-manager/src import { v4 as uuid4 } from 'uuid' import Debug from 'debug' import { DiffCallback, VeramoJsonCache, VeramoJsonStore } from '../types' -import structuredClone from '@ungap/structured-clone' +import { serialize, deserialize } from '@ungap/structured-clone' const debug = Debug('veramo:data-store-json:private-key-store') @@ -42,7 +42,7 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore { } async get({ alias }: { alias: string }): Promise { - const key = structuredClone(this.cacheTree.privateKeys[alias]) + const key = deserialize(serialize(this.cacheTree.privateKeys[alias])) if (!key) throw Error('not_found: PrivateKey not found') if (this.secretBox && key.privateKeyHex) { key.privateKeyHex = await this.secretBox.decrypt(key.privateKeyHex) @@ -54,7 +54,7 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore { debug(`Deleting private key data for alias=${alias}`) const privateKeyEntry = this.cacheTree.privateKeys[alias] if (privateKeyEntry) { - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) delete this.cacheTree.privateKeys[alias] await this.notifyUpdate(oldTree, this.cacheTree) } @@ -64,10 +64,10 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore { async import(args: ImportablePrivateKey): Promise { debug('Saving private key data', args.alias) const alias = args.alias || uuid4() - const key: ManagedPrivateKey = structuredClone({ + const key: ManagedPrivateKey = deserialize(serialize({ ...args, alias, - }) + })) if (this.secretBox && key.privateKeyHex) { const copy = key.privateKeyHex key.privateKeyHex = await this.secretBox.encrypt(copy) @@ -79,7 +79,7 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore { ) } - const oldTree = structuredClone(this.cacheTree, { lossy: true }) + const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) this.cacheTree.privateKeys[key.alias] = key await this.notifyUpdate(oldTree, this.cacheTree) @@ -87,6 +87,6 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore { } async list(): Promise> { - return structuredClone(Object.values(this.cacheTree.privateKeys)) + return deserialize(serialize(Object.values(this.cacheTree.privateKeys))) } }