]> git.codecow.com Git - libnemo.git/commitdiff
Set seed to null when locking and destroying. Import salt as entropy when fetching...
authorChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 05:08:35 +0000 (22:08 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 05:08:35 +0000 (22:08 -0700)
src/lib/account.ts
src/lib/wallets/wallet.ts
src/lib/workers/safe.ts

index 2cd9842d20ee3a953a2598002a9bd1e5d56227a0..d16352f42e25a3febe6997ead18217f4ba335604 100644 (file)
@@ -72,8 +72,8 @@ export class Account {
        async destroy (): Promise<void> {\r
                await SafeWorker.assign({\r
                        method: 'destroy',\r
-                       [this.publicKey]: this.publicKey,\r
-                       store: 'Account'\r
+                       store: 'Account',\r
+                       [this.publicKey]: this.publicKey\r
                })\r
                this.#frontier = undefined\r
                this.#balance = undefined\r
index 98505c3f7a310411b2686df44fe55fabe0ab72b1..6acacb37499b2d81f11f49e1ec4abea4db6e31d3 100644 (file)
@@ -24,13 +24,13 @@ export abstract class Wallet {
        #id: Entropy\r
        #locked: boolean = true\r
        #m: Bip39Mnemonic | null\r
-       #s: Uint8Array<ArrayBuffer>\r
+       #s: Uint8Array<ArrayBuffer> | null\r
 \r
        get id () { return `libnemo_${this.#id.hex}` }\r
        get isLocked () { return this.#locked }\r
        get isUnlocked () { return !this.#locked }\r
        get mnemonic () { return this.#m instanceof Bip39Mnemonic ? this.#m.phrase : null }\r
-       get seed () { return 0 === +(bytes.toHex(this.#s)) ? null : bytes.toHex(this.#s) }\r
+       get seed () { return this.#s == null ? this.#s : bytes.toHex(this.#s) }\r
 \r
        constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
                if (this.constructor === Wallet) {\r
@@ -39,7 +39,7 @@ export abstract class Wallet {
                this.#accounts = new AccountList()\r
                this.#id = id\r
                this.#m = mnemonic ?? null\r
-               this.#s = seed ?? new Uint8Array(0)\r
+               this.#s = seed ?? null\r
        }\r
 \r
        /**\r
@@ -144,6 +144,7 @@ export abstract class Wallet {
                }\r
                this.#m = null\r
                bytes.erase(this.#s)\r
+               this.#s = null\r
                await SafeWorker.assign({\r
                        store: 'Wallet',\r
                        method: 'destroy',\r
@@ -187,6 +188,7 @@ export abstract class Wallet {
                        bytes.erase(password)\r
                }\r
                bytes.erase(this.#s)\r
+               this.#s = null\r
                this.#m = null\r
                this.#locked = true\r
                return true\r
index 2cc38b9636c8e617f8610234cd87fcc975c01624..f3ef9c1493747931a68de5846aca9c1aecf63603 100644 (file)
@@ -136,10 +136,10 @@ export class Safe extends WorkerInterface {
                        }
                        const decryptionKeys: { [salt: string]: CryptoKey } = {}
                        for (const record of records) {
-                               const salt = bytes.toHex(new Uint8Array(record.salt))
-                               decryptionKeys[salt] ??= await this.#createAesKey('decrypt', password, record.salt)
+                               const salt = await Entropy.import(record.salt)
+                               decryptionKeys[salt.hex] ??= await this.#createAesKey('decrypt', password, salt.buffer)
                                const iv = await Entropy.import(record.iv)
-                               const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[salt], record.encrypted)
+                               const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[salt.hex], record.encrypted)
                                results[record.label] = decrypted
                        }
                        return results