mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-05-17 21:09:32 +00:00
* chore: update ABIs and deployed address * chore: remove storage contract references * feat: upgrading adapter to basic rlnv2 * feat: rate limit * chore: upgrade packages revert * fix: tests * chore: remove uneeded file * feat(rln): implement RLNv2 rate limiting and membership states - Add rate limit validation and handling in proof generation/verification - Implement membership lifecycle state management (Active/GracePeriod/Expired) - Add new membership management methods: - getMembershipInfo - extendMembership - eraseMembership - registerMembership - Update proof verification to include rate limit checks - Refactor message serialization to include rate limit data Breaking changes: - verifyWithRoots now takes roots as array instead of spread parameters - Proof verification methods now accept optional rateLimit parameter * fix: typo * chore: add to cspell * chore: reduce diff * chore: simplify subdir for abi * chore: address comments * chore: simplify access to variables * chore: address comments * chore: simplify constants * chore: add error handling * chore: change rln v2 references to rln * fix: check
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import type {
|
|
IDecodedMessage,
|
|
IMessage,
|
|
IRateLimitProof
|
|
} from "@waku/interfaces";
|
|
import * as utils from "@waku/utils/bytes";
|
|
|
|
import { RLNInstance } from "./rln.js";
|
|
import { epochBytesToInt } from "./utils/index.js";
|
|
|
|
export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
|
const contentTopicBytes = utils.utf8ToBytes(contentTopic ?? "");
|
|
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
|
}
|
|
|
|
export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
public pubsubTopic = "";
|
|
|
|
public constructor(
|
|
public rlnInstance: RLNInstance,
|
|
public msg: T,
|
|
public rateLimitProof: IRateLimitProof | undefined
|
|
) {}
|
|
|
|
public verify(roots: Uint8Array[]): boolean | undefined {
|
|
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;
|
|
}
|
|
|
|
public verifyNoRoot(): boolean | undefined {
|
|
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;
|
|
}
|
|
|
|
public get payload(): Uint8Array {
|
|
return this.msg.payload;
|
|
}
|
|
|
|
public get contentTopic(): string {
|
|
return this.msg.contentTopic;
|
|
}
|
|
|
|
public get timestamp(): Date | undefined {
|
|
return this.msg.timestamp;
|
|
}
|
|
|
|
public get ephemeral(): boolean | undefined {
|
|
return this.msg.ephemeral;
|
|
}
|
|
|
|
public get meta(): Uint8Array | undefined {
|
|
return this.msg.meta;
|
|
}
|
|
|
|
public get epoch(): number | undefined {
|
|
const bytes = this.rateLimitProof?.epoch;
|
|
if (!bytes) return undefined;
|
|
|
|
return epochBytesToInt(bytes);
|
|
}
|
|
}
|