@waku/core 0.0.26-7eb3375.0 → 0.0.26

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/bundle/{base_protocol-46017f51.js → base_protocol-pDODy0G6.js} +22 -230
  3. package/bundle/{browser-9a6558bb.js → browser-mTOOnVZp.js} +80 -1
  4. package/bundle/index-cmONXM-V.js +595 -0
  5. package/bundle/index.js +358 -425
  6. package/bundle/lib/base_protocol.js +3 -3
  7. package/bundle/lib/message/version_0.js +3 -3
  8. package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
  9. package/bundle/{version_0-7190df43.js → version_0-LQTFNC7k.js} +118 -11
  10. package/dist/.tsbuildinfo +1 -1
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +2 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/base_protocol.d.ts +3 -2
  15. package/dist/lib/base_protocol.js +12 -6
  16. package/dist/lib/base_protocol.js.map +1 -1
  17. package/dist/lib/connection_manager.js.map +1 -1
  18. package/dist/lib/filter/index.js +7 -4
  19. package/dist/lib/filter/index.js.map +1 -1
  20. package/dist/lib/filterPeers.js.map +1 -1
  21. package/dist/lib/keep_alive_manager.js +2 -2
  22. package/dist/lib/keep_alive_manager.js.map +1 -1
  23. package/dist/lib/light_push/index.js +1 -2
  24. package/dist/lib/light_push/index.js.map +1 -1
  25. package/dist/lib/message/version_0.d.ts +3 -3
  26. package/dist/lib/message/version_0.js +5 -6
  27. package/dist/lib/message/version_0.js.map +1 -1
  28. package/dist/lib/metadata/index.d.ts +3 -0
  29. package/dist/lib/metadata/index.js +67 -0
  30. package/dist/lib/metadata/index.js.map +1 -0
  31. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  32. package/dist/lib/store/history_rpc.js.map +1 -1
  33. package/dist/lib/store/index.js +1 -2
  34. package/dist/lib/store/index.js.map +1 -1
  35. package/dist/lib/stream_manager.js.map +1 -1
  36. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  37. package/dist/lib/waku.d.ts +3 -3
  38. package/dist/lib/waku.js +12 -6
  39. package/dist/lib/waku.js.map +1 -1
  40. package/package.json +127 -1
  41. package/src/index.ts +3 -1
  42. package/src/lib/base_protocol.ts +29 -7
  43. package/src/lib/filter/index.ts +10 -3
  44. package/src/lib/keep_alive_manager.ts +2 -2
  45. package/src/lib/light_push/index.ts +1 -2
  46. package/src/lib/message/version_0.ts +16 -8
  47. package/src/lib/metadata/index.ts +110 -0
  48. package/src/lib/store/index.ts +1 -2
  49. package/src/lib/waku.ts +14 -4
  50. package/bundle/index-7581d519.js +0 -31
  51. package/dist/lib/constants.d.ts +0 -4
  52. package/dist/lib/constants.js +0 -5
  53. package/dist/lib/constants.js.map +0 -1
  54. package/src/lib/constants.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
5
5
  The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.26](https://github.com/waku-org/js-waku/compare/core-v0.0.25...core-v0.0.26) (2024-01-10)
9
+
10
+
11
+ ### ⚠ BREAKING CHANGES
12
+
13
+ * add support for sharded pubsub topics & remove support for named pubsub topics ([#1697](https://github.com/waku-org/js-waku/issues/1697))
14
+ * change all instances of `PubSubTopic` to `PubsubTopic` ([#1703](https://github.com/waku-org/js-waku/issues/1703))
15
+
16
+ ### Features
17
+
18
+ * Add support for autosharded pubsub topics ([2bc3735](https://github.com/waku-org/js-waku/commit/2bc3735e4dcf85f06b3dee542024d7f20a40fac2))
19
+ * Add support for sharded pubsub topics & remove support for named pubsub topics ([#1697](https://github.com/waku-org/js-waku/issues/1697)) ([4cf2ffe](https://github.com/waku-org/js-waku/commit/4cf2ffefa75e0571805036b71644d2cdd4fe3192))
20
+ * Metadata protocol ([#1732](https://github.com/waku-org/js-waku/issues/1732)) ([9ac2a3f](https://github.com/waku-org/js-waku/commit/9ac2a3f36352523b79fcd8f8a94bd6e0e109fc30))
21
+ * Track node connection state ([#1719](https://github.com/waku-org/js-waku/issues/1719)) ([1d0e2ac](https://github.com/waku-org/js-waku/commit/1d0e2ace7fa5b44ab192505c7ebce01a7ce343e0))
22
+
23
+
24
+ ### Miscellaneous Chores
25
+
26
+ * Change all instances of `PubSubTopic` to `PubsubTopic` ([#1703](https://github.com/waku-org/js-waku/issues/1703)) ([3166a51](https://github.com/waku-org/js-waku/commit/3166a5135e77583da4fa722ee2aa47c785854a38))
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * The following workspace dependencies were updated
32
+ * dependencies
33
+ * @waku/enr bumped from ^0.0.19 to ^0.0.20
34
+ * @waku/interfaces bumped from 0.0.20 to 0.0.21
35
+ * @waku/proto bumped from 0.0.5 to 0.0.6
36
+ * @waku/utils bumped from 0.0.13 to 0.0.14
37
+
8
38
  ## [0.0.25](https://github.com/waku-org/js-waku/compare/core-v0.0.24...core-v0.0.25) (2023-11-01)
9
39
 
10
40
 
@@ -1,227 +1,5 @@
1
- import { i as identityBase, h as base2, j as base8, k as base10, l as base16, m as base32, n as base36, o as base58, p as base64, q as base256emoji } from './browser-9a6558bb.js';
2
- import { L as Logger } from './index-7581d519.js';
3
-
4
- // @ts-check
5
-
6
-
7
- const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji };
8
-
9
- /**
10
- * To guarantee Uint8Array semantics, convert nodejs Buffers
11
- * into vanilla Uint8Arrays
12
- */
13
- function asUint8Array(buf) {
14
- if (globalThis.Buffer != null) {
15
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
16
- }
17
- return buf;
18
- }
19
-
20
- /**
21
- * Returns a `Uint8Array` of the requested size. Referenced memory will
22
- * be initialized to 0.
23
- */
24
- function alloc(size = 0) {
25
- if (globalThis.Buffer?.alloc != null) {
26
- return asUint8Array(globalThis.Buffer.alloc(size));
27
- }
28
- return new Uint8Array(size);
29
- }
30
- /**
31
- * Where possible returns a Uint8Array of the requested size that references
32
- * uninitialized memory. Only use if you are certain you will immediately
33
- * overwrite every value in the returned `Uint8Array`.
34
- */
35
- function allocUnsafe(size = 0) {
36
- if (globalThis.Buffer?.allocUnsafe != null) {
37
- return asUint8Array(globalThis.Buffer.allocUnsafe(size));
38
- }
39
- return new Uint8Array(size);
40
- }
41
-
42
- function createCodec(name, prefix, encode, decode) {
43
- return {
44
- name,
45
- prefix,
46
- encoder: {
47
- name,
48
- prefix,
49
- encode
50
- },
51
- decoder: {
52
- decode
53
- }
54
- };
55
- }
56
- const string = createCodec('utf8', 'u', (buf) => {
57
- const decoder = new TextDecoder('utf8');
58
- return 'u' + decoder.decode(buf);
59
- }, (str) => {
60
- const encoder = new TextEncoder();
61
- return encoder.encode(str.substring(1));
62
- });
63
- const ascii = createCodec('ascii', 'a', (buf) => {
64
- let string = 'a';
65
- for (let i = 0; i < buf.length; i++) {
66
- string += String.fromCharCode(buf[i]);
67
- }
68
- return string;
69
- }, (str) => {
70
- str = str.substring(1);
71
- const buf = allocUnsafe(str.length);
72
- for (let i = 0; i < str.length; i++) {
73
- buf[i] = str.charCodeAt(i);
74
- }
75
- return buf;
76
- });
77
- const BASES = {
78
- utf8: string,
79
- 'utf-8': string,
80
- hex: bases.base16,
81
- latin1: ascii,
82
- ascii,
83
- binary: ascii,
84
- ...bases
85
- };
86
-
87
- /**
88
- * Turns a `Uint8Array` into a string.
89
- *
90
- * Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
91
- *
92
- * Also `ascii` which is similar to node's 'binary' encoding.
93
- */
94
- function toString(array, encoding = 'utf8') {
95
- const base = BASES[encoding];
96
- if (base == null) {
97
- throw new Error(`Unsupported encoding "${encoding}"`);
98
- }
99
- if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
100
- return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
101
- }
102
- // strip multibase prefix
103
- return base.encoder.encode(array).substring(1);
104
- }
105
-
106
- /**
107
- * Create a `Uint8Array` from the passed string
108
- *
109
- * Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
110
- *
111
- * Also `ascii` which is similar to node's 'binary' encoding.
112
- */
113
- function fromString(string, encoding = 'utf8') {
114
- const base = BASES[encoding];
115
- if (base == null) {
116
- throw new Error(`Unsupported encoding "${encoding}"`);
117
- }
118
- if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
119
- return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
120
- }
121
- // add multibase prefix
122
- return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
123
- }
124
-
125
- var Protocols;
126
- (function (Protocols) {
127
- Protocols["Relay"] = "relay";
128
- Protocols["Store"] = "store";
129
- Protocols["LightPush"] = "lightpush";
130
- Protocols["Filter"] = "filter";
131
- })(Protocols || (Protocols = {}));
132
- var SendError;
133
- (function (SendError) {
134
- /** Could not determine the origin of the fault. Best to check connectivity and try again */
135
- SendError["GENERIC_FAIL"] = "Generic error";
136
- /**
137
- * Failure to protobuf encode the message. This is not recoverable and needs
138
- * further investigation.
139
- */
140
- SendError["ENCODE_FAILED"] = "Failed to encode";
141
- /**
142
- * Failure to protobuf decode the message. May be due to a remote peer issue,
143
- * ensuring that messages are sent via several peer enable mitigation of this error.
144
- */
145
- SendError["DECODE_FAILED"] = "Failed to decode";
146
- /**
147
- * The message payload is empty, making the message invalid. Ensure that a non-empty
148
- * payload is set on the outgoing message.
149
- */
150
- SendError["EMPTY_PAYLOAD"] = "Payload is empty";
151
- /**
152
- * The message size is above the maximum message size allowed on the Waku Network.
153
- * Compressing the message or using an alternative strategy for large messages is recommended.
154
- */
155
- SendError["SIZE_TOO_BIG"] = "Size is too big";
156
- /**
157
- * The PubsubTopic passed to the send function is not configured on the Waku node.
158
- * Please ensure that the PubsubTopic is used when initializing the Waku node.
159
- */
160
- SendError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
161
- /**
162
- * Failure to find a peer with suitable protocols. This may due to a connection issue.
163
- * Mitigation can be: retrying after a given time period, display connectivity issue
164
- * to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
165
- * on the connection manager before retrying.
166
- */
167
- SendError["NO_PEER_AVAILABLE"] = "No peer available";
168
- /**
169
- * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
170
- * or `DECODE_FAILED` can be used.
171
- */
172
- SendError["REMOTE_PEER_FAULT"] = "Remote peer fault";
173
- /**
174
- * The remote peer rejected the message. Information provided by the remote peer
175
- * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
176
- * or `DECODE_FAILED` can be used.
177
- */
178
- SendError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
179
- })(SendError || (SendError = {}));
180
-
181
- var PageDirection;
182
- (function (PageDirection) {
183
- PageDirection["BACKWARD"] = "backward";
184
- PageDirection["FORWARD"] = "forward";
185
- })(PageDirection || (PageDirection = {}));
186
-
187
- var Tags;
188
- (function (Tags) {
189
- Tags["BOOTSTRAP"] = "bootstrap";
190
- Tags["PEER_EXCHANGE"] = "peer-exchange";
191
- })(Tags || (Tags = {}));
192
- var EPeersByDiscoveryEvents;
193
- (function (EPeersByDiscoveryEvents) {
194
- EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
195
- EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
196
- EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
197
- EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
198
- })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
199
- var EConnectionStateEvents;
200
- (function (EConnectionStateEvents) {
201
- EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
202
- })(EConnectionStateEvents || (EConnectionStateEvents = {}));
203
-
204
- /**
205
- * Decode byte array to utf-8 string.
206
- */
207
- const bytesToUtf8 = (b) => toString(b, "utf8");
208
- /**
209
- * Encode utf-8 string to byte array.
210
- */
211
- const utf8ToBytes = (s) => fromString(s, "utf8");
212
- /**
213
- * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
214
- */
215
- function concat(byteArrays, totalLength) {
216
- const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
217
- const res = new Uint8Array(len);
218
- let offset = 0;
219
- for (const bytes of byteArrays) {
220
- res.set(bytes, offset);
221
- offset += bytes.length;
222
- }
223
- return res;
224
- }
1
+ import { T as Tags } from './browser-mTOOnVZp.js';
2
+ import { k as bytesToUtf8, L as Logger, s as shardInfoToPubsubTopics, D as DefaultPubsubTopic } from './index-cmONXM-V.js';
225
3
 
226
4
  /**
227
5
  * Returns a pseudo-random peer that supports the given protocol.
@@ -272,6 +50,16 @@ async function getPeersForProtocol(peerStore, protocols) {
272
50
  });
273
51
  return peers;
274
52
  }
53
+ async function getConnectedPeersForProtocol(connections, peerStore, protocols) {
54
+ const openConnections = connections.filter((connection) => connection.status === "open");
55
+ const peerPromises = openConnections.map(async (connection) => {
56
+ const peer = await peerStore.get(connection.remotePeer);
57
+ const supportsProtocol = peer.protocols.some((protocol) => protocols.includes(protocol));
58
+ return supportsProtocol ? peer : null;
59
+ });
60
+ const peersWithNulls = await Promise.all(peerPromises);
61
+ return peersWithNulls.filter((peer) => peer !== null);
62
+ }
275
63
  /**
276
64
  * Returns a peer that supports the given protocol.
277
65
  * If peerId is provided, the peer with that id is returned.
@@ -446,7 +234,7 @@ class BaseProtocol {
446
234
  return peer;
447
235
  }
448
236
  /**
449
- * Retrieves a list of peers based on the specified criteria.
237
+ * Retrieves a list of connected peers based on the specified criteria.
450
238
  *
451
239
  * @param numPeers - The total number of peers to retrieve. If 0, all peers are returned.
452
240
  * @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
@@ -456,13 +244,17 @@ class BaseProtocol {
456
244
  maxBootstrapPeers: 1,
457
245
  numPeers: 0
458
246
  }) {
459
- // Retrieve all peers that support the protocol
460
- const allPeersForProtocol = await getPeersForProtocol(this.peerStore, [
461
- this.multicodec
462
- ]);
247
+ // Retrieve all connected peers that support the protocol
248
+ const allPeersForProtocol = await getConnectedPeersForProtocol(this.components.connectionManager.getConnections(), this.peerStore, [this.multicodec]);
463
249
  // Filter the peers based on the specified criteria
464
250
  return filterPeers(allPeersForProtocol, numPeers, maxBootstrapPeers);
465
251
  }
252
+ initializePubsubTopic(options) {
253
+ return (options?.pubsubTopics ??
254
+ (options?.shardInfo
255
+ ? shardInfoToPubsubTopics(options.shardInfo)
256
+ : [DefaultPubsubTopic]));
257
+ }
466
258
  }
467
259
 
468
- export { BaseProtocol as B, EConnectionStateEvents as E, Protocols as P, SendError as S, Tags as T, allocUnsafe as a, asUint8Array as b, bases as c, EPeersByDiscoveryEvents as d, alloc as e, fromString as f, concat as g, StreamManager as h, toString as t, utf8ToBytes as u };
260
+ export { BaseProtocol as B, StreamManager as S };
@@ -793,6 +793,85 @@ var identityBase = /*#__PURE__*/Object.freeze({
793
793
  new TextEncoder();
794
794
  new TextDecoder();
795
795
 
796
+ var Protocols;
797
+ (function (Protocols) {
798
+ Protocols["Relay"] = "relay";
799
+ Protocols["Store"] = "store";
800
+ Protocols["LightPush"] = "lightpush";
801
+ Protocols["Filter"] = "filter";
802
+ })(Protocols || (Protocols = {}));
803
+ var SendError;
804
+ (function (SendError) {
805
+ /** Could not determine the origin of the fault. Best to check connectivity and try again */
806
+ SendError["GENERIC_FAIL"] = "Generic error";
807
+ /**
808
+ * Failure to protobuf encode the message. This is not recoverable and needs
809
+ * further investigation.
810
+ */
811
+ SendError["ENCODE_FAILED"] = "Failed to encode";
812
+ /**
813
+ * Failure to protobuf decode the message. May be due to a remote peer issue,
814
+ * ensuring that messages are sent via several peer enable mitigation of this error.
815
+ */
816
+ SendError["DECODE_FAILED"] = "Failed to decode";
817
+ /**
818
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
819
+ * payload is set on the outgoing message.
820
+ */
821
+ SendError["EMPTY_PAYLOAD"] = "Payload is empty";
822
+ /**
823
+ * The message size is above the maximum message size allowed on the Waku Network.
824
+ * Compressing the message or using an alternative strategy for large messages is recommended.
825
+ */
826
+ SendError["SIZE_TOO_BIG"] = "Size is too big";
827
+ /**
828
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
829
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
830
+ */
831
+ SendError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
832
+ /**
833
+ * Failure to find a peer with suitable protocols. This may due to a connection issue.
834
+ * Mitigation can be: retrying after a given time period, display connectivity issue
835
+ * to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
836
+ * on the connection manager before retrying.
837
+ */
838
+ SendError["NO_PEER_AVAILABLE"] = "No peer available";
839
+ /**
840
+ * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
841
+ * or `DECODE_FAILED` can be used.
842
+ */
843
+ SendError["REMOTE_PEER_FAULT"] = "Remote peer fault";
844
+ /**
845
+ * The remote peer rejected the message. Information provided by the remote peer
846
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
847
+ * or `DECODE_FAILED` can be used.
848
+ */
849
+ SendError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
850
+ })(SendError || (SendError = {}));
851
+
852
+ var PageDirection;
853
+ (function (PageDirection) {
854
+ PageDirection["BACKWARD"] = "backward";
855
+ PageDirection["FORWARD"] = "forward";
856
+ })(PageDirection || (PageDirection = {}));
857
+
858
+ var Tags;
859
+ (function (Tags) {
860
+ Tags["BOOTSTRAP"] = "bootstrap";
861
+ Tags["PEER_EXCHANGE"] = "peer-exchange";
862
+ })(Tags || (Tags = {}));
863
+ var EPeersByDiscoveryEvents;
864
+ (function (EPeersByDiscoveryEvents) {
865
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
866
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
867
+ EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
868
+ EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
869
+ })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
870
+ var EConnectionStateEvents;
871
+ (function (EConnectionStateEvents) {
872
+ EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
873
+ })(EConnectionStateEvents || (EConnectionStateEvents = {}));
874
+
796
875
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
797
876
 
798
877
  function getDefaultExportFromCjs (x) {
@@ -1546,4 +1625,4 @@ var common = setup;
1546
1625
  var browserExports = browser.exports;
1547
1626
  var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
1548
1627
 
1549
- export { base58btc as a, base32 as b, coerce as c, commonjsGlobal as d, equals as e, getDefaultExportFromCjs as f, getAugmentedNamespace as g, base2$1 as h, identityBase as i, base8$1 as j, base10$1 as k, base16$1 as l, base32$1 as m, base36$1 as n, base58 as o, base64$1 as p, base256emoji$1 as q, debug as r };
1628
+ export { EConnectionStateEvents as E, Protocols as P, SendError as S, Tags as T, base58btc as a, base32 as b, coerce as c, commonjsGlobal as d, equals as e, EPeersByDiscoveryEvents as f, getAugmentedNamespace as g, getDefaultExportFromCjs as h, identityBase as i, base2$1 as j, base8$1 as k, base10$1 as l, base16$1 as m, base32$1 as n, base36$1 as o, base58 as p, base64$1 as q, base256emoji$1 as r, debug as s };