21 lines
568 B
TypeScript
Raw Normal View History

2022-03-07 13:33:20 +11:00
import * as secp from "@noble/secp256k1";
import type { NodeId } from "@waku/interfaces";
import { bytesToHex } from "@waku/utils/bytes";
2022-11-02 22:25:47 +11:00
import { keccak256 } from "./crypto.js";
2022-03-07 13:33:20 +11:00
export async function sign(
privKey: Uint8Array,
msg: Uint8Array
): Promise<Uint8Array> {
2022-05-20 10:54:48 +10:00
return secp.sign(keccak256(msg), privKey, {
2022-03-07 13:33:20 +11:00
der: false,
});
}
export function nodeId(pubKey: Uint8Array): NodeId {
2022-03-07 13:33:20 +11:00
const publicKey = secp.Point.fromHex(pubKey);
const uncompressedPubkey = publicKey.toRawBytes(false);
2022-05-20 11:27:57 +10:00
return bytesToHex(keccak256(uncompressedPubkey.slice(1)));
}