@waku/rln
Version:
RLN (Rate Limiting Nullifier) implementation for Waku
63 lines (60 loc) • 2.2 kB
JavaScript
import { Version } from '../../core/dist/lib/message/version_0.js';
import '../../core/dist/lib/filter/filter.js';
import '../../core/dist/lib/light_push/light_push.js';
import '../../core/dist/lib/store/store.js';
import '../../core/dist/lib/connection_manager/connection_manager.js';
import '../../interfaces/dist/protocols.js';
import '../../interfaces/dist/connection_manager.js';
import '../../interfaces/dist/health_status.js';
import { utf8ToBytes } from '../../utils/dist/bytes/index.js';
import '../../../node_modules/debug/src/browser.js';
import '../../core/dist/lib/metadata/metadata.js';
import { epochBytesToInt } from './utils/epoch.js';
function toRLNSignal(contentTopic, msg) {
const contentTopicBytes = utf8ToBytes(contentTopic ?? "");
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
}
class RlnMessage {
rlnInstance;
msg;
rateLimitProof;
pubsubTopic = "";
version = 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);
}
}
export { RlnMessage, toRLNSignal };