]> git.codecow.com Git - libnemo.git/commitdiff
Add locked wallet destroy test. Return null seed when locked.
authorChris Duncan <chris@zoso.dev>
Tue, 22 Jul 2025 00:35:14 +0000 (17:35 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 22 Jul 2025 00:35:14 +0000 (17:35 -0700)
src/lib/account.ts
src/lib/wallets/wallet.ts
test/test.create-wallet.mjs

index a3abc10673688ee41932ef5c8f56d4edfe9d8e5c..2cd9842d20ee3a953a2598002a9bd1e5d56227a0 100644 (file)
@@ -72,7 +72,7 @@ export class Account {
        async destroy (): Promise<void> {\r
                await SafeWorker.assign({\r
                        method: 'destroy',\r
-                       name: this.publicKey,\r
+                       [this.publicKey]: this.publicKey,\r
                        store: 'Account'\r
                })\r
                this.#frontier = undefined\r
index 2157b8aff7e19036f167de92d8c7c2c1ea15fd8d..50e9da876516ac3d75a16bedd3a167c0865db9cb 100644 (file)
@@ -30,7 +30,7 @@ export abstract class Wallet {
        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 bytes.toHex(this.#s) }\r
+       get seed () { return 0 === +(bytes.toHex(this.#s)) ? null : bytes.toHex(this.#s) }\r
 \r
        constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
                if (this.constructor === Wallet) {\r
@@ -86,6 +86,10 @@ export abstract class Wallet {
        * @returns {AccountList} Object with keys of account indexes and values of the corresponding Accounts\r
        */\r
        async accounts (from: number = 0, to: number = from): Promise<AccountList> {\r
+       console.log(this.seed)\r
+       if (this.seed == null) {\r
+               throw new Error('wallet must be unlocked to derive accounts')\r
+       }\r
                if (from > to) {\r
                        const swap = from\r
                        from = to\r
index 620949214795fd5ea674e2d5014a891da2b7cc1c..d899a445a2a1741ae2117a443529231c0981dec9 100644 (file)
@@ -10,6 +10,16 @@ import { Bip44Wallet, Blake2bWallet } from '../dist/main.min.js'
 await Promise.all([\r
        suite('Create wallets', async () => {\r
 \r
+               await test('destroy BIP-44 wallet before unlocking', async () => {\r
+                       const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
+                       await assert.resolves(wallet.destroy())\r
+                       assert.ok('mnemonic' in wallet)\r
+                       assert.ok('seed' in wallet)\r
+                       assert.nullish(wallet.mnemonic)\r
+                       assert.nullish(wallet.seed)\r
+                       await assert.rejects(wallet.unlock(NANO_TEST_VECTORS.PASSWORD))\r
+       })\r
+\r
                await test('BIP-44 wallet with random entropy', async () => {\r
                        const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
                        await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r