mirror of https://github.com/status-im/js-waku.git
Remove unused code
This commit is contained in:
parent
ee8ba791cc
commit
c6189170e0
|
@ -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", () => {
|
||||
|
|
|
@ -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<Uint8Array> {
|
||||
return sign(this.privateKey, msg);
|
||||
}
|
||||
|
||||
public verify(msg: Uint8Array, sig: Uint8Array): boolean {
|
||||
return verify(this.publicKey, msg, sig);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue