@waku/core 0.0.34-c43cec2.0 → 0.0.34-c8128d1.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.
Files changed (64) hide show
  1. package/bundle/{base_protocol-DxFKDXX2.js → base_protocol-Bp5a9PNG.js} +19 -20
  2. package/bundle/{index-yLOEQnIE.js → index-G1eRBjeI.js} +115 -84
  3. package/bundle/index.js +1828 -153
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-Che4t3mN.js → version_0-DJZG2fB2.js} +163 -42
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.js +0 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/base_protocol.d.ts +2 -2
  12. package/dist/lib/base_protocol.js +2 -2
  13. package/dist/lib/base_protocol.js.map +1 -1
  14. package/dist/lib/connection_manager/connection_manager.d.ts +56 -3
  15. package/dist/lib/connection_manager/connection_manager.js +96 -13
  16. package/dist/lib/connection_manager/connection_manager.js.map +1 -1
  17. package/dist/lib/filter/filter.d.ts +18 -0
  18. package/dist/lib/filter/filter.js +209 -0
  19. package/dist/lib/filter/filter.js.map +1 -0
  20. package/dist/lib/filter/index.d.ts +1 -18
  21. package/dist/lib/filter/index.js +1 -208
  22. package/dist/lib/filter/index.js.map +1 -1
  23. package/dist/lib/light_push/index.d.ts +1 -15
  24. package/dist/lib/light_push/index.js +1 -144
  25. package/dist/lib/light_push/index.js.map +1 -1
  26. package/dist/lib/light_push/light_push.d.ts +15 -0
  27. package/dist/lib/light_push/light_push.js +144 -0
  28. package/dist/lib/light_push/light_push.js.map +1 -0
  29. package/dist/lib/light_push/utils.d.ts +0 -2
  30. package/dist/lib/light_push/utils.js +9 -17
  31. package/dist/lib/light_push/utils.js.map +1 -1
  32. package/dist/lib/metadata/index.d.ts +1 -3
  33. package/dist/lib/metadata/index.js +1 -118
  34. package/dist/lib/metadata/index.js.map +1 -1
  35. package/dist/lib/metadata/metadata.d.ts +3 -0
  36. package/dist/lib/metadata/metadata.js +119 -0
  37. package/dist/lib/metadata/metadata.js.map +1 -0
  38. package/dist/lib/store/index.d.ts +1 -9
  39. package/dist/lib/store/index.js +1 -82
  40. package/dist/lib/store/index.js.map +1 -1
  41. package/dist/lib/store/store.d.ts +9 -0
  42. package/dist/lib/store/store.js +83 -0
  43. package/dist/lib/store/store.js.map +1 -0
  44. package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
  45. package/dist/lib/stream_manager/stream_manager.js +16 -17
  46. package/dist/lib/stream_manager/stream_manager.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/index.ts +0 -2
  49. package/src/lib/base_protocol.ts +3 -3
  50. package/src/lib/connection_manager/connection_manager.ts +114 -20
  51. package/src/lib/filter/filter.ts +315 -0
  52. package/src/lib/filter/index.ts +1 -315
  53. package/src/lib/light_push/index.ts +1 -189
  54. package/src/lib/light_push/light_push.ts +188 -0
  55. package/src/lib/light_push/utils.ts +13 -21
  56. package/src/lib/metadata/index.ts +1 -182
  57. package/src/lib/metadata/metadata.ts +182 -0
  58. package/src/lib/store/index.ts +1 -136
  59. package/src/lib/store/store.ts +136 -0
  60. package/src/lib/stream_manager/stream_manager.ts +16 -18
  61. package/dist/lib/health_manager.d.ts +0 -14
  62. package/dist/lib/health_manager.js +0 -70
  63. package/dist/lib/health_manager.js.map +0 -1
  64. package/src/lib/health_manager.ts +0 -90
@@ -1,4 +1,4 @@
1
- import { L as Logger } from './index-yLOEQnIE.js';
1
+ import { L as Logger } from './index-G1eRBjeI.js';
2
2
 
3
3
  function selectOpenConnection(connections) {
4
4
  return connections
@@ -22,36 +22,36 @@ class StreamManager {
22
22
  this.log = new Logger(`stream-manager:${multicodec}`);
23
23
  this.addEventListener("peer:update", this.handlePeerUpdateStreamPool);
24
24
  }
25
- async getStream(peer) {
26
- const peerId = peer.id.toString();
27
- const scheduledStream = this.streamPool.get(peerId);
25
+ async getStream(peerId) {
26
+ const peerIdStr = peerId.toString();
27
+ const scheduledStream = this.streamPool.get(peerIdStr);
28
28
  if (scheduledStream) {
29
- this.streamPool.delete(peerId);
29
+ this.streamPool.delete(peerIdStr);
30
30
  await scheduledStream;
31
31
  }
32
- let stream = this.getOpenStreamForCodec(peer.id);
32
+ let stream = this.getOpenStreamForCodec(peerId);
33
33
  if (stream) {
34
- this.log.info(`Found existing stream peerId=${peer.id.toString()} multicodec=${this.multicodec}`);
35
- this.lockStream(peer.id.toString(), stream);
34
+ this.log.info(`Found existing stream peerId=${peerIdStr} multicodec=${this.multicodec}`);
35
+ this.lockStream(peerIdStr, stream);
36
36
  return stream;
37
37
  }
38
- stream = await this.createStream(peer);
39
- this.lockStream(peer.id.toString(), stream);
38
+ stream = await this.createStream(peerId);
39
+ this.lockStream(peerIdStr, stream);
40
40
  return stream;
41
41
  }
42
- async createStream(peer, retries = 0) {
43
- const connections = this.getConnections(peer.id);
42
+ async createStream(peerId, retries = 0) {
43
+ const connections = this.getConnections(peerId);
44
44
  const connection = selectOpenConnection(connections);
45
45
  if (!connection) {
46
- throw new Error(`Failed to get a connection to the peer peerId=${peer.id.toString()} multicodec=${this.multicodec}`);
46
+ throw new Error(`Failed to get a connection to the peer peerId=${peerId.toString()} multicodec=${this.multicodec}`);
47
47
  }
48
48
  let lastError;
49
49
  let stream;
50
50
  for (let i = 0; i < retries + 1; i++) {
51
51
  try {
52
- this.log.info(`Attempting to create a stream for peerId=${peer.id.toString()} multicodec=${this.multicodec}`);
52
+ this.log.info(`Attempting to create a stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
53
53
  stream = await connection.newStream(this.multicodec);
54
- this.log.info(`Created stream for peerId=${peer.id.toString()} multicodec=${this.multicodec}`);
54
+ this.log.info(`Created stream for peerId=${peerId.toString()} multicodec=${this.multicodec}`);
55
55
  break;
56
56
  }
57
57
  catch (error) {
@@ -59,8 +59,7 @@ class StreamManager {
59
59
  }
60
60
  }
61
61
  if (!stream) {
62
- throw new Error(`Failed to create a new stream for ${peer.id.toString()} -- ` +
63
- lastError);
62
+ throw new Error(`Failed to create a new stream for ${peerId.toString()} -- ` + lastError);
64
63
  }
65
64
  return stream;
66
65
  }
@@ -72,7 +71,7 @@ class StreamManager {
72
71
  }
73
72
  try {
74
73
  this.ongoingCreation.add(peerId);
75
- await this.createStream(peer);
74
+ await this.createStream(peer.id);
76
75
  }
77
76
  catch (error) {
78
77
  this.log.error(`Failed to createStreamWithLock:`, error);
@@ -145,8 +144,8 @@ class BaseProtocol {
145
144
  this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
146
145
  this.streamManager = new StreamManager(multicodec, components.connectionManager.getConnections.bind(components.connectionManager), this.addLibp2pEventListener);
147
146
  }
148
- async getStream(peer) {
149
- return this.streamManager.getStream(peer);
147
+ async getStream(peerId) {
148
+ return this.streamManager.getStream(peerId);
150
149
  }
151
150
  }
152
151
 
@@ -1,3 +1,16 @@
1
+ function equals(aa, bb) {
2
+ if (aa === bb)
3
+ return true;
4
+ if (aa.byteLength !== bb.byteLength) {
5
+ return false;
6
+ }
7
+ for (let ii = 0; ii < aa.byteLength; ii++) {
8
+ if (aa[ii] !== bb[ii]) {
9
+ return false;
10
+ }
11
+ }
12
+ return true;
13
+ }
1
14
  function coerce(o) {
2
15
  if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
3
16
  return o;
@@ -641,43 +654,24 @@ var Protocols;
641
654
  })(Protocols || (Protocols = {}));
642
655
  var ProtocolError;
643
656
  (function (ProtocolError) {
644
- /** Could not determine the origin of the fault. Best to check connectivity and try again */
657
+ //
658
+ // GENERAL ERRORS SECTION
659
+ //
660
+ /**
661
+ * Could not determine the origin of the fault. Best to check connectivity and try again
662
+ * */
645
663
  ProtocolError["GENERIC_FAIL"] = "Generic error";
646
664
  /**
647
- * Failure to protobuf encode the message. This is not recoverable and needs
648
- * further investigation.
665
+ * The remote peer rejected the message. Information provided by the remote peer
666
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
667
+ * or `DECODE_FAILED` can be used.
649
668
  */
650
- ProtocolError["ENCODE_FAILED"] = "Failed to encode";
669
+ ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
651
670
  /**
652
671
  * Failure to protobuf decode the message. May be due to a remote peer issue,
653
672
  * ensuring that messages are sent via several peer enable mitigation of this error.
654
673
  */
655
674
  ProtocolError["DECODE_FAILED"] = "Failed to decode";
656
- /**
657
- * The message payload is empty, making the message invalid. Ensure that a non-empty
658
- * payload is set on the outgoing message.
659
- */
660
- ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
661
- /**
662
- * The message size is above the maximum message size allowed on the Waku Network.
663
- * Compressing the message or using an alternative strategy for large messages is recommended.
664
- */
665
- ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
666
- /**
667
- * The PubsubTopic passed to the send function is not configured on the Waku node.
668
- * Please ensure that the PubsubTopic is used when initializing the Waku node.
669
- */
670
- ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
671
- /**
672
- * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
673
- * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
674
- */
675
- ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
676
- /**
677
- * The topics passed in the decoders do not match each other, or don't exist at all.
678
- * Ensure that all the pubsub topics used in the decoders are valid and match each other.
679
- */
680
- ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
681
675
  /**
682
676
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
683
677
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -695,37 +689,51 @@ var ProtocolError;
695
689
  * or `DECODE_FAILED` can be used.
696
690
  */
697
691
  ProtocolError["NO_RESPONSE"] = "No response received";
692
+ //
693
+ // SEND ERRORS SECTION
694
+ //
698
695
  /**
699
- * The remote peer rejected the message. Information provided by the remote peer
700
- * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
701
- * or `DECODE_FAILED` can be used.
696
+ * Failure to protobuf encode the message. This is not recoverable and needs
697
+ * further investigation.
702
698
  */
703
- ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
699
+ ProtocolError["ENCODE_FAILED"] = "Failed to encode";
704
700
  /**
705
- * The protocol request timed out without a response. This may be due to a connection issue.
706
- * Mitigation can be: retrying after a given time period
701
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
702
+ * payload is set on the outgoing message.
707
703
  */
708
- ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
704
+ ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
709
705
  /**
710
- * Missing credentials info message.
711
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
706
+ * The message size is above the maximum message size allowed on the Waku Network.
707
+ * Compressing the message or using an alternative strategy for large messages is recommended.
712
708
  */
713
- ProtocolError["RLN_IDENTITY_MISSING"] = "Identity credentials are not set";
709
+ ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
714
710
  /**
715
- * Membership index missing info message.
716
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
711
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
712
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
717
713
  */
718
- ProtocolError["RLN_MEMBERSHIP_INDEX"] = "Membership index is not set";
714
+ ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
719
715
  /**
720
- * Message limit is missing.
721
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
716
+ * Fails when
722
717
  */
723
- ProtocolError["RLN_LIMIT_MISSING"] = "User message limit is not set";
718
+ ProtocolError["STREAM_ABORTED"] = "Stream aborted";
724
719
  /**
725
720
  * General proof generation error message.
726
721
  * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
727
722
  */
728
723
  ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
724
+ //
725
+ // RECEIVE ERRORS SECTION
726
+ //
727
+ /**
728
+ * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
729
+ * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
730
+ */
731
+ ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
732
+ /**
733
+ * The topics passed in the decoders do not match each other, or don't exist at all.
734
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
735
+ */
736
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
729
737
  })(ProtocolError || (ProtocolError = {}));
730
738
 
731
739
  var Tags;
@@ -746,6 +754,10 @@ var EConnectionStateEvents;
746
754
  EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
747
755
  })(EConnectionStateEvents || (EConnectionStateEvents = {}));
748
756
 
757
+ var HealthStatusChangeEvents;
758
+ (function (HealthStatusChangeEvents) {
759
+ HealthStatusChangeEvents["StatusChange"] = "health:change";
760
+ })(HealthStatusChangeEvents || (HealthStatusChangeEvents = {}));
749
761
  var HealthStatus;
750
762
  (function (HealthStatus) {
751
763
  HealthStatus["Unhealthy"] = "Unhealthy";
@@ -1097,24 +1109,62 @@ function setup(env) {
1097
1109
  createDebug.names = [];
1098
1110
  createDebug.skips = [];
1099
1111
 
1100
- let i;
1101
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
1102
- const len = split.length;
1112
+ const split = (typeof namespaces === 'string' ? namespaces : '')
1113
+ .trim()
1114
+ .replace(' ', ',')
1115
+ .split(',')
1116
+ .filter(Boolean);
1103
1117
 
1104
- for (i = 0; i < len; i++) {
1105
- if (!split[i]) {
1106
- // ignore empty strings
1107
- continue;
1118
+ for (const ns of split) {
1119
+ if (ns[0] === '-') {
1120
+ createDebug.skips.push(ns.slice(1));
1121
+ } else {
1122
+ createDebug.names.push(ns);
1108
1123
  }
1124
+ }
1125
+ }
1109
1126
 
1110
- namespaces = split[i].replace(/\*/g, '.*?');
1111
-
1112
- if (namespaces[0] === '-') {
1113
- createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
1127
+ /**
1128
+ * Checks if the given string matches a namespace template, honoring
1129
+ * asterisks as wildcards.
1130
+ *
1131
+ * @param {String} search
1132
+ * @param {String} template
1133
+ * @return {Boolean}
1134
+ */
1135
+ function matchesTemplate(search, template) {
1136
+ let searchIndex = 0;
1137
+ let templateIndex = 0;
1138
+ let starIndex = -1;
1139
+ let matchIndex = 0;
1140
+
1141
+ while (searchIndex < search.length) {
1142
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
1143
+ // Match character or proceed with wildcard
1144
+ if (template[templateIndex] === '*') {
1145
+ starIndex = templateIndex;
1146
+ matchIndex = searchIndex;
1147
+ templateIndex++; // Skip the '*'
1148
+ } else {
1149
+ searchIndex++;
1150
+ templateIndex++;
1151
+ }
1152
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
1153
+ // Backtrack to the last '*' and try to match more characters
1154
+ templateIndex = starIndex + 1;
1155
+ matchIndex++;
1156
+ searchIndex = matchIndex;
1114
1157
  } else {
1115
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
1158
+ return false; // No match
1116
1159
  }
1117
1160
  }
1161
+
1162
+ // Handle trailing '*' in template
1163
+ while (templateIndex < template.length && template[templateIndex] === '*') {
1164
+ templateIndex++;
1165
+ }
1166
+
1167
+ return templateIndex === template.length;
1118
1168
  }
1119
1169
 
1120
1170
  /**
@@ -1125,8 +1175,8 @@ function setup(env) {
1125
1175
  */
1126
1176
  function disable() {
1127
1177
  const namespaces = [
1128
- ...createDebug.names.map(toNamespace),
1129
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
1178
+ ...createDebug.names,
1179
+ ...createDebug.skips.map(namespace => '-' + namespace)
1130
1180
  ].join(',');
1131
1181
  createDebug.enable('');
1132
1182
  return namespaces;
@@ -1140,21 +1190,14 @@ function setup(env) {
1140
1190
  * @api public
1141
1191
  */
1142
1192
  function enabled(name) {
1143
- if (name[name.length - 1] === '*') {
1144
- return true;
1145
- }
1146
-
1147
- let i;
1148
- let len;
1149
-
1150
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
1151
- if (createDebug.skips[i].test(name)) {
1193
+ for (const skip of createDebug.skips) {
1194
+ if (matchesTemplate(name, skip)) {
1152
1195
  return false;
1153
1196
  }
1154
1197
  }
1155
1198
 
1156
- for (i = 0, len = createDebug.names.length; i < len; i++) {
1157
- if (createDebug.names[i].test(name)) {
1199
+ for (const ns of createDebug.names) {
1200
+ if (matchesTemplate(name, ns)) {
1158
1201
  return true;
1159
1202
  }
1160
1203
  }
@@ -1162,19 +1205,6 @@ function setup(env) {
1162
1205
  return false;
1163
1206
  }
1164
1207
 
1165
- /**
1166
- * Convert regexp to namespace
1167
- *
1168
- * @param {RegExp} regxep
1169
- * @return {String} namespace
1170
- * @api private
1171
- */
1172
- function toNamespace(regexp) {
1173
- return regexp.toString()
1174
- .substring(2, regexp.toString().length - 2)
1175
- .replace(/\.\*\?$/, '*');
1176
- }
1177
-
1178
1208
  /**
1179
1209
  * Coerce `val`.
1180
1210
  *
@@ -1336,6 +1366,7 @@ var common = setup;
1336
1366
 
1337
1367
  // Is webkit? http://stackoverflow.com/a/16459606/376773
1338
1368
  // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
1369
+ // eslint-disable-next-line no-return-assign
1339
1370
  return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
1340
1371
  // Is firebug? http://stackoverflow.com/a/398120/376773
1341
1372
  (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
@@ -1509,4 +1540,4 @@ class Logger {
1509
1540
  }
1510
1541
  }
1511
1542
 
1512
- export { EPeersByDiscoveryEvents as E, HealthStatus as H, Logger as L, ProtocolError as P, Tags as T, EConnectionStateEvents as a, Protocols as b, base2$1 as c, base8$1 as d, base10$1 as e, base16$1 as f, base32$1 as g, base36$1 as h, identityBase as i, base58 as j, base64$1 as k, base256emoji$1 as l };
1543
+ export { EPeersByDiscoveryEvents as E, Logger as L, ProtocolError as P, Tags as T, base32 as a, base36 as b, coerce as c, base58btc as d, equals as e, EConnectionStateEvents as f, base2$1 as g, base8$1 as h, identityBase as i, base10$1 as j, base16$1 as k, base32$1 as l, base36$1 as m, base58 as n, base64$1 as o, base256emoji$1 as p };