mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-02-01 14:53:15 +00:00
* move constants & core's func to @waku/utils * setup @waku/relay * use @waku/relay for create * address: principal review * fix: size-limit * move all constants to @waku/core * move TopicOnlyDecoder to relay * merge: master * fix: tests * Move constants out of core (#1340) * update package.lock * change constants folder into a ts file * use dependency version as * instead of version number * add constants import from @waku/core * add empty changelog file for relay --------- Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import type {
|
|
IDecodedMessage,
|
|
IDecoder,
|
|
IProtoMessage,
|
|
} from "@waku/interfaces";
|
|
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
|
import debug from "debug";
|
|
|
|
const log = debug("waku:message:topic-only");
|
|
|
|
export class TopicOnlyMessage implements IDecodedMessage {
|
|
public payload: Uint8Array = new Uint8Array();
|
|
public rateLimitProof: undefined;
|
|
public timestamp: undefined;
|
|
public meta: undefined;
|
|
public ephemeral: undefined;
|
|
|
|
constructor(
|
|
public pubSubTopic: string,
|
|
private proto: ProtoTopicOnlyMessage
|
|
) {}
|
|
|
|
get contentTopic(): string {
|
|
return this.proto.contentTopic;
|
|
}
|
|
}
|
|
|
|
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
|
public contentTopic = "";
|
|
|
|
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
|
const protoMessage = ProtoTopicOnlyMessage.decode(bytes);
|
|
log("Message decoded", protoMessage);
|
|
return Promise.resolve({
|
|
contentTopic: protoMessage.contentTopic,
|
|
payload: new Uint8Array(),
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
meta: undefined,
|
|
version: undefined,
|
|
ephemeral: undefined,
|
|
});
|
|
}
|
|
|
|
async fromProtoObj(
|
|
pubSubTopic: string,
|
|
proto: IProtoMessage
|
|
): Promise<TopicOnlyMessage | undefined> {
|
|
return new TopicOnlyMessage(pubSubTopic, proto);
|
|
}
|
|
}
|