From fc6166671a55a55d0a1ec091c7f58a9277176c58 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 20 Nov 2024 21:34:08 -0800 Subject: [PATCH] Remove duplicate ckd function. Post index along with key from worker back to caller. --- src/lib/workers/ckdBip44.ts | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/lib/workers/ckdBip44.ts b/src/lib/workers/ckdBip44.ts index a1f0175..369742f 100644 --- a/src/lib/workers/ckdBip44.ts +++ b/src/lib/workers/ckdBip44.ts @@ -19,35 +19,13 @@ if (addEventListener == null || postMessage == null) { } /** -* Derives BIP-44 Nano account private keys. -* -* @param {number} index - Index of the account -* @returns {Promise} +* Listens for messages from a calling function. */ addEventListener('message', (message) => { const { seed, index } = message.data ?? message - ckd(seed, index).then(postMessage) + nanoCKD(seed, index).then(key => postMessage({ index, key })) }) -/** -* 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 {string} seed - Hexadecimal seed derived from mnemonic phrase -* @param {number} index - Account number between 0 and 2^31-1 -* @returns Private child key for the account -*/ -async function ckd (seed: string, index: number): Promise { - if (!Number.isSafeInteger(index) || index < 0 || index > 0x7fffffff) { - throw new RangeError(`Invalid child key index 0x${index.toString(16)}`) - } - const masterKey = await slip10(SLIP10_ED25519, seed) - const purposeKey = await CKDpriv(masterKey, BIP44_PURPOSE + HARDENED_OFFSET) - const coinKey = await CKDpriv(purposeKey, BIP44_COIN_NANO + HARDENED_OFFSET) - const accountKey = await CKDpriv(coinKey, index + HARDENED_OFFSET) - return accountKey.privateKey -} - /** * 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. -- 2.34.1