mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-05 15:13:12 +00:00
38 lines
889 B
TypeScript
38 lines
889 B
TypeScript
import { Message, RateLimitProof } from "js-waku/lib/interfaces";
|
|
|
|
import { epochBytesToInt } from "./epoch.js";
|
|
import { RLNInstance } from "./rln.js";
|
|
|
|
export class RlnMessage<T extends Message> implements Message {
|
|
constructor(
|
|
public rlnInstance: RLNInstance,
|
|
public msg: T,
|
|
public rateLimitProof: RateLimitProof | undefined
|
|
) {}
|
|
|
|
public verify(): boolean | undefined {
|
|
return this.rateLimitProof
|
|
? this.rlnInstance.verifyProof(this.rateLimitProof)
|
|
: undefined;
|
|
}
|
|
|
|
get payload(): Uint8Array | undefined {
|
|
return this.msg.payload;
|
|
}
|
|
|
|
get contentTopic(): string | undefined {
|
|
return this.msg.contentTopic;
|
|
}
|
|
|
|
get timestamp(): Date | undefined {
|
|
return this.msg.timestamp;
|
|
}
|
|
|
|
get epoch(): number | undefined {
|
|
const bytes = this.msg.rateLimitProof?.epoch;
|
|
if (!bytes) return;
|
|
|
|
return epochBytesToInt(bytes);
|
|
}
|
|
}
|