]> git.codecow.com Git - libnemo.git/commitdiff
Revert stringification of vault classes and use initialization method called within...
authorChris Duncan <chris@zoso.dev>
Sat, 30 Aug 2025 09:04:57 +0000 (02:04 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 30 Aug 2025 09:04:57 +0000 (02:04 -0700)
src/lib/vault/index.ts
src/lib/vault/vault-timer.ts
src/lib/vault/vault-worker.ts

index 39bdce976b5cb50e2c260cf388f2d8e3e570aeb2..4d107cdc261a86386871838fff11416a3e0a4237 100644 (file)
@@ -6,8 +6,8 @@ import { Data, NamedData } from '#types'
 import { default as Constants } from '../constants'
 import { default as Convert } from '../convert'
 import { Bip39, Bip44, Blake2b, NanoNaCl } from '../crypto'
-import { default as VaultTimer } from './vault-timer'
-import { default as VaultWorker } from './vault-worker'
+import { VaultTimer } from './vault-timer'
+import { VaultWorker } from './vault-worker'
 
 type Task = {
        id: number
@@ -28,8 +28,9 @@ export class Vault {
                        const Bip44 = ${Bip44}
                        const Blake2b = ${Blake2b}
                        const NanoNaCl = ${NanoNaCl}
-                       ${VaultTimer}
-                       ${VaultWorker}
+                       const VaultTimer = ${VaultTimer}
+                       const VaultWorker = ${VaultWorker}
+                       VaultWorker.init()
                `
        }
        static #instances: Vault[] = []
index 9bc2d3cac73e36e8b430ac05fb5f6b2f5970390e..96af34ad5152564730549dc0873224dd0f6f58b8 100644 (file)
@@ -30,5 +30,3 @@ export class VaultTimer {
                }
        }
 }
-
-export default `const VaultTimer = ${VaultTimer}`
index f047ef094529b18ffbe683b1932d65f7f8c8194f..48f6bf3dcbfe0ba16ba9b763e45e3f937746ee16 100644 (file)
@@ -12,17 +12,19 @@ import { VaultTimer } from './vault-timer'
 * Cross-platform worker for managing wallet secrets.
 */
 export class VaultWorker {
-       static locked: boolean = true
-       static timeout: VaultTimer = new VaultTimer(() => { }, 0)
+       static locked: boolean
+       static timeout: VaultTimer
        static type?: 'BIP-44' | 'BLAKE2b'
        static seed?: ArrayBuffer
        static mnemonic?: ArrayBuffer
        static parentPort?: any
-       static {
-               NODE: this.parentPort = parentPort
-       }
 
-       static {
+       static init (): void {
+               this.locked = true
+               this.timeout = new VaultTimer(() => { }, 0)
+               this.type = undefined
+               this.seed = undefined
+               this.mnemonic = undefined
                NODE: this.parentPort = parentPort
                const listener = (message: MessageEvent<any>): Promise<void> => {
                        return this._extractData(message.data)
@@ -120,11 +122,11 @@ export class VaultWorker {
                        const entropy = crypto.getRandomValues(new Uint8Array(32))
                        return Bip39.fromEntropy(entropy)
                                .then(bip39 => this._load(type, key, keySalt, bip39.phrase, mnemonicSalt))
-                               .then(record => {
+                               .then(({ iv, salt, encrypted }) => {
                                        if (this.seed == null || this.mnemonic == null) {
                                                throw new Error('Failed to generate seed and mnemonic')
                                        }
-                                       return { ...record, seed: this.seed.slice(), mnemonic: this.mnemonic.slice() }
+                                       return { iv, salt, encrypted, seed: this.seed.slice(), mnemonic: this.mnemonic.slice() }
                                })
                } catch (err) {
                        console.error(err)
@@ -641,5 +643,3 @@ export class VaultWorker {
                }
        }
 }
-
-export default `const VaultWorker = ${VaultWorker}`