@waku/enr 0.0.27-f599932.0 → 0.0.28-b6339f7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/decoder.ts CHANGED
@@ -37,7 +37,7 @@ async function fromValues(values: Uint8Array[]): Promise<ENR> {
37
37
  }
38
38
  const _seq = decodeSeq(seq);
39
39
 
40
- const enr = await ENR.create(obj, _seq, signature);
40
+ const enr = ENR.create(obj, _seq, signature);
41
41
  checkSignature(seq, kvs, enr, signature);
42
42
  return enr;
43
43
  }
package/src/enr.ts CHANGED
@@ -34,16 +34,16 @@ export class ENR extends RawEnr implements IEnr {
34
34
  public static readonly RECORD_PREFIX = "enr:";
35
35
  public peerId?: PeerId;
36
36
 
37
- public static async create(
37
+ public static create(
38
38
  kvs: Record<ENRKey, ENRValue> = {},
39
39
  seq: SequenceNumber = BigInt(1),
40
40
  signature?: Uint8Array
41
- ): Promise<ENR> {
41
+ ): ENR {
42
42
  const enr = new ENR(kvs, seq, signature);
43
43
  try {
44
44
  const publicKey = enr.publicKey;
45
45
  if (publicKey) {
46
- enr.peerId = await createPeerIdFromPublicKey(publicKey);
46
+ enr.peerId = createPeerIdFromPublicKey(publicKey);
47
47
  }
48
48
  } catch (e) {
49
49
  log.error("Could not calculate peer id for ENR", e);
package/src/peer_id.ts CHANGED
@@ -1,38 +1,13 @@
1
- import { unmarshalPrivateKey, unmarshalPublicKey } from "@libp2p/crypto/keys";
2
- import { supportedKeys } from "@libp2p/crypto/keys";
3
- import type { PeerId } from "@libp2p/interface";
4
- import { peerIdFromKeys } from "@libp2p/peer-id";
1
+ import { publicKeyFromRaw } from "@libp2p/crypto/keys";
2
+ import { type PeerId } from "@libp2p/interface";
3
+ import { peerIdFromPublicKey } from "@libp2p/peer-id";
5
4
 
6
- export function createPeerIdFromPublicKey(
7
- publicKey: Uint8Array
8
- ): Promise<PeerId> {
9
- const _publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(publicKey);
10
- return peerIdFromKeys(_publicKey.bytes, undefined);
11
- }
12
-
13
- export function getPublicKeyFromPeerId(peerId: PeerId): Uint8Array {
14
- if (peerId.type !== "secp256k1") {
15
- throw new Error("Unsupported peer id type");
16
- }
5
+ export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
17
6
 
18
- if (!peerId.publicKey) {
19
- throw new Error("Public key not present on peer id");
7
+ export function createPeerIdFromPublicKey(publicKey: Uint8Array): PeerId {
8
+ const pubKey = publicKeyFromRaw(publicKey);
9
+ if (pubKey.type !== "secp256k1") {
10
+ throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
20
11
  }
21
-
22
- return unmarshalPublicKey(peerId.publicKey).marshal();
23
- }
24
-
25
- // Only used in tests
26
- export async function getPrivateKeyFromPeerId(
27
- peerId: PeerId
28
- ): Promise<Uint8Array> {
29
- if (peerId.type !== "secp256k1") {
30
- throw new Error("Unsupported peer id type");
31
- }
32
- if (!peerId.privateKey) {
33
- throw new Error("Private key not present on peer id");
34
- }
35
-
36
- const privateKey = await unmarshalPrivateKey(peerId.privateKey);
37
- return privateKey.marshal();
12
+ return peerIdFromPublicKey(pubKey);
38
13
  }