2025-06-03 11:08:02 +02:00
|
|
|
import type { ContentTopic, PubsubTopic } from "./misc.js";
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
import type { IRoutingInfo } from "./sharding.js";
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 18:07:38 +10:00
|
|
|
export interface EncoderOptions {
|
|
|
|
|
/**
|
|
|
|
|
* The routing information for the message (cluster id, shard id, pubsubTopic)
|
|
|
|
|
*/
|
|
|
|
|
routingInfo: IRoutingInfo;
|
|
|
|
|
/** 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;
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export interface IEncoder {
|
2022-12-05 17:00:24 +11:00
|
|
|
contentTopic: string;
|
|
|
|
|
ephemeral: boolean;
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
routingInfo: IRoutingInfo;
|
2025-07-19 21:25:21 +10:00
|
|
|
pubsubTopic: PubsubTopic;
|
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> {
|
2022-12-05 17:00:24 +11:00
|
|
|
contentTopic: string;
|
2025-07-19 21:25:21 +10:00
|
|
|
pubsubTopic: PubsubTopic;
|
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
|
|
|
}
|