const indexes = []\r
for (let i = from; i <= to; i++) {\r
if (this.#accounts[i] == null) {\r
- // this.#accounts[i] = await this.ckd(i)\r
indexes.push(i)\r
}\r
}\r
- let results = await this.ckd(indexes)\r
- if (!Array.isArray(results)) results = [results]\r
- for (const result of results) {\r
- if (result.index == null) {\r
- console.error('Wallet account calculated with null index')\r
- } else {\r
- this.#accounts[result.index] = result\r
+ if (indexes.length > 0) {\r
+ let results = await this.ckd(indexes)\r
+ if (!Array.isArray(results)) results = [results]\r
+ for (const result of results) {\r
+ if (result.index == null) {\r
+ throw new RangeError('Account key derived but index missing')\r
+ } else {\r
+ this.#accounts[result.index] = result\r
+ }\r
}\r
}\r
return this.#accounts.slice(from, to + 1)\r
return wallet\r
}\r
\r
- /**\r
- * Derives BIP-44 Nano account private keys.\r
- *\r
- * @param {number} index - Index of the account\r
- * @returns {Promise<Account>}\r
- */\r
- async ckd_old (index: number | number[]): Promise<Account[]> {\r
- if (!Array.isArray(index)) index = [index]\r
- const keys = []\r
- let now = performance.now()\r
- for (const i of index) {\r
- const key = await nanoCKD(this.seed, i)\r
- if (typeof key !== 'string') {\r
- throw new TypeError('BIP-44 child key derivation returned invalid data')\r
- }\r
- keys.push({ key, i })\r
- }\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('bip44 ckd done')\r
- const accounts = []\r
- for (const key of keys) {\r
- accounts.push(await Account.fromPrivateKey(key.key, key.i))\r
- }\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('bip44 account list done')\r
- return accounts\r
- }\r
-\r
/**\r
* Derives BIP-44 Nano account private keys.\r
*\r
async ckd (index: number | number[]): Promise<Account[]> {\r
if (!Array.isArray(index)) index = [index]\r
const data: any = []\r
- let now = performance.now()\r
index.forEach(i => data.push({ seed: this.seed, index: i }))\r
const results: [{ index: number, key: string }] = await this.#pool.work(data)\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('bip44 ckd done')\r
const accounts = []\r
for (const result of results) {\r
const { index, key } = result\r
}\r
accounts.push(await Account.fromPrivateKey(key, index))\r
}\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('bip44 account list done')\r
return accounts\r
}\r
}\r
return wallet\r
}\r
\r
- /**\r
- * Derives BLAKE2b account private keys.\r
- *\r
- * @param {number} index - Index of the account\r
- * @returns {Promise<Account>}\r
- */\r
- async ckd_old (index: number | number[]): Promise<Account[]> {\r
- if (!Array.isArray(index)) index = [index]\r
- const keys = []\r
- let now = performance.now()\r
- for (const i of index) {\r
- const input = `${this.seed}${dec.toHex(i, 8)}`\r
- const key = blake2b(32).update(hex.toBytes(input)).digest('hex')\r
- if (typeof key !== 'string') {\r
- throw new TypeError('BLAKE2b child key derivation returned invalid data')\r
- }\r
- keys.push({ key, i })\r
- }\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('blake2b ckd done')\r
- const accounts = []\r
- for (const key of keys) {\r
- accounts.push(await Account.fromPrivateKey(key.key, key.i))\r
- }\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('blake2b account list done')\r
- return accounts\r
- }\r
-\r
/**\r
* Derives BLAKE2b account private keys.\r
*\r
async ckd (index: number | number[]): Promise<Account[]> {\r
if (!Array.isArray(index)) index = [index]\r
const data: any = []\r
- let now = performance.now()\r
index.forEach(i => data.push({ seed: this.seed, index: i }))\r
const results: [{ index: number, key: string }] = await this.#pool.work(data)\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('blake2b ckd done')\r
const accounts = []\r
for (const result of results) {\r
const { index, key } = result\r
}\r
accounts.push(await Account.fromPrivateKey(key, index))\r
}\r
- console.log(-now + (now = performance.now()), 'ms')\r
- console.log('blake2b account list done')\r
return accounts\r
}\r
}\r