]> git.codecow.com Git - libnemo.git/commitdiff
Reorganize secret parsing steps.
authorChris Duncan <chris@codecow.com>
Wed, 5 Aug 2026 07:18:45 +0000 (00:18 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 5 Aug 2026 07:18:45 +0000 (00:18 -0700)
src/lib/vault/parsers.ts

index b703afa4c00f012a152a39622fbcc566f40310a5..44fbceebd3ddf0c4c9fa4f0d35f77f3f947b64f9 100644 (file)
@@ -40,17 +40,16 @@ export function parseData (action: string, data: Record<string, unknown>) {
                }
 
                // 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<string, unknown>) {
                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<string, unknown>) {
                        : 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') {