From 29e4b7514b2a2a278fb57296fc63631643670dc5 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 5 Aug 2026 00:18:45 -0700 Subject: [PATCH] Reorganize secret parsing steps. --- src/lib/vault/parsers.ts | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/lib/vault/parsers.ts b/src/lib/vault/parsers.ts index b703afa..44fbcee 100644 --- a/src/lib/vault/parsers.ts +++ b/src/lib/vault/parsers.ts @@ -40,17 +40,16 @@ export function parseData (action: string, data: Record) { } // Seed to load - if (action === 'load') { - if (data.seed == null) { - throw new TypeError('Seed required to load wallet') - } + if ('seed' in data) { if (!(data.seed instanceof ArrayBuffer)) { throw new TypeError('Invalid wallet seed') } - seed = data.seed.slice() + if (action === 'load') { + seed = data.seed.slice() + } + new Uint8Array(data.seed).fill(0) + delete data.seed } - new Uint8Array(data.seed as ArrayBuffer).fill(0) - delete data.seed // Mnemonic phrase to load if (action === 'load' && 'mnemonicPhrase' in data && typeof data.mnemonicPhrase !== 'string') { @@ -71,17 +70,16 @@ export function parseData (action: string, data: Record) { delete data.mnemonicSalt // Encrypted seed and possibly mnemonic - if (action === 'unlock') { - if (data.encrypted == null) { - throw new TypeError('Wallet encrypted secrets not found') - } - if (!(data.encrypted instanceof ArrayBuffer)) { + if ('encrypted' in data) { + if (action === 'unlock') { + if (!(data.encrypted instanceof ArrayBuffer)) { throw new TypeError('Invalid wallet encrypted secrets') + } + encrypted = data.encrypted.slice() } - encrypted = data.encrypted.slice() + new Uint8Array(data.encrypted as ArrayBuffer).fill(0) + delete data.encrypted } - new Uint8Array(data.encrypted as ArrayBuffer).fill(0) - delete data.encrypted // Index for child account to derive or sign if ((action === 'derive' || action === 'sign') && typeof data.index !== 'number') { @@ -92,17 +90,16 @@ export function parseData (action: string, data: Record) { : undefined // Data to sign - if (action === 'sign') { - if (data.message == null) { - throw new TypeError('Data to sign not found') + if ('message' in data) { + if (action === 'sign') { + if (!(data.message instanceof ArrayBuffer)) { + throw new TypeError('Invalid data to sign') + } + message = data.message.slice() } - if (!(data.message instanceof ArrayBuffer)) { - throw new TypeError('Invalid data to sign') - } - message = data.message.slice() - } - new Uint8Array(data.message as ArrayBuffer).fill(0) - delete data.message + new Uint8Array(data.message as ArrayBuffer).fill(0) + delete data.message + } // Vault configuration if (action === 'config') { -- 2.52.0