@@ -3,7 +3,7 @@ import { ImportablePrivateKey, ManagedPrivateKey } from '@veramo/key-manager/src
3
3
import { v4 as uuid4 } from 'uuid'
4
4
import Debug from 'debug'
5
5
import { DiffCallback , VeramoJsonCache , VeramoJsonStore } from '../types'
6
- import structuredClone from '@ungap/structured-clone'
6
+ import { serialize , deserialize } from '@ungap/structured-clone'
7
7
8
8
const debug = Debug ( 'veramo:data-store-json:private-key-store' )
9
9
@@ -42,7 +42,7 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore {
42
42
}
43
43
44
44
async get ( { alias } : { alias : string } ) : Promise < ManagedPrivateKey > {
45
- const key = structuredClone ( this . cacheTree . privateKeys [ alias ] )
45
+ const key = deserialize ( serialize ( this . cacheTree . privateKeys [ alias ] ) )
46
46
if ( ! key ) throw Error ( 'not_found: PrivateKey not found' )
47
47
if ( this . secretBox && key . privateKeyHex ) {
48
48
key . privateKeyHex = await this . secretBox . decrypt ( key . privateKeyHex )
@@ -54,7 +54,7 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore {
54
54
debug ( `Deleting private key data for alias=${ alias } ` )
55
55
const privateKeyEntry = this . cacheTree . privateKeys [ alias ]
56
56
if ( privateKeyEntry ) {
57
- const oldTree = structuredClone ( this . cacheTree , { lossy : true } )
57
+ const oldTree = deserialize ( serialize ( this . cacheTree , { lossy : true } ) )
58
58
delete this . cacheTree . privateKeys [ alias ]
59
59
await this . notifyUpdate ( oldTree , this . cacheTree )
60
60
}
@@ -64,10 +64,10 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore {
64
64
async import ( args : ImportablePrivateKey ) : Promise < ManagedPrivateKey > {
65
65
debug ( 'Saving private key data' , args . alias )
66
66
const alias = args . alias || uuid4 ( )
67
- const key : ManagedPrivateKey = structuredClone ( {
67
+ const key : ManagedPrivateKey = deserialize ( serialize ( {
68
68
...args ,
69
69
alias,
70
- } )
70
+ } ) )
71
71
if ( this . secretBox && key . privateKeyHex ) {
72
72
const copy = key . privateKeyHex
73
73
key . privateKeyHex = await this . secretBox . encrypt ( copy )
@@ -79,14 +79,14 @@ export class PrivateKeyStoreJson extends AbstractPrivateKeyStore {
79
79
)
80
80
}
81
81
82
- const oldTree = structuredClone ( this . cacheTree , { lossy : true } )
82
+ const oldTree = deserialize ( serialize ( this . cacheTree , { lossy : true } ) )
83
83
this . cacheTree . privateKeys [ key . alias ] = key
84
84
await this . notifyUpdate ( oldTree , this . cacheTree )
85
85
86
86
return key
87
87
}
88
88
89
89
async list ( ) : Promise < Array < ManagedPrivateKey > > {
90
- return structuredClone ( Object . values ( this . cacheTree . privateKeys ) )
90
+ return deserialize ( serialize ( Object . values ( this . cacheTree . privateKeys ) ) )
91
91
}
92
92
}
0 commit comments