UNPKG

@w3bstream/w3bstream-http-client-simulator

Version:

[![npm](https://img.shields.io/npm/v/@w3bstream/w3bstream-http-client-simulator)](https://www.npmjs.com/package/@w3bstream/w3bstream-http-client-simulator)

23 lines (22 loc) 641 B
import crypto from "crypto"; import { Keccak } from "sha3"; const curveName = "prime256v1"; const ecdh = crypto.createECDH(curveName); export class SimulatorKeys { static generateKeys() { ecdh.generateKeys(); return { publicKey: ecdh.getPublicKey("hex"), privateKey: ecdh.getPrivateKey("hex"), }; } static derivePublicKey(privateKey) { ecdh.setPrivateKey(privateKey, "hex"); return ecdh.getPublicKey("hex"); } static hashPublicKey(publicKey) { const hash = new Keccak(256); hash.update(publicKey); return hash.digest("hex"); } }