static async work (headers: Headers, data: Data): Promise<any[]> {
let { coin, indexes } = headers
let { seed } = data
- if (typeof coin !== 'number' || !Number.isInteger(coin)) {
+ if (coin != null && (typeof coin !== 'number' || !Number.isInteger(coin))) {
throw new TypeError('BIP-44 coin derivation level must be an integer')
}
if (!Array.isArray(indexes)) indexes = [indexes]
throw new TypeError('BIP-44 account derivation level must be an integer')
}
try {
- const pk = (coin !== this.BIP44_PURPOSE)
- ? await this.ckd(seed, coin, i)
- : await this.nanoCKD(seed, i)
+ const pk = await this.ckd(seed, coin, i)
privateKeys.push(pk)
} catch (err) {
console.log(err)
* @returns {Promise<string>} Private child key for the account
*/
static async nanoCKD (seed: ArrayBuffer, index: number): Promise<ArrayBuffer> {
- if (!Number.isSafeInteger(index) || index < 0 || index > 0x7fffffff) {
- throw new RangeError(`Invalid child key index 0x${index.toString(16)}`)
- }
return await this.ckd(seed, this.BIP44_COIN_NANO, index)
}
/**
* Derives a private child key for a coin by following the specified BIP-32 and
- * BIP-44 derivation path. Purpose is always 44'. Only hardened child keys are
- * defined.
+ * BIP-44 derivation path. Purpose is always 44'. Coin defaults to Nano. Only
+ * hardened child keys are defined.
*
* @param {string} seed - Hexadecimal seed derived from mnemonic phrase
* @param {number} coin - Number registered to a specific coin in SLIP-044
* @param {number} index - Account number between 0 and 2^31-1
* @returns {Promise<string>} Private child key for the account
*/
- static async ckd (seed: ArrayBuffer, coin: number, index: number): Promise<ArrayBuffer> {
+ static async ckd (seed: ArrayBuffer, coin: number = this.BIP44_COIN_NANO, index: number): Promise<ArrayBuffer> {
if (seed.byteLength < 16 || seed.byteLength > 64) {
throw new RangeError(`Invalid seed length`)
}
const coinKey = await this.CKDpriv(purposeKey, coin + this.HARDENED_OFFSET)
const accountKey = await this.CKDpriv(coinKey, index + this.HARDENED_OFFSET)
return accountKey.privateKey.buffer
- // const privateKey = new Uint8Array(accountKey.privateKey.buffer)
- // let hex = ''
- // for (let i = 0; i < privateKey.length; i++) {
- // hex += privateKey[i].toString(16).padStart(2, '0')
- // }
- // return hex
}
static async slip10 (curve: string, S: ArrayBuffer): Promise<ExtendedKey> {