UNPKG

@waku/enr

Version:
25 lines 816 B
import { utf8ToBytes } from "@waku/utils/bytes"; import { compressPublicKey } from "./crypto.js"; import { ENR } from "./enr.js"; export class EnrCreator { static fromPublicKey(publicKey, kvs = {}) { // EIP-778 specifies that the key must be in compressed format, 33 bytes if (publicKey.length !== 33) { publicKey = compressPublicKey(publicKey); } return ENR.create({ ...kvs, id: utf8ToBytes("v4"), secp256k1: publicKey }); } static async fromPeerId(peerId, kvs = {}) { switch (peerId.type) { case "secp256k1": return EnrCreator.fromPublicKey(peerId.publicKey.raw, kvs); default: throw new Error(); } } } //# sourceMappingURL=creator.js.map