@waku/interfaces 0.0.29-66cf711.0 → 0.0.29-9094860.0

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,13 @@
1
1
  import type { Libp2p } from "@libp2p/interface";
2
2
  import type { PeerId } from "@libp2p/interface";
3
- import type { Peer } from "@libp2p/interface";
3
+ import type { ConnectionManagerOptions } from "./connection_manager.js";
4
+ import type { FilterProtocolOptions } from "./filter.js";
4
5
  import type { CreateLibp2pOptions } from "./libp2p.js";
6
+ import type { LightPushProtocolOptions } from "./light_push.js";
5
7
  import type { IDecodedMessage } from "./message.js";
6
- import { ThisAndThat, ThisOrThat } from "./misc.js";
7
- import { AutoSharding, StaticSharding } from "./sharding.js";
8
+ import type { ThisAndThat, ThisOrThat } from "./misc.js";
9
+ import type { AutoSharding, StaticSharding } from "./sharding.js";
10
+ import type { StoreProtocolOptions } from "./store.js";
8
11
  export declare enum Protocols {
9
12
  Relay = "relay",
10
13
  Store = "store",
@@ -13,43 +16,24 @@ export declare enum Protocols {
13
16
  }
14
17
  export type IBaseProtocolCore = {
15
18
  multicodec: string;
16
- allPeers: () => Promise<Peer[]>;
17
- connectedPeers: () => Promise<Peer[]>;
18
19
  addLibp2pEventListener: Libp2p["addEventListener"];
19
20
  removeLibp2pEventListener: Libp2p["removeEventListener"];
20
21
  };
21
- export type IBaseProtocolSDK = {
22
- readonly connectedPeers: Peer[];
23
- renewPeer: (peerToDisconnect: PeerId) => Promise<Peer | undefined>;
24
- readonly numPeersToUse: number;
25
- };
26
22
  export type NetworkConfig = StaticSharding | AutoSharding;
27
- /**
28
- * Options for using LightPush and Filter
29
- */
30
- export type ProtocolUseOptions = {
31
- /**
32
- * Optional flag to force using all available peers
33
- */
34
- forceUseAllPeers?: boolean;
23
+ export type CreateNodeOptions = {
35
24
  /**
36
- * Optional maximum number of attempts for exponential backoff
25
+ * Set the user agent string to be used in identification of the node.
26
+ *
27
+ * @default "js-waku"
37
28
  */
38
- maxAttempts?: number;
39
- };
40
- export type ProtocolCreateOptions = {
29
+ userAgent?: string;
41
30
  /**
42
- * Configuration for determining the network in use.
43
- *
44
- * If using Static Sharding:
45
- * Default value is configured for The Waku Network.
46
- * The format to specify a shard is: clusterId: number, shards: number[]
47
- * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
31
+ * Starts Waku node automatically upon creations.
32
+ * Calls {@link @waku/sdk!WakuNode.start} before returning {@link @waku/sdk!WakuNode}
48
33
  *
49
- * If using Auto Sharding:
50
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
51
- * You cannot add or remove content topics after initialization of the node.
34
+ * @default true
52
35
  */
36
+ autoStart?: boolean;
53
37
  /**
54
38
  * Configuration for determining the network in use.
55
39
  * Network configuration refers to the shards and clusters used in the network.
@@ -78,10 +62,9 @@ export type ProtocolCreateOptions = {
78
62
  libp2p?: Partial<CreateLibp2pOptions>;
79
63
  /**
80
64
  * Number of peers to connect to, for the usage of the protocol.
81
- * This is used by:
82
- * - Light Push to send messages,
83
- * - Filter to retrieve messages.
84
- * Defaults to 2.
65
+ * This is used by Filter to retrieve messages.
66
+ *
67
+ * @default 2.
85
68
  */
86
69
  numPeersToUse?: number;
87
70
  /**
@@ -98,46 +81,44 @@ export type ProtocolCreateOptions = {
98
81
  * List of peers to use to bootstrap the node. Ignored if defaultBootstrap is set to true.
99
82
  */
100
83
  bootstrapPeers?: string[];
101
- };
102
- export type Callback<T extends IDecodedMessage> = (msg: T) => void | Promise<void>;
103
- export declare enum ProtocolError {
104
- /** Could not determine the origin of the fault. Best to check connectivity and try again */
105
- GENERIC_FAIL = "Generic error",
106
84
  /**
107
- * Failure to protobuf encode the message. This is not recoverable and needs
108
- * further investigation.
85
+ * Configuration for connection manager.
86
+ * If not specified - default values are applied.
109
87
  */
110
- ENCODE_FAILED = "Failed to encode",
88
+ connectionManager?: Partial<ConnectionManagerOptions>;
111
89
  /**
112
- * Failure to protobuf decode the message. May be due to a remote peer issue,
113
- * ensuring that messages are sent via several peer enable mitigation of this error.
90
+ * Configuration for Filter protocol.
91
+ * If not specified - default values are applied.
114
92
  */
115
- DECODE_FAILED = "Failed to decode",
93
+ filter?: Partial<FilterProtocolOptions>;
116
94
  /**
117
- * The message payload is empty, making the message invalid. Ensure that a non-empty
118
- * payload is set on the outgoing message.
95
+ * Options for the Store protocol.
96
+ * If not specified - default values are applied.
119
97
  */
120
- EMPTY_PAYLOAD = "Payload is empty",
98
+ store?: Partial<StoreProtocolOptions>;
121
99
  /**
122
- * The message size is above the maximum message size allowed on the Waku Network.
123
- * Compressing the message or using an alternative strategy for large messages is recommended.
100
+ * Options for the LightPush protocol.
101
+ * If not specified - default values are applied.
124
102
  */
125
- SIZE_TOO_BIG = "Size is too big",
103
+ lightPush?: Partial<LightPushProtocolOptions>;
104
+ };
105
+ export type Callback<T extends IDecodedMessage> = (msg: T) => void | Promise<void>;
106
+ export declare enum ProtocolError {
126
107
  /**
127
- * The PubsubTopic passed to the send function is not configured on the Waku node.
128
- * Please ensure that the PubsubTopic is used when initializing the Waku node.
129
- */
130
- TOPIC_NOT_CONFIGURED = "Topic not configured",
108
+ * Could not determine the origin of the fault. Best to check connectivity and try again
109
+ * */
110
+ GENERIC_FAIL = "Generic error",
131
111
  /**
132
- * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
133
- * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
112
+ * The remote peer rejected the message. Information provided by the remote peer
113
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
114
+ * or `DECODE_FAILED` can be used.
134
115
  */
135
- TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
116
+ REMOTE_PEER_REJECTED = "Remote peer rejected",
136
117
  /**
137
- * The topics passed in the decoders do not match each other, or don't exist at all.
138
- * Ensure that all the pubsub topics used in the decoders are valid and match each other.
118
+ * Failure to protobuf decode the message. May be due to a remote peer issue,
119
+ * ensuring that messages are sent via several peer enable mitigation of this error.
139
120
  */
140
- INVALID_DECODER_TOPICS = "Invalid decoder topics",
121
+ DECODE_FAILED = "Failed to decode",
141
122
  /**
142
123
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
143
124
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -156,36 +137,44 @@ export declare enum ProtocolError {
156
137
  */
157
138
  NO_RESPONSE = "No response received",
158
139
  /**
159
- * The remote peer rejected the message. Information provided by the remote peer
160
- * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
161
- * or `DECODE_FAILED` can be used.
140
+ * Failure to protobuf encode the message. This is not recoverable and needs
141
+ * further investigation.
162
142
  */
163
- REMOTE_PEER_REJECTED = "Remote peer rejected",
143
+ ENCODE_FAILED = "Failed to encode",
164
144
  /**
165
- * The protocol request timed out without a response. This may be due to a connection issue.
166
- * Mitigation can be: retrying after a given time period
145
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
146
+ * payload is set on the outgoing message.
167
147
  */
168
- REQUEST_TIMEOUT = "Request timeout",
148
+ EMPTY_PAYLOAD = "Payload is empty",
169
149
  /**
170
- * Missing credentials info message.
171
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
150
+ * The message size is above the maximum message size allowed on the Waku Network.
151
+ * Compressing the message or using an alternative strategy for large messages is recommended.
172
152
  */
173
- RLN_IDENTITY_MISSING = "Identity credentials are not set",
153
+ SIZE_TOO_BIG = "Size is too big",
174
154
  /**
175
- * Membership index missing info message.
176
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
155
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
156
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
177
157
  */
178
- RLN_MEMBERSHIP_INDEX = "Membership index is not set",
158
+ TOPIC_NOT_CONFIGURED = "Topic not configured",
179
159
  /**
180
- * Message limit is missing.
181
- * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
160
+ * Fails when
182
161
  */
183
- RLN_LIMIT_MISSING = "User message limit is not set",
162
+ STREAM_ABORTED = "Stream aborted",
184
163
  /**
185
164
  * General proof generation error message.
186
165
  * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
187
166
  */
188
- RLN_PROOF_GENERATION = "Proof generation failed"
167
+ RLN_PROOF_GENERATION = "Proof generation failed",
168
+ /**
169
+ * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
170
+ * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
171
+ */
172
+ TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
173
+ /**
174
+ * The topics passed in the decoders do not match each other, or don't exist at all.
175
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
176
+ */
177
+ INVALID_DECODER_TOPICS = "Invalid decoder topics"
189
178
  }
190
179
  export interface Failure {
191
180
  error: ProtocolError;
package/dist/protocols.js CHANGED
@@ -7,43 +7,24 @@ export var Protocols;
7
7
  })(Protocols || (Protocols = {}));
8
8
  export var ProtocolError;
9
9
  (function (ProtocolError) {
10
- /** Could not determine the origin of the fault. Best to check connectivity and try again */
10
+ //
11
+ // GENERAL ERRORS SECTION
12
+ //
13
+ /**
14
+ * Could not determine the origin of the fault. Best to check connectivity and try again
15
+ * */
11
16
  ProtocolError["GENERIC_FAIL"] = "Generic error";
12
17
  /**
13
- * Failure to protobuf encode the message. This is not recoverable and needs
14
- * further investigation.
18
+ * The remote peer rejected the message. Information provided by the remote peer
19
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
20
+ * or `DECODE_FAILED` can be used.
15
21
  */
16
- ProtocolError["ENCODE_FAILED"] = "Failed to encode";
22
+ ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
17
23
  /**
18
24
  * Failure to protobuf decode the message. May be due to a remote peer issue,
19
25
  * ensuring that messages are sent via several peer enable mitigation of this error.
20
26
  */
21
27
  ProtocolError["DECODE_FAILED"] = "Failed to decode";
22
- /**
23
- * The message payload is empty, making the message invalid. Ensure that a non-empty
24
- * payload is set on the outgoing message.
25
- */
26
- ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
27
- /**
28
- * The message size is above the maximum message size allowed on the Waku Network.
29
- * Compressing the message or using an alternative strategy for large messages is recommended.
30
- */
31
- ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
32
- /**
33
- * The PubsubTopic passed to the send function is not configured on the Waku node.
34
- * Please ensure that the PubsubTopic is used when initializing the Waku node.
35
- */
36
- ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
37
- /**
38
- * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
39
- * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
40
- */
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";
47
28
  /**
48
29
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
49
30
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -61,36 +42,50 @@ export var ProtocolError;
61
42
  * or `DECODE_FAILED` can be used.
62
43
  */
63
44
  ProtocolError["NO_RESPONSE"] = "No response received";
45
+ //
46
+ // SEND ERRORS SECTION
47
+ //
64
48
  /**
65
- * The remote peer rejected the message. Information provided by the remote peer
66
- * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
67
- * or `DECODE_FAILED` can be used.
49
+ * Failure to protobuf encode the message. This is not recoverable and needs
50
+ * further investigation.
68
51
  */
69
- ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
52
+ ProtocolError["ENCODE_FAILED"] = "Failed to encode";
70
53
  /**
71
- * The protocol request timed out without a response. This may be due to a connection issue.
72
- * Mitigation can be: retrying after a given time period
54
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
55
+ * payload is set on the outgoing message.
73
56
  */
74
- ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
57
+ ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
75
58
  /**
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
59
+ * The message size is above the maximum message size allowed on the Waku Network.
60
+ * Compressing the message or using an alternative strategy for large messages is recommended.
78
61
  */
79
- ProtocolError["RLN_IDENTITY_MISSING"] = "Identity credentials are not set";
62
+ ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
80
63
  /**
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
64
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
65
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
83
66
  */
84
- ProtocolError["RLN_MEMBERSHIP_INDEX"] = "Membership index is not set";
67
+ ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
85
68
  /**
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
69
+ * Fails when
88
70
  */
89
- ProtocolError["RLN_LIMIT_MISSING"] = "User message limit is not set";
71
+ ProtocolError["STREAM_ABORTED"] = "Stream aborted";
90
72
  /**
91
73
  * General proof generation error message.
92
74
  * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
93
75
  */
94
76
  ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
77
+ //
78
+ // RECEIVE ERRORS SECTION
79
+ //
80
+ /**
81
+ * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
82
+ * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
83
+ */
84
+ ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
85
+ /**
86
+ * The topics passed in the decoders do not match each other, or don't exist at all.
87
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
88
+ */
89
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
95
90
  })(ProtocolError || (ProtocolError = {}));
96
91
  //# 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;AAoGD,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"}
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AAYA,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;AA4GD,MAAM,CAAN,IAAY,aA8FX;AA9FD,WAAY,aAAa;IACvB,EAAE;IACF,yBAAyB;IACzB,EAAE;IACF;;SAEK;IACL,+CAA8B,CAAA;IAE9B;;;;OAIG;IACH,8DAA6C,CAAA;IAE7C;;;OAGG;IACH,mDAAkC,CAAA;IAElC;;;;;OAKG;IACH,wDAAuC,CAAA;IAEvC;;;OAGG;IACH,4DAA2C,CAAA;IAE3C;;;OAGG;IACH,qDAAoC,CAAA;IAEpC,EAAE;IACF,sBAAsB;IACtB,EAAE;IACF;;;OAGG;IACH,mDAAkC,CAAA;IAElC;;;OAGG;IACH,mDAAkC,CAAA;IAElC;;;OAGG;IACH,iDAAgC,CAAA;IAEhC;;;OAGG;IACH,8DAA6C,CAAA;IAE7C;;OAEG;IACH,kDAAiC,CAAA;IAEjC;;;OAGG;IACH,iEAAgD,CAAA;IAEhD,EAAE;IACF,yBAAyB;IACzB,EAAE;IACF;;;OAGG;IACH,kEAAiD,CAAA;IAEjD;;;OAGG;IACH,kEAAiD,CAAA;AACnD,CAAC,EA9FW,aAAa,KAAb,aAAa,QA8FxB"}
package/dist/sender.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { IEncoder, IMessage } from "./message.js";
2
2
  import { SDKProtocolResult } from "./protocols.js";
3
- export type ISenderOptions = {
3
+ export type ISendOptions = {
4
4
  /**
5
5
  * Enables retry of a message that was failed to be sent.
6
- * @default false
6
+ * @default true
7
7
  */
8
8
  autoRetry?: boolean;
9
9
  /**
@@ -13,5 +13,5 @@ export type ISenderOptions = {
13
13
  maxAttempts?: number;
14
14
  };
15
15
  export interface ISender {
16
- send: (encoder: IEncoder, message: IMessage, sendOptions?: ISenderOptions) => Promise<SDKProtocolResult>;
16
+ send: (encoder: IEncoder, message: IMessage, sendOptions?: ISendOptions) => Promise<SDKProtocolResult>;
17
17
  }
package/dist/store.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { IDecodedMessage, IDecoder } from "./message.js";
2
- import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
2
+ import type { IBaseProtocolCore } from "./protocols.js";
3
3
  export type StoreCursor = Uint8Array;
4
4
  /**
5
5
  * Parameters for a store query request, as specified in the Waku Store v3 RFC.
@@ -66,10 +66,13 @@ export type QueryRequestParams = {
66
66
  paginationLimit?: number;
67
67
  };
68
68
  export type IStoreCore = IBaseProtocolCore;
69
- export type IStore = IBaseProtocolSDK & {
69
+ export type IStore = {
70
70
  protocol: IBaseProtocolCore;
71
71
  createCursor(message: IDecodedMessage): StoreCursor;
72
72
  queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: Partial<QueryRequestParams>) => AsyncGenerator<Promise<T | undefined>[]>;
73
73
  queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
74
74
  queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
75
75
  };
76
+ export type StoreProtocolOptions = {
77
+ peer: string;
78
+ };
package/dist/waku.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { PeerId, Stream } from "@libp2p/interface";
1
+ import type { Peer, PeerId, Stream } from "@libp2p/interface";
2
2
  import type { MultiaddrInput } from "@multiformats/multiaddr";
3
- import { IConnectionManager } from "./connection_manager.js";
3
+ import type { IConnectionManager } from "./connection_manager.js";
4
4
  import type { IFilter } from "./filter.js";
5
- import { IHealthManager } from "./health_manager.js";
5
+ import type { IHealthIndicator } from "./health_indicator.js";
6
6
  import type { Libp2p } from "./libp2p.js";
7
7
  import type { ILightPush } from "./light_push.js";
8
- import { Protocols } from "./protocols.js";
8
+ import type { Protocols } from "./protocols.js";
9
9
  import type { IRelay } from "./relay.js";
10
10
  import type { IStore } from "./store.js";
11
11
  export interface IWaku {
@@ -14,8 +14,8 @@ export interface IWaku {
14
14
  store?: IStore;
15
15
  filter?: IFilter;
16
16
  lightPush?: ILightPush;
17
- health: IHealthManager;
18
17
  connectionManager: IConnectionManager;
18
+ health: IHealthIndicator;
19
19
  /**
20
20
  * Returns a unique identifier for a node on the network.
21
21
  *
@@ -110,6 +110,10 @@ export interface IWaku {
110
110
  * @returns {boolean} `true` if the node has working connection and `false` otherwise
111
111
  */
112
112
  isConnected(): boolean;
113
+ /**
114
+ * @returns {Peer[]} an array of all connected peers
115
+ */
116
+ getConnectedPeers(): Promise<Peer[]>;
113
117
  }
114
118
  export interface LightNode extends IWaku {
115
119
  relay: undefined;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@waku/interfaces","version":"0.0.29-66cf711.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":">=20"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^14.1.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"2.1.8"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.9-66cf711.0"}}
1
+ {"name":"@waku/interfaces","version":"0.0.29-9094860.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":">=20"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^14.1.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"2.1.8"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.9-9094860.0"}}
@@ -8,22 +8,44 @@ export enum Tags {
8
8
  LOCAL = "local-peer-cache"
9
9
  }
10
10
 
11
- export interface ConnectionManagerOptions {
11
+ export type ConnectionManagerOptions = {
12
12
  /**
13
- * Number of attempts before a peer is considered non-dialable
14
- * This is used to not spam a peer with dial attempts when it is not dialable
13
+ * Number of attempts before a peer is considered non-dialable.
14
+ * This is used to not spam a peer with dial attempts when it is not dialable.
15
+ *
16
+ * @default 3
15
17
  */
16
18
  maxDialAttemptsForPeer: number;
19
+
17
20
  /**
18
- * Max number of bootstrap peers allowed to be connected to, initially
19
- * This is used to increase intention of dialing non-bootstrap peers, found using other discovery mechanisms (like Peer Exchange)
21
+ * Max number of bootstrap peers allowed to be connected to initially.
22
+ * This is used to increase intention of dialing non-bootstrap peers, found using other discovery mechanisms (like Peer Exchange).
23
+ *
24
+ * @default 1
20
25
  */
21
26
  maxBootstrapPeersAllowed: number;
27
+
22
28
  /**
23
- * Max number of parallel dials allowed
29
+ * Max number of parallel dials allowed.
30
+ *
31
+ * @default 3
24
32
  */
25
33
  maxParallelDials: number;
26
- }
34
+
35
+ /**
36
+ * Keep alive libp2p pings interval in seconds.
37
+ *
38
+ * @default 300 seconds
39
+ */
40
+ pingKeepAlive: number;
41
+
42
+ /**
43
+ * Gossip sub specific keep alive interval in seconds.
44
+ *
45
+ * @default 300 seconds
46
+ */
47
+ relayKeepAlive: number;
48
+ };
27
49
 
28
50
  export enum EPeersByDiscoveryEvents {
29
51
  PEER_DISCOVERY_BOOTSTRAP = "peer:discovery:bootstrap",
@@ -63,7 +85,8 @@ export interface IConnectionStateEvents {
63
85
 
64
86
  export interface IConnectionManager
65
87
  extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
66
- configuredPubsubTopics: PubsubTopic[];
88
+ pubsubTopics: PubsubTopic[];
89
+ getConnectedPeers(codec?: string): Promise<Peer[]>;
67
90
  dropConnection(peerId: PeerId): Promise<void>;
68
91
  getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
69
92
  stop(): void;
package/src/filter.ts CHANGED
@@ -5,9 +5,7 @@ import type { ContentTopic, ThisOrThat } from "./misc.js";
5
5
  import type {
6
6
  Callback,
7
7
  IBaseProtocolCore,
8
- IBaseProtocolSDK,
9
8
  ProtocolError,
10
- ProtocolUseOptions,
11
9
  SDKProtocolResult
12
10
  } from "./protocols.js";
13
11
  import type { IReceiver } from "./receiver.js";
@@ -17,17 +15,34 @@ export type SubscriptionCallback<T extends IDecodedMessage> = {
17
15
  callback: Callback<T>;
18
16
  };
19
17
 
20
- export type SubscribeOptions = {
21
- keepAlive?: number;
22
- pingsBeforePeerRenewed?: number;
23
- enableLightPushFilterCheck?: boolean;
18
+ export type FilterProtocolOptions = {
19
+ /**
20
+ * Interval with which Filter subscription will attempt to send ping requests to subscribed peers.
21
+ *
22
+ * @default 60_000
23
+ */
24
+ keepAliveIntervalMs: number;
25
+
26
+ /**
27
+ * Number of failed pings allowed to make to a remote peer before attempting to subscribe to a new one.
28
+ *
29
+ * @default 3
30
+ */
31
+ pingsBeforePeerRenewed: number;
32
+
33
+ /**
34
+ * Enables js-waku to send probe LightPush message over subscribed pubsubTopics on created subscription.
35
+ * In case message won't be received back through Filter - js-waku will attempt to subscribe to another peer.
36
+ *
37
+ * @default false
38
+ */
39
+ enableLightPushFilterCheck: boolean;
24
40
  };
25
41
 
26
42
  export interface ISubscription {
27
43
  subscribe<T extends IDecodedMessage>(
28
44
  decoders: IDecoder<T> | IDecoder<T>[],
29
- callback: Callback<T>,
30
- options?: SubscribeOptions
45
+ callback: Callback<T>
31
46
  ): Promise<SDKProtocolResult>;
32
47
 
33
48
  unsubscribe(contentTopics: ContentTopic[]): Promise<SDKProtocolResult>;
@@ -37,15 +52,12 @@ export interface ISubscription {
37
52
  unsubscribeAll(): Promise<SDKProtocolResult>;
38
53
  }
39
54
 
40
- export type IFilter = IReceiver &
41
- IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
42
- subscribe<T extends IDecodedMessage>(
43
- decoders: IDecoder<T> | IDecoder<T>[],
44
- callback: Callback<T>,
45
- protocolUseOptions?: ProtocolUseOptions,
46
- subscribeOptions?: SubscribeOptions
47
- ): Promise<SubscribeResult>;
48
- };
55
+ export type IFilter = IReceiver & { protocol: IBaseProtocolCore } & {
56
+ subscribe<T extends IDecodedMessage>(
57
+ decoders: IDecoder<T> | IDecoder<T>[],
58
+ callback: Callback<T>
59
+ ): Promise<SubscribeResult>;
60
+ };
49
61
 
50
62
  export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
51
63
 
@@ -0,0 +1,24 @@
1
+ import { TypedEventEmitter } from "@libp2p/interface";
2
+
3
+ import { Libp2p } from "./libp2p.js";
4
+
5
+ export enum HealthStatusChangeEvents {
6
+ StatusChange = "health:change"
7
+ }
8
+
9
+ export enum HealthStatus {
10
+ Unhealthy = "Unhealthy",
11
+ MinimallyHealthy = "MinimallyHealthy",
12
+ SufficientlyHealthy = "SufficientlyHealthy"
13
+ }
14
+
15
+ export type HealthIndicatorEvents = {
16
+ [HealthStatusChangeEvents.StatusChange]: CustomEvent<HealthStatus>;
17
+ };
18
+
19
+ export interface IHealthIndicator
20
+ extends TypedEventEmitter<HealthIndicatorEvents> {}
21
+
22
+ export type HealthIndicatorParams = {
23
+ libp2p: Libp2p;
24
+ };
package/src/index.ts CHANGED
@@ -12,10 +12,9 @@ export * from "./sender.js";
12
12
  export * from "./receiver.js";
13
13
  export * from "./misc.js";
14
14
  export * from "./libp2p.js";
15
- export * from "./keep_alive_manager.js";
16
15
  export * from "./dns_discovery.js";
17
16
  export * from "./metadata.js";
18
17
  export * from "./constants.js";
19
18
  export * from "./local_storage.js";
20
- export * from "./health_manager.js";
21
19
  export * from "./sharding.js";
20
+ export * from "./health_indicator.js";
package/src/light_push.ts CHANGED
@@ -1,4 +1,23 @@
1
1
  import { IBaseProtocolCore } from "./protocols.js";
2
- import type { ISender } from "./sender.js";
2
+ import type { ISender, ISendOptions } from "./sender.js";
3
3
 
4
- export type ILightPush = ISender & { protocol: IBaseProtocolCore };
4
+ export type LightPushProtocolOptions = ISendOptions & {
5
+ /**
6
+ * The interval in milliseconds to wait before retrying a failed push.
7
+ * @default 1000
8
+ */
9
+ retryIntervalMs: number;
10
+
11
+ /**
12
+ * Number of peers to send message to.
13
+ *
14
+ * @default 1
15
+ */
16
+ numPeersToUse?: number;
17
+ };
18
+
19
+ export type ILightPush = ISender & {
20
+ start: () => void;
21
+ stop: () => void;
22
+ protocol: IBaseProtocolCore;
23
+ };