-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
79 lines (73 loc) · 2.26 KB
/
App.tsx
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { FormEvent, useState } from "react";
import "./App.css";
import { CircomExample, getAddress } from "@blockhackers/protocol";
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider();
const example = new CircomExample(
provider,
getAddress("chain-31337", "CircomExample")
);
function App() {
const [status, setStatus] = useState<"init" | "error" | "success">("init");
const [proof, setProof] = useState<string>("");
const [provingTime, setProvingTime] = useState<number | undefined>();
const [verifyingTime, setVerifyingTime] = useState<number | undefined>();
async function onSubmit(e: FormEvent<HTMLFormElement>) {
setStatus("init");
setProof("");
e.preventDefault();
const data = new FormData(e.currentTarget);
const a = Number(data.get("a"));
const b = Number(data.get("b"));
const c = Number(data.get("c"));
let time = new Date();
const proof = await example.multiplierProve(a, b);
setProvingTime(Number(new Date()) - Number(time));
setProof(proof);
time = new Date();
try {
await example.multiplierVerify(proof, c);
setStatus("success");
} catch (err) {
setStatus("error");
}
setVerifyingTime(Number(new Date()) - Number(time));
}
return (
<div>
<h2>Prove and Verify your zkSNARK</h2>
<blockquote>a x b = c</blockquote>
<form onSubmit={onSubmit}>
<label htmlFor="a">
a:
<input type="number" name="a" />
</label>
<label>
b:
<input type="number" name="b" />
</label>
<label>
c:
<input type="number" name="c" />
</label>
{status === "init" && <button>Prove and verify</button>}
{status === "error" && (
<button>
Try Again <span className="error">×</span>
</button>
)}
{status === "success" && (
<button>
Proof is valid <span className="success">✓</span>
</button>
)}
{provingTime !== undefined && <div>Proof took {provingTime}ms</div>}
{verifyingTime !== undefined && (
<div>Verification took {verifyingTime}ms</div>
)}
</form>
{proof && <pre>{proof}</pre>}
</div>
);
}
export default App;