-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreditProof.js
63 lines (58 loc) · 1.73 KB
/
creditProof.js
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
const circomlibjs = require("circomlibjs");
const snarkjs = require("snarkjs");
const fs = require("fs");
async function poseidonHash(inputs) {
const poseidon = await circomlibjs.buildPoseidon();
const poseidonHash = poseidon.F.toString(poseidon(inputs));
return poseidonHash;
}
// Create credit proof
async function createCreditProof(
address,
creditScore,
minCreditScore,
maxCreditScore
) {
const hash = await poseidonHash([address, creditScore]);
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
{
creditScore: creditScore,
minCreditScore: minCreditScore,
maxCreditScore: maxCreditScore,
address: address,
hash: hash,
},
"./circuit_js/circuit.wasm",
"circuit_final.zkey"
);
fs.writeFileSync("proof.json", JSON.stringify(proof));
fs.writeFileSync("publicSignals.json", JSON.stringify(publicSignals));
return { proof, publicSignals };
}
// async function verifyAgeProof(proof, publicSignals) {
// const vKey = JSON.parse(fs.readFileSync("verification_key.json"));
// return await snarkjs.groth16.verify(vKey, publicSignals, proof);
// }
async function main() {
try {
const { proof, publicSignals } = await createCreditProof(
"0x210706cbd9D26c26c727f4d3007D819390934375",
700,
600,
20000
);
console.log({ proof, publicSignals });
fs.writeFileSync("proof.json", JSON.stringify(proof));
fs.writeFileSync("public.json", JSON.stringify(publicSignals));
// const verification = await verifyAgeProof(proof, publicSignals);
// console.log({ verification });
} catch (err) {
console.log(err);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exitCode = 1;
});