mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-09 17:23:11 +00:00
* `ProtocolCreateOptions` now has `pubSubTopic` as `pubSubTopic[]` * chore: update encoder & decoder to support `PubSubTopic` * feat(protocols): allow multiple `PubSubTopic[]` * feat(relay): allow multiple `PubSubTopic[]` * chore(tests): update for new API * chore: minor fixes * chore: make store more robust * fix(relay): correctly set types * chore(address comments): update terminology around configured pubsub topics * chore(address comments): minor refactoring * chore(relay): split `subscribe` into smaller functions for readability & modularity * chore(address comments): refactor `waitForGossipSubPeerInMesh` * chore(store): only allow to query one `pubSubTopic` * fix: `store` bug * feat(tests): add some basic tests * sharding utils * address comments * feat(relay): re-add API for `getMeshPeers` * update error message Co-authored-by: fryorcraken <110212804+fryorcraken@users.noreply.github.com> * refactor for new API * feat: simplify handling of observers (#1614) * refactor: simplify handling of observers * refactor: Remove redundant PubSubTopic from Observer * use `??` instead of `||` * update `pubsubTopic` to `pubSubTopic` * update `interval` typo * change occurence of `pubsubTopic` to `pubSubTopic` * relay: rm `getAllMeshPeers` and make `pubSubTopics` public * relay: use `push_or_init_map` and move to `utils` * fix: update API for tests * fix: relay waitForRemotePeer --------- Co-authored-by: fryorcraken <110212804+fryorcraken@users.noreply.github.com>
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import type { PubSubTopic } from "./misc.js";
|
|
|
|
export interface IRateLimitProof {
|
|
proof: Uint8Array;
|
|
merkleRoot: Uint8Array;
|
|
epoch: Uint8Array;
|
|
shareX: Uint8Array;
|
|
shareY: Uint8Array;
|
|
nullifier: Uint8Array;
|
|
rlnIdentifier: Uint8Array;
|
|
}
|
|
|
|
/**
|
|
* Interface matching the protobuf library.
|
|
* Field types matches the protobuf type over the wire
|
|
*/
|
|
export interface IProtoMessage {
|
|
payload: Uint8Array;
|
|
contentTopic: string;
|
|
version: number | undefined;
|
|
timestamp: bigint | undefined;
|
|
meta: Uint8Array | undefined;
|
|
rateLimitProof: IRateLimitProof | undefined;
|
|
ephemeral: boolean | undefined;
|
|
}
|
|
|
|
/**
|
|
* Interface for messages to encode and send.
|
|
*/
|
|
export interface IMessage {
|
|
payload: Uint8Array;
|
|
timestamp?: Date;
|
|
rateLimitProof?: IRateLimitProof;
|
|
}
|
|
|
|
export interface IMetaSetter {
|
|
(message: IProtoMessage & { meta: undefined }): Uint8Array;
|
|
}
|
|
|
|
export interface EncoderOptions {
|
|
pubSubTopic?: PubSubTopic;
|
|
/** 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;
|
|
}
|
|
|
|
export interface IEncoder {
|
|
pubSubTopic: PubSubTopic;
|
|
contentTopic: string;
|
|
ephemeral: boolean;
|
|
toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
|
|
toProtoObj: (message: IMessage) => Promise<IProtoMessage | undefined>;
|
|
}
|
|
|
|
export interface IDecodedMessage {
|
|
payload: Uint8Array;
|
|
contentTopic: string;
|
|
pubSubTopic: PubSubTopic;
|
|
timestamp: Date | undefined;
|
|
rateLimitProof: IRateLimitProof | undefined;
|
|
ephemeral: boolean | undefined;
|
|
meta: Uint8Array | undefined;
|
|
}
|
|
|
|
export interface IDecoder<T extends IDecodedMessage> {
|
|
pubSubTopic: PubSubTopic;
|
|
contentTopic: string;
|
|
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
|
|
fromProtoObj: (
|
|
pubSubTopic: string,
|
|
proto: IProtoMessage
|
|
) => Promise<T | undefined>;
|
|
}
|