mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-19 16:33:15 +00:00
22 lines
563 B
TypeScript
22 lines
563 B
TypeScript
import * as secp from "@noble/secp256k1";
|
|
import type { NodeId } from "@waku/interfaces";
|
|
import { bytesToHex } from "@waku/utils";
|
|
|
|
import { keccak256 } from "./crypto.js";
|
|
|
|
export async function sign(
|
|
privKey: Uint8Array,
|
|
msg: Uint8Array
|
|
): Promise<Uint8Array> {
|
|
return secp.sign(keccak256(msg), privKey, {
|
|
der: false,
|
|
});
|
|
}
|
|
|
|
export function nodeId(pubKey: Uint8Array): NodeId {
|
|
const publicKey = secp.Point.fromHex(pubKey);
|
|
const uncompressedPubkey = publicKey.toRawBytes(false);
|
|
|
|
return bytesToHex(keccak256(uncompressedPubkey.slice(1)));
|
|
}
|