mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-15 12:13:06 +00:00
* chore: update noise * update: package.lock * update: @chainsafe/libp2p-gossipsub * rm unwanted libp2p interface deps & bump up libp2p * refactor code for new deps * update: new package.lock * setup prettier, refactor eslint and rm trailing commas * update package.lock * fix build * import type for interface * fix imports for merge * update typedoc exports * add: CustomEvent import * use new libp2p interface * add aegir as dev dep for tests
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);
|
|
}
|
|
}
|