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) {
+ if (from < 0 || 0x100000000 < from || to < 0 || 0x100000000 < 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')
}
if (to - from > MAX_DERIVATIONS) {
- throw new RangeError('Maximum 1000 accounts per call')
+ throw new RangeError(`Maximum ${MAX_DERIVATIONS} accounts per call`)
}
const output = new Map<number, Account>()
const missing: number[] = []
- for (let i = from; i <= to; i++) {
+ for (let i = from; i < to; i++) {
const account = accounts.get(i)
if (account == null) {
missing.push(i)
\r
/**\r
* Retrieves an account from a wallet using its child key derivation function.\r
- * Defaults to the first account at index 0.\r
+ * Defaults to the first account at index 0. If a range of indexes is passed,\r
+ * derives up to but not including the larger value.\r
*\r
* The returned object will have keys corresponding with the requested range\r
* of account indexes. The value of each key will be the Account derived for\r
* // { address: <...>, publicKey: <...>, index: 1, <etc...> }\r
* ```\r
*\r
- * @param {number} index - Wallet index of account. Default: 0\r
+ * @param {number} index - Wallet index of account. Default: 0; Maximum: 2³²-1\r
* @returns Promise for the Account at the specified index\r
*/\r
async account (index: number = 0): Promise<Account> {\r
\r
/**\r
* Retrieves accounts from a wallet using its child key derivation function.\r
- * Defaults to the first account at index 0.\r
+ * Defaults to the first account at index 0. If\r
*\r
* Derives a maximum of 1000 accounts per call and will throw an error if\r
* exceeded. This is not a hard limit since the method can be called multiple\r
* that index in the wallet.\r
*\r
* ```\r
- * const accounts = await wallet.accounts(0, 1))\r
+ * const accounts = await wallet.accounts(0, 2))\r
* // outputs the first and second account of the wallet\r
* console.log(accounts)\r
* // {\r
*\r
* If `from` is greater than `to`, their values will be swapped.\r
* @param {number} [from=0] - Start index of accounts. Default: 0\r
- * @param {number} [to=from] - End index of accounts. Default: `from`\r
+ * @param {number} [to=from+1] - End index of accounts. Default: `from + 1`\r
* @returns {Promise<Map<number, Account>>} Promise for a list of Accounts at the specified indexes\r
*/\r
- async accounts (from: number = 0, to: number = from): Promise<Map<number, Account>> {\r
+ async accounts (from: number = 0, to: number = from + 1): Promise<Map<number, Account>> {\r
return _accounts(this.type, this.#accounts, this.#vault, from, to)\r
}\r
\r