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++) {