-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_full.js
More file actions
42 lines (35 loc) · 1.59 KB
/
Copy pathtest_full.js
File metadata and controls
42 lines (35 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { groth16 } = require("snarkjs");
const { buildPoseidon } = require("circomlibjs");
const fs = require("fs");
const path = require("path");
async function main() {
const poseidon = await buildPoseidon();
const F = poseidon.F;
const patientName = BigInt("12345");
const patientSecret = BigInt("33333");
const nullifier = F.toObject(poseidon([patientName, patientSecret]));
const inputs = {
patientName: patientName.toString(),
reportHash: "67890",
reportType: 1,
insuranceName: "11111",
treatmentCode: "22222",
patientSecret: patientSecret.toString(),
expectedReportType: 1,
nullifier: nullifier.toString(),
commitmentRoot: "0",
};
const wasmPath = "/app/circuits/eligibility/eligibility_js/eligibility_js/eligibility.wasm";
const zkeyPath = "/app/src/zkp/keys/eligibility_final.zkey";
const vkeyPath = "/app/src/zkp/keys/eligibility_vkey.json";
console.log("Generating proof...");
const { proof, publicSignals } = await groth16.fullProve(inputs, wasmPath, zkeyPath);
console.log("Public signals:", JSON.stringify(publicSignals));
// Write files for CLI verification
fs.writeFileSync("/tmp/proof.json", JSON.stringify(proof));
fs.writeFileSync("/tmp/public.json", JSON.stringify(publicSignals));
const vKey = JSON.parse(fs.readFileSync(vkeyPath, "utf-8"));
const valid = await groth16.verify(vKey, publicSignals, proof);
console.log("JS VERIFICATION:", valid);
}
main().catch(e => { console.error("ERROR:", e.message); process.exit(1); });