return ''\r
}\r
\r
- abstract ckd (index: number | number[]): Promise<KeyPair> | Promise<KeyPair[]>\r
+ abstract ckd (index: number[]): Promise<KeyPair[]>\r
\r
constructor (seed?: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
if (this.constructor === Wallet) {\r
}\r
if (indexes.length > 0) {\r
let results = await this.ckd(indexes)\r
- if (!Array.isArray(results)) results = [results]\r
const data: any = []\r
results.forEach(r => data.push({ privateKey: hex.toBytes(r.privateKey as string), index: r.index }))\r
let now = performance.now()\r
/**\r
* Derives BIP-44 Nano account private keys.\r
*\r
- * @param {number} index - Index of the account\r
+ * @param {number[]} indexes - Indexes of the accounts\r
* @returns {Promise<Account>}\r
*/\r
- async ckd (index: number | number[]): Promise<KeyPair[]> {\r
- if (!Array.isArray(index)) index = [index]\r
+ async ckd (indexes: number[]): Promise<KeyPair[]> {\r
const data: any = []\r
- index.forEach(i => data.push({ seed: this.seed, index: i }))\r
+ indexes.forEach(i => data.push({ seed: this.seed, index: i }))\r
let now = performance.now()\r
const privateKeys: KeyPair[] = await this.#pool.work(data)\r
console.log(`ckd: ${-now + (now = performance.now())} ms`)\r
/**\r
* Derives BLAKE2b account private keys.\r
*\r
- * @param {number} index - Index of the account\r
+ * @param {number[]} indexes - Indexes of the accounts\r
* @returns {Promise<Account>}\r
*/\r
- async ckd (index: number | number[]): Promise<KeyPair[]> {\r
- if (!Array.isArray(index)) index = [index]\r
- const data: any = []\r
+ async ckd (indexes: number[]): Promise<KeyPair[]> {\r
let now = performance.now()\r
- const results = index.map(index => {\r
+ const results = indexes.map(index => {\r
const indexHex = index.toString(16).padStart(8, '0').toUpperCase()\r
const inputHex = `${this.seed}${indexHex}`.padStart(72, '0')\r
const inputArray = (inputHex.match(/.{1,2}/g) ?? []).map(h => parseInt(h, 16))\r
/**\r
* Gets the public key for an account from the Ledger device.\r
*\r
- * @param {number} index - Index of the account\r
+ * @param {number[]} indexes - Indexes of the accounts\r
* @returns {Promise<Account>}\r
*/\r
- async ckd (index: number): Promise<KeyPair> {\r
- const { status, publicKey } = await this.ledger.account(index)\r
- if (status === 'OK' && publicKey != null) {\r
- return { publicKey, index }\r
+ async ckd (indexes: number[]): Promise<KeyPair[]> {\r
+ const results: KeyPair[] = []\r
+ for (const index of indexes) {\r
+ const { status, publicKey } = await this.ledger.account(index)\r
+ if (status === 'OK' && publicKey != null) {\r
+ results.push({ publicKey, index })\r
+ } else {\r
+ throw new Error(`Error getting Ledger account: ${status}`)\r
+ }\r
}\r
- throw new Error(`Error getting Ledger account: ${status}`)\r
+ return results\r
}\r
\r
/**\r