From 71812f34ac88fc96256ec2bf66158370c48064c1 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 9 Aug 2026 23:13:08 -0700 Subject: [PATCH] Fix tests and documentation around updated accounts range. --- README.md | 2 +- src/lib/wallet/unopened.ts | 4 ++-- test/test.derive-accounts.mjs | 18 +++++++++--------- test/test.import-wallet.mjs | 6 +++--- test/test.ledger.mjs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 17baf08..0526e5a 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ try { const firstAccount = await wallet.account(); const secondAccount = await wallet.account(1); -const multipleAccounts = await wallet.accounts(2, 3); +const multipleAccounts = await wallet.accounts(2, 4); const thirdAccount = multipleAccounts[2]; const { address, publicKey } = firstAccount; diff --git a/src/lib/wallet/unopened.ts b/src/lib/wallet/unopened.ts index 49beff1..812ab75 100644 --- a/src/lib/wallet/unopened.ts +++ b/src/lib/wallet/unopened.ts @@ -16,7 +16,7 @@ export async function _unopened (wallet: Wallet, rpc: unknown, batchSize: unknow if (typeof from !== 'number' || from < 0 || 0xffffffff < from) { throw new TypeError('Invalid starting account index', { cause: from }) } - const to = (from + batchSize > 0xffffffff) ? 0xffffffff : from + batchSize + const to = (from + batchSize > 0x100000000) ? 0x100000000 : from + batchSize const accounts = await wallet.accounts(from, to) const addresses = [] for (const account of accounts.values()) { @@ -42,5 +42,5 @@ export async function _unopened (wallet: Wallet, rpc: unknown, batchSize: unknow if (to >= 0xffffffff) { throw new RangeError('Max index reached') } - return await _unopened(wallet, rpc, batchSize, to + 1) + return await _unopened(wallet, rpc, batchSize, to) } diff --git a/test/test.derive-accounts.mjs b/test/test.derive-accounts.mjs index e2ddf08..e299471 100644 --- a/test/test.derive-accounts.mjs +++ b/test/test.derive-accounts.mjs @@ -41,7 +41,7 @@ await Promise.all([ await test('derive low indexed accounts from the given BIP-44 seed', async () => { const wallet = await Wallet.load('BIP-44', TEST_PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(1, 2) + const accounts = await wallet.accounts(1, 3) assert.equal(accounts.size, 2) @@ -61,10 +61,10 @@ await Promise.all([ await test('derive high indexed accounts from the given BIP-44 seed', async () => { const wallet = await Wallet.load('BIP-44', TEST_PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0x70000000, 0x7000000f) + const accounts = await wallet.accounts(0x70000000, 0x70000010) assert.equal(accounts.size, 0x10) - for (let i = 0x70000000; i < 0x7000000f; i++) { + for (let i = 0x70000000; i < 0x70000010; i++) { const a = accounts.get(i) assert.exists(a) assert.exists(a.address) @@ -128,7 +128,7 @@ await Promise.all([ await test('derive low indexed accounts from the given BLAKE2b seed', async () => { const wallet = await Wallet.load('BLAKE2b', TEST_PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(2, 3) + const accounts = await wallet.accounts(2, 4) assert.equal(accounts.size, 2) @@ -148,10 +148,10 @@ await Promise.all([ await test('derive high indexed accounts from the given BLAKE2b seed', async () => { const wallet = await Wallet.load('BLAKE2b', TEST_PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0x70000000, 0x7000000f) + const accounts = await wallet.accounts(0x70000000, 0x70000010) assert.equal(accounts.size, 0x10) - for (let i = 0x70000000; i < 0x7000000f; i++) { + for (let i = 0x70000000; i < 0x70000010; i++) { const a = accounts.get(i) assert.exists(a) assert.exists(a.address) @@ -213,7 +213,7 @@ await Promise.all([ await test('derive low indexed accounts from the given Exodus seed', async () => { const wallet = await Wallet.load('Exodus', TEST_PASSWORD, BIP39_SEED_1) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(1, 2) + const accounts = await wallet.accounts(1, 3) assert.equal(accounts.size, 2) @@ -235,10 +235,10 @@ await Promise.all([ await test('derive high indexed accounts from the given Exodus seed', async () => { const wallet = await Wallet.load('Exodus', TEST_PASSWORD, BIP39_SEED_0) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0x70000000, 0x7000000f) + const accounts = await wallet.accounts(0x70000000, 0x70000010) assert.equal(accounts.size, 0x10) - for (let i = 0x70000000; i < 0x7000000f; i++) { + for (let i = 0x70000000; i < 0x70000010; i++) { const a = accounts.get(i) assert.exists(a) assert.exists(a.address) diff --git a/test/test.import-wallet.mjs b/test/test.import-wallet.mjs index 9eb538d..963a7e3 100644 --- a/test/test.import-wallet.mjs +++ b/test/test.import-wallet.mjs @@ -95,7 +95,7 @@ await Promise.all([ await test('BIP-44 zero-string entropy', async () => { const wallet = await Wallet.load('BIP-44', TEST_PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0, TREZOR_TEST_VECTORS.MNEMONIC_SALT) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0, 3) + const accounts = await wallet.accounts(0, 4) assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) @@ -116,7 +116,7 @@ await Promise.all([ await test('BLAKE2b zero-string seed', async () => { const wallet = await Wallet.load('BLAKE2b', TEST_PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0, 3) + const accounts = await wallet.accounts(0, 4) assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) @@ -139,7 +139,7 @@ await Promise.all([ await test('Trezor-derived BLAKE2b test vectors verified with third-party libraries', async () => { const wallet = await Wallet.load('BLAKE2b', TEST_PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1) await wallet.unlock(TEST_PASSWORD) - const accounts = await wallet.accounts(0, 1) + const accounts = await wallet.accounts(0, 2) assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.MNEMONIC_1)) assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.ENTROPY_1)) diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs index 945dab1..bb2ae71 100644 --- a/test/test.ledger.mjs +++ b/test/test.ledger.mjs @@ -217,7 +217,7 @@ await Promise.all([ }) await test('get second and third accounts', async () => { - const accounts = await wallet.accounts(1, 2) + const accounts = await wallet.accounts(1, 3) assert.exists(accounts) assert.equal(accounts.size, 2) for (const account of accounts.values()) { -- 2.52.0