From: Chris Duncan Date: Sat, 30 Aug 2025 09:04:57 +0000 (-0700) Subject: Revert stringification of vault classes and use initialization method called within... X-Git-Tag: v0.10.5~38^2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=fffc196d42587951a1f74785a4e16ddbc9898496;p=libnemo.git Revert stringification of vault classes and use initialization method called within worker string. --- diff --git a/src/lib/vault/index.ts b/src/lib/vault/index.ts index 39bdce9..4d107cd 100644 --- a/src/lib/vault/index.ts +++ b/src/lib/vault/index.ts @@ -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[] = [] diff --git a/src/lib/vault/vault-timer.ts b/src/lib/vault/vault-timer.ts index 9bc2d3c..96af34a 100644 --- a/src/lib/vault/vault-timer.ts +++ b/src/lib/vault/vault-timer.ts @@ -30,5 +30,3 @@ export class VaultTimer { } } } - -export default `const VaultTimer = ${VaultTimer}` diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index f047ef0..48f6bf3 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -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): Promise => { 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}`