chore: remove unnecessary functions

This commit is contained in:
fryorcraken.eth 2023-03-03 12:51:56 +11:00
parent 4eacc39a9d
commit 05b122e646
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 9 additions and 23 deletions

View File

@ -27,7 +27,7 @@ import { compressPublicKey, keccak256, verifySignature } from "./crypto.js";
import { import {
createKeypair, createKeypair,
createKeypairFromPeerId, createKeypairFromPeerId,
createPeerIdFromKeypair, createPeerIdFromPublicKey,
IKeypair, IKeypair,
KeypairType, KeypairType,
} from "./keypair/index.js"; } from "./keypair/index.js";
@ -63,8 +63,7 @@ export class ENR extends Map<ENRKey, ENRValue> implements IEnr {
try { try {
const publicKey = enr.publicKey; const publicKey = enr.publicKey;
if (publicKey) { if (publicKey) {
const keypair = createKeypair(enr.keypairType, undefined, publicKey); enr.peerId = await createPeerIdFromPublicKey(publicKey);
enr.peerId = await createPeerIdFromKeypair(keypair);
} }
} catch (e) { } catch (e) {
log("Could not calculate peer id for ENR", e); log("Could not calculate peer id for ENR", e);

View File

@ -10,6 +10,13 @@ export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
export * from "./types.js"; export * from "./types.js";
export * from "./secp256k1.js"; export * from "./secp256k1.js";
export function createPeerIdFromPublicKey(
publicKey: Uint8Array
): Promise<PeerId> {
const _publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(publicKey);
return peerIdFromKeys(_publicKey.bytes, undefined);
}
export function createKeypair( export function createKeypair(
type: KeypairType, type: KeypairType,
privateKey?: Uint8Array, privateKey?: Uint8Array,
@ -23,26 +30,6 @@ export function createKeypair(
} }
} }
export async function createPeerIdFromKeypair(
keypair: IKeypair
): Promise<PeerId> {
switch (keypair.type) {
case KeypairType.secp256k1: {
const publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(
keypair.publicKey
);
const privateKey = keypair.hasPrivateKey()
? new supportedKeys.secp256k1.Secp256k1PrivateKey(keypair.privateKey)
: undefined;
return peerIdFromKeys(publicKey.bytes, privateKey?.bytes);
}
default:
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
}
}
export async function createKeypairFromPeerId( export async function createKeypairFromPeerId(
peerId: PeerId peerId: PeerId
): Promise<IKeypair> { ): Promise<IKeypair> {