mirror of https://github.com/waku-org/js-waku.git
fix: peer id / keypair conversion
This commit is contained in:
parent
5d5e035edb
commit
a10d3ae7d3
|
@ -1,9 +1,5 @@
|
||||||
import {
|
import { unmarshalPrivateKey, unmarshalPublicKey } from "@libp2p/crypto/keys";
|
||||||
marshalPrivateKey,
|
import { supportedKeys } from "@libp2p/crypto/keys";
|
||||||
marshalPublicKey,
|
|
||||||
unmarshalPrivateKey,
|
|
||||||
unmarshalPublicKey,
|
|
||||||
} from "@libp2p/crypto/keys";
|
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import { peerIdFromKeys } from "@libp2p/peer-id";
|
import { peerIdFromKeys } from "@libp2p/peer-id";
|
||||||
|
|
||||||
|
@ -42,15 +38,15 @@ export async function createPeerIdFromKeypair(
|
||||||
): Promise<PeerId> {
|
): Promise<PeerId> {
|
||||||
switch (keypair.type) {
|
switch (keypair.type) {
|
||||||
case KeypairType.secp256k1: {
|
case KeypairType.secp256k1: {
|
||||||
// manually create a peer id to avoid expensive ops
|
const publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(
|
||||||
|
keypair.publicKey
|
||||||
|
);
|
||||||
|
|
||||||
const privateKey = keypair.hasPrivateKey()
|
const privateKey = keypair.hasPrivateKey()
|
||||||
? marshalPrivateKey({ bytes: keypair.privateKey })
|
? new supportedKeys.secp256k1.Secp256k1PrivateKey(keypair.privateKey)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return peerIdFromKeys(
|
return peerIdFromKeys(publicKey.bytes, privateKey?.bytes);
|
||||||
marshalPublicKey({ bytes: keypair.publicKey }),
|
|
||||||
privateKey
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
|
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
|
||||||
|
|
Loading…
Reference in New Issue