UNPKG

@waku/core

Version:

TypeScript implementation of the Waku v2 protocol

53 lines (52 loc) 2.6 kB
import type { EncoderOptions, IDecodedMessage, IDecoder, IEncoder, IMessage, IMetaSetter, IProtoMessage, IRateLimitProof, PubsubTopic, SingleShardInfo } from "@waku/interfaces"; import { proto_message as proto } from "@waku/proto"; export declare const Version = 0; export { proto }; export declare class DecodedMessage implements IDecodedMessage { pubsubTopic: string; private proto; constructor(pubsubTopic: string, proto: proto.WakuMessage); get ephemeral(): boolean; get payload(): Uint8Array; get contentTopic(): string; get timestamp(): Date | undefined; get meta(): Uint8Array | undefined; get version(): number; get rateLimitProof(): IRateLimitProof | undefined; } export declare class Encoder implements IEncoder { contentTopic: string; ephemeral: boolean; pubsubTopic: PubsubTopic; metaSetter?: IMetaSetter | undefined; constructor(contentTopic: string, ephemeral: boolean | undefined, pubsubTopic: PubsubTopic, metaSetter?: IMetaSetter | undefined); toWire(message: IMessage): Promise<Uint8Array>; toProtoObj(message: IMessage): Promise<IProtoMessage>; } /** * Creates an encoder that encode messages without Waku level encryption or signature. * * An encoder is used to encode messages in the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/) * format to be sent over the Waku network. The resulting encoder can then be * pass to { @link @waku/interfaces!ISender.send } to automatically encode outgoing * messages. */ export declare function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, ephemeral, metaSetter }: EncoderOptions): Encoder; export declare class Decoder implements IDecoder<IDecodedMessage> { pubsubTopic: PubsubTopic; contentTopic: string; constructor(pubsubTopic: PubsubTopic, contentTopic: string); fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined>; fromProtoObj(pubsubTopic: string, proto: IProtoMessage): Promise<IDecodedMessage | undefined>; } /** * Creates a decoder that decode messages without Waku level encryption. * * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/) * format when received from the Waku network. The resulting decoder can then be * pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decode incoming * messages. * * @param contentTopic The resulting decoder will only decode messages with this content topic. */ export declare function createDecoder(contentTopic: string, pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic): Decoder;