@waku/core 0.0.17 → 0.0.19

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 (84) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/bundle/{browser-2f1afe46.js → browser-bde977a3.js} +12 -9
  3. package/bundle/index.js +911 -32802
  4. package/bundle/lib/base_protocol.js +4 -1
  5. package/bundle/lib/message/version_0.js +2 -3
  6. package/bundle/{peer_exchange-1229c8b0.js → version_0-9c941081.js} +569 -63
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.js +5 -5
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/base_protocol.js +3 -0
  11. package/dist/lib/base_protocol.js.map +1 -1
  12. package/dist/lib/connection_manager.d.ts +1 -0
  13. package/dist/lib/connection_manager.js +33 -25
  14. package/dist/lib/connection_manager.js.map +1 -1
  15. package/dist/lib/filter/{filter_rpc.d.ts → v1/filter_rpc.d.ts} +1 -3
  16. package/dist/lib/filter/{filter_rpc.js → v1/filter_rpc.js} +1 -0
  17. package/dist/lib/filter/v1/filter_rpc.js.map +1 -0
  18. package/dist/lib/filter/{index.d.ts → v1/index.d.ts} +0 -2
  19. package/dist/lib/filter/{index.js → v1/index.js} +7 -4
  20. package/dist/lib/filter/v1/index.js.map +1 -0
  21. package/dist/lib/filter/v2/filter_rpc.d.ts +40 -0
  22. package/dist/lib/filter/v2/filter_rpc.js +109 -0
  23. package/dist/lib/filter/v2/filter_rpc.js.map +1 -0
  24. package/dist/lib/filter/v2/index.d.ts +3 -0
  25. package/dist/lib/filter/v2/index.js +235 -0
  26. package/dist/lib/filter/v2/index.js.map +1 -0
  27. package/dist/lib/keep_alive_manager.d.ts +1 -0
  28. package/dist/lib/keep_alive_manager.js +5 -1
  29. package/dist/lib/keep_alive_manager.js.map +1 -1
  30. package/dist/lib/light_push/index.d.ts +1 -1
  31. package/dist/lib/light_push/index.js +27 -7
  32. package/dist/lib/light_push/index.js.map +1 -1
  33. package/dist/lib/light_push/push_rpc.js +1 -0
  34. package/dist/lib/light_push/push_rpc.js.map +1 -1
  35. package/dist/lib/message/index.d.ts +0 -1
  36. package/dist/lib/message/index.js +0 -1
  37. package/dist/lib/message/index.js.map +1 -1
  38. package/dist/lib/message/version_0.d.ts +1 -2
  39. package/dist/lib/message/version_0.js +6 -0
  40. package/dist/lib/message/version_0.js.map +1 -1
  41. package/dist/lib/store/history_rpc.js +1 -0
  42. package/dist/lib/store/history_rpc.js.map +1 -1
  43. package/dist/lib/store/index.js +2 -0
  44. package/dist/lib/store/index.js.map +1 -1
  45. package/dist/lib/waku.d.ts +5 -5
  46. package/dist/lib/waku.js +6 -0
  47. package/dist/lib/waku.js.map +1 -1
  48. package/package.json +9 -13
  49. package/src/index.ts +6 -11
  50. package/src/lib/connection_manager.ts +13 -4
  51. package/src/lib/filter/{filter_rpc.ts → v1/filter_rpc.ts} +1 -4
  52. package/src/lib/filter/{index.ts → v1/index.ts} +6 -7
  53. package/src/lib/filter/v2/filter_rpc.ts +131 -0
  54. package/src/lib/filter/v2/index.ts +413 -0
  55. package/src/lib/keep_alive_manager.ts +1 -2
  56. package/src/lib/light_push/index.ts +26 -9
  57. package/src/lib/message/index.ts +0 -1
  58. package/src/lib/message/version_0.ts +1 -1
  59. package/src/lib/waku.ts +5 -7
  60. package/bundle/lib/message/topic_only_message.js +0 -3
  61. package/bundle/topic_only_message-e8406994.js +0 -43
  62. package/bundle/version_0-5a4becbc.js +0 -149
  63. package/dist/lib/filter/filter_rpc.js.map +0 -1
  64. package/dist/lib/filter/index.js.map +0 -1
  65. package/dist/lib/group_by.d.ts +0 -3
  66. package/dist/lib/group_by.js +0 -13
  67. package/dist/lib/group_by.js.map +0 -1
  68. package/dist/lib/message/topic_only_message.d.ts +0 -18
  69. package/dist/lib/message/topic_only_message.js +0 -35
  70. package/dist/lib/message/topic_only_message.js.map +0 -1
  71. package/dist/lib/relay/constants.d.ts +0 -63
  72. package/dist/lib/relay/constants.js +0 -64
  73. package/dist/lib/relay/constants.js.map +0 -1
  74. package/dist/lib/relay/index.d.ts +0 -11
  75. package/dist/lib/relay/index.js +0 -181
  76. package/dist/lib/relay/index.js.map +0 -1
  77. package/dist/lib/relay/message_validator.d.ts +0 -4
  78. package/dist/lib/relay/message_validator.js +0 -25
  79. package/dist/lib/relay/message_validator.js.map +0 -1
  80. package/src/lib/group_by.ts +0 -14
  81. package/src/lib/message/topic_only_message.ts +0 -51
  82. package/src/lib/relay/constants.ts +0 -74
  83. package/src/lib/relay/index.ts +0 -294
  84. package/src/lib/relay/message_validator.ts +0 -35
@@ -0,0 +1,413 @@
1
+ import { Stream } from "@libp2p/interface-connection";
2
+ import type { Libp2p } from "@libp2p/interface-libp2p";
3
+ import type { PeerId } from "@libp2p/interface-peer-id";
4
+ import type { Peer } from "@libp2p/interface-peer-store";
5
+ import type { IncomingStreamData } from "@libp2p/interface-registrar";
6
+ import type {
7
+ Callback,
8
+ ContentTopic,
9
+ IAsyncIterator,
10
+ IDecodedMessage,
11
+ IDecoder,
12
+ IFilterV2,
13
+ IProtoMessage,
14
+ IReceiver,
15
+ PeerIdStr,
16
+ ProtocolCreateOptions,
17
+ ProtocolOptions,
18
+ PubSubTopic,
19
+ Unsubscribe,
20
+ } from "@waku/interfaces";
21
+ import { WakuMessage } from "@waku/proto";
22
+ import { groupByContentTopic, toAsyncIterator } from "@waku/utils";
23
+ import debug from "debug";
24
+ import all from "it-all";
25
+ import * as lp from "it-length-prefixed";
26
+ import { pipe } from "it-pipe";
27
+
28
+ import { BaseProtocol } from "../../base_protocol.js";
29
+ import { DefaultPubSubTopic } from "../../constants.js";
30
+
31
+ import {
32
+ FilterPushRpc,
33
+ FilterSubscribeResponse,
34
+ FilterSubscribeRpc,
35
+ } from "./filter_rpc.js";
36
+
37
+ const log = debug("waku:filter:v2");
38
+
39
+ type SubscriptionCallback<T extends IDecodedMessage> = {
40
+ decoders: IDecoder<T>[];
41
+ callback: Callback<T>;
42
+ };
43
+
44
+ const FilterV2Codecs = {
45
+ SUBSCRIBE: "/vac/waku/filter-subscribe/2.0.0-beta1",
46
+ PUSH: "/vac/waku/filter-push/2.0.0-beta1",
47
+ };
48
+
49
+ class Subscription {
50
+ private readonly peer: Peer;
51
+ private readonly pubSubTopic: PubSubTopic;
52
+ private newStream: (peer: Peer) => Promise<Stream>;
53
+
54
+ private subscriptionCallbacks: Map<
55
+ ContentTopic,
56
+ SubscriptionCallback<IDecodedMessage>
57
+ >;
58
+
59
+ constructor(
60
+ pubSubTopic: PubSubTopic,
61
+ remotePeer: Peer,
62
+ newStream: (peer: Peer) => Promise<Stream>
63
+ ) {
64
+ this.peer = remotePeer;
65
+ this.pubSubTopic = pubSubTopic;
66
+ this.newStream = newStream;
67
+ this.subscriptionCallbacks = new Map();
68
+ }
69
+
70
+ async subscribe<T extends IDecodedMessage>(
71
+ decoders: IDecoder<T> | IDecoder<T>[],
72
+ callback: Callback<T>
73
+ ): Promise<void> {
74
+ const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
75
+ const decodersGroupedByCT = groupByContentTopic(decodersArray);
76
+ const contentTopics = Array.from(decodersGroupedByCT.keys());
77
+
78
+ const stream = await this.newStream(this.peer);
79
+
80
+ const request = FilterSubscribeRpc.createSubscribeRequest(
81
+ this.pubSubTopic,
82
+ contentTopics
83
+ );
84
+
85
+ try {
86
+ const res = await pipe(
87
+ [request.encode()],
88
+ lp.encode,
89
+ stream,
90
+ lp.decode,
91
+ async (source) => await all(source)
92
+ );
93
+
94
+ const { statusCode, requestId, statusDesc } =
95
+ FilterSubscribeResponse.decode(res[0].slice());
96
+
97
+ if (statusCode < 200 || statusCode >= 300) {
98
+ throw new Error(
99
+ `Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`
100
+ );
101
+ }
102
+
103
+ log(
104
+ "Subscribed to peer ",
105
+ this.peer.id.toString(),
106
+ "for content topics",
107
+ contentTopics
108
+ );
109
+ } catch (e) {
110
+ throw new Error(
111
+ "Error subscribing to peer: " +
112
+ this.peer.id.toString() +
113
+ " for content topics: " +
114
+ contentTopics +
115
+ ": " +
116
+ e
117
+ );
118
+ }
119
+
120
+ // Save the callback functions by content topics so they
121
+ // can easily be removed (reciprocally replaced) if `unsubscribe` (reciprocally `subscribe`)
122
+ // is called for those content topics
123
+ decodersGroupedByCT.forEach((decoders, contentTopic) => {
124
+ // Cast the type because a given `subscriptionCallbacks` map may hold
125
+ // Decoder that decode to different implementations of `IDecodedMessage`
126
+ const subscriptionCallback = {
127
+ decoders,
128
+ callback,
129
+ } as unknown as SubscriptionCallback<IDecodedMessage>;
130
+
131
+ // The callback and decoder may override previous values, this is on
132
+ // purpose as the user may call `subscribe` to refresh the subscription
133
+ this.subscriptionCallbacks.set(contentTopic, subscriptionCallback);
134
+ });
135
+ }
136
+
137
+ async unsubscribe(contentTopics: ContentTopic[]): Promise<void> {
138
+ const stream = await this.newStream(this.peer);
139
+ const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(
140
+ this.pubSubTopic,
141
+ contentTopics
142
+ );
143
+
144
+ try {
145
+ await pipe([unsubscribeRequest.encode()], lp.encode, stream.sink);
146
+ } catch (error) {
147
+ throw new Error("Error subscribing: " + error);
148
+ }
149
+
150
+ contentTopics.forEach((contentTopic: string) => {
151
+ this.subscriptionCallbacks.delete(contentTopic);
152
+ });
153
+ }
154
+
155
+ async ping(): Promise<void> {
156
+ const stream = await this.newStream(this.peer);
157
+
158
+ const request = FilterSubscribeRpc.createSubscriberPingRequest();
159
+
160
+ try {
161
+ const res = await pipe(
162
+ [request.encode()],
163
+ lp.encode,
164
+ stream,
165
+ lp.decode,
166
+ async (source) => await all(source)
167
+ );
168
+
169
+ const { statusCode, requestId, statusDesc } =
170
+ FilterSubscribeResponse.decode(res[0].slice());
171
+
172
+ if (statusCode < 200 || statusCode >= 300) {
173
+ throw new Error(
174
+ `Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`
175
+ );
176
+ }
177
+
178
+ log("Ping successful");
179
+ } catch (error) {
180
+ log("Error pinging: ", error);
181
+ throw new Error("Error pinging: " + error);
182
+ }
183
+ }
184
+
185
+ async unsubscribeAll(): Promise<void> {
186
+ const stream = await this.newStream(this.peer);
187
+
188
+ const request = FilterSubscribeRpc.createUnsubscribeAllRequest(
189
+ this.pubSubTopic
190
+ );
191
+
192
+ try {
193
+ const res = await pipe(
194
+ [request.encode()],
195
+ lp.encode,
196
+ stream,
197
+ lp.decode,
198
+ async (source) => await all(source)
199
+ );
200
+
201
+ const { statusCode, requestId, statusDesc } =
202
+ FilterSubscribeResponse.decode(res[0].slice());
203
+
204
+ if (statusCode < 200 || statusCode >= 300) {
205
+ throw new Error(
206
+ `Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`
207
+ );
208
+ }
209
+
210
+ this.subscriptionCallbacks.clear();
211
+ log("Unsubscribed from all content topics");
212
+ } catch (error) {
213
+ throw new Error("Error unsubscribing from all content topics: " + error);
214
+ }
215
+ }
216
+
217
+ async processMessage(message: WakuMessage): Promise<void> {
218
+ const contentTopic = message.contentTopic;
219
+ const subscriptionCallback = this.subscriptionCallbacks.get(contentTopic);
220
+ if (!subscriptionCallback) {
221
+ log("No subscription callback available for ", contentTopic);
222
+ return;
223
+ }
224
+ await pushMessage(subscriptionCallback, this.pubSubTopic, message);
225
+ }
226
+ }
227
+
228
+ class FilterV2 extends BaseProtocol implements IReceiver {
229
+ private readonly options: ProtocolCreateOptions;
230
+ private activeSubscriptions = new Map<string, Subscription>();
231
+
232
+ private getActiveSubscription(
233
+ pubSubTopic: PubSubTopic,
234
+ peerIdStr: PeerIdStr
235
+ ): Subscription | undefined {
236
+ return this.activeSubscriptions.get(`${pubSubTopic}_${peerIdStr}`);
237
+ }
238
+
239
+ private setActiveSubscription(
240
+ pubSubTopic: PubSubTopic,
241
+ peerIdStr: PeerIdStr,
242
+ subscription: Subscription
243
+ ): Subscription {
244
+ this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription);
245
+ return subscription;
246
+ }
247
+
248
+ constructor(public libp2p: Libp2p, options?: ProtocolCreateOptions) {
249
+ super(
250
+ FilterV2Codecs.SUBSCRIBE,
251
+ libp2p.peerStore,
252
+ libp2p.getConnections.bind(libp2p)
253
+ );
254
+
255
+ this.libp2p
256
+ .handle(FilterV2Codecs.PUSH, this.onRequest.bind(this))
257
+ .catch((e) => {
258
+ log("Failed to register ", FilterV2Codecs.PUSH, e);
259
+ });
260
+
261
+ this.activeSubscriptions = new Map();
262
+
263
+ this.options = options ?? {};
264
+ }
265
+
266
+ async createSubscription(
267
+ pubSubTopic?: string,
268
+ peerId?: PeerId
269
+ ): Promise<Subscription> {
270
+ const _pubSubTopic =
271
+ pubSubTopic ?? this.options.pubSubTopic ?? DefaultPubSubTopic;
272
+
273
+ const peer = await this.getPeer(peerId);
274
+
275
+ const subscription =
276
+ this.getActiveSubscription(_pubSubTopic, peer.id.toString()) ??
277
+ this.setActiveSubscription(
278
+ _pubSubTopic,
279
+ peer.id.toString(),
280
+ new Subscription(_pubSubTopic, peer, this.newStream.bind(this, peer))
281
+ );
282
+
283
+ return subscription;
284
+ }
285
+
286
+ public toSubscriptionIterator<T extends IDecodedMessage>(
287
+ decoders: IDecoder<T> | IDecoder<T>[],
288
+ opts?: ProtocolOptions | undefined
289
+ ): Promise<IAsyncIterator<T>> {
290
+ return toAsyncIterator(this, decoders, opts);
291
+ }
292
+
293
+ /**
294
+ * This method is used to satisfy the `IReceiver` interface.
295
+ *
296
+ * @hidden
297
+ *
298
+ * @param decoders The decoders to use for the subscription.
299
+ * @param callback The callback function to use for the subscription.
300
+ * @param opts Optional protocol options for the subscription.
301
+ *
302
+ * @returns A Promise that resolves to a function that unsubscribes from the subscription.
303
+ *
304
+ * @remarks
305
+ * This method should not be used directly.
306
+ * Instead, use `createSubscription` to create a new subscription.
307
+ */
308
+ async subscribe<T extends IDecodedMessage>(
309
+ decoders: IDecoder<T> | IDecoder<T>[],
310
+ callback: Callback<T>,
311
+ opts?: ProtocolOptions
312
+ ): Promise<Unsubscribe> {
313
+ const subscription = await this.createSubscription(undefined, opts?.peerId);
314
+
315
+ subscription.subscribe(decoders, callback);
316
+
317
+ const contentTopics = Array.from(
318
+ groupByContentTopic(
319
+ Array.isArray(decoders) ? decoders : [decoders]
320
+ ).keys()
321
+ );
322
+
323
+ return async () => {
324
+ await subscription.unsubscribe(contentTopics);
325
+ };
326
+ }
327
+
328
+ private onRequest(streamData: IncomingStreamData): void {
329
+ log("Receiving message push");
330
+ try {
331
+ pipe(streamData.stream, lp.decode, async (source) => {
332
+ for await (const bytes of source) {
333
+ const response = FilterPushRpc.decode(bytes.slice());
334
+
335
+ const { pubsubTopic, wakuMessage } = response;
336
+
337
+ if (!wakuMessage) {
338
+ log("Received empty message");
339
+ return;
340
+ }
341
+
342
+ if (!pubsubTopic) {
343
+ log("PubSub topic missing from push message");
344
+ return;
345
+ }
346
+
347
+ const peerIdStr = streamData.connection.remotePeer.toString();
348
+ const subscription = this.getActiveSubscription(
349
+ pubsubTopic,
350
+ peerIdStr
351
+ );
352
+
353
+ if (!subscription) {
354
+ log(`No subscription locally registered for topic ${pubsubTopic}`);
355
+ return;
356
+ }
357
+
358
+ await subscription.processMessage(wakuMessage);
359
+ }
360
+ }).then(
361
+ () => {
362
+ log("Receiving pipe closed.");
363
+ },
364
+ (e) => {
365
+ log("Error with receiving pipe", e);
366
+ }
367
+ );
368
+ } catch (e) {
369
+ log("Error decoding message", e);
370
+ }
371
+ }
372
+ }
373
+
374
+ export function wakuFilterV2(
375
+ init: Partial<ProtocolCreateOptions> = {}
376
+ ): (libp2p: Libp2p) => IFilterV2 {
377
+ return (libp2p: Libp2p) => new FilterV2(libp2p, init);
378
+ }
379
+
380
+ async function pushMessage<T extends IDecodedMessage>(
381
+ subscriptionCallback: SubscriptionCallback<T>,
382
+ pubSubTopic: PubSubTopic,
383
+ message: WakuMessage
384
+ ): Promise<void> {
385
+ const { decoders, callback } = subscriptionCallback;
386
+
387
+ const { contentTopic } = message;
388
+ if (!contentTopic) {
389
+ log("Message has no content topic, skipping");
390
+ return;
391
+ }
392
+
393
+ let didDecodeMsg = false;
394
+ // We don't want to wait for decoding failure, just attempt to decode
395
+ // all messages and do the call back on the one that works
396
+ // noinspection ES6MissingAwait
397
+ decoders.forEach(async (dec: IDecoder<T>) => {
398
+ if (didDecodeMsg) return;
399
+ const decoded = await dec.fromProtoObj(
400
+ pubSubTopic,
401
+ message as IProtoMessage
402
+ );
403
+ // const decoded = await dec.fromProtoObj(pubSubTopic, message);
404
+ if (!decoded) {
405
+ log("Not able to decode message");
406
+ return;
407
+ }
408
+ // This is just to prevent more decoding attempt
409
+ // TODO: Could be better if we were to abort promises
410
+ didDecodeMsg = Boolean(decoded);
411
+ await callback(decoded);
412
+ });
413
+ }
@@ -5,8 +5,7 @@ import type { Libp2p } from "libp2p";
5
5
 
6
6
  import { createEncoder } from "../index.js";
7
7
 
8
- import { RelayPingContentTopic } from "./relay/constants.js";
9
-
8
+ export const RelayPingContentTopic = "/relay-ping/1/ping/null";
10
9
  const log = debug("waku:keep-alive");
11
10
 
12
11
  export interface KeepAliveOptions {
@@ -1,14 +1,16 @@
1
1
  import type { Libp2p } from "@libp2p/interface-libp2p";
2
2
  import type { PeerId } from "@libp2p/interface-peer-id";
3
- import type {
3
+ import {
4
4
  IEncoder,
5
5
  ILightPush,
6
6
  IMessage,
7
7
  ProtocolCreateOptions,
8
8
  ProtocolOptions,
9
+ SendError,
9
10
  SendResult,
10
11
  } from "@waku/interfaces";
11
12
  import { PushResponse } from "@waku/proto";
13
+ import { isSizeValid } from "@waku/utils";
12
14
  import debug from "debug";
13
15
  import all from "it-all";
14
16
  import * as lp from "it-length-prefixed";
@@ -47,12 +49,24 @@ class LightPush extends BaseProtocol implements ILightPush {
47
49
  const stream = await this.newStream(peer);
48
50
 
49
51
  const recipients: PeerId[] = [];
52
+ let error: undefined | SendError = undefined;
50
53
 
51
54
  try {
55
+ if (!isSizeValid(message.payload)) {
56
+ log("Failed to send waku light push: message is bigger that 1MB");
57
+ return {
58
+ recipients,
59
+ error: SendError.SIZE_TOO_BIG,
60
+ };
61
+ }
62
+
52
63
  const protoMessage = await encoder.toProtoObj(message);
53
64
  if (!protoMessage) {
54
65
  log("Failed to encode to protoMessage, aborting push");
55
- return { recipients };
66
+ return {
67
+ recipients,
68
+ error: SendError.ENCODE_FAILED,
69
+ };
56
70
  }
57
71
  const query = PushRpc.createRequest(protoMessage, pubSubTopic);
58
72
  const res = await pipe(
@@ -70,21 +84,24 @@ class LightPush extends BaseProtocol implements ILightPush {
70
84
 
71
85
  const response = PushRpc.decode(bytes).response;
72
86
 
73
- if (!response) {
74
- log("No response in PushRPC");
75
- return { recipients };
76
- }
77
-
78
- if (response.isSuccess) {
87
+ if (response?.isSuccess) {
79
88
  recipients.push(peer.id);
89
+ } else {
90
+ log("No response in PushRPC");
91
+ error = SendError.NO_RPC_RESPONSE;
80
92
  }
81
93
  } catch (err) {
82
94
  log("Failed to decode push reply", err);
95
+ error = SendError.DECODE_FAILED;
83
96
  }
84
97
  } catch (err) {
85
98
  log("Failed to send waku light push request", err);
99
+ error = SendError.GENERIC_FAIL;
86
100
  }
87
- return { recipients };
101
+ return {
102
+ error,
103
+ recipients,
104
+ };
88
105
  }
89
106
  }
90
107
 
@@ -1,2 +1 @@
1
1
  export * as version_0 from "./version_0.js";
2
- export * as topic_only_message from "./topic_only_message.js";
@@ -1,10 +1,10 @@
1
- import { IMetaSetter } from "@waku/interfaces";
2
1
  import type {
3
2
  EncoderOptions,
4
3
  IDecodedMessage,
5
4
  IDecoder,
6
5
  IEncoder,
7
6
  IMessage,
7
+ IMetaSetter,
8
8
  IProtoMessage,
9
9
  IRateLimitProof,
10
10
  } from "@waku/interfaces";
package/src/lib/waku.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { Stream } from "@libp2p/interface-connection";
2
2
  import type { Libp2p } from "@libp2p/interface-libp2p";
3
- import type { PeerId } from "@libp2p/interface-peer-id";
4
- import { isPeerId } from "@libp2p/interface-peer-id";
5
- import type { Multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
6
- import { multiaddr } from "@multiformats/multiaddr";
3
+ import { isPeerId, PeerId } from "@libp2p/interface-peer-id";
4
+ import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
7
5
  import type {
8
6
  IFilter,
7
+ IFilterV2,
9
8
  ILightPush,
10
9
  IRelay,
11
10
  IStore,
@@ -48,7 +47,7 @@ export class WakuNode implements Waku {
48
47
  public libp2p: Libp2p;
49
48
  public relay?: IRelay;
50
49
  public store?: IStore;
51
- public filter?: IFilter;
50
+ public filter?: IFilter | IFilterV2;
52
51
  public lightPush?: ILightPush;
53
52
  public connectionManager: ConnectionManager;
54
53
 
@@ -57,7 +56,7 @@ export class WakuNode implements Waku {
57
56
  libp2p: Libp2p,
58
57
  store?: (libp2p: Libp2p) => IStore,
59
58
  lightPush?: (libp2p: Libp2p) => ILightPush,
60
- filter?: (libp2p: Libp2p) => IFilter,
59
+ filter?: (libp2p: Libp2p) => IFilter | IFilterV2,
61
60
  relay?: (libp2p: Libp2p) => IRelay
62
61
  ) {
63
62
  this.libp2p = libp2p;
@@ -192,7 +191,6 @@ export class WakuNode implements Waku {
192
191
  return localMultiaddr + "/p2p/" + this.libp2p.peerId.toString();
193
192
  }
194
193
  }
195
-
196
194
  function mapToPeerIdOrMultiaddr(
197
195
  peerId: PeerId | MultiaddrInput
198
196
  ): PeerId | Multiaddr {
@@ -1,3 +0,0 @@
1
- import '../../peer_exchange-1229c8b0.js';
2
- import '../../browser-2f1afe46.js';
3
- export { T as TopicOnlyDecoder, a as TopicOnlyMessage } from '../../topic_only_message-e8406994.js';
@@ -1,43 +0,0 @@
1
- import { T as TopicOnlyMessage$1 } from './peer_exchange-1229c8b0.js';
2
- import { d as debug } from './browser-2f1afe46.js';
3
-
4
- const log = debug("waku:message:topic-only");
5
- class TopicOnlyMessage {
6
- constructor(pubSubTopic, proto) {
7
- this.pubSubTopic = pubSubTopic;
8
- this.proto = proto;
9
- this.payload = new Uint8Array();
10
- }
11
- get contentTopic() {
12
- return this.proto.contentTopic;
13
- }
14
- }
15
- class TopicOnlyDecoder {
16
- constructor() {
17
- this.contentTopic = "";
18
- }
19
- fromWireToProtoObj(bytes) {
20
- const protoMessage = TopicOnlyMessage$1.decode(bytes);
21
- log("Message decoded", protoMessage);
22
- return Promise.resolve({
23
- contentTopic: protoMessage.contentTopic,
24
- payload: new Uint8Array(),
25
- rateLimitProof: undefined,
26
- timestamp: undefined,
27
- meta: undefined,
28
- version: undefined,
29
- ephemeral: undefined,
30
- });
31
- }
32
- async fromProtoObj(pubSubTopic, proto) {
33
- return new TopicOnlyMessage(pubSubTopic, proto);
34
- }
35
- }
36
-
37
- var topic_only_message = /*#__PURE__*/Object.freeze({
38
- __proto__: null,
39
- TopicOnlyDecoder: TopicOnlyDecoder,
40
- TopicOnlyMessage: TopicOnlyMessage
41
- });
42
-
43
- export { TopicOnlyDecoder as T, TopicOnlyMessage as a, topic_only_message as t };