]> zoso.dev Git - libnemo.git/commitdiff
Fix lock and unlock when account indices are skipped and update relevant test.
authorChris Duncan <chris@zoso.dev>
Sat, 26 Oct 2024 03:35:42 +0000 (20:35 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 26 Oct 2024 03:35:42 +0000 (20:35 -0700)
src/lib/wallet.ts
test/derive-accounts.test.mjs

index 2443aa91558b7cb726c7af31c14d9e0f1e9abbe7..4b0c0bd4dff3a73f45567c04a08068ca6a8c2a14 100644 (file)
@@ -168,9 +168,7 @@ abstract class Wallet {
                                data.seed = this.#seed\r
                        }\r
                        success &&= await this.#safe.put(this.id, passkey as string, data)\r
-                       for (const a of this.#accounts) {\r
-                               success &&= await a.lock(passkey as string)\r
-                       }\r
+                       await Promise.all(this.#accounts.map((a) => a.lock(passkey as string)))\r
                        if (!success) {\r
                                throw null\r
                        }\r
@@ -203,9 +201,7 @@ abstract class Wallet {
                        if (id !== this.id) {\r
                                throw null\r
                        }\r
-                       for (const a of this.#accounts) {\r
-                               await a.unlock(passkey as string)\r
-                       }\r
+                       await Promise.all(this.#accounts.map((a) => a.unlock(passkey as string)))\r
                        if (mnemonic != null) {\r
                                this.#mnemonic = await Bip39Mnemonic.fromPhrase(mnemonic)\r
                        }\r
index 55cad424484c5f8bc9d1d246f34a06572662da9b..81153acf1ab344aa798e8868bfcc55868d0eaf85 100644 (file)
@@ -24,18 +24,15 @@ describe('derive child accounts from the same seed', async () => {
        })\r
 \r
        it('should derive low indexed accounts from the given BIP-44 seed', async function () {\r
-               const accounts = await wallet.accounts(0, 2)\r
-\r
-               assert.equal(accounts.length, 3)\r
-               assert.equal(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
-               assert.equal(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
-               assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
-               assert.equal(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_1)\r
-               assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_1)\r
-               assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_1)\r
-               assert.equal(accounts[2].privateKey, NANO_TEST_VECTORS.PRIVATE_2)\r
-               assert.equal(accounts[2].publicKey, NANO_TEST_VECTORS.PUBLIC_2)\r
-               assert.equal(accounts[2].address, NANO_TEST_VECTORS.ADDRESS_2)\r
+               const accounts = await wallet.accounts(1, 2)\r
+\r
+               assert.equal(accounts.length, 2)\r
+               assert.equal(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_1)\r
+               assert.equal(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_1)\r
+               assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_1)\r
+               assert.equal(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_2)\r
+               assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_2)\r
+               assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2)\r
        })\r
 \r
        it('should derive high indexed accounts from the given seed', async function () {\r