@waku/core 0.0.1

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 (235) hide show
  1. package/CHANGELOG.md +614 -0
  2. package/README.md +56 -0
  3. package/bundle/browser-1e1a2f27.js +722 -0
  4. package/bundle/crypto-8551d579.js +2585 -0
  5. package/bundle/crypto-b00764b7.js +1772 -0
  6. package/bundle/enr-564d4a51.js +20785 -0
  7. package/bundle/enr-9fc5eed8.js +20786 -0
  8. package/bundle/enr-f6e82a53.js +20785 -0
  9. package/bundle/events-158407bb.js +1929 -0
  10. package/bundle/events-fcbda4dc.js +76 -0
  11. package/bundle/index-02d21809.js +20 -0
  12. package/bundle/index-0a4bdddc.js +2976 -0
  13. package/bundle/index-2ae915be.js +1854 -0
  14. package/bundle/index-64ce43f0.js +69 -0
  15. package/bundle/index-691c0be6.js +4059 -0
  16. package/bundle/index-a013a259.js +20 -0
  17. package/bundle/index-ba42b4fc.js +862 -0
  18. package/bundle/index.js +13428 -0
  19. package/bundle/lib/enr.js +8 -0
  20. package/bundle/lib/peer_discovery_dns.js +5018 -0
  21. package/bundle/lib/peer_discovery_static_list.js +75 -0
  22. package/bundle/lib/predefined_bootstrap_nodes.js +59 -0
  23. package/bundle/lib/utils.js +1 -0
  24. package/bundle/lib/wait_for_remote_peer.js +327 -0
  25. package/bundle/lib/waku_message/topic_only_message.js +4 -0
  26. package/bundle/lib/waku_message/version_0.js +4 -0
  27. package/bundle/lib/waku_message/version_1.js +463 -0
  28. package/bundle/message-e2db79d7.js +8393 -0
  29. package/bundle/multiaddr_to_peer_info-c406b1e1.js +19 -0
  30. package/bundle/multiaddr_to_peer_info-fd1de516.js +19 -0
  31. package/bundle/random_subset-75d1c511.js +26 -0
  32. package/bundle/topic_only_message-34f36fa6.js +82 -0
  33. package/bundle/utils-9a3221f2.js +815 -0
  34. package/bundle/version_0-e6fe440c.js +317 -0
  35. package/dist/index.d.ts +16 -0
  36. package/dist/index.js +17 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/lib/constants.d.ts +4 -0
  39. package/dist/lib/constants.js +5 -0
  40. package/dist/lib/constants.js.map +1 -0
  41. package/dist/lib/crypto.d.ts +34 -0
  42. package/dist/lib/crypto.js +79 -0
  43. package/dist/lib/crypto.js.map +1 -0
  44. package/dist/lib/enr/constants.d.ts +4 -0
  45. package/dist/lib/enr/constants.js +8 -0
  46. package/dist/lib/enr/constants.js.map +1 -0
  47. package/dist/lib/enr/enr.d.ts +90 -0
  48. package/dist/lib/enr/enr.js +432 -0
  49. package/dist/lib/enr/enr.js.map +1 -0
  50. package/dist/lib/enr/index.d.ts +5 -0
  51. package/dist/lib/enr/index.js +6 -0
  52. package/dist/lib/enr/index.js.map +1 -0
  53. package/dist/lib/enr/keypair/index.d.ts +8 -0
  54. package/dist/lib/enr/keypair/index.js +53 -0
  55. package/dist/lib/enr/keypair/index.js.map +1 -0
  56. package/dist/lib/enr/keypair/secp256k1.d.ts +13 -0
  57. package/dist/lib/enr/keypair/secp256k1.js +57 -0
  58. package/dist/lib/enr/keypair/secp256k1.js.map +1 -0
  59. package/dist/lib/enr/keypair/types.d.ts +13 -0
  60. package/dist/lib/enr/keypair/types.js +7 -0
  61. package/dist/lib/enr/keypair/types.js.map +1 -0
  62. package/dist/lib/enr/multiaddr_from_fields.d.ts +2 -0
  63. package/dist/lib/enr/multiaddr_from_fields.js +8 -0
  64. package/dist/lib/enr/multiaddr_from_fields.js.map +1 -0
  65. package/dist/lib/enr/multiaddrs_codec.d.ts +3 -0
  66. package/dist/lib/enr/multiaddrs_codec.js +32 -0
  67. package/dist/lib/enr/multiaddrs_codec.js.map +1 -0
  68. package/dist/lib/enr/types.d.ts +8 -0
  69. package/dist/lib/enr/types.js +3 -0
  70. package/dist/lib/enr/types.js.map +1 -0
  71. package/dist/lib/enr/v4.d.ts +3 -0
  72. package/dist/lib/enr/v4.js +14 -0
  73. package/dist/lib/enr/v4.js.map +1 -0
  74. package/dist/lib/enr/waku2_codec.d.ts +8 -0
  75. package/dist/lib/enr/waku2_codec.js +36 -0
  76. package/dist/lib/enr/waku2_codec.js.map +1 -0
  77. package/dist/lib/group_by.d.ts +3 -0
  78. package/dist/lib/group_by.js +13 -0
  79. package/dist/lib/group_by.js.map +1 -0
  80. package/dist/lib/multiaddr_to_peer_info.d.ts +3 -0
  81. package/dist/lib/multiaddr_to_peer_info.js +15 -0
  82. package/dist/lib/multiaddr_to_peer_info.js.map +1 -0
  83. package/dist/lib/peer_discovery_dns/dns.d.ts +48 -0
  84. package/dist/lib/peer_discovery_dns/dns.js +158 -0
  85. package/dist/lib/peer_discovery_dns/dns.js.map +1 -0
  86. package/dist/lib/peer_discovery_dns/dns_over_https.d.ts +32 -0
  87. package/dist/lib/peer_discovery_dns/dns_over_https.js +87 -0
  88. package/dist/lib/peer_discovery_dns/dns_over_https.js.map +1 -0
  89. package/dist/lib/peer_discovery_dns/enrtree.d.ts +33 -0
  90. package/dist/lib/peer_discovery_dns/enrtree.js +76 -0
  91. package/dist/lib/peer_discovery_dns/enrtree.js.map +1 -0
  92. package/dist/lib/peer_discovery_dns/fetch_nodes.d.ts +14 -0
  93. package/dist/lib/peer_discovery_dns/fetch_nodes.js +133 -0
  94. package/dist/lib/peer_discovery_dns/fetch_nodes.js.map +1 -0
  95. package/dist/lib/peer_discovery_dns/index.d.ts +30 -0
  96. package/dist/lib/peer_discovery_dns/index.js +54 -0
  97. package/dist/lib/peer_discovery_dns/index.js.map +1 -0
  98. package/dist/lib/peer_discovery_static_list.d.ts +44 -0
  99. package/dist/lib/peer_discovery_static_list.js +72 -0
  100. package/dist/lib/peer_discovery_static_list.js.map +1 -0
  101. package/dist/lib/predefined_bootstrap_nodes.d.ts +35 -0
  102. package/dist/lib/predefined_bootstrap_nodes.js +56 -0
  103. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -0
  104. package/dist/lib/push_or_init_map.d.ts +1 -0
  105. package/dist/lib/push_or_init_map.js +9 -0
  106. package/dist/lib/push_or_init_map.js.map +1 -0
  107. package/dist/lib/random_subset.d.ts +4 -0
  108. package/dist/lib/random_subset.js +25 -0
  109. package/dist/lib/random_subset.js.map +1 -0
  110. package/dist/lib/select_connection.d.ts +2 -0
  111. package/dist/lib/select_connection.js +19 -0
  112. package/dist/lib/select_connection.js.map +1 -0
  113. package/dist/lib/select_peer.d.ts +15 -0
  114. package/dist/lib/select_peer.js +59 -0
  115. package/dist/lib/select_peer.js.map +1 -0
  116. package/dist/lib/to_proto_message.d.ts +3 -0
  117. package/dist/lib/to_proto_message.js +11 -0
  118. package/dist/lib/to_proto_message.js.map +1 -0
  119. package/dist/lib/utils.d.ts +22 -0
  120. package/dist/lib/utils.js +40 -0
  121. package/dist/lib/utils.js.map +1 -0
  122. package/dist/lib/wait_for_remote_peer.d.ts +22 -0
  123. package/dist/lib/wait_for_remote_peer.js +113 -0
  124. package/dist/lib/wait_for_remote_peer.js.map +1 -0
  125. package/dist/lib/waku.d.ts +61 -0
  126. package/dist/lib/waku.js +174 -0
  127. package/dist/lib/waku.js.map +1 -0
  128. package/dist/lib/waku_filter/filter_rpc.d.ts +25 -0
  129. package/dist/lib/waku_filter/filter_rpc.js +44 -0
  130. package/dist/lib/waku_filter/filter_rpc.js.map +1 -0
  131. package/dist/lib/waku_filter/index.d.ts +50 -0
  132. package/dist/lib/waku_filter/index.js +181 -0
  133. package/dist/lib/waku_filter/index.js.map +1 -0
  134. package/dist/lib/waku_light_push/index.d.ts +38 -0
  135. package/dist/lib/waku_light_push/index.js +83 -0
  136. package/dist/lib/waku_light_push/index.js.map +1 -0
  137. package/dist/lib/waku_light_push/push_rpc.d.ts +11 -0
  138. package/dist/lib/waku_light_push/push_rpc.js +31 -0
  139. package/dist/lib/waku_light_push/push_rpc.js.map +1 -0
  140. package/dist/lib/waku_message/constants.d.ts +12 -0
  141. package/dist/lib/waku_message/constants.js +10 -0
  142. package/dist/lib/waku_message/constants.js.map +1 -0
  143. package/dist/lib/waku_message/ecies.d.ts +17 -0
  144. package/dist/lib/waku_message/ecies.js +126 -0
  145. package/dist/lib/waku_message/ecies.js.map +1 -0
  146. package/dist/lib/waku_message/symmetric.d.ts +3 -0
  147. package/dist/lib/waku_message/symmetric.js +18 -0
  148. package/dist/lib/waku_message/symmetric.js.map +1 -0
  149. package/dist/lib/waku_message/topic_only_message.d.ts +15 -0
  150. package/dist/lib/waku_message/topic_only_message.js +31 -0
  151. package/dist/lib/waku_message/topic_only_message.js.map +1 -0
  152. package/dist/lib/waku_message/version_0.d.ts +26 -0
  153. package/dist/lib/waku_message/version_0.js +96 -0
  154. package/dist/lib/waku_message/version_0.js.map +1 -0
  155. package/dist/lib/waku_message/version_1.d.ts +93 -0
  156. package/dist/lib/waku_message/version_1.js +325 -0
  157. package/dist/lib/waku_message/version_1.js.map +1 -0
  158. package/dist/lib/waku_relay/constants.d.ts +63 -0
  159. package/dist/lib/waku_relay/constants.js +67 -0
  160. package/dist/lib/waku_relay/constants.js.map +1 -0
  161. package/dist/lib/waku_relay/index.d.ts +65 -0
  162. package/dist/lib/waku_relay/index.js +111 -0
  163. package/dist/lib/waku_relay/index.js.map +1 -0
  164. package/dist/lib/waku_store/history_rpc.d.ts +27 -0
  165. package/dist/lib/waku_store/history_rpc.js +71 -0
  166. package/dist/lib/waku_store/history_rpc.js.map +1 -0
  167. package/dist/lib/waku_store/index.d.ts +126 -0
  168. package/dist/lib/waku_store/index.js +218 -0
  169. package/dist/lib/waku_store/index.js.map +1 -0
  170. package/dist/proto/filter.d.ts +65 -0
  171. package/dist/proto/filter.js +425 -0
  172. package/dist/proto/filter.js.map +1 -0
  173. package/dist/proto/light_push.d.ts +57 -0
  174. package/dist/proto/light_push.js +369 -0
  175. package/dist/proto/light_push.js.map +1 -0
  176. package/dist/proto/message.d.ts +29 -0
  177. package/dist/proto/message.js +215 -0
  178. package/dist/proto/message.js.map +1 -0
  179. package/dist/proto/store.d.ts +104 -0
  180. package/dist/proto/store.js +602 -0
  181. package/dist/proto/store.js.map +1 -0
  182. package/dist/proto/topic_only_message.d.ts +10 -0
  183. package/dist/proto/topic_only_message.js +46 -0
  184. package/dist/proto/topic_only_message.js.map +1 -0
  185. package/package.json +292 -0
  186. package/src/index.ts +33 -0
  187. package/src/lib/constants.ts +4 -0
  188. package/src/lib/crypto.ts +100 -0
  189. package/src/lib/enr/constants.ts +10 -0
  190. package/src/lib/enr/enr.ts +516 -0
  191. package/src/lib/enr/index.ts +5 -0
  192. package/src/lib/enr/keypair/index.ts +76 -0
  193. package/src/lib/enr/keypair/secp256k1.ts +69 -0
  194. package/src/lib/enr/keypair/types.ts +14 -0
  195. package/src/lib/enr/multiaddr_from_fields.ts +18 -0
  196. package/src/lib/enr/multiaddrs_codec.ts +50 -0
  197. package/src/lib/enr/types.ts +11 -0
  198. package/src/lib/enr/v4.ts +22 -0
  199. package/src/lib/enr/waku2_codec.ts +39 -0
  200. package/src/lib/group_by.ts +14 -0
  201. package/src/lib/multiaddr_to_peer_info.ts +17 -0
  202. package/src/lib/peer_discovery_dns/dns.ts +223 -0
  203. package/src/lib/peer_discovery_dns/dns_over_https.ts +98 -0
  204. package/src/lib/peer_discovery_dns/enrtree.ts +123 -0
  205. package/src/lib/peer_discovery_dns/fetch_nodes.ts +180 -0
  206. package/src/lib/peer_discovery_dns/index.ts +84 -0
  207. package/src/lib/peer_discovery_static_list.ts +118 -0
  208. package/src/lib/predefined_bootstrap_nodes.ts +72 -0
  209. package/src/lib/push_or_init_map.ts +13 -0
  210. package/src/lib/random_subset.ts +30 -0
  211. package/src/lib/select_connection.ts +24 -0
  212. package/src/lib/select_peer.ts +77 -0
  213. package/src/lib/to_proto_message.ts +15 -0
  214. package/src/lib/utils.ts +50 -0
  215. package/src/lib/wait_for_remote_peer.ts +151 -0
  216. package/src/lib/waku.ts +258 -0
  217. package/src/lib/waku_filter/filter_rpc.ts +57 -0
  218. package/src/lib/waku_filter/index.ts +291 -0
  219. package/src/lib/waku_light_push/index.ts +137 -0
  220. package/src/lib/waku_light_push/push_rpc.ts +39 -0
  221. package/src/lib/waku_message/constants.ts +10 -0
  222. package/src/lib/waku_message/ecies.ts +194 -0
  223. package/src/lib/waku_message/symmetric.ts +33 -0
  224. package/src/lib/waku_message/topic_only_message.ts +40 -0
  225. package/src/lib/waku_message/version_0.ts +121 -0
  226. package/src/lib/waku_message/version_1.ts +457 -0
  227. package/src/lib/waku_relay/constants.ts +77 -0
  228. package/src/lib/waku_relay/index.ts +189 -0
  229. package/src/lib/waku_store/history_rpc.ts +94 -0
  230. package/src/lib/waku_store/index.ts +372 -0
  231. package/src/proto/filter.ts +602 -0
  232. package/src/proto/light_push.ts +526 -0
  233. package/src/proto/message.ts +304 -0
  234. package/src/proto/store.ts +844 -0
  235. package/src/proto/topic_only_message.ts +67 -0
@@ -0,0 +1,218 @@
1
+ import debug from "debug";
2
+ import all from "it-all";
3
+ import * as lp from "it-length-prefixed";
4
+ import { pipe } from "it-pipe";
5
+ import { Uint8ArrayList } from "uint8arraylist";
6
+ import * as proto from "../../proto/store.js";
7
+ import { DefaultPubSubTopic } from "../constants.js";
8
+ import { selectConnection } from "../select_connection.js";
9
+ import { getPeersForProtocol, selectPeerForProtocol } from "../select_peer.js";
10
+ import { toProtoMessage } from "../to_proto_message.js";
11
+ import { HistoryRPC, PageDirection } from "./history_rpc.js";
12
+ var HistoryError = proto.HistoryResponse.HistoryError;
13
+ const log = debug("waku:store");
14
+ export const StoreCodec = "/vac/waku/store/2.0.0-beta4";
15
+ export const DefaultPageSize = 10;
16
+ export { PageDirection };
17
+ /**
18
+ * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
19
+ *
20
+ * The Waku Store protocol can be used to retrieved historical messages.
21
+ */
22
+ export class WakuStore {
23
+ constructor(libp2p, options) {
24
+ this.libp2p = libp2p;
25
+ this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
26
+ }
27
+ /**
28
+ * Do a query to a Waku Store to retrieve historical/missed messages.
29
+ *
30
+ * The callback function takes a `WakuMessage` in input,
31
+ * messages are processed in order:
32
+ * - oldest to latest if `options.pageDirection` == { @link PageDirection.FORWARD }
33
+ * - latest to oldest if `options.pageDirection` == { @link PageDirection.BACKWARD }
34
+ *
35
+ * The ordering may affect performance.
36
+ * The ordering depends on the behavior of the remote store node.
37
+ * If strong ordering is needed, you may need to handle this at application level
38
+ * and set your own timestamps too (the WakuMessage timestamps are not certified).
39
+ *
40
+ * @throws If not able to reach a Waku Store peer to query,
41
+ * or if an error is encountered when processing the reply,
42
+ * or if two decoders with the same content topic are passed.
43
+ */
44
+ async queryOrderedCallback(decoders, callback, options) {
45
+ let abort = false;
46
+ for await (const promises of this.queryGenerator(decoders, options)) {
47
+ if (abort)
48
+ break;
49
+ const messagesOrUndef = await Promise.all(promises);
50
+ let messages = messagesOrUndef.filter(isDefined);
51
+ // Messages in pages are ordered from oldest (first) to most recent (last).
52
+ // https://github.com/vacp2p/rfc/issues/533
53
+ if (typeof options?.pageDirection === "undefined" ||
54
+ options?.pageDirection === PageDirection.BACKWARD) {
55
+ messages = messages.reverse();
56
+ }
57
+ await Promise.all(messages.map(async (msg) => {
58
+ if (msg && !abort) {
59
+ abort = Boolean(await callback(msg));
60
+ }
61
+ }));
62
+ }
63
+ }
64
+ /**
65
+ * Do a query to a Waku Store to retrieve historical/missed messages.
66
+ *
67
+ * The callback function takes a `Promise<WakuMessage>` in input,
68
+ * useful if messages needs to be decrypted and performance matters.
69
+ *
70
+ * The order of the messages passed to the callback is as follows:
71
+ * - within a page, messages are expected to be ordered from oldest to most recent
72
+ * - pages direction depends on { @link QueryOptions.pageDirection }
73
+ *
74
+ * Do note that the resolution of the `Promise<WakuMessage | undefined` may
75
+ * break the order as it may rely on the browser decryption API, which in turn,
76
+ * may have a different speed depending on the type of decryption.
77
+ *
78
+ * @throws If not able to reach a Waku Store peer to query,
79
+ * or if an error is encountered when processing the reply,
80
+ * or if two decoders with the same content topic are passed.
81
+ */
82
+ async queryCallbackOnPromise(decoders, callback, options) {
83
+ let abort = false;
84
+ let promises = [];
85
+ for await (const page of this.queryGenerator(decoders, options)) {
86
+ const _promises = page.map(async (msg) => {
87
+ if (!abort) {
88
+ abort = Boolean(await callback(msg));
89
+ }
90
+ });
91
+ promises = promises.concat(_promises);
92
+ }
93
+ await Promise.all(promises);
94
+ }
95
+ /**
96
+ * Do a query to a Waku Store to retrieve historical/missed messages.
97
+ *
98
+ * This is a generator, useful if you want most control on how messages
99
+ * are processed.
100
+ *
101
+ * The order of the messages returned by the remote Waku node SHOULD BE
102
+ * as follows:
103
+ * - within a page, messages SHOULD be ordered from oldest to most recent
104
+ * - pages direction depends on { @link QueryOptions.pageDirection }
105
+ *
106
+ * However, there is no way to guarantee the behavior of the remote node.
107
+ *
108
+ * @throws If not able to reach a Waku Store peer to query,
109
+ * or if an error is encountered when processing the reply,
110
+ * or if two decoders with the same content topic are passed.
111
+ */
112
+ async *queryGenerator(decoders, options) {
113
+ let startTime, endTime;
114
+ if (options?.timeFilter) {
115
+ startTime = options.timeFilter.startTime;
116
+ endTime = options.timeFilter.endTime;
117
+ }
118
+ const decodersAsMap = new Map();
119
+ decoders.forEach((dec) => {
120
+ if (decodersAsMap.has(dec.contentTopic)) {
121
+ throw new Error("API does not support different decoder per content topic");
122
+ }
123
+ decodersAsMap.set(dec.contentTopic, dec);
124
+ });
125
+ const contentTopics = decoders.map((dec) => dec.contentTopic);
126
+ const queryOpts = Object.assign({
127
+ pubSubTopic: this.pubSubTopic,
128
+ pageDirection: PageDirection.BACKWARD,
129
+ pageSize: DefaultPageSize,
130
+ }, options, { contentTopics, startTime, endTime });
131
+ log("Querying history with the following options", {
132
+ peerId: options?.peerId?.toString(),
133
+ ...options,
134
+ });
135
+ const res = await selectPeerForProtocol(this.libp2p.peerStore, [StoreCodec], options?.peerId);
136
+ if (!res) {
137
+ throw new Error("Failed to get a peer");
138
+ }
139
+ const { peer, protocol } = res;
140
+ const connections = this.libp2p.connectionManager.getConnections(peer.id);
141
+ const connection = selectConnection(connections);
142
+ if (!connection)
143
+ throw "Failed to get a connection to the peer";
144
+ for await (const messages of paginate(connection, protocol, queryOpts, decodersAsMap)) {
145
+ yield messages;
146
+ }
147
+ }
148
+ /**
149
+ * Returns known peers from the address book (`libp2p.peerStore`) that support
150
+ * store protocol. Waku may or may not be currently connected to these peers.
151
+ */
152
+ async peers() {
153
+ return getPeersForProtocol(this.libp2p.peerStore, [StoreCodec]);
154
+ }
155
+ }
156
+ async function* paginate(connection, protocol, queryOpts, decoders) {
157
+ if (queryOpts.contentTopics.toString() !==
158
+ Array.from(decoders.keys()).toString()) {
159
+ throw new Error("Internal error, the decoders should match the query's content topics");
160
+ }
161
+ let cursor = undefined;
162
+ while (true) {
163
+ queryOpts = Object.assign(queryOpts, { cursor });
164
+ const stream = await connection.newStream(protocol);
165
+ const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
166
+ log("Querying store peer", connection.remoteAddr.toString(), `for (${queryOpts.pubSubTopic})`, queryOpts.contentTopics);
167
+ const res = await pipe([historyRpcQuery.encode()], lp.encode(), stream, lp.decode(), async (source) => await all(source));
168
+ const bytes = new Uint8ArrayList();
169
+ res.forEach((chunk) => {
170
+ bytes.append(chunk);
171
+ });
172
+ const reply = historyRpcQuery.decode(bytes);
173
+ if (!reply.response) {
174
+ log("Stopping pagination due to store `response` field missing");
175
+ break;
176
+ }
177
+ const response = reply.response;
178
+ if (response.error &&
179
+ response.error !== HistoryError.ERROR_NONE_UNSPECIFIED) {
180
+ throw "History response contains an Error: " + response.error;
181
+ }
182
+ if (!response.messages || !response.messages.length) {
183
+ log("Stopping pagination due to store `response.messages` field missing or empty");
184
+ break;
185
+ }
186
+ log(`${response.messages.length} messages retrieved from store`);
187
+ yield response.messages.map((protoMsg) => {
188
+ const contentTopic = protoMsg.contentTopic;
189
+ if (typeof contentTopic !== "undefined") {
190
+ const decoder = decoders.get(contentTopic);
191
+ if (decoder) {
192
+ return decoder.fromProtoObj(toProtoMessage(protoMsg));
193
+ }
194
+ }
195
+ return Promise.resolve(undefined);
196
+ });
197
+ cursor = response.pagingInfo?.cursor;
198
+ if (typeof cursor === "undefined") {
199
+ // If the server does not return cursor then there is an issue,
200
+ // Need to abort, or we end up in an infinite loop
201
+ log("Stopping pagination due to `response.pagingInfo.cursor` missing from store response");
202
+ break;
203
+ }
204
+ const responsePageSize = response.pagingInfo?.pageSize;
205
+ const queryPageSize = historyRpcQuery.query?.pagingInfo?.pageSize;
206
+ if (
207
+ // Response page size smaller than query, meaning this is the last page
208
+ responsePageSize &&
209
+ queryPageSize &&
210
+ responsePageSize < queryPageSize) {
211
+ break;
212
+ }
213
+ }
214
+ }
215
+ export function isDefined(msg) {
216
+ return !!msg;
217
+ }
218
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/waku_store/index.ts"],"names":[],"mappings":"AAIA,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,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAU,MAAM,eAAe,CAAC;AAElE,IAAO,YAAY,GAAG,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC;AAEzD,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,6BA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UAAU,SAAS,CAAI,GAAkB;IAC7C,OAAO,CAAC,CAAC,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Uint8ArrayList } from "uint8arraylist";
2
+ import type { Codec } from "protons-runtime";
3
+ export interface FilterRequest {
4
+ subscribe?: boolean;
5
+ topic?: string;
6
+ contentFilters: FilterRequest.ContentFilter[];
7
+ }
8
+ export declare namespace FilterRequest {
9
+ interface ContentFilter {
10
+ contentTopic?: string;
11
+ }
12
+ namespace ContentFilter {
13
+ const codec: () => Codec<ContentFilter>;
14
+ const encode: (obj: ContentFilter) => Uint8Array;
15
+ const decode: (buf: Uint8Array | Uint8ArrayList) => ContentFilter;
16
+ }
17
+ const codec: () => Codec<FilterRequest>;
18
+ const encode: (obj: FilterRequest) => Uint8Array;
19
+ const decode: (buf: Uint8Array | Uint8ArrayList) => FilterRequest;
20
+ }
21
+ export interface MessagePush {
22
+ messages: WakuMessage[];
23
+ }
24
+ export declare namespace MessagePush {
25
+ const codec: () => Codec<MessagePush>;
26
+ const encode: (obj: MessagePush) => Uint8Array;
27
+ const decode: (buf: Uint8Array | Uint8ArrayList) => MessagePush;
28
+ }
29
+ export interface FilterRPC {
30
+ requestId?: string;
31
+ request?: FilterRequest;
32
+ push?: MessagePush;
33
+ }
34
+ export declare namespace FilterRPC {
35
+ const codec: () => Codec<FilterRPC>;
36
+ const encode: (obj: FilterRPC) => Uint8Array;
37
+ const decode: (buf: Uint8Array | Uint8ArrayList) => FilterRPC;
38
+ }
39
+ export interface RateLimitProof {
40
+ proof: Uint8Array;
41
+ merkleRoot: Uint8Array;
42
+ epoch: Uint8Array;
43
+ shareX: Uint8Array;
44
+ shareY: Uint8Array;
45
+ nullifier: Uint8Array;
46
+ rlnIdentifier: Uint8Array;
47
+ }
48
+ export declare namespace RateLimitProof {
49
+ const codec: () => Codec<RateLimitProof>;
50
+ const encode: (obj: RateLimitProof) => Uint8Array;
51
+ const decode: (buf: Uint8Array | Uint8ArrayList) => RateLimitProof;
52
+ }
53
+ export interface WakuMessage {
54
+ payload?: Uint8Array;
55
+ contentTopic?: string;
56
+ version?: number;
57
+ timestampDeprecated?: number;
58
+ timestamp?: bigint;
59
+ rateLimitProof?: RateLimitProof;
60
+ }
61
+ export declare namespace WakuMessage {
62
+ const codec: () => Codec<WakuMessage>;
63
+ const encode: (obj: WakuMessage) => Uint8Array;
64
+ const decode: (buf: Uint8Array | Uint8ArrayList) => WakuMessage;
65
+ }