]> git.codecow.com Git - libnemo.git/commitdiff
Improve account derivation range checks.
authorChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 19:36:45 +0000 (12:36 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 19:36:45 +0000 (12:36 -0700)
src/lib/wallet/accounts.ts

index 9d380debeb2a171a6486618ac6579c503ae4f88c..65f79e2c0eac8b66b9c38b0b7b1a2185bb76446b 100644 (file)
@@ -11,10 +11,19 @@ export async function _accounts (type: WalletType, accounts: Map<number, Account
 export async function _accounts (type: WalletType, accounts: Map<number, Account>, vault: Vault, from: unknown, to?: unknown): Promise<Account | Map<number, Account>> {
        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<number, Account>()
        const indexes: number[] = []
        for (let i = from; i <= to; i++) {