2025-06-03 11:08:02 +02:00
|
|
|
import type { ContentTopic, PubsubTopic } from "./misc.js";
|
2023-09-27 15:28:07 +05:30
|
|
|
|
2023-11-28 15:57:18 +05:30
|
|
|
export interface SingleShardInfo {
|
2023-11-29 17:37:59 +05:30
|
|
|
clusterId: number;
|
2023-11-16 15:17:17 +03:00
|
|
|
/**
|
feat!: re-architect connection manager (#2445)
* remove public pubsub field and redundant util
* add hangUp and improve dial operations, improve keepAliveManager and remove unused method, move utils and add tests
* improve public dial method to start keep alive checks
* move dial method
* implement discovery dialer
* implement discovery dialer with queue with tests
* add discovery dialer e2e tests, change local discovery log tag, update other tests
* remove comment
* add issue link, remove only
* implement shard reader component
* create evetns module, remove unused connection manager events and related tests
* implement network indicator
* implement connection limiter, change public API of connection manager, implement recovery strategy
* decouple keep alive maanger
* add connection manager js-doc
* refactor keep alive manager, cover with tests
* add tests for connection manager main facade
* add tests for connection limiter
* add e2e tests for connection manager modules
pass js-waku config during test node init
remove dns discovery for js-waku
* restructure dialing tests
* address last e2e tests
* address review
* add logging for main methods
* decouple pure dialer class, update network monitor with specific metrics
* remove console.log
* remove usage of protocols
* update sdk package tests
* add connect await promise
* add debug for e2e tests
* enable only packages tests
* use only one file
* revert debugging
* up interface for netwrok manager
* add logs
* add more logs
* add more logs
* add another logs
* remove .only
* remove log statements
* skip the test with follow up
2025-07-09 21:23:14 +02:00
|
|
|
* TODO: make shard required
|
2023-11-16 15:17:17 +03:00
|
|
|
* Specifying this field indicates to the encoder/decoder that static sharding must be used.
|
|
|
|
|
*/
|
2024-03-04 18:40:08 -08:00
|
|
|
shard?: number;
|
2023-11-28 15:57:18 +05:30
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IRateLimitProof {
|
2022-12-05 17:00:24 +11:00
|
|
|
proof: Uint8Array;
|
|
|
|
|
merkleRoot: Uint8Array;
|
|
|
|
|
epoch: Uint8Array;
|
|
|
|
|
shareX: Uint8Array;
|
|
|
|
|
shareY: Uint8Array;
|
|
|
|
|
nullifier: Uint8Array;
|
|
|
|
|
rlnIdentifier: Uint8Array;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-03 11:08:02 +02:00
|
|
|
export interface IDecodedMessage {
|
|
|
|
|
version: number;
|
|
|
|
|
payload: Uint8Array;
|
|
|
|
|
contentTopic: ContentTopic;
|
|
|
|
|
pubsubTopic: PubsubTopic;
|
|
|
|
|
timestamp: Date | undefined;
|
|
|
|
|
rateLimitProof: IRateLimitProof | undefined;
|
|
|
|
|
ephemeral: boolean | undefined;
|
|
|
|
|
meta: Uint8Array | undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IRlnMessage extends IDecodedMessage {
|
|
|
|
|
epoch: number | undefined;
|
|
|
|
|
verify(roots: Uint8Array[]): boolean | undefined;
|
|
|
|
|
verifyNoRoot(): boolean | undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IEncryptedMessage extends IDecodedMessage {
|
|
|
|
|
signature?: Uint8Array;
|
|
|
|
|
signaturePublicKey?: Uint8Array;
|
|
|
|
|
verifySignature(publicKey: Uint8Array): boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ITopicOnlyMessage extends IDecodedMessage {
|
|
|
|
|
payload: Uint8Array;
|
|
|
|
|
contentTopic: ContentTopic;
|
|
|
|
|
pubsubTopic: PubsubTopic;
|
|
|
|
|
timestamp: undefined;
|
|
|
|
|
rateLimitProof: undefined;
|
|
|
|
|
ephemeral: undefined;
|
|
|
|
|
meta: undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:00:24 +11:00
|
|
|
/**
|
|
|
|
|
* Interface matching the protobuf library.
|
|
|
|
|
* Field types matches the protobuf type over the wire
|
|
|
|
|
*/
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IProtoMessage {
|
2023-02-24 23:22:04 +11:00
|
|
|
payload: Uint8Array;
|
|
|
|
|
contentTopic: string;
|
2022-12-05 17:00:24 +11:00
|
|
|
version: number | undefined;
|
|
|
|
|
timestamp: bigint | undefined;
|
2023-03-10 14:41:07 +11:00
|
|
|
meta: Uint8Array | undefined;
|
2022-12-05 17:07:03 +11:00
|
|
|
rateLimitProof: IRateLimitProof | undefined;
|
2022-12-05 17:00:24 +11:00
|
|
|
ephemeral: boolean | undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface for messages to encode and send.
|
|
|
|
|
*/
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IMessage {
|
2023-02-24 23:22:04 +11:00
|
|
|
payload: Uint8Array;
|
2022-12-05 17:00:24 +11:00
|
|
|
timestamp?: Date;
|
2022-12-05 17:07:03 +11:00
|
|
|
rateLimitProof?: IRateLimitProof;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:41:07 +11:00
|
|
|
export interface IMetaSetter {
|
|
|
|
|
(message: IProtoMessage & { meta: undefined }): Uint8Array;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 11:37:28 +05:30
|
|
|
export interface EncoderOptions {
|
2024-01-09 23:34:30 -08:00
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
pubsubTopic?: PubsubTopic;
|
2023-11-28 15:57:18 +05:30
|
|
|
pubsubTopicShardInfo?: SingleShardInfo;
|
2023-02-02 11:37:28 +05:30
|
|
|
/** The content topic to set on outgoing messages. */
|
|
|
|
|
contentTopic: string;
|
|
|
|
|
/**
|
|
|
|
|
* An optional flag to mark message as ephemeral, i.e., not to be stored by Waku Store nodes.
|
|
|
|
|
* @defaultValue `false`
|
|
|
|
|
*/
|
|
|
|
|
ephemeral?: boolean;
|
2023-03-10 14:41:07 +11:00
|
|
|
/**
|
|
|
|
|
* A function called when encoding messages to set the meta field.
|
|
|
|
|
* @param IProtoMessage The message encoded for wire, without the meta field.
|
|
|
|
|
* If encryption is used, `metaSetter` only accesses _encrypted_ payload.
|
|
|
|
|
*/
|
|
|
|
|
metaSetter?: IMetaSetter;
|
2023-02-02 11:37:28 +05:30
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IEncoder {
|
2023-11-14 21:22:52 +05:30
|
|
|
pubsubTopic: PubsubTopic;
|
2022-12-05 17:00:24 +11:00
|
|
|
contentTopic: string;
|
|
|
|
|
ephemeral: boolean;
|
2022-12-05 17:07:03 +11:00
|
|
|
toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
|
|
|
|
|
toProtoObj: (message: IMessage) => Promise<IProtoMessage | undefined>;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IDecoder<T extends IDecodedMessage> {
|
2023-11-14 21:22:52 +05:30
|
|
|
pubsubTopic: PubsubTopic;
|
2022-12-05 17:00:24 +11:00
|
|
|
contentTopic: string;
|
2022-12-05 17:07:03 +11:00
|
|
|
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
|
2023-03-10 16:43:21 +11:00
|
|
|
fromProtoObj: (
|
2023-10-16 12:52:32 +05:30
|
|
|
pubsubTopic: string,
|
2023-08-16 20:18:13 +05:30
|
|
|
proto: IProtoMessage
|
2023-03-10 16:43:21 +11:00
|
|
|
) => Promise<T | undefined>;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|