feat: expose verifyNotRoot API

This commit is contained in:
fryorcraken.eth 2022-10-10 09:59:24 -05:00
parent ccac8291e1
commit 93fe74619e
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 37 additions and 0 deletions

View File

@ -53,6 +53,7 @@ describe("RLN codec with version 0", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -92,6 +93,7 @@ describe("RLN codec with version 0", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -134,6 +136,7 @@ describe("RLN codec with version 1", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -175,6 +178,7 @@ describe("RLN codec with version 1", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -216,6 +220,7 @@ describe("RLN codec with version 1", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -258,6 +263,7 @@ describe("RLN codec with version 1", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch).to.be.gt(0);
@ -302,6 +308,7 @@ describe("RLN Codec - epoch", () => {
expect(msg.rateLimitProof).to.not.be.undefined;
expect(msg.verify()).to.be.true;
expect(msg.verifyNoRoot()).to.be.true;
expect(msg.epoch).to.not.be.undefined;
expect(msg.epoch!.toString(10).length).to.eq(9);
expect(msg.epoch).to.eq(epoch);

View File

@ -22,6 +22,15 @@ export class RlnMessage<T extends Message> implements Message {
: undefined;
}
public verifyNoRoot(): boolean | undefined {
return this.rateLimitProof
? this.rlnInstance.verifyWithNoRoot(
this.rateLimitProof,
toRLNSignal(this)
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
: undefined;
}
get payload(): Uint8Array | undefined {
return this.msg.payload;
}

View File

@ -225,4 +225,25 @@ export class RLNInstance {
root
);
}
verifyWithNoRoot(
proof: RateLimitProof | Uint8Array,
msg: Uint8Array
): boolean {
let pBytes: Uint8Array;
if (proof instanceof Uint8Array) {
pBytes = proof;
} else {
pBytes = proofToBytes(proof);
}
// calculate message length
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
return zerokitRLN.verifyWithRoots(
this.zkRLN,
concatenate(pBytes, msgLen, msg),
new Uint8Array()
);
}
}