@waku/rln
Version:
RLN (Rate Limiting Nullifier) implementation for Waku
51 lines • 1.72 kB
JavaScript
import { message } from "@waku/core";
import * as utils from "@waku/utils/bytes";
import { epochBytesToInt } from "./utils/index.js";
export function toRLNSignal(contentTopic, msg) {
const contentTopicBytes = utils.utf8ToBytes(contentTopic ?? "");
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
}
export class RlnMessage {
rlnInstance;
msg;
rateLimitProof;
pubsubTopic = "";
version = message.version_0.Version;
constructor(rlnInstance, msg, rateLimitProof) {
this.rlnInstance = rlnInstance;
this.msg = msg;
this.rateLimitProof = rateLimitProof;
}
verify(roots) {
return this.rateLimitProof
? this.rlnInstance.zerokit.verifyWithRoots(this.rateLimitProof, toRLNSignal(this.msg.contentTopic, this.msg), roots) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
: undefined;
}
verifyNoRoot() {
return this.rateLimitProof
? this.rlnInstance.zerokit.verifyWithNoRoot(this.rateLimitProof, toRLNSignal(this.msg.contentTopic, this.msg)) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
: undefined;
}
get payload() {
return this.msg.payload;
}
get contentTopic() {
return this.msg.contentTopic;
}
get timestamp() {
return this.msg.timestamp;
}
get ephemeral() {
return this.msg.ephemeral;
}
get meta() {
return this.msg.meta;
}
get epoch() {
const bytes = this.rateLimitProof?.epoch;
if (!bytes)
return undefined;
return epochBytesToInt(bytes);
}
}
//# sourceMappingURL=message.js.map