20 lines
502 B
TypeScript
Raw Normal View History

2022-01-05 01:42:34 +01:00
import { ec } from "elliptic";
import { utils } from "js-waku";
2022-01-05 01:42:34 +01:00
const EC = new ec("secp256k1");
const hexToBuf = utils.hexToBuf;
export { hexToBuf };
/**
* Return hex string with 0x prefix (commonly used for string format of a community id/public key.
*/
export function bufToHex(buf: Uint8Array): string {
return "0x" + utils.bufToHex(buf);
}
2022-01-05 01:42:34 +01:00
export function compressPublicKey(key: Uint8Array): string {
const PubKey = EC.keyFromPublic(key);
return "0x" + PubKey.getPublic(true, "hex");
}