]> git.codecow.com Git - libnemo.git/commitdiff
Fix restored wallets with undefined type.
authorChris Duncan <chris@zoso.dev>
Sat, 13 Sep 2025 05:46:52 +0000 (22:46 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 13 Sep 2025 05:46:52 +0000 (22:46 -0700)
src/lib/vault/vault-worker.ts
test/test.derive-accounts.mjs
test/test.lock-unlock.mjs

index 363ede0278fb727e749f8265dd2ac399d9340307..afc0cb8841ef79446f94cb8176120a8455f47c91 100644 (file)
@@ -231,7 +231,7 @@ export class VaultWorker {
        /**
        * Decrypts the input and sets the seed and, if it is included, the mnemonic.
        */
-       unlock (type?: string, key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
+       unlock (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
                if (type == null) {
                        throw new TypeError('Wallet type is required')
                }
@@ -253,6 +253,7 @@ export class VaultWorker {
                                if (mnemonic != null && !(mnemonic instanceof ArrayBuffer)) {
                                        throw new TypeError('Invalid mnemonic')
                                }
+                               this.#type = type
                                this.#seed = seed
                                this.#mnemonic = mnemonic
                                this.#locked = false
index e90d28de9a659df955a4465b7bd69ec7f0bd9f85..713cc4022d3ad44182edef72f46e715f93721928 100644 (file)
@@ -73,6 +73,24 @@ await Promise.all([
 \r
                        await assert.resolves(wallet.destroy())\r
                })\r
+\r
+               await test('derive from restored BIP-44 wallet', async () => {\r
+                       const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+                       const restored = await Wallet.restore(wallet.id)\r
+                       await restored.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+                       const account = await restored.account()\r
+\r
+                       assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
+                       assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
+                       assert.equal(account.index, 0)\r
+\r
+                       const accounts = await restored.accounts()\r
+                       assert.exists(accounts.get(0))\r
+                       assert.equal(account, accounts.get(0))\r
+\r
+                       await assert.resolves(wallet.destroy())\r
+                       await assert.resolves(restored.destroy())\r
+               })\r
        }),\r
 \r
        suite('Derive accounts from BLAKE2b wallet', async () => {\r
@@ -134,5 +152,23 @@ await Promise.all([
 \r
                        await assert.resolves(wallet.destroy())\r
                })\r
+\r
+               await test('derive from restored BLAKE2b wallet', async () => {\r
+                       const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
+                       const restored = await Wallet.restore(wallet.id)\r
+                       await restored.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+                       const account = await restored.account(1)\r
+\r
+                       assert.equal(account.publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_1)\r
+                       assert.equal(account.address, NANO_TEST_VECTORS.BLAKE2B_ADDRESS_1)\r
+                       assert.equal(account.index, 1)\r
+\r
+                       const accounts = await restored.accounts(1)\r
+                       assert.exists(accounts.get(1))\r
+                       assert.equal(account, accounts.get(1))\r
+\r
+                       await assert.resolves(wallet.destroy())\r
+                       await assert.resolves(restored.destroy())\r
+               })\r
        })\r
 ])\r
index 14386df9e90191a33e0f4aaa986eefd3d44dfeed..a6ce21cb3e00a6b0fa1802a6b4e9f91322fd2f5f 100644 (file)
@@ -64,7 +64,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('fail to unlock a Bip44Wallet with different passwords', async () => {\r
+               await test('fail to unlock a BIP-44 wallet with different passwords', async () => {\r
                        const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
                        await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                        wallet.lock()\r
@@ -87,7 +87,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('fail to unlock a Bip44Wallet with invalid input', async () => {\r
+               await test('fail to unlock a BIP-44 wallet with invalid input', async () => {\r
                        const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
                        await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
 \r
@@ -98,7 +98,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('locking and unlocking a Blake2bWallet with a password', async () => {\r
+               await test('locking and unlocking a BLAKE2b wallet with a password', async () => {\r
                        const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
 \r
                        assert.ok('mnemonic' in wallet)\r
@@ -114,7 +114,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('fail to unlock a Blake2bWallet with different passwords', async () => {\r
+               await test('fail to unlock a BLAKE2b wallet with different passwords', async () => {\r
                        const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
 \r
                        await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' })\r
@@ -128,7 +128,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('fail to unlock a Blake2bWallet with no input', async () => {\r
+               await test('fail to unlock a BLAKE2b wallet with no input', async () => {\r
                        const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
 \r
                        await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' })\r