feat: use merkle root tracker to verify proof

This commit is contained in:
Richard Ramos 2023-05-11 17:30:23 -04:00
parent d7bb3016ff
commit fb970ff65f
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
1 changed files with 7 additions and 3 deletions

View File

@ -12,7 +12,7 @@ import {
RLNDecoder, RLNDecoder,
RLNEncoder, RLNEncoder,
RLNContract, RLNContract,
} from "https://unpkg.com/@waku/rln@0.1.0/bundle/index.js"; } from "https://unpkg.com/@waku/rln@0.1.1/bundle/index.js";
import { ethers } from "https://unpkg.com/ethers@5.7.2/dist/ethers.esm.min.js"; import { ethers } from "https://unpkg.com/ethers@5.7.2/dist/ethers.esm.min.js";
const ContentTopic = "/toy-chat/2/luzhou/proto"; const ContentTopic = "/toy-chat/2/luzhou/proto";
@ -47,6 +47,7 @@ async function initRLN(ui) {
const result = { const result = {
encoder: undefined, encoder: undefined,
rlnInstance: undefined, rlnInstance: undefined,
contract: undefined,
}; };
const provider = new ethers.providers.Web3Provider(window.ethereum, "any"); const provider = new ethers.providers.Web3Provider(window.ethereum, "any");
@ -55,11 +56,14 @@ async function initRLN(ui) {
const rlnInstance = await create(); const rlnInstance = await create();
ui.setRlnStatus("WASM Blob download in progress... done!"); ui.setRlnStatus("WASM Blob download in progress... done!");
const rlnContract = new RLNContract({ const rlnContract = new RLNContract(
rlnInstance, {
address: rlnAddress, address: rlnAddress,
provider: provider.getSigner(), provider: provider.getSigner(),
}); });
result.contract = rlnContract;
// Wallet logic // Wallet logic
window.ethereum.on("accountsChanged", ui.setAccount); window.ethereum.on("accountsChanged", ui.setAccount);
window.ethereum.on("chainChanged", (chainId) => { window.ethereum.on("chainChanged", (chainId) => {
@ -184,7 +188,7 @@ async function initWaku(ui, rln) {
try { try {
console.log("Verifying proof without roots"); console.log("Verifying proof without roots");
console.time("proof_verify_timer"); console.time("proof_verify_timer");
const res = message.verifyNoRoot(); const res = message.verify(rln.contract.roots());
console.timeEnd("proof_verify_timer"); console.timeEnd("proof_verify_timer");
console.log("proof verified without roots", res); console.log("proof verified without roots", res);
if (res === undefined) { if (res === undefined) {