mirror of https://github.com/waku-org/js-waku.git
chore: remove unnecessary functions
This commit is contained in:
parent
4eacc39a9d
commit
05b122e646
|
@ -27,7 +27,7 @@ import { compressPublicKey, keccak256, verifySignature } from "./crypto.js";
|
|||
import {
|
||||
createKeypair,
|
||||
createKeypairFromPeerId,
|
||||
createPeerIdFromKeypair,
|
||||
createPeerIdFromPublicKey,
|
||||
IKeypair,
|
||||
KeypairType,
|
||||
} from "./keypair/index.js";
|
||||
|
@ -63,8 +63,7 @@ export class ENR extends Map<ENRKey, ENRValue> implements IEnr {
|
|||
try {
|
||||
const publicKey = enr.publicKey;
|
||||
if (publicKey) {
|
||||
const keypair = createKeypair(enr.keypairType, undefined, publicKey);
|
||||
enr.peerId = await createPeerIdFromKeypair(keypair);
|
||||
enr.peerId = await createPeerIdFromPublicKey(publicKey);
|
||||
}
|
||||
} catch (e) {
|
||||
log("Could not calculate peer id for ENR", e);
|
||||
|
|
|
@ -10,6 +10,13 @@ export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
|
|||
export * from "./types.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(
|
||||
type: KeypairType,
|
||||
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(
|
||||
peerId: PeerId
|
||||
): Promise<IKeypair> {
|
||||
|
|
Loading…
Reference in New Issue