2022-03-07 13:33:20 +11:00
|
|
|
import * as secp from "@noble/secp256k1";
|
2022-12-13 12:31:27 +11:00
|
|
|
import type { NodeId } from "@waku/interfaces";
|
2023-03-14 10:10:38 +05:30
|
|
|
import { bytesToHex } from "@waku/utils/bytes";
|
2021-10-26 16:58:26 +11:00
|
|
|
|
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,
|
|
|
|
|
});
|
2021-10-26 16:58:26 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2021-10-26 16:58:26 +11:00
|
|
|
|
2022-05-20 11:27:57 +10:00
|
|
|
return bytesToHex(keccak256(uncompressedPubkey.slice(1)));
|
2021-10-26 16:58:26 +11:00
|
|
|
}
|