mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 15:23:12 +00:00
* feat: introduce eslint flag * chore: update logger * chore: update enr * chore: update core * chore: update sdk * chore: update relay * chore: update discovery * chore: update message-encryption * chore: update tests * chore: fix modifiers * chore(tests): fix access modifiers * chore: fix rebase
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { DefaultPubsubTopic } from "@waku/interfaces";
|
|
import type {
|
|
IDecodedMessage,
|
|
IDecoder,
|
|
IProtoMessage
|
|
} from "@waku/interfaces";
|
|
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
|
|
|
export class TopicOnlyMessage implements IDecodedMessage {
|
|
public payload: Uint8Array = new Uint8Array();
|
|
public rateLimitProof: undefined;
|
|
public timestamp: undefined;
|
|
public meta: undefined;
|
|
public ephemeral: undefined;
|
|
|
|
public constructor(
|
|
public pubsubTopic: string,
|
|
private proto: ProtoTopicOnlyMessage
|
|
) {}
|
|
|
|
public get contentTopic(): string {
|
|
return this.proto.contentTopic;
|
|
}
|
|
}
|
|
|
|
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
|
public pubsubTopic = DefaultPubsubTopic;
|
|
public contentTopic = "";
|
|
|
|
public fromWireToProtoObj(
|
|
bytes: Uint8Array
|
|
): Promise<IProtoMessage | undefined> {
|
|
const protoMessage = ProtoTopicOnlyMessage.decode(bytes);
|
|
return Promise.resolve({
|
|
contentTopic: protoMessage.contentTopic,
|
|
payload: new Uint8Array(),
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
meta: undefined,
|
|
version: undefined,
|
|
ephemeral: undefined
|
|
});
|
|
}
|
|
|
|
public async fromProtoObj(
|
|
pubsubTopic: string,
|
|
proto: IProtoMessage
|
|
): Promise<TopicOnlyMessage | undefined> {
|
|
return new TopicOnlyMessage(pubsubTopic, proto);
|
|
}
|
|
}
|