From d227141c38b7a2fffa9d09d73631627d6d8f5e1c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 3 Aug 2026 12:36:45 -0700 Subject: [PATCH] Improve account derivation range checks. --- src/lib/wallet/accounts.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/wallet/accounts.ts b/src/lib/wallet/accounts.ts index 9d380de..65f79e2 100644 --- a/src/lib/wallet/accounts.ts +++ b/src/lib/wallet/accounts.ts @@ -11,10 +11,19 @@ export async function _accounts (type: WalletType, accounts: Map, vault: Vault, from: unknown, to?: unknown): Promise> { const isSingle = to === undefined to ??= from - if (typeof from !== 'number' || typeof to !== 'number') { - throw new TypeError('Invalid account range', { cause: `${from}-${to}` }) + if (typeof from !== 'number') { + throw new Error('Invalid account range start argument', { cause: `${typeof from} ${from}` }) + } + if (typeof to !== 'number') { + throw new Error('Invalid account range end argument', { cause: `${typeof to} ${to}` }) } if (from > to) [from as number, to as number] = [to, from] + if (from < 0 || 0xffffffff < from || to < 0 || 0xffffffff < to) { + throw new TypeError('Invalid account range', { cause: `${from}-${to}` }) + } + if (to - from > 100) { + console.warn(`libnemo performance may degrade when deriving many accounts at once`) + } const output = new Map() const indexes: number[] = [] for (let i = from; i <= to; i++) { -- 2.52.0