From d6dc6bc6759c5f4b8b803f97e7b2788c22e2640f Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 8 Nov 2024 09:06:16 -0800 Subject: [PATCH] Promisify BIP-44 serialization methods. --- src/lib/bip32-key-derivation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/bip32-key-derivation.ts b/src/lib/bip32-key-derivation.ts index 8580ad0..a622b99 100644 --- a/src/lib/bip32-key-derivation.ts +++ b/src/lib/bip32-key-derivation.ts @@ -39,14 +39,14 @@ async function slip10 (curve: string, S: string): Promise { async function CKDpriv ({ privateKey, chainCode }: ExtendedKey, index: number): Promise { const key = hex.toBytes(chainCode) - const data = hex.toBytes(`00${bytes.toHex(ser256(privateKey))}${bytes.toHex(ser32(index))}`) + const data = hex.toBytes(`00${bytes.toHex(await ser256(privateKey))}${bytes.toHex(await ser32(index))}`) const I = await hmac(key, data) const IL = I.slice(0, I.length / 2) const IR = I.slice(I.length / 2) return ({ privateKey: IL, chainCode: IR }) } -function ser32 (integer: number): Uint8Array { +async function ser32 (integer: number): Promise { const bits = integer.toString(2) if (bits.length > 32) { throw new RangeError(`Expected 32-bit integer, received ${bits.length} bits: ${bits}`) @@ -57,7 +57,7 @@ function ser32 (integer: number): Uint8Array { return result } -function ser256 (integer: string): Uint8Array { +async function ser256 (integer: string): Promise { const bits = hex.toBin(integer) if (bits.length > 256) { throw new RangeError(`Expected 256-bit integer, received ${bits.length} bits: ${bits}`) -- 2.34.1