mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-07 16:23:09 +00:00
* chore: update noise * update: package.lock * update: @chainsafe/libp2p-gossipsub * rm unwanted libp2p interface deps & bump up libp2p * refactor code for new deps * update: new package.lock * setup prettier, refactor eslint and rm trailing commas * update package.lock * fix build * import type for interface * fix imports for merge * update typedoc exports * add: CustomEvent import * use new libp2p interface * add aegir as dev dep for tests
21 lines
567 B
TypeScript
21 lines
567 B
TypeScript
import * as secp from "@noble/secp256k1";
|
|
import type { NodeId } from "@waku/interfaces";
|
|
import { bytesToHex } from "@waku/utils/bytes";
|
|
|
|
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)));
|
|
}
|