From: Chris Duncan Date: Fri, 8 Nov 2024 17:06:16 +0000 (-0800) Subject: Promisify BIP-44 serialization methods. X-Git-Tag: v0.0.20~41 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=d6dc6bc6759c5f4b8b803f97e7b2788c22e2640f;p=libnemo.git Promisify BIP-44 serialization methods. --- 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}`)