@waku/core 0.0.26-678635e.0 → 0.0.26

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 (59) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/bundle/base_protocol-pDODy0G6.js +260 -0
  3. package/bundle/{base_protocol-4bcf7514.js → browser-mTOOnVZp.js} +751 -381
  4. package/bundle/index-cmONXM-V.js +595 -0
  5. package/bundle/index.js +637 -1879
  6. package/bundle/lib/base_protocol.js +3 -3
  7. package/bundle/lib/message/version_0.js +3 -3
  8. package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
  9. package/bundle/{version_0-2f1176e3.js → version_0-LQTFNC7k.js} +118 -11
  10. package/dist/.tsbuildinfo +1 -1
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +2 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/base_protocol.d.ts +3 -2
  15. package/dist/lib/base_protocol.js +12 -6
  16. package/dist/lib/base_protocol.js.map +1 -1
  17. package/dist/lib/connection_manager.d.ts +8 -4
  18. package/dist/lib/connection_manager.js +34 -12
  19. package/dist/lib/connection_manager.js.map +1 -1
  20. package/dist/lib/filter/index.js +8 -5
  21. package/dist/lib/filter/index.js.map +1 -1
  22. package/dist/lib/filterPeers.js.map +1 -1
  23. package/dist/lib/keep_alive_manager.d.ts +1 -0
  24. package/dist/lib/keep_alive_manager.js +6 -3
  25. package/dist/lib/keep_alive_manager.js.map +1 -1
  26. package/dist/lib/light_push/index.js +1 -2
  27. package/dist/lib/light_push/index.js.map +1 -1
  28. package/dist/lib/message/version_0.d.ts +7 -7
  29. package/dist/lib/message/version_0.js +5 -6
  30. package/dist/lib/message/version_0.js.map +1 -1
  31. package/dist/lib/metadata/index.d.ts +3 -0
  32. package/dist/lib/metadata/index.js +67 -0
  33. package/dist/lib/metadata/index.js.map +1 -0
  34. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  35. package/dist/lib/store/history_rpc.js.map +1 -1
  36. package/dist/lib/store/index.js +10 -11
  37. package/dist/lib/store/index.js.map +1 -1
  38. package/dist/lib/stream_manager.js.map +1 -1
  39. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  40. package/dist/lib/waku.d.ts +4 -3
  41. package/dist/lib/waku.js +15 -6
  42. package/dist/lib/waku.js.map +1 -1
  43. package/package.json +127 -1
  44. package/src/index.ts +3 -1
  45. package/src/lib/base_protocol.ts +29 -7
  46. package/src/lib/connection_manager.ts +44 -13
  47. package/src/lib/filter/index.ts +18 -11
  48. package/src/lib/keep_alive_manager.ts +9 -3
  49. package/src/lib/light_push/index.ts +3 -4
  50. package/src/lib/message/version_0.ts +18 -10
  51. package/src/lib/metadata/index.ts +110 -0
  52. package/src/lib/store/index.ts +12 -13
  53. package/src/lib/waku.ts +19 -5
  54. package/bundle/browser-90197c87.js +0 -754
  55. package/bundle/index-27b91e3b.js +0 -31
  56. package/dist/lib/constants.d.ts +0 -4
  57. package/dist/lib/constants.js +0 -5
  58. package/dist/lib/constants.js.map +0 -1
  59. package/src/lib/constants.ts +0 -4
@@ -13,13 +13,16 @@ import type {
13
13
  Libp2p,
14
14
  PeerIdStr,
15
15
  ProtocolCreateOptions,
16
- PubSubTopic,
16
+ PubsubTopic,
17
+ SingleShardInfo,
17
18
  Unsubscribe
18
19
  } from "@waku/interfaces";
20
+ import { DefaultPubsubTopic } from "@waku/interfaces";
19
21
  import { WakuMessage } from "@waku/proto";
20
22
  import {
21
23
  ensurePubsubTopicIsConfigured,
22
24
  groupByContentTopic,
25
+ singleShardInfoToPubsubTopic,
23
26
  toAsyncIterator
24
27
  } from "@waku/utils";
25
28
  import { Logger } from "@waku/utils";
@@ -28,7 +31,6 @@ import * as lp from "it-length-prefixed";
28
31
  import { pipe } from "it-pipe";
29
32
 
30
33
  import { BaseProtocol } from "../base_protocol.js";
31
- import { DefaultPubSubTopic } from "../constants.js";
32
34
 
33
35
  import {
34
36
  FilterPushRpc,
@@ -50,7 +52,7 @@ export const FilterCodecs = {
50
52
 
51
53
  class Subscription {
52
54
  private readonly peer: Peer;
53
- private readonly pubsubTopic: PubSubTopic;
55
+ private readonly pubsubTopic: PubsubTopic;
54
56
  private newStream: (peer: Peer) => Promise<Stream>;
55
57
 
56
58
  private subscriptionCallbacks: Map<
@@ -59,7 +61,7 @@ class Subscription {
59
61
  >;
60
62
 
61
63
  constructor(
62
- pubsubTopic: PubSubTopic,
64
+ pubsubTopic: PubsubTopic,
63
65
  remotePeer: Peer,
64
66
  newStream: (peer: Peer) => Promise<Stream>
65
67
  ) {
@@ -256,19 +258,19 @@ class Subscription {
256
258
  }
257
259
 
258
260
  class Filter extends BaseProtocol implements IReceiver {
259
- private readonly pubsubTopics: PubSubTopic[] = [];
261
+ private readonly pubsubTopics: PubsubTopic[] = [];
260
262
  private activeSubscriptions = new Map<string, Subscription>();
261
263
  private readonly NUM_PEERS_PROTOCOL = 1;
262
264
 
263
265
  private getActiveSubscription(
264
- pubsubTopic: PubSubTopic,
266
+ pubsubTopic: PubsubTopic,
265
267
  peerIdStr: PeerIdStr
266
268
  ): Subscription | undefined {
267
269
  return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
268
270
  }
269
271
 
270
272
  private setActiveSubscription(
271
- pubsubTopic: PubSubTopic,
273
+ pubsubTopic: PubsubTopic,
272
274
  peerIdStr: PeerIdStr,
273
275
  subscription: Subscription
274
276
  ): Subscription {
@@ -279,7 +281,7 @@ class Filter extends BaseProtocol implements IReceiver {
279
281
  constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
280
282
  super(FilterCodecs.SUBSCRIBE, libp2p.components);
281
283
 
282
- this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
284
+ this.pubsubTopics = this.initializePubsubTopic(options);
283
285
 
284
286
  libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
285
287
  log.error("Failed to register ", FilterCodecs.PUSH, e);
@@ -289,8 +291,13 @@ class Filter extends BaseProtocol implements IReceiver {
289
291
  }
290
292
 
291
293
  async createSubscription(
292
- pubsubTopic: string = DefaultPubSubTopic
294
+ pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
293
295
  ): Promise<Subscription> {
296
+ const pubsubTopic =
297
+ typeof pubsubTopicShardInfo == "string"
298
+ ? pubsubTopicShardInfo
299
+ : singleShardInfoToPubsubTopic(pubsubTopicShardInfo);
300
+
294
301
  ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
295
302
 
296
303
  //TODO: get a relevant peer for the topic/shard
@@ -367,7 +374,7 @@ class Filter extends BaseProtocol implements IReceiver {
367
374
  }
368
375
 
369
376
  if (!pubsubTopic) {
370
- log.error("PubSub topic missing from push message");
377
+ log.error("Pubsub topic missing from push message");
371
378
  return;
372
379
  }
373
380
 
@@ -408,7 +415,7 @@ export function wakuFilter(
408
415
 
409
416
  async function pushMessage<T extends IDecodedMessage>(
410
417
  subscriptionCallback: SubscriptionCallback<T>,
411
- pubsubTopic: PubSubTopic,
418
+ pubsubTopic: PubsubTopic,
412
419
  message: WakuMessage
413
420
  ): Promise<void> {
414
421
  const { decoders, callback } = subscriptionCallback;
@@ -2,7 +2,7 @@ import type { PeerId } from "@libp2p/interface/peer-id";
2
2
  import type { PeerStore } from "@libp2p/interface/peer-store";
3
3
  import type { IRelay, PeerIdStr } from "@waku/interfaces";
4
4
  import type { KeepAliveOptions } from "@waku/interfaces";
5
- import { Logger } from "@waku/utils";
5
+ import { Logger, pubsubTopicToSingleShardInfo } from "@waku/utils";
6
6
  import { utf8ToBytes } from "@waku/utils/bytes";
7
7
  import type { PingService } from "libp2p/ping";
8
8
 
@@ -111,19 +111,25 @@ export class KeepAliveManager {
111
111
  this.relayKeepAliveTimers.clear();
112
112
  }
113
113
 
114
+ public connectionsExist(): boolean {
115
+ return (
116
+ this.pingKeepAliveTimers.size > 0 || this.relayKeepAliveTimers.size > 0
117
+ );
118
+ }
119
+
114
120
  private scheduleRelayPings(
115
121
  relay: IRelay,
116
122
  relayPeriodSecs: number,
117
123
  peerIdStr: PeerIdStr
118
124
  ): NodeJS.Timeout[] {
119
- // send a ping message to each PubSubTopic the peer is part of
125
+ // send a ping message to each PubsubTopic the peer is part of
120
126
  const intervals: NodeJS.Timeout[] = [];
121
127
  for (const topic of relay.pubsubTopics) {
122
128
  const meshPeers = relay.getMeshPeers(topic);
123
129
  if (!meshPeers.includes(peerIdStr)) continue;
124
130
 
125
131
  const encoder = createEncoder({
126
- pubsubTopic: topic,
132
+ pubsubTopicShardInfo: pubsubTopicToSingleShardInfo(topic),
127
133
  contentTopic: RelayPingContentTopic,
128
134
  ephemeral: true
129
135
  });
@@ -6,7 +6,7 @@ import {
6
6
  IMessage,
7
7
  Libp2p,
8
8
  ProtocolCreateOptions,
9
- PubSubTopic,
9
+ PubsubTopic,
10
10
  SendError,
11
11
  SendResult
12
12
  } from "@waku/interfaces";
@@ -22,7 +22,6 @@ import { pipe } from "it-pipe";
22
22
  import { Uint8ArrayList } from "uint8arraylist";
23
23
 
24
24
  import { BaseProtocol } from "../base_protocol.js";
25
- import { DefaultPubSubTopic } from "../constants.js";
26
25
 
27
26
  import { PushRpc } from "./push_rpc.js";
28
27
 
@@ -45,12 +44,12 @@ type PreparePushMessageResult =
45
44
  * Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
46
45
  */
47
46
  class LightPush extends BaseProtocol implements ILightPush {
48
- private readonly pubsubTopics: PubSubTopic[];
47
+ private readonly pubsubTopics: PubsubTopic[];
49
48
  private readonly NUM_PEERS_PROTOCOL = 1;
50
49
 
51
50
  constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
52
51
  super(LightPushCodec, libp2p.components);
53
- this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
52
+ this.pubsubTopics = this.initializePubsubTopic(options);
54
53
  }
55
54
 
56
55
  private async preparePushMessage(
@@ -7,12 +7,11 @@ import type {
7
7
  IMetaSetter,
8
8
  IProtoMessage,
9
9
  IRateLimitProof,
10
- PubSubTopic
10
+ PubsubTopic,
11
+ SingleShardInfo
11
12
  } from "@waku/interfaces";
12
13
  import { proto_message as proto } from "@waku/proto";
13
- import { Logger } from "@waku/utils";
14
-
15
- import { DefaultPubSubTopic } from "../constants.js";
14
+ import { determinePubsubTopic, Logger } from "@waku/utils";
16
15
 
17
16
  const log = new Logger("message:version-0");
18
17
  const OneMillion = BigInt(1_000_000);
@@ -76,7 +75,7 @@ export class Encoder implements IEncoder {
76
75
  constructor(
77
76
  public contentTopic: string,
78
77
  public ephemeral: boolean = false,
79
- public pubsubTopic: PubSubTopic,
78
+ public pubsubTopic: PubsubTopic,
80
79
  public metaSetter?: IMetaSetter
81
80
  ) {
82
81
  if (!contentTopic || contentTopic === "") {
@@ -119,17 +118,23 @@ export class Encoder implements IEncoder {
119
118
  * messages.
120
119
  */
121
120
  export function createEncoder({
122
- pubsubTopic = DefaultPubSubTopic,
121
+ pubsubTopic,
122
+ pubsubTopicShardInfo,
123
123
  contentTopic,
124
124
  ephemeral,
125
125
  metaSetter
126
126
  }: EncoderOptions): Encoder {
127
- return new Encoder(contentTopic, ephemeral, pubsubTopic, metaSetter);
127
+ return new Encoder(
128
+ contentTopic,
129
+ ephemeral,
130
+ determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
131
+ metaSetter
132
+ );
128
133
  }
129
134
 
130
135
  export class Decoder implements IDecoder<DecodedMessage> {
131
136
  constructor(
132
- public pubsubTopic: PubSubTopic,
137
+ public pubsubTopic: PubsubTopic,
133
138
  public contentTopic: string
134
139
  ) {
135
140
  if (!contentTopic || contentTopic === "") {
@@ -182,7 +187,10 @@ export class Decoder implements IDecoder<DecodedMessage> {
182
187
  */
183
188
  export function createDecoder(
184
189
  contentTopic: string,
185
- pubsubTopic: PubSubTopic = DefaultPubSubTopic
190
+ pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
186
191
  ): Decoder {
187
- return new Decoder(pubsubTopic, contentTopic);
192
+ return new Decoder(
193
+ determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
194
+ contentTopic
195
+ );
188
196
  }
@@ -0,0 +1,110 @@
1
+ import type { PeerId } from "@libp2p/interface/peer-id";
2
+ import { IncomingStreamData } from "@libp2p/interface/stream-handler";
3
+ import { encodeRelayShard } from "@waku/enr";
4
+ import type {
5
+ IMetadata,
6
+ Libp2pComponents,
7
+ ShardInfo,
8
+ ShardingParams
9
+ } from "@waku/interfaces";
10
+ import { proto_metadata } from "@waku/proto";
11
+ import { Logger } from "@waku/utils";
12
+ import all from "it-all";
13
+ import * as lp from "it-length-prefixed";
14
+ import { pipe } from "it-pipe";
15
+ import { Uint8ArrayList } from "uint8arraylist";
16
+
17
+ import { BaseProtocol } from "../base_protocol.js";
18
+
19
+ const log = new Logger("metadata");
20
+
21
+ export const MetadataCodec = "/vac/waku/metadata/1.0.0";
22
+
23
+ class Metadata extends BaseProtocol {
24
+ private readonly shardInfo: ShardingParams;
25
+ private libp2pComponents: Libp2pComponents;
26
+ constructor(shardInfo: ShardingParams, libp2p: Libp2pComponents) {
27
+ super(MetadataCodec, libp2p.components);
28
+ this.libp2pComponents = libp2p;
29
+ this.shardInfo = shardInfo;
30
+ void libp2p.registrar.handle(MetadataCodec, (streamData) => {
31
+ void this.onRequest(streamData);
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Handle an incoming metadata request
37
+ */
38
+ private async onRequest(streamData: IncomingStreamData): Promise<void> {
39
+ try {
40
+ const { stream, connection } = streamData;
41
+ const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
42
+ this.shardInfo
43
+ );
44
+
45
+ const encodedResponse = await pipe(
46
+ [encodedShardInfo],
47
+ lp.encode,
48
+ stream,
49
+ lp.decode,
50
+ async (source) => await all(source)
51
+ );
52
+
53
+ const remoteShardInfoResponse =
54
+ this.decodeMetadataResponse(encodedResponse);
55
+
56
+ // add or update the shardInfo to peer store
57
+ await this.libp2pComponents.peerStore.merge(connection.remotePeer, {
58
+ metadata: {
59
+ shardInfo: encodeRelayShard(remoteShardInfoResponse)
60
+ }
61
+ });
62
+ } catch (error) {
63
+ log.error("Error handling metadata request", error);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Make a metadata query to a peer
69
+ */
70
+ async query(peerId: PeerId): Promise<ShardInfo> {
71
+ const request = proto_metadata.WakuMetadataRequest.encode(this.shardInfo);
72
+
73
+ const peer = await this.getPeer(peerId);
74
+
75
+ const stream = await this.getStream(peer);
76
+
77
+ const encodedResponse = await pipe(
78
+ [request],
79
+ lp.encode,
80
+ stream,
81
+ lp.decode,
82
+ async (source) => await all(source)
83
+ );
84
+
85
+ const decodedResponse = this.decodeMetadataResponse(encodedResponse);
86
+
87
+ return decodedResponse;
88
+ }
89
+
90
+ private decodeMetadataResponse(encodedResponse: Uint8ArrayList[]): ShardInfo {
91
+ const bytes = new Uint8ArrayList();
92
+
93
+ encodedResponse.forEach((chunk) => {
94
+ bytes.append(chunk);
95
+ });
96
+ const response = proto_metadata.WakuMetadataResponse.decode(
97
+ bytes
98
+ ) as ShardInfo;
99
+
100
+ if (!response) log.error("Error decoding metadata response");
101
+
102
+ return response;
103
+ }
104
+ }
105
+
106
+ export function wakuMetadata(
107
+ shardInfo: ShardingParams
108
+ ): (components: Libp2pComponents) => IMetadata {
109
+ return (components: Libp2pComponents) => new Metadata(shardInfo, components);
110
+ }
@@ -7,7 +7,7 @@ import {
7
7
  IStore,
8
8
  Libp2p,
9
9
  ProtocolCreateOptions,
10
- PubSubTopic
10
+ PubsubTopic
11
11
  } from "@waku/interfaces";
12
12
  import { proto_store as proto } from "@waku/proto";
13
13
  import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
@@ -19,7 +19,6 @@ import { pipe } from "it-pipe";
19
19
  import { Uint8ArrayList } from "uint8arraylist";
20
20
 
21
21
  import { BaseProtocol } from "../base_protocol.js";
22
- import { DefaultPubSubTopic } from "../constants.js";
23
22
  import { toProtoMessage } from "../to_proto_message.js";
24
23
 
25
24
  import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
@@ -75,12 +74,12 @@ export interface QueryOptions {
75
74
  * The Waku Store protocol can be used to retrieved historical messages.
76
75
  */
77
76
  class Store extends BaseProtocol implements IStore {
78
- private readonly pubsubTopics: PubSubTopic[];
77
+ private readonly pubsubTopics: PubsubTopic[];
79
78
  private readonly NUM_PEERS_PROTOCOL = 1;
80
79
 
81
80
  constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
82
81
  super(StoreCodec, libp2p.components);
83
- this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
82
+ this.pubsubTopics = this.initializePubsubTopic(options);
84
83
  }
85
84
 
86
85
  /**
@@ -230,29 +229,29 @@ class Store extends BaseProtocol implements IStore {
230
229
  }
231
230
 
232
231
  // convert array to set to remove duplicates
233
- const uniquePubSubTopicsInQuery = Array.from(
232
+ const uniquePubsubTopicsInQuery = Array.from(
234
233
  new Set(decoders.map((decoder) => decoder.pubsubTopic))
235
234
  );
236
235
 
237
236
  // If multiple pubsub topics are provided, throw an error
238
- if (uniquePubSubTopicsInQuery.length > 1) {
237
+ if (uniquePubsubTopicsInQuery.length > 1) {
239
238
  throw new Error(
240
239
  "API does not support querying multiple pubsub topics at once"
241
240
  );
242
241
  }
243
242
 
244
243
  // we can be certain that there is only one pubsub topic in the query
245
- const pubSubTopicForQuery = uniquePubSubTopicsInQuery[0];
244
+ const pubsubTopicForQuery = uniquePubsubTopicsInQuery[0];
246
245
 
247
- ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics);
246
+ ensurePubsubTopicIsConfigured(pubsubTopicForQuery, this.pubsubTopics);
248
247
 
249
248
  // check that the pubsubTopic from the Cursor and Decoder match
250
249
  if (
251
250
  options?.cursor?.pubsubTopic &&
252
- options.cursor.pubsubTopic !== pubSubTopicForQuery
251
+ options.cursor.pubsubTopic !== pubsubTopicForQuery
253
252
  ) {
254
253
  throw new Error(
255
- `Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubSubTopicForQuery})`
254
+ `Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubsubTopicForQuery})`
256
255
  );
257
256
  }
258
257
 
@@ -267,16 +266,16 @@ class Store extends BaseProtocol implements IStore {
267
266
  });
268
267
 
269
268
  const contentTopics = decoders
270
- .filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery)
269
+ .filter((decoder) => decoder.pubsubTopic === pubsubTopicForQuery)
271
270
  .map((dec) => dec.contentTopic);
272
271
 
273
272
  if (contentTopics.length === 0) {
274
- throw new Error("No decoders found for topic " + pubSubTopicForQuery);
273
+ throw new Error("No decoders found for topic " + pubsubTopicForQuery);
275
274
  }
276
275
 
277
276
  const queryOpts = Object.assign(
278
277
  {
279
- pubsubTopic: pubSubTopicForQuery,
278
+ pubsubTopic: pubsubTopicForQuery,
280
279
  pageDirection: PageDirection.BACKWARD,
281
280
  pageSize: DefaultPageSize
282
281
  },
package/src/lib/waku.ts CHANGED
@@ -7,11 +7,12 @@ import type {
7
7
  IRelay,
8
8
  IStore,
9
9
  Libp2p,
10
- PubSubTopic,
10
+ PubsubTopic,
11
+ ShardingParams,
11
12
  Waku
12
13
  } from "@waku/interfaces";
13
- import { Protocols } from "@waku/interfaces";
14
- import { Logger } from "@waku/utils";
14
+ import { DefaultPubsubTopic, Protocols } from "@waku/interfaces";
15
+ import { Logger, shardInfoToPubsubTopics } from "@waku/utils";
15
16
 
16
17
  import { ConnectionManager } from "./connection_manager.js";
17
18
 
@@ -50,16 +51,25 @@ export class WakuNode implements Waku {
50
51
  public filter?: IFilter;
51
52
  public lightPush?: ILightPush;
52
53
  public connectionManager: ConnectionManager;
54
+ public readonly pubsubTopics: PubsubTopic[];
53
55
 
54
56
  constructor(
55
57
  options: WakuOptions,
56
- public readonly pubsubTopics: PubSubTopic[],
58
+ pubsubTopics: PubsubTopic[] = [],
57
59
  libp2p: Libp2p,
60
+ pubsubShardInfo?: ShardingParams,
58
61
  store?: (libp2p: Libp2p) => IStore,
59
62
  lightPush?: (libp2p: Libp2p) => ILightPush,
60
63
  filter?: (libp2p: Libp2p) => IFilter,
61
64
  relay?: (libp2p: Libp2p) => IRelay
62
65
  ) {
66
+ if (!pubsubShardInfo) {
67
+ this.pubsubTopics =
68
+ pubsubTopics.length > 0 ? pubsubTopics : [DefaultPubsubTopic];
69
+ } else {
70
+ this.pubsubTopics = shardInfoToPubsubTopics(pubsubShardInfo);
71
+ }
72
+
63
73
  this.libp2p = libp2p;
64
74
 
65
75
  if (store) {
@@ -88,7 +98,7 @@ export class WakuNode implements Waku {
88
98
  peerId,
89
99
  libp2p,
90
100
  { pingKeepAlive, relayKeepAlive },
91
- pubsubTopics,
101
+ this.pubsubTopics,
92
102
  this.relay
93
103
  );
94
104
 
@@ -178,6 +188,10 @@ export class WakuNode implements Waku {
178
188
  return this.libp2p.isStarted();
179
189
  }
180
190
 
191
+ isConnected(): boolean {
192
+ return this.connectionManager.isConnected();
193
+ }
194
+
181
195
  /**
182
196
  * Return the local multiaddr with peer id on which libp2p is listening.
183
197
  *