fix: correct nip44v1 secp256k1 getSharedSecret argument types

The @noble/curves secp256k1.getSharedSecret expects Uint8Array arguments,
not hex strings. Use hex.decode() to convert the private and public keys.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Patrick Mulligan 2026-02-14 12:55:09 -05:00
parent b6d2143134
commit bc63d30af6

View file

@ -1,14 +1,14 @@
import { base64 } from "@scure/base"; import { base64, hex } from "@scure/base";
import { randomBytes } from "@noble/hashes/utils"; import { randomBytes } from "@noble/hashes/utils";
import { streamXOR as xchacha20 } from "@stablelib/xchacha20"; import { streamXOR as xchacha20 } from "@stablelib/xchacha20";
import { secp256k1 } from "@noble/curves/secp256k1"; import { secp256k1 } from "@noble/curves/secp256k1.js";
import { sha256 } from "@noble/hashes/sha256"; import { sha256 } from "@noble/hashes/sha256";
export type EncryptedData = { export type EncryptedData = {
ciphertext: Uint8Array; ciphertext: Uint8Array;
nonce: Uint8Array; nonce: Uint8Array;
} }
export const getSharedSecret = (privateKey: string, publicKey: string) => { export const getSharedSecret = (privateKey: string, publicKey: string) => {
const key = secp256k1.getSharedSecret(privateKey, "02" + publicKey); const key = secp256k1.getSharedSecret(hex.decode(privateKey), hex.decode("02" + publicKey));
return sha256(key.slice(1, 33)); return sha256(key.slice(1, 33));
} }