]> git.codecow.com Git - libnemo.git/commitdiff
Simplify BIP-44 child key derivation and use Nano coin by default.
authorChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 18:30:40 +0000 (11:30 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 18:30:40 +0000 (11:30 -0700)
src/lib/bip44-ckd.ts
src/lib/safe.ts

index 73915ab91bc5422a55321c72586f8b73ce36b5c3..5377a649166e245a5054c00bdde9fef166ed5e2a 100644 (file)
@@ -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<ArrayBuffer>} Private child key for the account
-       */
-       static async nanoCKD (seed: ArrayBuffer, index: number): Promise<ArrayBuffer> {
-               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<ArrayBuffer>} Private child key for the account
        */
-       static async ckd (seed: ArrayBuffer, coin: number = this.BIP44_COIN_NANO, index: number): Promise<ArrayBuffer> {
+       static async ckd (seed: ArrayBuffer, index: number, coin: number = this.BIP44_COIN_NANO): Promise<ArrayBuffer> {
                if (seed.byteLength < 16 || seed.byteLength > 64) {
                        throw new RangeError(`Invalid seed length`)
                }
index 76a6c2fc7151fe874564540f4c523f4f2d474fa0..2c3c041603316afb0dfe9cfa103b0bcb9b170896 100644 (file)
@@ -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) {