-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88fa525
commit 698c312
Showing
23 changed files
with
203 additions
and
1,064 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const emailWalletUtils = require("@zk-email/relayer-utils"); | ||
|
||
export async function genPsiPointsInput( | ||
emailAddr: string, | ||
accountCode: string, | ||
relayerRand: string, | ||
): Promise<{ | ||
email_addr: number[]; | ||
account_code: string; | ||
relayer_rand: string; | ||
}> { | ||
const paddedEmailAddr = emailWalletUtils.padEmailAddr(emailAddr); | ||
return { | ||
email_addr: paddedEmailAddr, | ||
account_code: accountCode, | ||
relayer_rand: relayerRand, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* | ||
* This script is for generating input for the claim circuit. | ||
* | ||
*/ | ||
|
||
import { program } from "commander"; | ||
import fs from "fs"; | ||
import { promisify } from "util"; | ||
import { genPsiPointsInput } from "../helpers/psi_points"; | ||
import path from "path"; | ||
const snarkjs = require("snarkjs"); | ||
|
||
program | ||
.requiredOption("--email-addr <string>", "User's email address") | ||
.requiredOption("--account-code <string>", "User's account code") | ||
.requiredOption("--relayer-rand <string>", "Relayer's randomness") | ||
.requiredOption("--input-file <string>", "Path of a json file to write the generated input") | ||
.option("--silent", "No console logs") | ||
.option("--prove", "Also generate proof"); | ||
|
||
program.parse(); | ||
const args = program.opts(); | ||
|
||
function log(...message: any) { | ||
if (!args.silent) { | ||
console.log(...message); | ||
} | ||
} | ||
|
||
async function generate() { | ||
if (!args.inputFile.endsWith(".json")) { | ||
throw new Error("--input file path arg must end with .json"); | ||
} | ||
|
||
log("Generating Inputs for:", args); | ||
|
||
const circuitInputs = await genPsiPointsInput(args.emailAddr, args.accountCode, args.relayerRand); | ||
|
||
log("\n\nGenerated Inputs:", circuitInputs, "\n\n"); | ||
|
||
await promisify(fs.writeFile)(args.inputFile, JSON.stringify(circuitInputs, null, 2)); | ||
|
||
log("Inputs written to", args.inputFile); | ||
|
||
if (args.prove) { | ||
const dir = path.dirname(args.inputFile); | ||
const { proof, publicSignals } = await snarkjs.groth16.fullProve( | ||
circuitInputs, | ||
path.join(dir, "psi_points.wasm"), | ||
path.join(dir, "psi_points.zkey"), | ||
console, | ||
); | ||
await promisify(fs.writeFile)(path.join(dir, "psi_points_proof.json"), JSON.stringify(proof, null, 2)); | ||
await promisify(fs.writeFile)(path.join(dir, "psi_points_public.json"), JSON.stringify(publicSignals, null, 2)); | ||
log("✓ Proof for psi_points circuit generated"); | ||
} | ||
process.exit(0); | ||
} | ||
|
||
generate().catch((err) => { | ||
console.error("Error generating inputs", err); | ||
process.exit(1); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.