@waku/core 0.0.31-39f8920.0 → 0.0.31-514ce36.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.
@@ -1,4 +1,4 @@
1
- import { h as bytesToUtf8, T as Tags, L as Logger, e as pubsubTopicsToShardInfo } from './index-Gts2Ddu_.js';
1
+ import { h as bytesToUtf8, T as Tags, L as Logger, e as pubsubTopicsToShardInfo } from './index-tdQNdKHx.js';
2
2
 
3
3
  const decodeRelayShard = (bytes) => {
4
4
  // explicitly converting to Uint8Array to avoid Buffer
@@ -1058,7 +1058,7 @@ var ProtocolError;
1058
1058
  * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
1059
1059
  * or `DECODE_FAILED` can be used.
1060
1060
  */
1061
- ProtocolError["REMOTE_PEER_FAULT"] = "Remote peer fault";
1061
+ ProtocolError["NO_RESPONSE"] = "No response received";
1062
1062
  /**
1063
1063
  * The remote peer rejected the message. Information provided by the remote peer
1064
1064
  * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
@@ -1070,6 +1070,26 @@ var ProtocolError;
1070
1070
  * Mitigation can be: retrying after a given time period
1071
1071
  */
1072
1072
  ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
1073
+ /**
1074
+ * Missing credentials info message.
1075
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
1076
+ */
1077
+ ProtocolError["RLN_IDENTITY_MISSING"] = "Identity credentials are not set";
1078
+ /**
1079
+ * Membership index missing info message.
1080
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
1081
+ */
1082
+ ProtocolError["RLN_MEMBERSHIP_INDEX"] = "Membership index is not set";
1083
+ /**
1084
+ * Message limit is missing.
1085
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
1086
+ */
1087
+ ProtocolError["RLN_LIMIT_MISSING"] = "User message limit is not set";
1088
+ /**
1089
+ * General proof generation error message.
1090
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
1091
+ */
1092
+ ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
1073
1093
  })(ProtocolError || (ProtocolError = {}));
1074
1094
 
1075
1095
  var Tags;
@@ -2037,4 +2057,4 @@ class Logger {
2037
2057
  }
2038
2058
  }
2039
2059
 
2040
- export { EConnectionStateEvents as E, HealthStatus as H, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EPeersByDiscoveryEvents as d, pubsubTopicsToShardInfo as e, fromString as f, determinePubsubTopic as g, bytesToUtf8 as h, pubsubTopicToSingleShardInfo as p, shardInfoToPubsubTopics as s, utf8ToBytes as u };
2060
+ export { EPeersByDiscoveryEvents as E, HealthStatus as H, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EConnectionStateEvents as d, pubsubTopicsToShardInfo as e, fromString as f, determinePubsubTopic as g, bytesToUtf8 as h, pubsubTopicToSingleShardInfo as p, shardInfoToPubsubTopics as s, utf8ToBytes as u };
package/bundle/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse, S as StoreQueryRequest$1, f as StoreQueryResponse$1, g as createEncoder, W as WakuMetadataRequest, h as WakuMetadataResponse } from './version_0-CNRKFufI.js';
2
- export { i as createDecoder } from './version_0-CNRKFufI.js';
3
- import { a as allocUnsafe, b as alloc, L as Logger, P as ProtocolError, c as Protocols, u as utf8ToBytes, p as pubsubTopicToSingleShardInfo, E as EConnectionStateEvents, T as Tags, d as EPeersByDiscoveryEvents, s as shardInfoToPubsubTopics, H as HealthStatus, e as pubsubTopicsToShardInfo } from './index-Gts2Ddu_.js';
4
- import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-Dge5_tvU.js';
5
- export { S as StreamManager } from './base_protocol-Dge5_tvU.js';
1
+ import { v as version_0, e as encodingLength, a as encode$1, d as decode$1, M as MessagePush, F as FilterSubscribeRequest, b as FilterSubscribeResponse$1, P as PushRpc$1, c as PushResponse, S as StoreQueryRequest$1, f as StoreQueryResponse$1, g as createEncoder, W as WakuMetadataRequest, h as WakuMetadataResponse } from './version_0-BrbNEwD-.js';
2
+ export { i as createDecoder } from './version_0-BrbNEwD-.js';
3
+ import { a as allocUnsafe, b as alloc, L as Logger, P as ProtocolError, c as Protocols, u as utf8ToBytes, p as pubsubTopicToSingleShardInfo, T as Tags, E as EPeersByDiscoveryEvents, s as shardInfoToPubsubTopics, d as EConnectionStateEvents, H as HealthStatus, e as pubsubTopicsToShardInfo } from './index-tdQNdKHx.js';
4
+ import { B as BaseProtocol, d as decodeRelayShard, e as encodeRelayShard } from './base_protocol-C47QkJ2o.js';
5
+ export { S as StreamManager } from './base_protocol-C47QkJ2o.js';
6
6
 
7
7
  const MB = 1024 ** 2;
8
8
  const SIZE_CAP_IN_MB = 1;
@@ -1618,7 +1618,7 @@ class FilterCore extends BaseProtocol {
1618
1618
  return {
1619
1619
  success: null,
1620
1620
  failure: {
1621
- error: ProtocolError.REMOTE_PEER_FAULT,
1621
+ error: ProtocolError.NO_STREAM_AVAILABLE,
1622
1622
  peerId: peer.id
1623
1623
  }
1624
1624
  };
@@ -1649,7 +1649,7 @@ class FilterCore extends BaseProtocol {
1649
1649
  if (!res || !res.length) {
1650
1650
  return {
1651
1651
  failure: {
1652
- error: ProtocolError.REMOTE_PEER_FAULT,
1652
+ error: ProtocolError.NO_RESPONSE,
1653
1653
  peerId: peer.id
1654
1654
  },
1655
1655
  success: null
@@ -1681,7 +1681,7 @@ class FilterCore extends BaseProtocol {
1681
1681
  return {
1682
1682
  success: null,
1683
1683
  failure: {
1684
- error: ProtocolError.REMOTE_PEER_FAULT,
1684
+ error: ProtocolError.NO_STREAM_AVAILABLE,
1685
1685
  peerId: peer.id
1686
1686
  }
1687
1687
  };
@@ -1705,7 +1705,7 @@ class FilterCore extends BaseProtocol {
1705
1705
  return {
1706
1706
  success: null,
1707
1707
  failure: {
1708
- error: ProtocolError.REMOTE_PEER_FAULT,
1708
+ error: ProtocolError.NO_RESPONSE,
1709
1709
  peerId: peer.id
1710
1710
  }
1711
1711
  };
@@ -1793,6 +1793,31 @@ class PushRpc {
1793
1793
  }
1794
1794
  }
1795
1795
 
1796
+ // should match nwaku
1797
+ // https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
1798
+ // https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
1799
+ const RLN_GENERATION_PREFIX_ERROR = "could not generate rln-v2 proof";
1800
+ const isRLNResponseError = (info) => {
1801
+ if (!info) {
1802
+ return false;
1803
+ }
1804
+ return info.includes(RLN_GENERATION_PREFIX_ERROR);
1805
+ };
1806
+ const matchRLNErrorMessage = (info) => {
1807
+ const rlnErrorMap = {
1808
+ [ProtocolError.RLN_IDENTITY_MISSING]: ProtocolError.RLN_IDENTITY_MISSING,
1809
+ [ProtocolError.RLN_MEMBERSHIP_INDEX]: ProtocolError.RLN_MEMBERSHIP_INDEX,
1810
+ [ProtocolError.RLN_LIMIT_MISSING]: ProtocolError.RLN_LIMIT_MISSING
1811
+ };
1812
+ const infoLowerCase = info.toLowerCase();
1813
+ for (const errorKey in rlnErrorMap) {
1814
+ if (infoLowerCase.includes(errorKey.toLowerCase())) {
1815
+ return rlnErrorMap[errorKey];
1816
+ }
1817
+ }
1818
+ return ProtocolError.RLN_PROOF_GENERATION;
1819
+ };
1820
+
1796
1821
  const log$5 = new Logger("light-push");
1797
1822
  const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
1798
1823
  /**
@@ -1895,7 +1920,18 @@ class LightPushCore extends BaseProtocol {
1895
1920
  return {
1896
1921
  success: null,
1897
1922
  failure: {
1898
- error: ProtocolError.REMOTE_PEER_FAULT,
1923
+ error: ProtocolError.NO_RESPONSE,
1924
+ peerId: peer.id
1925
+ }
1926
+ };
1927
+ }
1928
+ if (isRLNResponseError(response.info)) {
1929
+ const rlnErrorCase = matchRLNErrorMessage(response.info);
1930
+ log$5.error("Remote peer rejected the message: ", rlnErrorCase);
1931
+ return {
1932
+ success: null,
1933
+ failure: {
1934
+ error: rlnErrorCase,
1899
1935
  peerId: peer.id
1900
1936
  }
1901
1937
  };
@@ -2525,23 +2561,7 @@ class TypedEventEmitter extends EventTarget {
2525
2561
  return this.dispatchEvent(new CustomEvent(type, detail));
2526
2562
  }
2527
2563
  }
2528
- /**
2529
- * CustomEvent is a standard event but it's not supported by node.
2530
- *
2531
- * Remove this when https://github.com/nodejs/node/issues/40678 is closed.
2532
- *
2533
- * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
2534
- */
2535
- class CustomEventPolyfill extends Event {
2536
- /** Returns any custom data event was created with. Typically used for synthetic events. */
2537
- detail;
2538
- constructor(message, data) {
2539
- super(message, data);
2540
- // @ts-expect-error could be undefined
2541
- this.detail = data?.detail;
2542
- }
2543
- }
2544
- const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill;
2564
+ const CustomEvent = globalThis.CustomEvent;
2545
2565
 
2546
2566
  const RelayPingContentTopic = "/relay-ping/1/ping/null";
2547
2567
  const log$2 = new Logger("keep-alive");
@@ -2666,25 +2686,12 @@ class ConnectionManager extends TypedEventEmitter {
2666
2686
  dialErrorsForPeer = new Map();
2667
2687
  currentActiveParallelDialCount = 0;
2668
2688
  pendingPeerDialQueue = [];
2669
- online = false;
2689
+ isP2PNetworkConnected = false;
2670
2690
  isConnected() {
2671
- return this.online;
2672
- }
2673
- toggleOnline() {
2674
- if (!this.online) {
2675
- this.online = true;
2676
- this.dispatchEvent(new CustomEvent(EConnectionStateEvents.CONNECTION_STATUS, {
2677
- detail: this.online
2678
- }));
2679
- }
2680
- }
2681
- toggleOffline() {
2682
- if (this.online && this.libp2p.getConnections().length == 0) {
2683
- this.online = false;
2684
- this.dispatchEvent(new CustomEvent(EConnectionStateEvents.CONNECTION_STATUS, {
2685
- detail: this.online
2686
- }));
2691
+ if (globalThis?.navigator && !globalThis?.navigator?.onLine) {
2692
+ return false;
2687
2693
  }
2694
+ return this.isP2PNetworkConnected;
2688
2695
  }
2689
2696
  static create(peerId, libp2p, keepAliveOptions, pubsubTopics, relay, options) {
2690
2697
  let instance = ConnectionManager.instances.get(peerId);
@@ -2699,6 +2706,7 @@ class ConnectionManager extends TypedEventEmitter {
2699
2706
  this.libp2p.removeEventListener("peer:connect", this.onEventHandlers["peer:connect"]);
2700
2707
  this.libp2p.removeEventListener("peer:disconnect", this.onEventHandlers["peer:disconnect"]);
2701
2708
  this.libp2p.removeEventListener("peer:discovery", this.onEventHandlers["peer:discovery"]);
2709
+ this.stopNetworkStatusListener();
2702
2710
  }
2703
2711
  async dropConnection(peerId) {
2704
2712
  try {
@@ -2775,7 +2783,7 @@ class ConnectionManager extends TypedEventEmitter {
2775
2783
  libp2p,
2776
2784
  options: keepAliveOptions
2777
2785
  });
2778
- this.run()
2786
+ this.startEventListeners()
2779
2787
  .then(() => log$1.info(`Connection Manager is now running`))
2780
2788
  .catch((error) => log$1.error(`Unexpected error while running service`, error));
2781
2789
  // libp2p emits `peer:discovery` events during its initialization
@@ -2798,11 +2806,11 @@ class ConnectionManager extends TypedEventEmitter {
2798
2806
  log$1.error(`Unexpected error while dialing peer store peers`, error);
2799
2807
  }
2800
2808
  }
2801
- async run() {
2802
- // start event listeners
2809
+ async startEventListeners() {
2803
2810
  this.startPeerDiscoveryListener();
2804
2811
  this.startPeerConnectionListener();
2805
2812
  this.startPeerDisconnectionListener();
2813
+ this.startNetworkStatusListener();
2806
2814
  }
2807
2815
  async dialPeer(peerId) {
2808
2816
  this.currentActiveParallelDialCount += 1;
@@ -2950,14 +2958,17 @@ class ConnectionManager extends TypedEventEmitter {
2950
2958
  detail: peerId
2951
2959
  }));
2952
2960
  }
2953
- this.toggleOnline();
2961
+ this.setP2PNetworkConnected();
2954
2962
  })();
2955
2963
  },
2956
2964
  "peer:disconnect": (evt) => {
2957
2965
  void (async () => {
2958
2966
  this.keepAliveManager.stop(evt.detail);
2959
- this.toggleOffline();
2967
+ this.setP2PNetworkDisconnected();
2960
2968
  })();
2969
+ },
2970
+ "browser:network": () => {
2971
+ this.dispatchWakuConnectionEvent();
2961
2972
  }
2962
2973
  };
2963
2974
  /**
@@ -3048,6 +3059,42 @@ class ConnectionManager extends TypedEventEmitter {
3048
3059
  return undefined;
3049
3060
  return decodeRelayShard(shardInfoBytes);
3050
3061
  }
3062
+ startNetworkStatusListener() {
3063
+ try {
3064
+ globalThis.addEventListener("online", this.onEventHandlers["browser:network"]);
3065
+ globalThis.addEventListener("offline", this.onEventHandlers["browser:network"]);
3066
+ }
3067
+ catch (err) {
3068
+ log$1.error(`Failed to start network listener: ${err}`);
3069
+ }
3070
+ }
3071
+ stopNetworkStatusListener() {
3072
+ try {
3073
+ globalThis.removeEventListener("online", this.onEventHandlers["browser:network"]);
3074
+ globalThis.removeEventListener("offline", this.onEventHandlers["browser:network"]);
3075
+ }
3076
+ catch (err) {
3077
+ log$1.error(`Failed to stop network listener: ${err}`);
3078
+ }
3079
+ }
3080
+ setP2PNetworkConnected() {
3081
+ if (!this.isP2PNetworkConnected) {
3082
+ this.isP2PNetworkConnected = true;
3083
+ this.dispatchWakuConnectionEvent();
3084
+ }
3085
+ }
3086
+ setP2PNetworkDisconnected() {
3087
+ if (this.isP2PNetworkConnected &&
3088
+ this.libp2p.getConnections().length === 0) {
3089
+ this.isP2PNetworkConnected = false;
3090
+ this.dispatchWakuConnectionEvent();
3091
+ }
3092
+ }
3093
+ dispatchWakuConnectionEvent() {
3094
+ this.dispatchEvent(new CustomEvent(EConnectionStateEvents.CONNECTION_STATUS, {
3095
+ detail: this.isConnected()
3096
+ }));
3097
+ }
3051
3098
  }
3052
3099
 
3053
3100
  class HealthManager {
@@ -1,2 +1,2 @@
1
- import '../index-Gts2Ddu_.js';
2
- export { B as BaseProtocol } from '../base_protocol-Dge5_tvU.js';
1
+ import '../index-tdQNdKHx.js';
2
+ export { B as BaseProtocol } from '../base_protocol-C47QkJ2o.js';
@@ -1,2 +1,2 @@
1
- export { D as DecodedMessage, j as Decoder, E as Encoder, V as Version, i as createDecoder, g as createEncoder, m as proto } from '../../version_0-CNRKFufI.js';
2
- import '../../index-Gts2Ddu_.js';
1
+ export { D as DecodedMessage, j as Decoder, E as Encoder, V as Version, i as createDecoder, g as createEncoder, m as proto } from '../../version_0-BrbNEwD-.js';
2
+ import '../../index-tdQNdKHx.js';
@@ -1,4 +1,4 @@
1
- import { a as allocUnsafe, f as fromString, b as alloc$1, L as Logger, g as determinePubsubTopic } from './index-Gts2Ddu_.js';
1
+ import { a as allocUnsafe, f as fromString, b as alloc$1, L as Logger, g as determinePubsubTopic } from './index-tdQNdKHx.js';
2
2
 
3
3
  /* eslint-disable no-fallthrough */
4
4
  const N1 = Math.pow(2, 7);