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:
parent
e3b1f7580e
commit
23ce7e2614
1 changed files with 3 additions and 3 deletions
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue