@waku/enr 0.0.20-678635e.0 → 0.0.20
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/CHANGELOG.md +8 -0
- package/bundle/index.js +3969 -2076
- package/dist/.tsbuildinfo +1 -1
- package/dist/creator.js.map +1 -1
- package/dist/crypto.js.map +1 -1
- package/dist/decoder.js.map +1 -1
- package/dist/encoder.js.map +1 -1
- package/dist/enr.js.map +1 -1
- package/dist/get_multiaddr.js.map +1 -1
- package/dist/multiaddrs_codec.js.map +1 -1
- package/dist/peer_id.js.map +1 -1
- package/dist/raw_enr.js.map +1 -1
- package/dist/relay_shard_codec.js +13 -13
- package/dist/relay_shard_codec.js.map +1 -1
- package/package.json +91 -1
- package/src/relay_shard_codec.ts +13 -13
package/package.json
CHANGED
@@ -1 +1,91 @@
|
|
1
|
-
{
|
1
|
+
{
|
2
|
+
"name": "@waku/enr",
|
3
|
+
"version": "0.0.20",
|
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": "^3.0.2",
|
56
|
+
"@libp2p/peer-id": "^3.0.3",
|
57
|
+
"@multiformats/multiaddr": "^12.0.0",
|
58
|
+
"@noble/secp256k1": "^1.7.1",
|
59
|
+
"@waku/utils": "0.0.14",
|
60
|
+
"debug": "^4.3.4",
|
61
|
+
"js-sha3": "^0.9.2"
|
62
|
+
},
|
63
|
+
"devDependencies": {
|
64
|
+
"@libp2p/peer-id-factory": "^3.0.3",
|
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.1",
|
70
|
+
"@waku/build-utils": "*",
|
71
|
+
"@waku/interfaces": "0.0.21",
|
72
|
+
"chai": "^4.3.10",
|
73
|
+
"cspell": "^7.3.2",
|
74
|
+
"fast-check": "^3.14.0",
|
75
|
+
"mocha": "^10.2.0",
|
76
|
+
"npm-run-all": "^4.1.5",
|
77
|
+
"process": "^0.11.10",
|
78
|
+
"rollup": "^4.6.0",
|
79
|
+
"uint8arrays": "^4.0.4"
|
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/relay_shard_codec.ts
CHANGED
@@ -8,9 +8,9 @@ export const decodeRelayShard = (bytes: Uint8Array): ShardInfo => {
|
|
8
8
|
if (bytes.length < 3) throw new Error("Insufficient data");
|
9
9
|
|
10
10
|
const view = new DataView(bytes.buffer);
|
11
|
-
const
|
11
|
+
const clusterId = view.getUint16(0);
|
12
12
|
|
13
|
-
const
|
13
|
+
const shards = [];
|
14
14
|
|
15
15
|
if (bytes.length === 130) {
|
16
16
|
// rsv format (Bit Vector)
|
@@ -18,7 +18,7 @@ export const decodeRelayShard = (bytes: Uint8Array): ShardInfo => {
|
|
18
18
|
const byteIndex = Math.floor(i / 8) + 2; // Adjusted for the 2-byte cluster field
|
19
19
|
const bitIndex = 7 - (i % 8);
|
20
20
|
if (view.getUint8(byteIndex) & (1 << bitIndex)) {
|
21
|
-
|
21
|
+
shards.push(i);
|
22
22
|
}
|
23
23
|
}
|
24
24
|
} else {
|
@@ -26,33 +26,33 @@ export const decodeRelayShard = (bytes: Uint8Array): ShardInfo => {
|
|
26
26
|
const numIndices = view.getUint8(2);
|
27
27
|
for (let i = 0, offset = 3; i < numIndices; i++, offset += 2) {
|
28
28
|
if (offset + 1 >= bytes.length) throw new Error("Unexpected end of data");
|
29
|
-
|
29
|
+
shards.push(view.getUint16(offset));
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
-
return {
|
33
|
+
return { clusterId, shards };
|
34
34
|
};
|
35
35
|
|
36
36
|
export const encodeRelayShard = (shardInfo: ShardInfo): Uint8Array => {
|
37
|
-
const {
|
38
|
-
const totalLength =
|
37
|
+
const { clusterId, shards } = shardInfo;
|
38
|
+
const totalLength = shards.length >= 64 ? 130 : 3 + 2 * shards.length;
|
39
39
|
const buffer = new ArrayBuffer(totalLength);
|
40
40
|
const view = new DataView(buffer);
|
41
41
|
|
42
|
-
view.setUint16(0,
|
42
|
+
view.setUint16(0, clusterId);
|
43
43
|
|
44
|
-
if (
|
44
|
+
if (shards.length >= 64) {
|
45
45
|
// rsv format (Bit Vector)
|
46
|
-
for (const index of
|
46
|
+
for (const index of shards) {
|
47
47
|
const byteIndex = Math.floor(index / 8) + 2; // Adjusted for the 2-byte cluster field
|
48
48
|
const bitIndex = 7 - (index % 8);
|
49
49
|
view.setUint8(byteIndex, view.getUint8(byteIndex) | (1 << bitIndex));
|
50
50
|
}
|
51
51
|
} else {
|
52
52
|
// rs format (Index List)
|
53
|
-
view.setUint8(2,
|
54
|
-
for (let i = 0, offset = 3; i <
|
55
|
-
view.setUint16(offset,
|
53
|
+
view.setUint8(2, shards.length);
|
54
|
+
for (let i = 0, offset = 3; i < shards.length; i++, offset += 2) {
|
55
|
+
view.setUint16(offset, shards[i]);
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|