diff --git a/packages/core/src/lib/waku_message/version_0.ts b/packages/core/src/lib/waku_message/version_0.ts index 056504a067..19d9ec586a 100644 --- a/packages/core/src/lib/waku_message/version_0.ts +++ b/packages/core/src/lib/waku_message/version_0.ts @@ -1,7 +1,7 @@ import type { - DecodedMessage, - Decoder, - Encoder, + DecodedMessage as IDecodedMessage, + Decoder as IDecoder, + Encoder as IEncoder, Message, ProtoMessage, RateLimitProof, @@ -16,7 +16,7 @@ const OneMillion = BigInt(1_000_000); export const Version = 0; export { proto }; -export class MessageV0 implements DecodedMessage { +export class DecodedMessage implements IDecodedMessage { constructor(protected proto: proto.WakuMessage) {} get _rawPayload(): Uint8Array | undefined { @@ -71,7 +71,7 @@ export class MessageV0 implements DecodedMessage { } } -export class EncoderV0 implements Encoder { +class Encoder implements IEncoder { constructor(public contentTopic: string, public ephemeral: boolean = false) {} async toWire(message: Partial): Promise { @@ -92,7 +92,14 @@ export class EncoderV0 implements Encoder { } } -export class DecoderV0 implements Decoder { +export function createEncoder( + contentTopic: string, + ephemeral = false +): Encoder { + return new Encoder(contentTopic, ephemeral); +} + +export class Decoder implements IDecoder { constructor(public contentTopic: string, public ephemeral: boolean = false) {} fromWireToProtoObj(bytes: Uint8Array): Promise { @@ -108,7 +115,7 @@ export class DecoderV0 implements Decoder { }); } - async fromProtoObj(proto: ProtoMessage): Promise { + async fromProtoObj(proto: ProtoMessage): Promise { // https://github.com/status-im/js-waku/issues/921 if (proto.version === undefined) { proto.version = 0; @@ -124,6 +131,13 @@ export class DecoderV0 implements Decoder { return Promise.resolve(undefined); } - return new MessageV0(proto); + return new DecodedMessage(proto); } } + +export function createDecoder( + contentTopic: string, + ephemeral = false +): Encoder { + return new Decoder(contentTopic, ephemeral); +}