@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.
@@ -1,10 +1,10 @@
1
1
  import type { Libp2p } from "@libp2p/interface";
2
2
  import type { PeerId } from "@libp2p/interface";
3
3
  import type { Peer, PeerStore } from "@libp2p/interface";
4
- import type { ShardInfo } from "./enr.js";
5
4
  import type { CreateLibp2pOptions } from "./libp2p.js";
6
5
  import type { IDecodedMessage } from "./message.js";
7
- import { PubsubTopic, ThisAndThat, ThisOrThat } from "./misc.js";
6
+ import { ThisAndThat, ThisOrThat } from "./misc.js";
7
+ import { AutoSharding, StaticSharding } from "./sharding.js";
8
8
  export declare enum Protocols {
9
9
  Relay = "relay",
10
10
  Store = "store",
@@ -12,7 +12,6 @@ export declare enum Protocols {
12
12
  Filter = "filter"
13
13
  }
14
14
  export type IBaseProtocolCore = {
15
- shardInfo?: ShardInfo;
16
15
  multicodec: string;
17
16
  peerStore: PeerStore;
18
17
  allPeers: () => Promise<Peer[]>;
@@ -21,20 +20,11 @@ export type IBaseProtocolCore = {
21
20
  removeLibp2pEventListener: Libp2p["removeEventListener"];
22
21
  };
23
22
  export type IBaseProtocolSDK = {
24
- renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
25
23
  readonly connectedPeers: Peer[];
24
+ renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
26
25
  readonly numPeersToUse: number;
27
26
  };
28
- export type ContentTopicInfo = {
29
- clusterId?: number;
30
- contentTopics: string[];
31
- };
32
- export type ApplicationInfo = {
33
- clusterId: number;
34
- application: string;
35
- version: string;
36
- };
37
- export type ShardingParams = ShardInfo | ContentTopicInfo | ApplicationInfo;
27
+ export type NetworkConfig = StaticSharding | AutoSharding;
38
28
  /**
39
29
  * Options for using LightPush and Filter
40
30
  */
@@ -62,34 +52,35 @@ export type ProtocolUseOptions = {
62
52
  };
63
53
  export type ProtocolCreateOptions = {
64
54
  /**
65
- * @deprecated
66
- * Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
67
- */
68
- pubsubTopics?: PubsubTopic[];
69
- /**
70
- * Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
71
- * The format to specify a shard is:
72
- * clusterId: number, shards: number[]
73
- * To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
74
- * The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
55
+ * Configuration for determining the network in use.
75
56
  *
76
- * If no pubsub topic is specified, the default pubsub topic is used.
77
- * The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well
78
- * You cannot currently add or remove pubsub topics after initialization.
79
- * This is used by:
80
- * - WakuRelay to receive, route and send messages,
81
- * - WakuLightPush to send messages,
82
- * - WakuStore to retrieve messages.
83
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
57
+ * If using Static Sharding:
58
+ * Default value is configured for The Waku Network.
59
+ * The format to specify a shard is: clusterId: number, shards: number[]
60
+ * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
84
61
  *
62
+ * If using Auto Sharding:
63
+ * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
64
+ * You cannot add or remove content topics after initialization of the node.
85
65
  */
86
- shardInfo?: Partial<ShardingParams>;
87
66
  /**
88
- * Content topics are used to determine pubsubTopics
89
- * If not provided pubsubTopics will be determined based on shardInfo
90
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
67
+ * Configuration for determining the network in use.
68
+ * Network configuration refers to the shards and clusters used in the network.
69
+ *
70
+ * If using Static Sharding:
71
+ * Cluster ID and shards are specified in the format: clusterId: number, shards: number[]
72
+ * The default value is configured for The Waku Network => clusterId: 0, shards: [0, 1, 2, 3, 4, 5, 6, 7]
73
+ * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
74
+ *
75
+ * If using Auto Sharding:
76
+ * Cluster ID and content topics are specified in the format: clusterId: number, contentTopics: string[]
77
+ * Content topics are used to determine the shards to be configured for the network.
78
+ * Cluster ID is optional, and defaults to The Waku Network's cluster ID => 0
79
+ * 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
80
+ *
81
+ * @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
91
82
  */
92
- contentTopics?: string[];
83
+ networkConfig?: NetworkConfig;
93
84
  /**
94
85
  * You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
95
86
  * 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)
@@ -155,6 +146,11 @@ export declare enum ProtocolError {
155
146
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
156
147
  */
157
148
  TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
149
+ /**
150
+ * The topics passed in the decoders do not match each other, or don't exist at all.
151
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
152
+ */
153
+ INVALID_DECODER_TOPICS = "Invalid decoder topics",
158
154
  /**
159
155
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
160
156
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -171,7 +167,7 @@ export declare enum ProtocolError {
171
167
  * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
172
168
  * or `DECODE_FAILED` can be used.
173
169
  */
174
- REMOTE_PEER_FAULT = "Remote peer fault",
170
+ NO_RESPONSE = "No response received",
175
171
  /**
176
172
  * The remote peer rejected the message. Information provided by the remote peer
177
173
  * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
@@ -182,7 +178,27 @@ export declare enum ProtocolError {
182
178
  * The protocol request timed out without a response. This may be due to a connection issue.
183
179
  * Mitigation can be: retrying after a given time period
184
180
  */
185
- REQUEST_TIMEOUT = "Request timeout"
181
+ REQUEST_TIMEOUT = "Request timeout",
182
+ /**
183
+ * Missing credentials info message.
184
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
185
+ */
186
+ RLN_IDENTITY_MISSING = "Identity credentials are not set",
187
+ /**
188
+ * Membership index missing info message.
189
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
190
+ */
191
+ RLN_MEMBERSHIP_INDEX = "Membership index is not set",
192
+ /**
193
+ * Message limit is missing.
194
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
195
+ */
196
+ RLN_LIMIT_MISSING = "User message limit is not set",
197
+ /**
198
+ * General proof generation error message.
199
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
200
+ */
201
+ RLN_PROOF_GENERATION = "Proof generation failed"
186
202
  }
187
203
  export interface Failure {
188
204
  error: ProtocolError;
package/dist/protocols.js CHANGED
@@ -39,6 +39,11 @@ export var ProtocolError;
39
39
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
40
40
  */
41
41
  ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
42
+ /**
43
+ * The topics passed in the decoders do not match each other, or don't exist at all.
44
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
45
+ */
46
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
42
47
  /**
43
48
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
44
49
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -55,7 +60,7 @@ export var ProtocolError;
55
60
  * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
56
61
  * or `DECODE_FAILED` can be used.
57
62
  */
58
- ProtocolError["REMOTE_PEER_FAULT"] = "Remote peer fault";
63
+ ProtocolError["NO_RESPONSE"] = "No response received";
59
64
  /**
60
65
  * The remote peer rejected the message. Information provided by the remote peer
61
66
  * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
@@ -67,5 +72,25 @@ export var ProtocolError;
67
72
  * Mitigation can be: retrying after a given time period
68
73
  */
69
74
  ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
75
+ /**
76
+ * Missing credentials info message.
77
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
78
+ */
79
+ ProtocolError["RLN_IDENTITY_MISSING"] = "Identity credentials are not set";
80
+ /**
81
+ * Membership index missing info message.
82
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
83
+ */
84
+ ProtocolError["RLN_MEMBERSHIP_INDEX"] = "Membership index is not set";
85
+ /**
86
+ * Message limit is missing.
87
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
88
+ */
89
+ ProtocolError["RLN_LIMIT_MISSING"] = "User message limit is not set";
90
+ /**
91
+ * General proof generation error message.
92
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
93
+ */
94
+ ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
70
95
  })(ProtocolError || (ProtocolError = {}));
71
96
  //# sourceMappingURL=protocols.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AA4HD,MAAM,CAAN,IAAY,aA6DX;AA7DD,WAAY,aAAa;IACvB,4FAA4F;IAC5F,+CAA8B,CAAA;IAC9B;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,iDAAgC,CAAA;IAChC;;;OAGG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;;;OAKG;IACH,wDAAuC,CAAA;IACvC;;;OAGG;IACH,4DAA2C,CAAA;IAC3C;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,oDAAmC,CAAA;AACrC,CAAC,EA7DW,aAAa,KAAb,aAAa,QA6DxB"}
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAiHD,MAAM,CAAN,IAAY,aAsFX;AAtFD,WAAY,aAAa;IACvB,4FAA4F;IAC5F,+CAA8B,CAAA;IAC9B;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,iDAAgC,CAAA;IAChC;;;OAGG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;;;OAKG;IACH,wDAAuC,CAAA;IACvC;;;OAGG;IACH,4DAA2C,CAAA;IAC3C;;;OAGG;IACH,qDAAoC,CAAA;IACpC;;;;OAIG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,oDAAmC,CAAA;IACnC;;;OAGG;IACH,0EAAyD,CAAA;IACzD;;;OAGG;IACH,qEAAoD,CAAA;IACpD;;;OAGG;IACH,oEAAmD,CAAA;IACnD;;;OAGG;IACH,iEAAgD,CAAA;AAClD,CAAC,EAtFW,aAAa,KAAb,aAAa,QAsFxB"}
@@ -4,5 +4,7 @@ import type { Callback } from "./protocols.js";
4
4
  export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
5
5
  export interface IReceiver {
6
6
  toSubscriptionIterator: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[]) => Promise<IAsyncIterator<T>>;
7
- subscribe: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => Unsubscribe | Promise<Unsubscribe>;
7
+ subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
8
8
  }
9
+ type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => Unsubscribe | Promise<Unsubscribe>;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ export type ShardInfo = {
2
+ clusterId: number;
3
+ shards: number[];
4
+ };
5
+ export type ContentTopicInfo = {
6
+ clusterId?: number;
7
+ contentTopics: string[];
8
+ };
9
+ export type StaticSharding = ShardInfo;
10
+ export type AutoSharding = ContentTopicInfo;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sharding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharding.js","sourceRoot":"","sources":["../src/sharding.ts"],"names":[],"mappings":""}
package/dist/store.d.ts CHANGED
@@ -1,51 +1,75 @@
1
- import { proto_store as proto } from "@waku/proto";
2
1
  import type { IDecodedMessage, IDecoder } from "./message.js";
3
2
  import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
4
- export declare enum PageDirection {
5
- BACKWARD = "backward",
6
- FORWARD = "forward"
7
- }
8
- export interface TimeFilter {
9
- startTime: Date;
10
- endTime: Date;
11
- }
12
- export interface Cursor {
13
- digest: Uint8Array;
14
- receiverTime: bigint;
15
- senderTime: bigint;
3
+ export type StoreCursor = Uint8Array;
4
+ /**
5
+ * Parameters for a store query request, as specified in the Waku Store v3 RFC.
6
+ */
7
+ export type QueryRequestParams = {
8
+ /**
9
+ * Whether to include the full message data in the response.
10
+ * - `true`: The response will include the message content and associated pubsub topic for each matching message.
11
+ * - `false`: The response will only include the message hashes for each matching message.
12
+ * @default true
13
+ */
14
+ includeData: boolean;
15
+ /**
16
+ * The pubsub topic to query. This field is mandatory.
17
+ * The query will only return messages that were published on this specific pubsub topic.
18
+ */
16
19
  pubsubTopic: string;
17
- }
18
- export type StoreQueryOptions = {
19
20
  /**
20
- * The direction in which pages are retrieved:
21
- * - { @link PageDirection.BACKWARD }: Most recent page first.
22
- * - { @link PageDirection.FORWARD }: Oldest page first.
23
- *
24
- * Note: This does not affect the ordering of messages with the page
25
- * (the oldest message is always first).
26
- *
27
- * @default { @link PageDirection.BACKWARD }
21
+ * The content topics to filter the messages.
22
+ * The query will only return messages that have a content topic included in this array.
23
+ * This field MUST be populated together with the `pubsubTopic` field for content topic filtering to be applied.
24
+ * If either `contentTopics` or `pubsubTopic` is not provided or empty, no content topic filtering will be applied.
25
+ */
26
+ contentTopics: string[];
27
+ /**
28
+ * The start time for the time range filter.
29
+ * The query will only return messages with a timestamp greater than or equal to `timeStart`.
30
+ * If not provided, no start time filtering will be applied.
31
+ */
32
+ timeStart?: Date;
33
+ /**
34
+ * The end time for the time range filter.
35
+ * The query will only return messages with a timestamp strictly less than `timeEnd`.
36
+ * If not provided, no end time filtering will be applied.
37
+ */
38
+ timeEnd?: Date;
39
+ /**
40
+ * The message hashes to lookup.
41
+ * If provided, the query will be a message hash lookup query and will only return messages that match the specified hashes.
42
+ * If not provided or empty, the query will be a content filtered query based on the other filter parameters.
43
+ * @default undefined
28
44
  */
29
- pageDirection?: PageDirection;
45
+ messageHashes?: Uint8Array[];
30
46
  /**
31
- * The number of message per page.
47
+ * The cursor to start the query from.
48
+ * The cursor represents the message hash of the last message returned in the previous query.
49
+ * The query will start from the message immediately following the cursor, excluding the message at the cursor itself.
50
+ * If not provided, the query will start from the beginning or end of the store, depending on the `paginationForward` option.
51
+ * @default undefined
32
52
  */
33
- pageSize?: number;
53
+ paginationCursor?: Uint8Array;
34
54
  /**
35
- * Retrieve messages with a timestamp within the provided values.
55
+ * The direction of pagination.
56
+ * - `true`: Forward pagination, starting from the oldest message and moving towards the newest.
57
+ * - `false`: Backward pagination, starting from the newest message and moving towards the oldest.
58
+ * @default false
36
59
  */
37
- timeFilter?: TimeFilter;
60
+ paginationForward: boolean;
38
61
  /**
39
- * Cursor as an index to start a query from. Must be generated from a Waku
40
- * Message.
62
+ * The maximum number of messages to retrieve per page.
63
+ * If not provided, the store's default pagination limit will be used.
64
+ * @default undefined
41
65
  */
42
- cursor?: proto.Index;
66
+ paginationLimit?: number;
43
67
  };
44
68
  export type IStoreCore = IBaseProtocolCore;
45
69
  export type IStoreSDK = IBaseProtocolSDK & {
46
70
  protocol: IBaseProtocolCore;
47
- createCursor(message: IDecodedMessage): Cursor;
48
- queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
49
- queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
50
- queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
71
+ createCursor(message: IDecodedMessage): StoreCursor;
72
+ queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: Partial<QueryRequestParams>) => AsyncGenerator<Promise<T | undefined>[]>;
73
+ queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
74
+ queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
51
75
  };
package/dist/store.js CHANGED
@@ -1,6 +1,2 @@
1
- export var PageDirection;
2
- (function (PageDirection) {
3
- PageDirection["BACKWARD"] = "backward";
4
- PageDirection["FORWARD"] = "forward";
5
- })(PageDirection || (PageDirection = {}));
1
+ export {};
6
2
  //# sourceMappingURL=store.js.map
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
package/dist/waku.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { PeerId, Stream } from "@libp2p/interface";
2
2
  import type { MultiaddrInput } from "@multiformats/multiaddr";
3
3
  import { IConnectionManager } from "./connection_manager.js";
4
4
  import type { IFilterSDK } from "./filter.js";
5
+ import { IHealthManager } from "./health_manager.js";
5
6
  import type { Libp2p } from "./libp2p.js";
6
7
  import type { ILightPushSDK } from "./light_push.js";
7
8
  import { Protocols } from "./protocols.js";
@@ -19,6 +20,7 @@ export interface Waku {
19
20
  stop(): Promise<void>;
20
21
  isStarted(): boolean;
21
22
  isConnected(): boolean;
23
+ health: IHealthManager;
22
24
  }
23
25
  export interface LightNode extends Waku {
24
26
  relay: undefined;
package/package.json CHANGED
@@ -1 +1,69 @@
1
- {"name":"@waku/interfaces","version":"0.0.26-ce62600.0","description":"Definition of Waku interfaces","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","fix":"run-s fix:*","fix:lint":"eslint src --fix","check":"run-s check:*","check:lint":"eslint src","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=18"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^12.0.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"^1.1.2"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.8-ce62600.0"}}
1
+ {
2
+ "name": "@waku/interfaces",
3
+ "version": "0.0.26",
4
+ "description": "Definition of Waku interfaces",
5
+ "types": "./dist/index.d.ts",
6
+ "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "type": "module",
14
+ "author": "Waku Team",
15
+ "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/waku-org/js-waku.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/waku-org/js-waku/issues"
22
+ },
23
+ "license": "MIT OR Apache-2.0",
24
+ "keywords": [
25
+ "waku",
26
+ "decentralized",
27
+ "secure",
28
+ "communication",
29
+ "web3",
30
+ "ethereum",
31
+ "dapps",
32
+ "privacy"
33
+ ],
34
+ "scripts": {
35
+ "build": "run-s build:**",
36
+ "build:esm": "tsc",
37
+ "fix": "run-s fix:*",
38
+ "fix:lint": "eslint src --fix",
39
+ "check": "run-s check:*",
40
+ "check:lint": "eslint src",
41
+ "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
42
+ "check:tsc": "tsc -p tsconfig.dev.json",
43
+ "prepublish": "npm run build",
44
+ "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
45
+ },
46
+ "engines": {
47
+ "node": ">=20"
48
+ },
49
+ "devDependencies": {
50
+ "@chainsafe/libp2p-gossipsub": "^13.1.0",
51
+ "@multiformats/multiaddr": "^12.0.0",
52
+ "cspell": "^8.6.1",
53
+ "npm-run-all": "^4.1.5",
54
+ "libp2p": "^1.8.1"
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "bundle",
59
+ "src/**/*.ts",
60
+ "!**/*.spec.*",
61
+ "!**/*.json",
62
+ "CHANGELOG.md",
63
+ "LICENSE",
64
+ "README.md"
65
+ ],
66
+ "dependencies": {
67
+ "@waku/proto": "^0.0.8"
68
+ }
69
+ }
@@ -1,5 +1,7 @@
1
1
  import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
2
2
 
3
+ import { PubsubTopic } from "./misc";
4
+
3
5
  export enum Tags {
4
6
  BOOTSTRAP = "bootstrap",
5
7
  PEER_EXCHANGE = "peer-exchange",
@@ -61,6 +63,7 @@ export interface IConnectionStateEvents {
61
63
 
62
64
  export interface IConnectionManager
63
65
  extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
66
+ configuredPubsubTopics: PubsubTopic[];
64
67
  dropConnection(peerId: PeerId): Promise<void>;
65
68
  getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
66
69
  stop(): void;
package/src/constants.ts CHANGED
@@ -1,9 +1,16 @@
1
- /**
2
- * DefaultPubsubTopic is the default gossipsub topic to use for Waku.
3
- */
4
- export const DefaultPubsubTopic = "/waku/2/default-waku/proto";
1
+ import type { ShardInfo } from "./sharding";
5
2
 
6
3
  /**
7
4
  * The default cluster ID for The Waku Network
8
5
  */
9
6
  export const DEFAULT_CLUSTER_ID = 1;
7
+
8
+ /**
9
+ * DefaultShardInfo is default configuration for The Waku Network.
10
+ */
11
+ export const DefaultShardInfo: ShardInfo = {
12
+ clusterId: DEFAULT_CLUSTER_ID,
13
+ shards: [0, 1, 2, 3, 4, 5, 6, 7, 8]
14
+ };
15
+
16
+ export const DefaultNetworkConfig = DefaultShardInfo;
package/src/enr.ts CHANGED
@@ -2,6 +2,8 @@ import type { PeerId } from "@libp2p/interface";
2
2
  import type { PeerInfo } from "@libp2p/interface";
3
3
  import type { Multiaddr } from "@multiformats/multiaddr";
4
4
 
5
+ import { ShardInfo } from "./sharding";
6
+
5
7
  export type ENRKey = string;
6
8
  export type ENRValue = Uint8Array;
7
9
  /**
@@ -18,11 +20,6 @@ export interface Waku2 {
18
20
  lightPush: boolean;
19
21
  }
20
22
 
21
- export interface ShardInfo {
22
- clusterId: number;
23
- shards: number[];
24
- }
25
-
26
23
  export interface IEnr extends Map<ENRKey, ENRValue> {
27
24
  nodeId?: NodeId;
28
25
  peerId?: PeerId;
package/src/filter.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  import type { PeerId } from "@libp2p/interface";
2
2
 
3
3
  import type { IDecodedMessage, IDecoder } from "./message.js";
4
- import type { ContentTopic, PubsubTopic, ThisOrThat } from "./misc.js";
4
+ import type { ContentTopic, ThisOrThat } from "./misc.js";
5
5
  import type {
6
6
  Callback,
7
7
  IBaseProtocolCore,
8
8
  IBaseProtocolSDK,
9
9
  ProtocolError,
10
10
  ProtocolUseOptions,
11
- SDKProtocolResult,
12
- ShardingParams
11
+ SDKProtocolResult
13
12
  } from "./protocols.js";
14
13
  import type { IReceiver } from "./receiver.js";
15
14
 
16
15
  export type SubscribeOptions = {
17
16
  keepAlive?: number;
18
17
  pingsBeforePeerRenewed?: number;
18
+ maxMissedMessagesThreshold?: number;
19
19
  };
20
20
 
21
21
  export type IFilter = IReceiver & IBaseProtocolCore;
@@ -36,12 +36,28 @@ export interface ISubscriptionSDK {
36
36
 
37
37
  export type IFilterSDK = IReceiver &
38
38
  IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
39
- createSubscription(
40
- pubsubTopicShardInfo?: ShardingParams | PubsubTopic,
41
- options?: ProtocolUseOptions
42
- ): Promise<CreateSubscriptionResult>;
39
+ subscribe<T extends IDecodedMessage>(
40
+ decoders: IDecoder<T> | IDecoder<T>[],
41
+ callback: Callback<T>,
42
+ protocolUseOptions?: ProtocolUseOptions,
43
+ subscribeOptions?: SubscribeOptions
44
+ ): Promise<SubscribeResult>;
43
45
  };
44
46
 
47
+ export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
48
+
49
+ type SubscriptionSuccess = {
50
+ subscription: ISubscriptionSDK;
51
+ error: null;
52
+ results: SDKProtocolResult;
53
+ };
54
+
55
+ type SubscriptionError = {
56
+ subscription: null;
57
+ error: ProtocolError;
58
+ results: null;
59
+ };
60
+
45
61
  export type CreateSubscriptionResult = ThisOrThat<
46
62
  "subscription",
47
63
  ISubscriptionSDK,
@@ -0,0 +1,26 @@
1
+ import { Protocols } from "./protocols";
2
+
3
+ export enum HealthStatus {
4
+ Unhealthy = "Unhealthy",
5
+ MinimallyHealthy = "MinimallyHealthy",
6
+ SufficientlyHealthy = "SufficientlyHealthy"
7
+ }
8
+
9
+ export interface IHealthManager {
10
+ getHealthStatus: () => HealthStatus;
11
+ getProtocolStatus: (protocol: Protocols) => ProtocolHealth | undefined;
12
+ updateProtocolHealth: (multicodec: string, connectedPeers: number) => void;
13
+ }
14
+
15
+ export type NodeHealth = {
16
+ overallStatus: HealthStatus;
17
+ protocolStatuses: ProtocolsHealthStatus;
18
+ };
19
+
20
+ export type ProtocolHealth = {
21
+ name: Protocols;
22
+ status: HealthStatus;
23
+ lastUpdate: Date;
24
+ };
25
+
26
+ export type ProtocolsHealthStatus = Map<Protocols, ProtocolHealth>;
package/src/index.ts CHANGED
@@ -17,3 +17,5 @@ export * from "./dns_discovery.js";
17
17
  export * from "./metadata.js";
18
18
  export * from "./constants.js";
19
19
  export * from "./local_storage.js";
20
+ export * from "./health_manager.js";
21
+ export * from "./sharding.js";
package/src/libp2p.ts CHANGED
@@ -30,4 +30,9 @@ export type CreateLibp2pOptions = Libp2pOptions & {
30
30
  */
31
31
  hideWebSocketInfo?: boolean;
32
32
  pingMaxInboundStreams?: number;
33
+ /**
34
+ * Applies secure web socket filters.
35
+ * @default true
36
+ */
37
+ filterMultiaddrs?: boolean;
33
38
  };
package/src/metadata.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { PeerId } from "@libp2p/interface";
2
2
 
3
- import { type ShardInfo } from "./enr.js";
4
- import { ThisOrThat } from "./misc.js";
5
- import type { IBaseProtocolCore, ShardingParams } from "./protocols.js";
3
+ import { PubsubTopic, ThisOrThat } from "./misc.js";
4
+ import type { IBaseProtocolCore } from "./protocols.js";
5
+ import type { ShardInfo } from "./sharding.js";
6
6
 
7
7
  export type MetadataQueryResult = ThisOrThat<"shardInfo", ShardInfo>;
8
8
 
9
9
  // IMetadata always has shardInfo defined while it is optionally undefined in IBaseProtocol
10
10
  export interface IMetadata extends Omit<IBaseProtocolCore, "shardInfo"> {
11
- shardInfo: ShardingParams;
11
+ pubsubTopics: PubsubTopic[];
12
12
  confirmOrAttemptHandshake(peerId: PeerId): Promise<MetadataQueryResult>;
13
13
  query(peerId: PeerId): Promise<MetadataQueryResult>;
14
14
  }