@waku/enr 0.0.20 → 0.0.22-070b625.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/CHANGELOG.md +25 -0
- package/bundle/index.js +6267 -19864
- package/dist/.tsbuildinfo +1 -1
- package/dist/creator.d.ts +1 -1
- package/dist/enr.d.ts +1 -2
- package/dist/enr.js +7 -3
- package/dist/enr.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/peer_id.d.ts +1 -1
- package/dist/raw_enr.js +1 -1
- package/dist/raw_enr.js.map +1 -1
- package/package.json +1 -91
- package/src/creator.ts +1 -1
- package/src/enr.ts +8 -5
- package/src/index.ts +0 -1
- package/src/peer_id.ts +1 -1
- package/src/raw_enr.ts +1 -1
- package/dist/relay_shard_codec.d.ts +0 -3
- package/dist/relay_shard_codec.js +0 -54
- package/dist/relay_shard_codec.js.map +0 -1
- package/src/relay_shard_codec.ts +0 -60
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
|
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,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 clusterId = view.getUint16(0);
|
9
|
-
const shards = [];
|
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
|
-
shards.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
|
-
shards.push(view.getUint16(offset));
|
27
|
-
}
|
28
|
-
}
|
29
|
-
return { clusterId, shards };
|
30
|
-
};
|
31
|
-
export const encodeRelayShard = (shardInfo) => {
|
32
|
-
const { clusterId, shards } = shardInfo;
|
33
|
-
const totalLength = shards.length >= 64 ? 130 : 3 + 2 * shards.length;
|
34
|
-
const buffer = new ArrayBuffer(totalLength);
|
35
|
-
const view = new DataView(buffer);
|
36
|
-
view.setUint16(0, clusterId);
|
37
|
-
if (shards.length >= 64) {
|
38
|
-
// rsv format (Bit Vector)
|
39
|
-
for (const index of shards) {
|
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, shards.length);
|
48
|
-
for (let i = 0, offset = 3; i < shards.length; i++, offset += 2) {
|
49
|
-
view.setUint16(offset, shards[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,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAEpC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACzB,0BAA0B;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,wCAAwC;YACjF,MAAM,QAAQ,GAAG,CAAC,GAAG,CAA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xB,0BAA0B;QAC1B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,wCAAwC;YACrF,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,yBAAyB;QACzB,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;YAChE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
package/src/relay_shard_codec.ts
DELETED
@@ -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 clusterId = view.getUint16(0);
|
12
|
-
|
13
|
-
const shards = [];
|
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
|
-
shards.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
|
-
shards.push(view.getUint16(offset));
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
return { clusterId, shards };
|
34
|
-
};
|
35
|
-
|
36
|
-
export const encodeRelayShard = (shardInfo: ShardInfo): Uint8Array => {
|
37
|
-
const { clusterId, shards } = shardInfo;
|
38
|
-
const totalLength = shards.length >= 64 ? 130 : 3 + 2 * shards.length;
|
39
|
-
const buffer = new ArrayBuffer(totalLength);
|
40
|
-
const view = new DataView(buffer);
|
41
|
-
|
42
|
-
view.setUint16(0, clusterId);
|
43
|
-
|
44
|
-
if (shards.length >= 64) {
|
45
|
-
// rsv format (Bit Vector)
|
46
|
-
for (const index of shards) {
|
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, shards.length);
|
54
|
-
for (let i = 0, offset = 3; i < shards.length; i++, offset += 2) {
|
55
|
-
view.setUint16(offset, shards[i]);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
return new Uint8Array(buffer);
|
60
|
-
};
|