From: Chris Duncan Date: Thu, 21 Nov 2024 05:34:08 +0000 (-0800) Subject: Remove duplicate ckd function. Post index along with key from worker back to caller. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=fc6166671a55a55d0a1ec091c7f58a9277176c58;p=libnemo.git Remove duplicate ckd function. Post index along with key from worker back to caller. --- 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.