Danish Arora 7c0ce7b2ec
chore: upgrade to libp2p v2 (#2143)
* chore: upgrade libp2p to v2 and related deps

* chore: fix ENR

* chore(core): remove CustomEvent polyfill import

* chore: `peer-id-factory` has been removed

* chore(discovery): fix local-cache & remove CustomEvent imports

* chore(sdk): update config

* chore(tests): update tests without peer-id-factory

* fix: spec tests

* chore: fix test

* chore: upgrade dataset-core

* chore: upgrade libp2p and stale references

* chore: upgrade playwright

* chore: rm console log

* fix: lock
2024-10-21 16:43:24 +05:30

14 lines
483 B
TypeScript

import { publicKeyFromRaw } from "@libp2p/crypto/keys";
import { type PeerId } from "@libp2p/interface";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
export function createPeerIdFromPublicKey(publicKey: Uint8Array): PeerId {
const pubKey = publicKeyFromRaw(publicKey);
if (pubKey.type !== "secp256k1") {
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
}
return peerIdFromPublicKey(pubKey);
}