From 1885a9fbf1e99ec236bbe3f47ca9deffb7efd8e0 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 4 Aug 2025 11:30:40 -0700 Subject: [PATCH] Simplify BIP-44 child key derivation and use Nano coin by default. --- src/lib/bip44-ckd.ts | 20 ++++---------------- src/lib/safe.ts | 4 ++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/lib/bip44-ckd.ts b/src/lib/bip44-ckd.ts index 73915ab..5377a64 100644 --- a/src/lib/bip44-ckd.ts +++ b/src/lib/bip44-ckd.ts @@ -12,29 +12,17 @@ export class Bip44Ckd { static HARDENED_OFFSET = 0x80000000 static SLIP10_ED25519 = 'ed25519 seed' - /** - * Derives a private child key following the BIP-32 and BIP-44 derivation path - * registered to the Nano block lattice. Only hardened child keys are defined. - * - * @param {ArrayBuffer} seed - Hexadecimal seed derived from mnemonic phrase - * @param {number} index - Account number between 0 and 2^31-1 - * @returns {Promise} Private child key for the account - */ - static async nanoCKD (seed: ArrayBuffer, index: number): Promise { - 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'. Coin defaults to Nano. Only - * hardened child keys are defined. + * BIP-44 derivation path. Purpose is always 44'. Only hardened child keys are + * defined. * * @param {ArrayBuffer} 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 + * @param {number} coin - Number registered to a specific coin in SLIP-044. Default: 165 (Nano) * @returns {Promise} Private child key for the account */ - static async ckd (seed: ArrayBuffer, coin: number = this.BIP44_COIN_NANO, index: number): Promise { + static async ckd (seed: ArrayBuffer, index: number, coin: number = this.BIP44_COIN_NANO): Promise { if (seed.byteLength < 16 || seed.byteLength > 64) { throw new RangeError(`Invalid seed length`) } diff --git a/src/lib/safe.ts b/src/lib/safe.ts index 76a6c2f..2c3c041 100644 --- a/src/lib/safe.ts +++ b/src/lib/safe.ts @@ -145,7 +145,7 @@ export class Safe { throw new Error('Invalid wallet account index') } const prv = this.#type === 'BIP-44' - ? await Bip44Ckd.nanoCKD(this.#seed, index) + ? await Bip44Ckd.ckd(this.#seed, index) : await Blake2bCkd.ckd(this.#seed, index) const pub = await NanoNaCl.convert(new Uint8Array(prv)) return { index, publicKey: pub.buffer } @@ -233,7 +233,7 @@ export class Safe { if (data == null) { throw new Error('Data to sign not found') } - const prv = await Bip44Ckd.nanoCKD(this.#seed, index) + const prv = await Bip44Ckd.ckd(this.#seed, index) const sig = await NanoNaCl.detached(new Uint8Array(data), new Uint8Array(prv)) return { signature: sig.buffer } } catch (err) { -- 2.47.3