From 4a894664c9191db5bcc35953cfa224b34f8f7764 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 25 Oct 2024 20:35:42 -0700 Subject: [PATCH] Fix lock and unlock when account indices are skipped and update relevant test. --- src/lib/wallet.ts | 8 ++------ test/derive-accounts.test.mjs | 21 +++++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 2443aa9..4b0c0bd 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -168,9 +168,7 @@ abstract class Wallet { data.seed = this.#seed } success &&= await this.#safe.put(this.id, passkey as string, data) - for (const a of this.#accounts) { - success &&= await a.lock(passkey as string) - } + await Promise.all(this.#accounts.map((a) => a.lock(passkey as string))) if (!success) { throw null } @@ -203,9 +201,7 @@ abstract class Wallet { if (id !== this.id) { throw null } - for (const a of this.#accounts) { - await a.unlock(passkey as string) - } + await Promise.all(this.#accounts.map((a) => a.unlock(passkey as string))) if (mnemonic != null) { this.#mnemonic = await Bip39Mnemonic.fromPhrase(mnemonic) } diff --git a/test/derive-accounts.test.mjs b/test/derive-accounts.test.mjs index 55cad42..81153ac 100644 --- a/test/derive-accounts.test.mjs +++ b/test/derive-accounts.test.mjs @@ -24,18 +24,15 @@ describe('derive child accounts from the same seed', async () => { }) it('should derive low indexed accounts from the given BIP-44 seed', async function () { - const accounts = await wallet.accounts(0, 2) - - assert.equal(accounts.length, 3) - assert.equal(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0) - assert.equal(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0) - assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) - assert.equal(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_1) - assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_1) - assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_1) - assert.equal(accounts[2].privateKey, NANO_TEST_VECTORS.PRIVATE_2) - assert.equal(accounts[2].publicKey, NANO_TEST_VECTORS.PUBLIC_2) - assert.equal(accounts[2].address, NANO_TEST_VECTORS.ADDRESS_2) + const accounts = await wallet.accounts(1, 2) + + assert.equal(accounts.length, 2) + assert.equal(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_1) + assert.equal(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_1) + assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_1) + assert.equal(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_2) + assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_2) + assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2) }) it('should derive high indexed accounts from the given seed', async function () { -- 2.34.1