From c6189170e04e9ad066a105692e61eda3e200bca1 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 20 May 2022 11:05:44 +1000 Subject: [PATCH] Remove unused code --- src/lib/enr/enr.spec.ts | 7 +++---- src/lib/enr/v4.ts | 39 +-------------------------------------- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/src/lib/enr/enr.spec.ts b/src/lib/enr/enr.spec.ts index 0b4738a338..c4ec51b474 100644 --- a/src/lib/enr/enr.spec.ts +++ b/src/lib/enr/enr.spec.ts @@ -2,6 +2,7 @@ import { assert, expect } from "chai"; import { Multiaddr } from "multiaddr"; import PeerId from "peer-id"; +import { getPublicKey } from "../crypto"; import { bytesToHex, hexToBytes, utf8ToBytes } from "../utils"; import { ERR_INVALID_ID } from "./constants"; @@ -9,8 +10,6 @@ import { ENR } from "./enr"; import { createKeypairFromPeerId, IKeypair } from "./keypair"; import { Waku2 } from "./waku2_codec"; -import { v4 } from "./index"; - describe("ENR", function () { describe("Txt codec", () => { it("should encodeTxt and decodeTxt", async () => { @@ -199,7 +198,7 @@ describe("ENR", function () { privateKey = hexToBytes( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ); - record = await ENR.createV4(v4.publicKey(privateKey)); + record = await ENR.createV4(getPublicKey(privateKey)); record.setLocationMultiaddr(new Multiaddr("/ip4/127.0.0.1/udp/30303")); record.seq = seq; await record.encodeTxt(privateKey); @@ -240,7 +239,7 @@ describe("ENR", function () { privateKey = hexToBytes( "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ); - record = await ENR.createV4(v4.publicKey(privateKey)); + record = await ENR.createV4(getPublicKey(privateKey)); }); it("should get / set UDP multiaddr", () => { diff --git a/src/lib/enr/v4.ts b/src/lib/enr/v4.ts index 4fd640df0d..f711361f9c 100644 --- a/src/lib/enr/v4.ts +++ b/src/lib/enr/v4.ts @@ -1,19 +1,11 @@ import * as secp from "@noble/secp256k1"; -import { keccak256, randomBytes } from "../crypto"; +import { keccak256 } from "../crypto"; import { bytesToHex } from "../utils"; import { createNodeId } from "./create"; import { NodeId } from "./types"; -export function createPrivateKey(): Uint8Array { - return randomBytes(32); -} - -export function publicKey(privKey: Uint8Array): Uint8Array { - return secp.getPublicKey(privKey, true); -} - export function compressPublicKey(publicKey: Uint8Array): Uint8Array { const point = secp.Point.fromHex(bytesToHex(publicKey)); return point.toRawBytes(true); @@ -47,32 +39,3 @@ export function nodeId(pubKey: Uint8Array): NodeId { return createNodeId(keccak256(uncompressedPubkey.slice(1))); } - -export class ENRKeyPair { - public constructor( - public readonly nodeId: NodeId, - public readonly privateKey: Uint8Array, - public readonly publicKey: Uint8Array - ) {} - - public static create(privateKey?: Uint8Array): ENRKeyPair { - if (privateKey) { - if (!secp.utils.isValidPrivateKey(privateKey)) { - throw new Error("Invalid private key"); - } - } - const _privateKey = privateKey || createPrivateKey(); - const _publicKey = publicKey(_privateKey); - const _nodeId = nodeId(_publicKey); - - return new ENRKeyPair(_nodeId, _privateKey, _publicKey); - } - - public async sign(msg: Uint8Array): Promise { - return sign(this.privateKey, msg); - } - - public verify(msg: Uint8Array, sig: Uint8Array): boolean { - return verify(this.publicKey, msg, sig); - } -}