@waku/enr 0.0.27 → 0.0.28-9f1d8ca.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/package.json CHANGED
@@ -1,99 +1 @@
1
- {
2
- "name": "@waku/enr",
3
- "version": "0.0.27",
4
- "description": "ENR (EIP-778) for Waku",
5
- "types": "./dist/index.d.ts",
6
- "module": "./dist/index.js",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js"
11
- }
12
- },
13
- "type": "module",
14
- "author": "Waku Team",
15
- "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/enr#readme",
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/waku-org/js-waku.git"
19
- },
20
- "bugs": {
21
- "url": "https://github.com/waku-org/js-waku/issues"
22
- },
23
- "license": "MIT OR Apache-2.0",
24
- "keywords": [
25
- "waku",
26
- "decentralized",
27
- "secure",
28
- "communication",
29
- "web3",
30
- "ethereum",
31
- "dapps",
32
- "privacy"
33
- ],
34
- "scripts": {
35
- "build": "run-s build:**",
36
- "build:esm": "tsc",
37
- "build:bundle": "rollup --config rollup.config.js",
38
- "fix": "run-s fix:*",
39
- "fix:lint": "eslint src *.js --fix",
40
- "check": "run-s check:*",
41
- "check:lint": "eslint src --ext .ts",
42
- "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
43
- "check:tsc": "tsc -p tsconfig.dev.json",
44
- "test": "NODE_ENV=test run-s test:*",
45
- "test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
46
- "test:browser": "NODE_ENV=test karma start karma.conf.cjs",
47
- "prepublish": "npm run build",
48
- "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
49
- },
50
- "engines": {
51
- "node": ">=20"
52
- },
53
- "dependencies": {
54
- "@ethersproject/rlp": "^5.7.0",
55
- "@libp2p/crypto": "^4.1.6",
56
- "@libp2p/peer-id": "^4.2.1",
57
- "@multiformats/multiaddr": "^12.0.0",
58
- "@noble/secp256k1": "^1.7.1",
59
- "@waku/utils": "0.0.21",
60
- "debug": "^4.3.4",
61
- "js-sha3": "^0.9.2"
62
- },
63
- "devDependencies": {
64
- "@libp2p/peer-id-factory": "^4.2.1",
65
- "@rollup/plugin-commonjs": "^25.0.7",
66
- "@rollup/plugin-json": "^6.0.0",
67
- "@rollup/plugin-node-resolve": "^15.2.3",
68
- "@types/chai": "^4.3.11",
69
- "@types/mocha": "^10.0.6",
70
- "@waku/build-utils": "*",
71
- "@waku/interfaces": "0.0.28",
72
- "chai": "^4.3.10",
73
- "cspell": "^8.6.1",
74
- "fast-check": "^3.19.0",
75
- "mocha": "^10.3.0",
76
- "npm-run-all": "^4.1.5",
77
- "process": "^0.11.10",
78
- "rollup": "^4.12.0",
79
- "uint8arrays": "^5.0.1"
80
- },
81
- "peerDependencies": {
82
- "@multiformats/multiaddr": "^12.0.0"
83
- },
84
- "peerDependenciesMeta": {
85
- "@multiformats/multiaddr": {
86
- "optional": true
87
- }
88
- },
89
- "files": [
90
- "dist",
91
- "bundle",
92
- "src/**/*.ts",
93
- "!**/*.spec.*",
94
- "!**/*.json",
95
- "CHANGELOG.md",
96
- "LICENSE",
97
- "README.md"
98
- ]
99
- }
1
+ {"name":"@waku/enr","version":"0.0.28-9f1d8ca.0","description":"ENR (EIP-778) for Waku","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/enr#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:lint":"eslint src --ext .ts","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=20"},"dependencies":{"@ethersproject/rlp":"^5.7.0","@libp2p/crypto":"^5.0.1","@libp2p/peer-id":"^5.0.1","@multiformats/multiaddr":"^12.0.0","@noble/secp256k1":"^1.7.1","@waku/utils":"0.0.22-9f1d8ca.0","debug":"^4.3.4","js-sha3":"^0.9.2"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/mocha":"^10.0.6","@waku/build-utils":"*","@waku/interfaces":"0.0.29-9f1d8ca.0","chai":"^4.3.10","cspell":"^8.6.1","fast-check":"^3.19.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0","uint8arrays":"^5.0.1"},"peerDependencies":{"@multiformats/multiaddr":"^12.0.0"},"peerDependenciesMeta":{"@multiformats/multiaddr":{"optional":true}},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
package/src/creator.ts CHANGED
@@ -4,13 +4,12 @@ import { utf8ToBytes } from "@waku/utils/bytes";
4
4
 
5
5
  import { compressPublicKey } from "./crypto.js";
6
6
  import { ENR } from "./enr.js";
7
- import { getPublicKeyFromPeerId } from "./peer_id.js";
8
7
 
9
8
  export class EnrCreator {
10
9
  public static fromPublicKey(
11
10
  publicKey: Uint8Array,
12
11
  kvs: Record<ENRKey, ENRValue> = {}
13
- ): Promise<ENR> {
12
+ ): ENR {
14
13
  // EIP-778 specifies that the key must be in compressed format, 33 bytes
15
14
  if (publicKey.length !== 33) {
16
15
  publicKey = compressPublicKey(publicKey);
@@ -28,7 +27,7 @@ export class EnrCreator {
28
27
  ): Promise<ENR> {
29
28
  switch (peerId.type) {
30
29
  case "secp256k1":
31
- return EnrCreator.fromPublicKey(getPublicKeyFromPeerId(peerId), kvs);
30
+ return EnrCreator.fromPublicKey(peerId.publicKey.raw, kvs);
32
31
  default:
33
32
  throw new Error();
34
33
  }
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
  }