@waku/enr 0.0.20-7eb3375.0 → 0.0.21

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 +1,91 @@
1
- {"name":"@waku/enr","version":"0.0.20-7eb3375.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":"run-s test:*","test:node":"TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"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":">=18"},"dependencies":{"@ethersproject/rlp":"^5.7.0","@libp2p/crypto":"^2.0.8","@libp2p/peer-id":"^3.0.3","@multiformats/multiaddr":"^12.0.0","@noble/secp256k1":"^1.7.1","@waku/utils":"0.0.14-7eb3375.0","debug":"^4.3.4","js-sha3":"^0.9.2"},"devDependencies":{"@libp2p/peer-id-factory":"^3.0.3","@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.1","@waku/build-utils":"*","@waku/interfaces":"0.0.21-7eb3375.0","chai":"^4.3.10","cspell":"^7.3.2","fast-check":"^3.13.1","mocha":"^10.2.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^3.29.2","uint8arrays":"^4.0.4"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
1
+ {
2
+ "name": "@waku/enr",
3
+ "version": "0.0.21",
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": ">=18"
52
+ },
53
+ "dependencies": {
54
+ "@ethersproject/rlp": "^5.7.0",
55
+ "@libp2p/crypto": "^4.0.0",
56
+ "@libp2p/peer-id": "^4.0.4",
57
+ "@multiformats/multiaddr": "^12.0.0",
58
+ "@noble/secp256k1": "^1.7.1",
59
+ "@waku/utils": "0.0.15",
60
+ "debug": "^4.3.4",
61
+ "js-sha3": "^0.9.2"
62
+ },
63
+ "devDependencies": {
64
+ "@libp2p/peer-id-factory": "^4.0.5",
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.22",
72
+ "chai": "^4.3.10",
73
+ "cspell": "^8.3.2",
74
+ "fast-check": "^3.15.1",
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
+ "files": [
82
+ "dist",
83
+ "bundle",
84
+ "src/**/*.ts",
85
+ "!**/*.spec.*",
86
+ "!**/*.json",
87
+ "CHANGELOG.md",
88
+ "LICENSE",
89
+ "README.md"
90
+ ]
91
+ }
package/src/creator.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { PeerId } from "@libp2p/interface/peer-id";
1
+ import type { PeerId } from "@libp2p/interface";
2
2
  import type { ENRKey, ENRValue } from "@waku/interfaces";
3
3
  import { utf8ToBytes } from "@waku/utils/bytes";
4
4
 
package/src/enr.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { PeerId } from "@libp2p/interface/peer-id";
2
- import type { PeerInfo } from "@libp2p/interface/peer-info";
1
+ import type { PeerId, PeerInfo } from "@libp2p/interface";
3
2
  import type { Multiaddr } from "@multiformats/multiaddr";
4
3
  import type {
5
4
  ENRKey,
@@ -108,7 +107,12 @@ export class ENR extends RawEnr implements IEnr {
108
107
 
109
108
  const _multiaddrs = this.multiaddrs ?? [];
110
109
 
111
- return multiaddrs.concat(_multiaddrs);
110
+ return multiaddrs.concat(_multiaddrs).map((ma) => {
111
+ if (this.peerId) {
112
+ return ma.encapsulate(`/p2p/${this.peerId.toString()}`);
113
+ }
114
+ return ma;
115
+ });
112
116
  }
113
117
 
114
118
  get peerInfo(): PeerInfo | undefined {
@@ -116,8 +120,7 @@ export class ENR extends RawEnr implements IEnr {
116
120
  if (!id) return;
117
121
  return {
118
122
  id,
119
- multiaddrs: this.getAllLocationMultiaddrs(),
120
- protocols: []
123
+ multiaddrs: this.getAllLocationMultiaddrs()
121
124
  };
122
125
  }
123
126
 
package/src/index.ts CHANGED
@@ -5,4 +5,3 @@ export * from "./enr.js";
5
5
  export * from "./peer_id.js";
6
6
  export * from "./waku2_codec.js";
7
7
  export * from "./crypto.js";
8
- export * from "./relay_shard_codec.js";
package/src/peer_id.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { unmarshalPrivateKey, unmarshalPublicKey } from "@libp2p/crypto/keys";
2
2
  import { supportedKeys } from "@libp2p/crypto/keys";
3
- import type { PeerId } from "@libp2p/interface/peer-id";
3
+ import type { PeerId } from "@libp2p/interface";
4
4
  import { peerIdFromKeys } from "@libp2p/peer-id";
5
5
 
6
6
  export function createPeerIdFromPublicKey(
package/src/raw_enr.ts CHANGED
@@ -10,11 +10,11 @@ import type {
10
10
  ShardInfo,
11
11
  Waku2
12
12
  } from "@waku/interfaces";
13
+ import { decodeRelayShard } from "@waku/utils";
13
14
  import { bytesToUtf8 } from "@waku/utils/bytes";
14
15
 
15
16
  import { ERR_INVALID_ID } from "./constants.js";
16
17
  import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec.js";
17
- import { decodeRelayShard } from "./relay_shard_codec.js";
18
18
  import { decodeWaku2, encodeWaku2 } from "./waku2_codec.js";
19
19
 
20
20
  export class RawEnr extends Map<ENRKey, ENRValue> {
@@ -1,3 +0,0 @@
1
- import type { ShardInfo } from "@waku/interfaces";
2
- export declare const decodeRelayShard: (bytes: Uint8Array) => ShardInfo;
3
- export declare const encodeRelayShard: (shardInfo: ShardInfo) => Uint8Array;
@@ -1,54 +0,0 @@
1
- export const decodeRelayShard = (bytes) => {
2
- // explicitly converting to Uint8Array to avoid Buffer
3
- // https://github.com/libp2p/js-libp2p/issues/2146
4
- bytes = new Uint8Array(bytes);
5
- if (bytes.length < 3)
6
- throw new Error("Insufficient data");
7
- const view = new DataView(bytes.buffer);
8
- const cluster = view.getUint16(0);
9
- const indexList = [];
10
- if (bytes.length === 130) {
11
- // rsv format (Bit Vector)
12
- for (let i = 0; i < 1024; i++) {
13
- const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
14
- const bitIndex = 7 - (i % 8);
15
- if (view.getUint8(byteIndex) & (1 << bitIndex)) {
16
- indexList.push(i);
17
- }
18
- }
19
- }
20
- else {
21
- // rs format (Index List)
22
- const numIndices = view.getUint8(2);
23
- for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
24
- if (offset + 1 >= bytes.length)
25
- throw new Error("Unexpected end of data");
26
- indexList.push(view.getUint16(offset));
27
- }
28
- }
29
- return { cluster, indexList };
30
- };
31
- export const encodeRelayShard = (shardInfo) => {
32
- const { cluster, indexList } = shardInfo;
33
- const totalLength = indexList.length >= 64 ? 130 : 3 + 2 * indexList.length;
34
- const buffer = new ArrayBuffer(totalLength);
35
- const view = new DataView(buffer);
36
- view.setUint16(0, cluster);
37
- if (indexList.length >= 64) {
38
- // rsv format (Bit Vector)
39
- for (const index of indexList) {
40
- const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
41
- const bitIndex = 7 - (index % 8);
42
- view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
43
- }
44
- }
45
- else {
46
- // rs format (Index List)
47
- view.setUint8(2, indexList.length);
48
- for (let i = 0, offset = 3; i < indexList.length; i++, offset += 2) {
49
- view.setUint16(offset, indexList[i]);
50
- }
51
- }
52
- return new Uint8Array(buffer);
53
- };
54
- //# sourceMappingURL=relay_shard_codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relay_shard_codec.js","sourceRoot":"","sources":["../src/relay_shard_codec.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAiB,EAAa,EAAE;IAC/D,sDAAsD;IACtD,kDAAkD;IAClD,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAE9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAE3D,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAElC,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE;QACxB,0BAA0B;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;YAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,wCAAwC;YACjF,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,EAAE;gBAC9C,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACnB;SACF;KACF;SAAM;QACL,yBAAyB;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAA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CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,EAAE;YAClE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SACtC;KACF;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC"}
@@ -1,60 +0,0 @@
1
- import type { ShardInfo } from "@waku/interfaces";
2
-
3
- export const decodeRelayShard = (bytes: Uint8Array): ShardInfo => {
4
- // explicitly converting to Uint8Array to avoid Buffer
5
- // https://github.com/libp2p/js-libp2p/issues/2146
6
- bytes = new Uint8Array(bytes);
7
-
8
- if (bytes.length < 3) throw new Error("Insufficient data");
9
-
10
- const view = new DataView(bytes.buffer);
11
- const cluster = view.getUint16(0);
12
-
13
- const indexList = [];
14
-
15
- if (bytes.length === 130) {
16
- // rsv format (Bit Vector)
17
- for (let i = 0; i < 1024; i++) {
18
- const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
19
- const bitIndex = 7 - (i % 8);
20
- if (view.getUint8(byteIndex) & (1 << bitIndex)) {
21
- indexList.push(i);
22
- }
23
- }
24
- } else {
25
- // rs format (Index List)
26
- const numIndices = view.getUint8(2);
27
- for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
28
- if (offset + 1 >= bytes.length) throw new Error("Unexpected end of data");
29
- indexList.push(view.getUint16(offset));
30
- }
31
- }
32
-
33
- return { cluster, indexList };
34
- };
35
-
36
- export const encodeRelayShard = (shardInfo: ShardInfo): Uint8Array => {
37
- const { cluster, indexList } = shardInfo;
38
- const totalLength = indexList.length >= 64 ? 130 : 3 + 2 * indexList.length;
39
- const buffer = new ArrayBuffer(totalLength);
40
- const view = new DataView(buffer);
41
-
42
- view.setUint16(0, cluster);
43
-
44
- if (indexList.length >= 64) {
45
- // rsv format (Bit Vector)
46
- for (const index of indexList) {
47
- const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
48
- const bitIndex = 7 - (index % 8);
49
- view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
50
- }
51
- } else {
52
- // rs format (Index List)
53
- view.setUint8(2, indexList.length);
54
- for (let i = 0, offset = 3; i < indexList.length; i++, offset += 2) {
55
- view.setUint16(offset, indexList[i]);
56
- }
57
- }
58
-
59
- return new Uint8Array(buffer);
60
- };