@waku/interfaces 0.0.26-ce62600.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.
package/src/protocols.ts CHANGED
@@ -2,10 +2,10 @@ import type { Libp2p } from "@libp2p/interface";
2
2
  import type { PeerId } from "@libp2p/interface";
3
3
  import type { Peer, PeerStore } from "@libp2p/interface";
4
4
 
5
- import type { ShardInfo } from "./enr.js";
6
5
  import type { CreateLibp2pOptions } from "./libp2p.js";
7
6
  import type { IDecodedMessage } from "./message.js";
8
- import { PubsubTopic, ThisAndThat, ThisOrThat } from "./misc.js";
7
+ import { ThisAndThat, ThisOrThat } from "./misc.js";
8
+ import { AutoSharding, StaticSharding } from "./sharding.js";
9
9
 
10
10
  export enum Protocols {
11
11
  Relay = "relay",
@@ -15,7 +15,6 @@ export enum Protocols {
15
15
  }
16
16
 
17
17
  export type IBaseProtocolCore = {
18
- shardInfo?: ShardInfo;
19
18
  multicodec: string;
20
19
  peerStore: PeerStore;
21
20
  allPeers: () => Promise<Peer[]>;
@@ -25,23 +24,12 @@ export type IBaseProtocolCore = {
25
24
  };
26
25
 
27
26
  export type IBaseProtocolSDK = {
28
- renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
29
27
  readonly connectedPeers: Peer[];
28
+ renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
30
29
  readonly numPeersToUse: number;
31
30
  };
32
31
 
33
- export type ContentTopicInfo = {
34
- clusterId?: number;
35
- contentTopics: string[];
36
- };
37
-
38
- export type ApplicationInfo = {
39
- clusterId: number;
40
- application: string;
41
- version: string;
42
- };
43
-
44
- export type ShardingParams = ShardInfo | ContentTopicInfo | ApplicationInfo;
32
+ export type NetworkConfig = StaticSharding | AutoSharding;
45
33
 
46
34
  //TODO: merge this with ProtocolCreateOptions or establish distinction: https://github.com/waku-org/js-waku/issues/2048
47
35
  /**
@@ -72,34 +60,35 @@ export type ProtocolUseOptions = {
72
60
 
73
61
  export type ProtocolCreateOptions = {
74
62
  /**
75
- * @deprecated
76
- * Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
77
- */
78
- pubsubTopics?: PubsubTopic[];
79
- /**
80
- * Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
81
- * The format to specify a shard is:
82
- * clusterId: number, shards: number[]
83
- * To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
84
- * The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
63
+ * Configuration for determining the network in use.
85
64
  *
86
- * If no pubsub topic is specified, the default pubsub topic is used.
87
- * The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well
88
- * You cannot currently add or remove pubsub topics after initialization.
89
- * This is used by:
90
- * - WakuRelay to receive, route and send messages,
91
- * - WakuLightPush to send messages,
92
- * - WakuStore to retrieve messages.
93
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
65
+ * If using Static Sharding:
66
+ * Default value is configured for The Waku Network.
67
+ * The format to specify a shard is: clusterId: number, shards: number[]
68
+ * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
94
69
  *
70
+ * If using Auto Sharding:
71
+ * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
72
+ * You cannot add or remove content topics after initialization of the node.
95
73
  */
96
- shardInfo?: Partial<ShardingParams>;
97
74
  /**
98
- * Content topics are used to determine pubsubTopics
99
- * If not provided pubsubTopics will be determined based on shardInfo
100
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
75
+ * Configuration for determining the network in use.
76
+ * Network configuration refers to the shards and clusters used in the network.
77
+ *
78
+ * If using Static Sharding:
79
+ * Cluster ID and shards are specified in the format: clusterId: number, shards: number[]
80
+ * The default value is configured for The Waku Network => clusterId: 0, shards: [0, 1, 2, 3, 4, 5, 6, 7]
81
+ * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
82
+ *
83
+ * If using Auto Sharding:
84
+ * Cluster ID and content topics are specified in the format: clusterId: number, contentTopics: string[]
85
+ * Content topics are used to determine the shards to be configured for the network.
86
+ * Cluster ID is optional, and defaults to The Waku Network's cluster ID => 0
87
+ * To specify content topics, see [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details
88
+ *
89
+ * @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
101
90
  */
102
- contentTopics?: string[];
91
+ networkConfig?: NetworkConfig;
103
92
  /**
104
93
  * You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
105
94
  * This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
@@ -169,6 +158,11 @@ export enum ProtocolError {
169
158
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
170
159
  */
171
160
  TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
161
+ /**
162
+ * The topics passed in the decoders do not match each other, or don't exist at all.
163
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
164
+ */
165
+ INVALID_DECODER_TOPICS = "Invalid decoder topics",
172
166
  /**
173
167
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
174
168
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -185,7 +179,7 @@ export enum ProtocolError {
185
179
  * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
186
180
  * or `DECODE_FAILED` can be used.
187
181
  */
188
- REMOTE_PEER_FAULT = "Remote peer fault",
182
+ NO_RESPONSE = "No response received",
189
183
  /**
190
184
  * The remote peer rejected the message. Information provided by the remote peer
191
185
  * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
@@ -196,7 +190,27 @@ export enum ProtocolError {
196
190
  * The protocol request timed out without a response. This may be due to a connection issue.
197
191
  * Mitigation can be: retrying after a given time period
198
192
  */
199
- REQUEST_TIMEOUT = "Request timeout"
193
+ REQUEST_TIMEOUT = "Request timeout",
194
+ /**
195
+ * Missing credentials info message.
196
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
197
+ */
198
+ RLN_IDENTITY_MISSING = "Identity credentials are not set",
199
+ /**
200
+ * Membership index missing info message.
201
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
202
+ */
203
+ RLN_MEMBERSHIP_INDEX = "Membership index is not set",
204
+ /**
205
+ * Message limit is missing.
206
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
207
+ */
208
+ RLN_LIMIT_MISSING = "User message limit is not set",
209
+ /**
210
+ * General proof generation error message.
211
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
212
+ */
213
+ RLN_PROOF_GENERATION = "Proof generation failed"
200
214
  }
201
215
 
202
216
  export interface Failure {
package/src/receiver.ts CHANGED
@@ -13,8 +13,10 @@ export interface IReceiver {
13
13
  toSubscriptionIterator: <T extends IDecodedMessage>(
14
14
  decoders: IDecoder<T> | IDecoder<T>[]
15
15
  ) => Promise<IAsyncIterator<T>>;
16
- subscribe: <T extends IDecodedMessage>(
17
- decoders: IDecoder<T> | IDecoder<T>[],
18
- callback: Callback<T>
19
- ) => Unsubscribe | Promise<Unsubscribe>;
16
+ subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
20
17
  }
18
+
19
+ type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(
20
+ decoders: IDecoder<T> | IDecoder<T>[],
21
+ callback: Callback<T>
22
+ ) => Unsubscribe | Promise<Unsubscribe>;
@@ -0,0 +1,12 @@
1
+ export type ShardInfo = {
2
+ clusterId: number;
3
+ shards: number[];
4
+ };
5
+
6
+ export type ContentTopicInfo = {
7
+ clusterId?: number;
8
+ contentTopics: string[];
9
+ };
10
+
11
+ export type StaticSharding = ShardInfo;
12
+ export type AutoSharding = ContentTopicInfo;
package/src/store.ts CHANGED
@@ -1,72 +1,101 @@
1
- import { proto_store as proto } from "@waku/proto";
2
-
3
1
  import type { IDecodedMessage, IDecoder } from "./message.js";
4
2
  import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
5
3
 
6
- export enum PageDirection {
7
- BACKWARD = "backward",
8
- FORWARD = "forward"
9
- }
4
+ export type StoreCursor = Uint8Array;
10
5
 
11
- export interface TimeFilter {
12
- startTime: Date;
13
- endTime: Date;
14
- }
6
+ /**
7
+ * Parameters for a store query request, as specified in the Waku Store v3 RFC.
8
+ */
9
+ export type QueryRequestParams = {
10
+ /**
11
+ * Whether to include the full message data in the response.
12
+ * - `true`: The response will include the message content and associated pubsub topic for each matching message.
13
+ * - `false`: The response will only include the message hashes for each matching message.
14
+ * @default true
15
+ */
16
+ includeData: boolean;
15
17
 
16
- export interface Cursor {
17
- digest: Uint8Array;
18
- receiverTime: bigint;
19
- senderTime: bigint;
18
+ /**
19
+ * The pubsub topic to query. This field is mandatory.
20
+ * The query will only return messages that were published on this specific pubsub topic.
21
+ */
20
22
  pubsubTopic: string;
21
- }
22
23
 
23
- export type StoreQueryOptions = {
24
24
  /**
25
- * The direction in which pages are retrieved:
26
- * - { @link PageDirection.BACKWARD }: Most recent page first.
27
- * - { @link PageDirection.FORWARD }: Oldest page first.
28
- *
29
- * Note: This does not affect the ordering of messages with the page
30
- * (the oldest message is always first).
31
- *
32
- * @default { @link PageDirection.BACKWARD }
25
+ * The content topics to filter the messages.
26
+ * The query will only return messages that have a content topic included in this array.
27
+ * This field MUST be populated together with the `pubsubTopic` field for content topic filtering to be applied.
28
+ * If either `contentTopics` or `pubsubTopic` is not provided or empty, no content topic filtering will be applied.
33
29
  */
34
- pageDirection?: PageDirection;
30
+ contentTopics: string[];
31
+
35
32
  /**
36
- * The number of message per page.
33
+ * The start time for the time range filter.
34
+ * The query will only return messages with a timestamp greater than or equal to `timeStart`.
35
+ * If not provided, no start time filtering will be applied.
37
36
  */
38
- pageSize?: number;
37
+ timeStart?: Date;
38
+
39
39
  /**
40
- * Retrieve messages with a timestamp within the provided values.
40
+ * The end time for the time range filter.
41
+ * The query will only return messages with a timestamp strictly less than `timeEnd`.
42
+ * If not provided, no end time filtering will be applied.
41
43
  */
42
- timeFilter?: TimeFilter;
44
+ timeEnd?: Date;
45
+
46
+ /**
47
+ * The message hashes to lookup.
48
+ * If provided, the query will be a message hash lookup query and will only return messages that match the specified hashes.
49
+ * If not provided or empty, the query will be a content filtered query based on the other filter parameters.
50
+ * @default undefined
51
+ */
52
+ messageHashes?: Uint8Array[];
53
+
54
+ /**
55
+ * The cursor to start the query from.
56
+ * The cursor represents the message hash of the last message returned in the previous query.
57
+ * The query will start from the message immediately following the cursor, excluding the message at the cursor itself.
58
+ * If not provided, the query will start from the beginning or end of the store, depending on the `paginationForward` option.
59
+ * @default undefined
60
+ */
61
+ paginationCursor?: Uint8Array;
62
+
63
+ /**
64
+ * The direction of pagination.
65
+ * - `true`: Forward pagination, starting from the oldest message and moving towards the newest.
66
+ * - `false`: Backward pagination, starting from the newest message and moving towards the oldest.
67
+ * @default false
68
+ */
69
+ paginationForward: boolean;
70
+
43
71
  /**
44
- * Cursor as an index to start a query from. Must be generated from a Waku
45
- * Message.
72
+ * The maximum number of messages to retrieve per page.
73
+ * If not provided, the store's default pagination limit will be used.
74
+ * @default undefined
46
75
  */
47
- cursor?: proto.Index;
76
+ paginationLimit?: number;
48
77
  };
49
78
 
50
79
  export type IStoreCore = IBaseProtocolCore;
51
80
 
52
81
  export type IStoreSDK = IBaseProtocolSDK & {
53
82
  protocol: IBaseProtocolCore;
54
- createCursor(message: IDecodedMessage): Cursor;
83
+ createCursor(message: IDecodedMessage): StoreCursor;
55
84
  queryGenerator: <T extends IDecodedMessage>(
56
85
  decoders: IDecoder<T>[],
57
- options?: StoreQueryOptions
86
+ options?: Partial<QueryRequestParams>
58
87
  ) => AsyncGenerator<Promise<T | undefined>[]>;
59
88
 
60
89
  queryWithOrderedCallback: <T extends IDecodedMessage>(
61
90
  decoders: IDecoder<T>[],
62
91
  callback: (message: T) => Promise<void | boolean> | boolean | void,
63
- options?: StoreQueryOptions
92
+ options?: Partial<QueryRequestParams>
64
93
  ) => Promise<void>;
65
94
  queryWithPromiseCallback: <T extends IDecodedMessage>(
66
95
  decoders: IDecoder<T>[],
67
96
  callback: (
68
97
  message: Promise<T | undefined>
69
98
  ) => Promise<void | boolean> | boolean | void,
70
- options?: StoreQueryOptions
99
+ options?: Partial<QueryRequestParams>
71
100
  ) => Promise<void>;
72
101
  };
package/src/waku.ts CHANGED
@@ -3,6 +3,7 @@ import type { MultiaddrInput } from "@multiformats/multiaddr";
3
3
 
4
4
  import { IConnectionManager } from "./connection_manager.js";
5
5
  import type { IFilterSDK } from "./filter.js";
6
+ import { IHealthManager } from "./health_manager.js";
6
7
  import type { Libp2p } from "./libp2p.js";
7
8
  import type { ILightPushSDK } from "./light_push.js";
8
9
  import { Protocols } from "./protocols.js";
@@ -27,6 +28,8 @@ export interface Waku {
27
28
  isStarted(): boolean;
28
29
 
29
30
  isConnected(): boolean;
31
+
32
+ health: IHealthManager;
30
33
  }
31
34
 
32
35
  export interface LightNode extends Waku {