@waku/core 0.0.5 → 0.0.7

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 (129) hide show
  1. package/CHANGELOG.md +51 -3
  2. package/bundle/index.js +31146 -26342
  3. package/bundle/lib/message/topic_only_message.js +33 -0
  4. package/bundle/lib/message/version_0.js +133 -0
  5. package/bundle/lib/predefined_bootstrap_nodes.js +24 -4
  6. package/bundle/{message-049c8b67.js → peer_exchange-53df2b11.js} +3579 -1007
  7. package/dist/index.d.ts +14 -13
  8. package/dist/index.js +11 -10
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
  11. package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
  12. package/dist/lib/filter/filter_rpc.js.map +1 -0
  13. package/dist/lib/filter/index.d.ts +25 -0
  14. package/dist/lib/{waku_filter → filter}/index.js +14 -9
  15. package/dist/lib/filter/index.js.map +1 -0
  16. package/dist/lib/light_push/index.d.ts +22 -0
  17. package/dist/lib/{waku_light_push → light_push}/index.js +14 -9
  18. package/dist/lib/light_push/index.js.map +1 -0
  19. package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
  20. package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
  21. package/dist/lib/light_push/push_rpc.js.map +1 -0
  22. package/dist/lib/message/topic_only_message.d.ts +16 -0
  23. package/dist/lib/{waku_message → message}/topic_only_message.js +2 -1
  24. package/dist/lib/message/topic_only_message.js.map +1 -0
  25. package/dist/lib/message/version_0.d.ts +54 -0
  26. package/dist/lib/{waku_message → message}/version_0.js +41 -6
  27. package/dist/lib/message/version_0.js.map +1 -0
  28. package/dist/lib/predefined_bootstrap_nodes.d.ts +1 -2
  29. package/dist/lib/predefined_bootstrap_nodes.js +0 -2
  30. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  31. package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
  32. package/dist/lib/{waku_relay → relay}/constants.js +0 -0
  33. package/dist/lib/relay/constants.js.map +1 -0
  34. package/dist/lib/relay/index.d.ts +24 -0
  35. package/dist/lib/{waku_relay → relay}/index.js +9 -6
  36. package/dist/lib/relay/index.js.map +1 -0
  37. package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
  38. package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
  39. package/dist/lib/store/history_rpc.js.map +1 -0
  40. package/dist/lib/store/index.d.ts +68 -0
  41. package/dist/lib/{waku_store → store}/index.js +41 -16
  42. package/dist/lib/store/index.js.map +1 -0
  43. package/dist/lib/to_proto_message.d.ts +3 -3
  44. package/dist/lib/to_proto_message.js +1 -0
  45. package/dist/lib/to_proto_message.js.map +1 -1
  46. package/dist/lib/wait_for_remote_peer.js +14 -5
  47. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  48. package/dist/lib/waku.d.ts +17 -15
  49. package/dist/lib/waku.js +49 -41
  50. package/dist/lib/waku.js.map +1 -1
  51. package/package.json +28 -31
  52. package/src/index.ts +25 -14
  53. package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
  54. package/src/lib/{waku_filter → filter}/index.ts +51 -30
  55. package/src/lib/{waku_light_push → light_push}/index.ts +38 -19
  56. package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
  57. package/src/lib/{waku_message → message}/topic_only_message.ts +12 -7
  58. package/src/lib/{waku_message → message}/version_0.ts +59 -18
  59. package/src/lib/predefined_bootstrap_nodes.ts +2 -6
  60. package/src/lib/{waku_relay → relay}/constants.ts +0 -0
  61. package/src/lib/{waku_relay → relay}/index.ts +30 -26
  62. package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
  63. package/src/lib/{waku_store → store}/index.ts +93 -28
  64. package/src/lib/to_proto_message.ts +5 -5
  65. package/src/lib/wait_for_remote_peer.ts +19 -7
  66. package/src/lib/waku.ts +78 -51
  67. package/bundle/browser-1e1a2f27.js +0 -722
  68. package/bundle/events-158407bb.js +0 -1929
  69. package/bundle/index-64ce43f0.js +0 -69
  70. package/bundle/index-8710041d.js +0 -2962
  71. package/bundle/index-a67d7136.js +0 -4059
  72. package/bundle/lib/peer_discovery_static_list.js +0 -89
  73. package/bundle/lib/wait_for_remote_peer.js +0 -326
  74. package/bundle/lib/waku_message/topic_only_message.js +0 -3
  75. package/bundle/lib/waku_message/version_0.js +0 -317
  76. package/bundle/random_subset-75d1c511.js +0 -26
  77. package/bundle/topic_only_message-5ad3a869.js +0 -82
  78. package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
  79. package/dist/lib/multiaddr_to_peer_info.js +0 -15
  80. package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
  81. package/dist/lib/peer_discovery_static_list.d.ts +0 -44
  82. package/dist/lib/peer_discovery_static_list.js +0 -72
  83. package/dist/lib/peer_discovery_static_list.js.map +0 -1
  84. package/dist/lib/select_connection.d.ts +0 -2
  85. package/dist/lib/select_connection.js +0 -19
  86. package/dist/lib/select_connection.js.map +0 -1
  87. package/dist/lib/select_peer.d.ts +0 -15
  88. package/dist/lib/select_peer.js +0 -59
  89. package/dist/lib/select_peer.js.map +0 -1
  90. package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
  91. package/dist/lib/waku_filter/index.d.ts +0 -50
  92. package/dist/lib/waku_filter/index.js.map +0 -1
  93. package/dist/lib/waku_light_push/index.d.ts +0 -38
  94. package/dist/lib/waku_light_push/index.js.map +0 -1
  95. package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
  96. package/dist/lib/waku_message/topic_only_message.d.ts +0 -15
  97. package/dist/lib/waku_message/topic_only_message.js.map +0 -1
  98. package/dist/lib/waku_message/version_0.d.ts +0 -27
  99. package/dist/lib/waku_message/version_0.js.map +0 -1
  100. package/dist/lib/waku_relay/constants.js.map +0 -1
  101. package/dist/lib/waku_relay/index.d.ts +0 -66
  102. package/dist/lib/waku_relay/index.js.map +0 -1
  103. package/dist/lib/waku_store/history_rpc.js.map +0 -1
  104. package/dist/lib/waku_store/index.d.ts +0 -126
  105. package/dist/lib/waku_store/index.js.map +0 -1
  106. package/dist/proto/filter.d.ts +0 -65
  107. package/dist/proto/filter.js +0 -425
  108. package/dist/proto/filter.js.map +0 -1
  109. package/dist/proto/light_push.d.ts +0 -57
  110. package/dist/proto/light_push.js +0 -369
  111. package/dist/proto/light_push.js.map +0 -1
  112. package/dist/proto/message.d.ts +0 -29
  113. package/dist/proto/message.js +0 -215
  114. package/dist/proto/message.js.map +0 -1
  115. package/dist/proto/store.d.ts +0 -104
  116. package/dist/proto/store.js +0 -602
  117. package/dist/proto/store.js.map +0 -1
  118. package/dist/proto/topic_only_message.d.ts +0 -10
  119. package/dist/proto/topic_only_message.js +0 -46
  120. package/dist/proto/topic_only_message.js.map +0 -1
  121. package/src/lib/multiaddr_to_peer_info.ts +0 -17
  122. package/src/lib/peer_discovery_static_list.ts +0 -118
  123. package/src/lib/select_connection.ts +0 -24
  124. package/src/lib/select_peer.ts +0 -77
  125. package/src/proto/filter.ts +0 -602
  126. package/src/proto/light_push.ts +0 -526
  127. package/src/proto/message.ts +0 -304
  128. package/src/proto/store.ts +0 -844
  129. package/src/proto/topic_only_message.ts +0 -67
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- export { DefaultPubSubTopic } from "./lib/constants";
2
- export * as proto_message from "./proto/message";
3
- export * as proto_topic_only_message from "./proto/topic_only_message";
4
- export * as waku from "./lib/waku";
5
- export { WakuNode } from "./lib/waku";
6
- export * as waku_filter from "./lib/waku_filter";
7
- export { WakuFilter } from "./lib/waku_filter";
8
- export * as waku_light_push from "./lib/waku_light_push";
9
- export { WakuLightPush, LightPushCodec, PushResponse, } from "./lib/waku_light_push";
10
- export * as waku_relay from "./lib/waku_relay";
11
- export { WakuRelay } from "./lib/waku_relay";
12
- export * as waku_store from "./lib/waku_store";
13
- export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store";
1
+ export { DefaultPubSubTopic } from "./lib/constants.js";
2
+ export { DefaultUserAgent } from "./lib/waku.js";
3
+ export { createEncoder, createDecoder, DecodedMessage, } from "./lib/message/version_0.js";
4
+ export * as waku from "./lib/waku.js";
5
+ export { WakuNode } from "./lib/waku.js";
6
+ export * as waku_filter from "./lib/filter/index.js";
7
+ export { wakuFilter } from "./lib/filter/index.js";
8
+ export * as waku_light_push from "./lib/light_push/index.js";
9
+ export { wakuLightPush, LightPushCodec, PushResponse, } from "./lib/light_push/index.js";
10
+ export * as waku_relay from "./lib/relay/index.js";
11
+ export { wakuRelay } from "./lib/relay/index.js";
12
+ export * as waku_store from "./lib/store/index.js";
13
+ export { PageDirection, wakuStore, StoreCodec, createCursor, } from "./lib/store/index.js";
14
+ export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
1
  export { DefaultPubSubTopic } from "./lib/constants.js";
2
- export * as proto_message from "./proto/message.js";
3
- export * as proto_topic_only_message from "./proto/topic_only_message.js";
2
+ export { DefaultUserAgent } from "./lib/waku.js";
3
+ export { createEncoder, createDecoder, DecodedMessage, } from "./lib/message/version_0.js";
4
4
  export * as waku from "./lib/waku.js";
5
5
  export { WakuNode } from "./lib/waku.js";
6
- export * as waku_filter from "./lib/waku_filter/index.js";
7
- export { WakuFilter } from "./lib/waku_filter/index.js";
8
- export * as waku_light_push from "./lib/waku_light_push/index.js";
9
- export { WakuLightPush, LightPushCodec, PushResponse, } from "./lib/waku_light_push/index.js";
10
- export * as waku_relay from "./lib/waku_relay/index.js";
11
- export { WakuRelay } from "./lib/waku_relay/index.js";
12
- export * as waku_store from "./lib/waku_store/index.js";
13
- export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store/index.js";
6
+ export * as waku_filter from "./lib/filter/index.js";
7
+ export { wakuFilter } from "./lib/filter/index.js";
8
+ export * as waku_light_push from "./lib/light_push/index.js";
9
+ export { wakuLightPush, LightPushCodec, PushResponse, } from "./lib/light_push/index.js";
10
+ export * as waku_relay from "./lib/relay/index.js";
11
+ export { wakuRelay } from "./lib/relay/index.js";
12
+ export * as waku_store from "./lib/store/index.js";
13
+ export { PageDirection, wakuStore, StoreCodec, createCursor, } from "./lib/store/index.js";
14
+ export { waitForRemotePeer } from "./lib/wait_for_remote_peer.js";
14
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,wBAAwB,MAAM,4BAA4B,CAAC;AAEvE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,GACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,eAAe,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,GACb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACL,aAAa,EACb,SAAS,EACT,UAAU,EACV,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -1,4 +1,4 @@
1
- import * as proto from "../../proto/filter";
1
+ import { proto_filter as proto } from "@waku/proto";
2
2
  export declare type ContentFilter = {
3
3
  contentTopic: string;
4
4
  };
@@ -1,5 +1,5 @@
1
+ import { proto_filter as proto } from "@waku/proto";
1
2
  import { v4 as uuid } from "uuid";
2
- import * as proto from "../../proto/filter.js";
3
3
  /**
4
4
  * FilterRPC represents a message conforming to the Waku Filter protocol
5
5
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter_rpc.js","sourceRoot":"","sources":["../../../src/lib/filter/filter_rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAMlC;;GAEG;AACH,MAAM,OAAO,SAAS;IACpB,YAA0B,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;IAAG,CAAC;IAEpD,MAAM,CAAC,aAAa,CAClB,KAAa,EACb,cAA+B,EAC/B,SAAkB,EAClB,SAAS,GAAG,IAAI;QAEhB,OAAO,IAAI,SAAS,CAAC;YACnB,SAAS,EAAE,SAAS,IAAI,IAAI,EAAE;YAC9B,OAAO,EAAE;gBACP,SAAS;gBACT,KAAK;gBACL,cAAc;aACf;YACD,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,KAAiB;QAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerStore } from "@libp2p/interface-peer-store";
3
+ import type { Registrar } from "@libp2p/interface-registrar";
4
+ import type { IFilter } from "@waku/interfaces";
5
+ import { ContentFilter } from "./filter_rpc.js";
6
+ export { ContentFilter };
7
+ export declare const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
8
+ export interface FilterComponents {
9
+ peerStore: PeerStore;
10
+ registrar: Registrar;
11
+ connectionManager: ConnectionManager;
12
+ }
13
+ export interface CreateOptions {
14
+ /**
15
+ * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
16
+ *
17
+ * The usage of the default pubsub topic is recommended.
18
+ * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
19
+ *
20
+ * @default {@link DefaultPubSubTopic}
21
+ */
22
+ pubSubTopic?: string;
23
+ }
24
+ export declare type UnsubscribeFunction = () => Promise<void>;
25
+ export declare function wakuFilter(init?: Partial<CreateOptions>): (components: FilterComponents) => IFilter;
@@ -1,11 +1,10 @@
1
+ import { getPeersForProtocol, selectConnection, selectPeerForProtocol, selectRandomPeer, } from "@waku/libp2p-utils";
1
2
  import debug from "debug";
2
3
  import all from "it-all";
3
4
  import * as lp from "it-length-prefixed";
4
5
  import { pipe } from "it-pipe";
5
6
  import { DefaultPubSubTopic } from "../constants.js";
6
7
  import { groupByContentTopic } from "../group_by.js";
7
- import { selectConnection } from "../select_connection.js";
8
- import { getPeersForProtocol, selectPeerForProtocol, selectRandomPeer, } from "../select_peer.js";
9
8
  import { toProtoMessage } from "../to_proto_message.js";
10
9
  import { FilterRPC } from "./filter_rpc.js";
11
10
  export const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
@@ -17,13 +16,13 @@ const log = debug("waku:filter");
17
16
  * - https://github.com/status-im/go-waku/issues/245
18
17
  * - https://github.com/status-im/nwaku/issues/948
19
18
  */
20
- export class WakuFilter {
21
- constructor(libp2p, options) {
22
- this.libp2p = libp2p;
19
+ class Filter {
20
+ constructor(components, options) {
21
+ this.components = components;
23
22
  this.subscriptions = new Map();
24
23
  this.decoders = new Map();
25
24
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
26
- this.libp2p
25
+ this.components.registrar
27
26
  .handle(FilterCodec, this.onRequest.bind(this))
28
27
  .catch((e) => log("Failed to register filter protocol", e));
29
28
  }
@@ -62,6 +61,9 @@ export class WakuFilter {
62
61
  this.deleteCallback(requestId);
63
62
  };
64
63
  }
64
+ get peerStore() {
65
+ return this.components.peerStore;
66
+ }
65
67
  onRequest(streamData) {
66
68
  log("Receiving message push");
67
69
  try {
@@ -157,7 +159,7 @@ export class WakuFilter {
157
159
  }
158
160
  }
159
161
  async newStream(peer) {
160
- const connections = this.libp2p.connectionManager.getConnections(peer.id);
162
+ const connections = this.components.connectionManager.getConnections(peer.id);
161
163
  const connection = selectConnection(connections);
162
164
  if (!connection) {
163
165
  throw new Error("Failed to get a connection to the peer");
@@ -165,17 +167,20 @@ export class WakuFilter {
165
167
  return connection.newStream(FilterCodec);
166
168
  }
167
169
  async getPeer(peerId) {
168
- const res = await selectPeerForProtocol(this.libp2p.peerStore, [FilterCodec], peerId);
170
+ const res = await selectPeerForProtocol(this.components.peerStore, [FilterCodec], peerId);
169
171
  if (!res) {
170
172
  throw new Error(`Failed to select peer for ${FilterCodec}`);
171
173
  }
172
174
  return res.peer;
173
175
  }
174
176
  async peers() {
175
- return getPeersForProtocol(this.libp2p.peerStore, [FilterCodec]);
177
+ return getPeersForProtocol(this.components.peerStore, [FilterCodec]);
176
178
  }
177
179
  async randomPeer() {
178
180
  return selectRandomPeer(await this.peers());
179
181
  }
180
182
  }
183
+ export function wakuFilter(init = {}) {
184
+ return (components) => new Filter(components, init);
185
+ }
181
186
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/filter/index.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAiB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI3D,MAAM,CAAC,MAAM,WAAW,GAAG,8BAA8B,CAAC;AAE1D,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;AAsBjC;;;;;;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U,CAAC,SAAS,EACzB,CAAC,WAAW,CAAC,EACb,MAAM,CACP,CAAC;QACF,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,EAAE,CAAC,CAAC;SAC7D;QACD,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,gBAAgB,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CACxB,OAA+B,EAAE;IAEjC,OAAO,CAAC,UAA4B,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { ConnectionManager } from "@libp2p/interface-connection-manager";
2
+ import type { PeerStore } from "@libp2p/interface-peer-store";
3
+ import type { ILightPush } from "@waku/interfaces";
4
+ import { PushResponse } from "@waku/proto";
5
+ export declare const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
6
+ export { PushResponse };
7
+ export interface LightPushComponents {
8
+ peerStore: PeerStore;
9
+ connectionManager: ConnectionManager;
10
+ }
11
+ export interface CreateOptions {
12
+ /**
13
+ * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
14
+ *
15
+ * The usage of the default pubsub topic is recommended.
16
+ * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
17
+ *
18
+ * @default {@link DefaultPubSubTopic}
19
+ */
20
+ pubSubTopic?: string;
21
+ }
22
+ export declare function wakuLightPush(init?: Partial<CreateOptions>): (components: LightPushComponents) => ILightPush;
@@ -1,12 +1,11 @@
1
+ import { getPeersForProtocol, selectConnection, selectPeerForProtocol, selectRandomPeer, } from "@waku/libp2p-utils";
2
+ import { PushResponse } from "@waku/proto";
1
3
  import debug from "debug";
2
4
  import all from "it-all";
3
5
  import * as lp from "it-length-prefixed";
4
6
  import { pipe } from "it-pipe";
5
7
  import { Uint8ArrayList } from "uint8arraylist";
6
- import { PushResponse } from "../../proto/light_push.js";
7
8
  import { DefaultPubSubTopic } from "../constants.js";
8
- import { selectConnection } from "../select_connection.js";
9
- import { getPeersForProtocol, selectPeerForProtocol, selectRandomPeer, } from "../select_peer.js";
10
9
  import { PushRPC } from "./push_rpc.js";
11
10
  const log = debug("waku:light-push");
12
11
  export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
@@ -14,19 +13,19 @@ export { PushResponse };
14
13
  /**
15
14
  * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
16
15
  */
17
- export class WakuLightPush {
18
- constructor(libp2p, options) {
19
- this.libp2p = libp2p;
16
+ class LightPush {
17
+ constructor(components, options) {
18
+ this.components = components;
20
19
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
21
20
  }
22
21
  async push(encoder, message, opts) {
23
22
  const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic;
24
- const res = await selectPeerForProtocol(this.libp2p.peerStore, [LightPushCodec], opts?.peerId);
23
+ const res = await selectPeerForProtocol(this.components.peerStore, [LightPushCodec], opts?.peerId);
25
24
  if (!res) {
26
25
  throw new Error("Failed to get a peer");
27
26
  }
28
27
  const { peer } = res;
29
- const connections = this.libp2p.connectionManager.getConnections(peer.id);
28
+ const connections = this.components.connectionManager.getConnections(peer.id);
30
29
  const connection = selectConnection(connections);
31
30
  if (!connection)
32
31
  throw "Failed to get a connection to the peer";
@@ -69,7 +68,7 @@ export class WakuLightPush {
69
68
  * peers.
70
69
  */
71
70
  async peers() {
72
- return getPeersForProtocol(this.libp2p.peerStore, [LightPushCodec]);
71
+ return getPeersForProtocol(this.components.peerStore, [LightPushCodec]);
73
72
  }
74
73
  /**
75
74
  * Returns a random peer that supports light push protocol from the address
@@ -79,5 +78,11 @@ export class WakuLightPush {
79
78
  async randomPeer() {
80
79
  return selectRandomPeer(await this.peers());
81
80
  }
81
+ get peerStore() {
82
+ return this.components.peerStore;
83
+ }
84
+ }
85
+ export function wakuLightPush(init = {}) {
86
+ return (components) => new LightPush(components, init);
82
87
  }
83
88
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/light_push/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,GAAG,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,CAAC;AAmBxB;;GAEG;AACH,MAAM,SAAS;IAGb,YAAmB,UAA+B,EAAE,OAAuB;QAAxD,eAAU,GAAV,UAAU,CAAqB;QAChD,IAAI,CAAC,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,kBAAkB,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,IAAI,CACR,OAAiB,EACjB,OAAiB,EACjB,IAAsB;QAEtB,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,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";
2
- import * as proto from "../../proto/light_push";
3
3
  export declare class PushRPC {
4
4
  proto: proto.PushRPC;
5
5
  constructor(proto: proto.PushRPC);
@@ -1,5 +1,5 @@
1
+ import { proto_lightpush as proto } from "@waku/proto";
1
2
  import { v4 as uuid } from "uuid";
2
- import * as proto from "../../proto/light_push.js";
3
3
  export class PushRPC {
4
4
  constructor(proto) {
5
5
  this.proto = proto;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push_rpc.js","sourceRoot":"","sources":["../../../src/lib/light_push/push_rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,OAAO,OAAO;IAClB,YAA0B,KAAoB;QAApB,UAAK,GAAL,KAAK,CAAe;IAAG,CAAC;IAElD,MAAM,CAAC,aAAa,CAClB,OAA0B,EAC1B,WAAmB;QAEnB,OAAO,IAAI,OAAO,CAAC;YACjB,SAAS,EAAE,IAAI,EAAE;YACjB,OAAO,EAAE;gBACP,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE,WAAW;aACzB;YACD,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAqB;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { IDecodedMessage, IDecoder, IProtoMessage } from "@waku/interfaces";
2
+ import { proto_topic_only_message as proto } from "@waku/proto";
3
+ export declare class TopicOnlyMessage implements IDecodedMessage {
4
+ private proto;
5
+ payload: undefined;
6
+ rateLimitProof: undefined;
7
+ timestamp: undefined;
8
+ ephemeral: undefined;
9
+ constructor(proto: proto.TopicOnlyMessage);
10
+ get contentTopic(): string;
11
+ }
12
+ export declare class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
13
+ contentTopic: string;
14
+ fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined>;
15
+ fromProtoObj(proto: IProtoMessage): Promise<TopicOnlyMessage | undefined>;
16
+ }
@@ -1,5 +1,5 @@
1
+ import { proto_topic_only_message as proto } from "@waku/proto";
1
2
  import debug from "debug";
2
- import * as proto from "../../proto/topic_only_message.js";
3
3
  const log = debug("waku:message:topic-only");
4
4
  export class TopicOnlyMessage {
5
5
  constructor(proto) {
@@ -22,6 +22,7 @@ export class TopicOnlyDecoder {
22
22
  rateLimitProof: undefined,
23
23
  timestamp: undefined,
24
24
  version: undefined,
25
+ ephemeral: undefined,
25
26
  });
26
27
  }
27
28
  async fromProtoObj(proto) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic_only_message.js","sourceRoot":"","sources":["../../../src/lib/message/topic_only_message.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C,MAAM,OAAO,gBAAgB;IAM3B,YAAoB,KAA6B;QAA7B,UAAK,GAAL,KAAK,CAAwB;IAAG,CAAC;IAErD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IAA7B;QACS,iBAAY,GAAG,EAAE,CAAC;IAoB3B,CAAC;IAlBC,kBAAkB,CAAC,KAAiB;QAClC,MAAM,YAAY,GAAG,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1D,GAAG,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,YAAY,EAAE,YAAY,CAAC,YAAY;YACvC,OAAO,EAAE,SAAS;YAClB,cAAc,EAAE,SAAS;YACzB,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,KAAoB;QAEpB,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ import type { IDecodedMessage, IDecoder, IEncoder, IMessage, IProtoMessage, IRateLimitProof } from "@waku/interfaces";
2
+ import { proto_message as proto } from "@waku/proto";
3
+ export declare const Version = 0;
4
+ export { proto };
5
+ export declare class DecodedMessage implements IDecodedMessage {
6
+ protected proto: proto.WakuMessage;
7
+ constructor(proto: proto.WakuMessage);
8
+ get _rawPayload(): Uint8Array | undefined;
9
+ get ephemeral(): boolean;
10
+ get payload(): Uint8Array | undefined;
11
+ get contentTopic(): string | undefined;
12
+ get _rawTimestamp(): bigint | undefined;
13
+ get timestamp(): Date | undefined;
14
+ get version(): number;
15
+ get rateLimitProof(): IRateLimitProof | undefined;
16
+ }
17
+ export declare class Encoder implements IEncoder {
18
+ contentTopic: string;
19
+ ephemeral: boolean;
20
+ constructor(contentTopic: string, ephemeral?: boolean);
21
+ toWire(message: IMessage): Promise<Uint8Array>;
22
+ toProtoObj(message: IMessage): Promise<IProtoMessage>;
23
+ }
24
+ /**
25
+ * Creates an encoder that encode messages without Waku level encryption or signature.
26
+ *
27
+ * An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
28
+ * format to be sent over the Waku network. The resulting encoder can then be
29
+ * pass to { @link @waku/interfaces.LightPush.push } or
30
+ * { @link @waku/interfaces.Relay.send } to automatically encode outgoing
31
+ * messages.
32
+ *
33
+ * @param contentTopic The content topic to set on outgoing messages.
34
+ * @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
35
+ */
36
+ export declare function createEncoder(contentTopic: string, ephemeral?: boolean): Encoder;
37
+ export declare class Decoder implements IDecoder<DecodedMessage> {
38
+ contentTopic: string;
39
+ constructor(contentTopic: string);
40
+ fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined>;
41
+ fromProtoObj(proto: IProtoMessage): Promise<DecodedMessage | undefined>;
42
+ }
43
+ /**
44
+ * Creates an decoder that decode messages without Waku level encryption.
45
+ *
46
+ * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
47
+ * format when received from the Waku network. The resulting decoder can then be
48
+ * pass to { @link @waku/interfaces.Filter.subscribe } or
49
+ * { @link @waku/interfaces.Relay.subscribe } to automatically decode incoming
50
+ * messages.
51
+ *
52
+ * @param contentTopic The resulting decoder will only decode messages with this content topic.
53
+ */
54
+ export declare function createDecoder(contentTopic: string): Decoder;
@@ -1,10 +1,10 @@
1
+ import { proto_message as proto } from "@waku/proto";
1
2
  import debug from "debug";
2
- import * as proto from "../../proto/message.js";
3
3
  const log = debug("waku:message:version-0");
4
4
  const OneMillion = BigInt(1000000);
5
5
  export const Version = 0;
6
6
  export { proto };
7
- export class MessageV0 {
7
+ export class DecodedMessage {
8
8
  constructor(proto) {
9
9
  this.proto = proto;
10
10
  }
@@ -14,6 +14,9 @@ export class MessageV0 {
14
14
  }
15
15
  return;
16
16
  }
17
+ get ephemeral() {
18
+ return Boolean(this.proto.ephemeral);
19
+ }
17
20
  get payload() {
18
21
  return this._rawPayload;
19
22
  }
@@ -49,9 +52,10 @@ export class MessageV0 {
49
52
  return this.proto.rateLimitProof;
50
53
  }
51
54
  }
52
- export class EncoderV0 {
53
- constructor(contentTopic) {
55
+ export class Encoder {
56
+ constructor(contentTopic, ephemeral = false) {
54
57
  this.contentTopic = contentTopic;
58
+ this.ephemeral = ephemeral;
55
59
  }
56
60
  async toWire(message) {
57
61
  return proto.WakuMessage.encode(await this.toProtoObj(message));
@@ -64,10 +68,26 @@ export class EncoderV0 {
64
68
  contentTopic: this.contentTopic,
65
69
  timestamp: BigInt(timestamp.valueOf()) * OneMillion,
66
70
  rateLimitProof: message.rateLimitProof,
71
+ ephemeral: this.ephemeral,
67
72
  };
68
73
  }
69
74
  }
70
- export class DecoderV0 {
75
+ /**
76
+ * Creates an encoder that encode messages without Waku level encryption or signature.
77
+ *
78
+ * An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
79
+ * format to be sent over the Waku network. The resulting encoder can then be
80
+ * pass to { @link @waku/interfaces.LightPush.push } or
81
+ * { @link @waku/interfaces.Relay.send } to automatically encode outgoing
82
+ * messages.
83
+ *
84
+ * @param contentTopic The content topic to set on outgoing messages.
85
+ * @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
86
+ */
87
+ export function createEncoder(contentTopic, ephemeral = false) {
88
+ return new Encoder(contentTopic, ephemeral);
89
+ }
90
+ export class Decoder {
71
91
  constructor(contentTopic) {
72
92
  this.contentTopic = contentTopic;
73
93
  }
@@ -80,6 +100,7 @@ export class DecoderV0 {
80
100
  version: protoMessage.version ?? undefined,
81
101
  timestamp: protoMessage.timestamp ?? undefined,
82
102
  rateLimitProof: protoMessage.rateLimitProof ?? undefined,
103
+ ephemeral: protoMessage.ephemeral ?? false,
83
104
  });
84
105
  }
85
106
  async fromProtoObj(proto) {
@@ -91,7 +112,21 @@ export class DecoderV0 {
91
112
  log("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
92
113
  return Promise.resolve(undefined);
93
114
  }
94
- return new MessageV0(proto);
115
+ return new DecodedMessage(proto);
95
116
  }
96
117
  }
118
+ /**
119
+ * Creates an decoder that decode messages without Waku level encryption.
120
+ *
121
+ * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
122
+ * format when received from the Waku network. The resulting decoder can then be
123
+ * pass to { @link @waku/interfaces.Filter.subscribe } or
124
+ * { @link @waku/interfaces.Relay.subscribe } to automatically decode incoming
125
+ * messages.
126
+ *
127
+ * @param contentTopic The resulting decoder will only decode messages with this content topic.
128
+ */
129
+ export function createDecoder(contentTopic) {
130
+ return new Decoder(contentTopic);
131
+ }
97
132
  //# sourceMappingURL=version_0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version_0.js","sourceRoot":"","sources":["../../../src/lib/message/version_0.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAS,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,MAAM,OAAO,cAAc;IACzB,YAAsB,KAAwB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IAElD,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;YACtB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC3C;QACD,OAAO;IACT,CAAC;IAED,IAAI,SAAS;QACX,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,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AAG,CACD,sDAAsD,EACtD,OAAO,EACP,WAAW,EACX,KAAK,CAAC,OAAO,CACd,CAAC;YACF,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACnC;QAED,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,YAAoB;IAChD,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;AACnC,CAAC"}
@@ -1,4 +1,3 @@
1
- import type { Multiaddr } from "@multiformats/multiaddr";
2
1
  export declare const DefaultWantedNumber = 1;
3
2
  export declare enum Fleet {
4
3
  Prod = "prod",
@@ -14,7 +13,7 @@ export declare enum Fleet {
14
13
  *
15
14
  * @returns An array of multiaddresses.
16
15
  */
17
- export declare function getPredefinedBootstrapNodes(fleet?: Fleet, wantedNumber?: number): Multiaddr[];
16
+ export declare function getPredefinedBootstrapNodes(fleet?: Fleet, wantedNumber?: number): string[];
18
17
  export declare const fleets: {
19
18
  fleets: {
20
19
  "wakuv2.prod": {
@@ -1,4 +1,3 @@
1
- import { multiaddr } from "@multiformats/multiaddr";
2
1
  import { getPseudoRandomSubset } from "./random_subset.js";
3
2
  export const DefaultWantedNumber = 1;
4
3
  export var Fleet;
@@ -32,7 +31,6 @@ export function getPredefinedBootstrapNodes(fleet = Fleet.Prod, wantedNumber = D
32
31
  nodes = fleets.fleets["wakuv2.prod"]["waku-websocket"];
33
32
  }
34
33
  nodes = Object.values(nodes);
35
- nodes = nodes.map((node) => multiaddr(node));
36
34
  return getPseudoRandomSubset(nodes, wantedNumber);
37
35
  }
38
36
  export const fleets = {
@@ -1 +1 @@
1
- {"version":3,"file":"predefined_bootstrap_nodes.js","sourceRoot":"","sources":["../../src/lib/predefined_bootstrap_nodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,qBAAqB,EAAE,M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gBACjI,6BAA6B,EAC3B,sHAAsH;gBACxH,sCAAsC,EACpC,+HAA+H;aAClI;SACF;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"predefined_bootstrap_nodes.js","sourceRoot":"","sources":["../../src/lib/predefined_bootstrap_nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,MAAM,CAAN,IAAY,KAGX;AAHD,WAAY,KAAK;IACf,sBAAa,CAAA;IACb,sBAAa,CAAA;AACf,CAAC,EAHW,KAAK,KAAL,KAAK,QAGhB;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAe,KAAK,CAAC,IAAI,EACzB,eAAuB,mBAAmB;IAE1C,IAAI,YAAY,IAAI,CAAC,EAAE;QACrB,OAAO,EAAE,CAAC;KACX;IAED,IAAI,KAAK,CAAC;IACV,QAAQ,KAAK,EAAE;QACb,KAAK,KAAK,CAAC,IAAI;YACb,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAAC;YACvD,MAAM;QACR,KAAK,KAAK,CAAC,IAAI;YACb,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAAC;YACvD,MAAM;QACR;YACE,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAAC;KAC1D;IAED,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAa,CAAC;IAEzC,OAAO,qBAAqB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM,EAAE;QACN,aAAa,EAAE;YACb,gBAAgB,EAAE;gBAChB,sCAAsC,EACpC,+HAA+H;gBACjI,6BAA6B,EAC3B,sHAAsH;gBACxH,sCAAsC,EACpC,+HAA+H;aAClI;SACF;QACD,aAAa,EAAE;YACb,gBAAgB,EAAE;gBAChB,sCAAsC,EACpC,+HAA+H;gBACjI,6BAA6B,EAC3B,sHAAsH;gBACxH,sCAAsC,EACpC,+HAA+H;aAClI;SACF;KACF;CACF,CAAC"}
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/relay/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,6BAA6B;IAC7B,uBAAuB;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { GossipSubComponents, GossipsubOpts } from "@chainsafe/libp2p-gossipsub";
2
+ import type { Callback, IDecoder, IRelay } from "@waku/interfaces";
3
+ import { IDecodedMessage } from "@waku/interfaces";
4
+ export declare type Observer<T extends IDecodedMessage> = {
5
+ decoder: IDecoder<T>;
6
+ callback: Callback<T>;
7
+ };
8
+ export declare type CreateOptions = {
9
+ /**
10
+ * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
11
+ *
12
+ * One and only one pubsub topic is used by Waku. This is used by:
13
+ * - WakuRelay to receive, route and send messages,
14
+ * - WakuLightPush to send messages,
15
+ * - WakuStore to retrieve messages.
16
+ *
17
+ * The usage of the default pubsub topic is recommended.
18
+ * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
19
+ *
20
+ * @default {@link DefaultPubSubTopic}
21
+ */
22
+ pubSubTopic?: string;
23
+ } & GossipsubOpts;
24
+ export declare function wakuRelay(init?: Partial<CreateOptions>): (components: GossipSubComponents) => IRelay;
@@ -2,8 +2,8 @@ import { GossipSub, } from "@chainsafe/libp2p-gossipsub";
2
2
  import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types";
3
3
  import debug from "debug";
4
4
  import { DefaultPubSubTopic } from "../constants.js";
5
+ import { TopicOnlyDecoder } from "../message/topic_only_message.js";
5
6
  import { pushOrInitMapSet } from "../push_or_init_map.js";
6
- import { TopicOnlyDecoder } from "../waku_message/topic_only_message.js";
7
7
  import * as constants from "./constants.js";
8
8
  const log = debug("waku:relay");
9
9
  /**
@@ -12,14 +12,14 @@ const log = debug("waku:relay");
12
12
  *
13
13
  * @implements {require('libp2p-interfaces/src/pubsub')}
14
14
  */
15
- export class WakuRelay extends GossipSub {
16
- constructor(options) {
15
+ class Relay extends GossipSub {
16
+ constructor(components, options) {
17
17
  options = Object.assign(options ?? {}, {
18
18
  // Ensure that no signature is included nor expected in the messages.
19
19
  globalSignaturePolicy: SignaturePolicy.StrictNoSign,
20
20
  fallbackToFloodsub: false,
21
21
  });
22
- super(options);
22
+ super(components, options);
23
23
  this.multicodecs = constants.RelayCodecs;
24
24
  this.observers = new Map();
25
25
  this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
@@ -106,6 +106,9 @@ export class WakuRelay extends GossipSub {
106
106
  return super.getMeshPeers(topic ?? this.pubSubTopic);
107
107
  }
108
108
  }
109
- WakuRelay.multicodec = constants.RelayCodecs[0];
110
- WakuRelay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
109
+ Relay.multicodec = constants.RelayCodecs[0];
110
+ Relay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
111
+ export function wakuRelay(init = {}) {
112
+ return (components) => new Relay(components, init);
113
+ }
111
114
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,GAIV,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAUpE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAwBhC;;;;;GAKG;AACH,MAAM,KAAM,SAAQ,SAAS;IAW3B,YACE,UAA+B,EAC/B,OAAgC;QAEhC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE;YACrC,qEAAqE;YACrE,qBAAqB,EAAE,eAAe,CAAC,YAAY;YACnD,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;QACH,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,S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