Running the Example

This guide will help to run the example project to test out the generated circuit.

Getting started

You only need a standard node environment to run the example.

Start by downloding the example from the registry home page

Example project directory structure

example/
├─ node_modules/
├─ circuit/
│  ├─ regex/
│  |  ├─ field.json
|  |  ├─ fieldRegex.circom
│  ├─ proof.circom
├─ lib/
│  ├─ generate_inputs.js
├─ index.ts
├─ generate_inputs_worker.js
├─ package.json
├─ tsconfig.json

Circuit Directory

├─ circuit/
│  ├─ proof.circom
│  ├─ regex/
│  |  ├─ field.json
|  |  ├─ fieldRegex.circom

This folder contains all the circuits that were auto-generated by the metadata from the pattern. You shouldn't directly edit the circom files in the regex/ directory. Use the zk-regex SDK to generate it from your field.json files.

zk-regex decomposed -d field.json -c fieldRegex.circom -t fieldRegex -g true

circuit/proof.circom will be the main entry point for the circuit. Later you will see that this is imported in the tests.

Library

├─ lib/
│  ├─ generate_inputs.js

This folder only contains a script to generate the circuit inputs from a given email. The output of the script will be directly used in the circuit for proof generation

Worker Script

├─ generate_inputs_worker.js

This script is used by the Registry SDK when generating circuit inputs in the browser. It basically acts as a sandboxed environment using WebWorkers to convert an email to circuit inputs.

Test Entry Point

├─ index.ts

This is the test entry point. You will need to paste in your raw email in a variable in the file before running it.

Unzip the project and install dependencies

cd example
yarn install | npm install

Add your raw email sample

index.ts

...
const rawEmail = `<paste your eml file here>`
...

Run the test

yarn/npm start

Once the witness generation is successful, the circuit works.

Last updated