2024-01-10 14:12:18 +00:00
|
|
|
const fs = require("fs")
|
2024-01-05 11:27:53 +00:00
|
|
|
|
2024-01-23 13:03:37 +00:00
|
|
|
const BASE_PATH = __dirname + "/networks"
|
2024-01-18 08:54:21 +00:00
|
|
|
const PROOF_FILE_NAME = "example-proof/proof.json"
|
2024-01-22 15:43:03 +00:00
|
|
|
const PUBLIC_INPUT_FILE_NAME = "example-proof/public.json"
|
2024-01-30 05:36:27 +00:00
|
|
|
const ZKEY_HASH_FILE_NAME = "zkey_hash.json"
|
2024-01-23 11:38:47 +00:00
|
|
|
const VERIFICATION_KEY_FILE_NAME =
|
2024-01-30 05:36:27 +00:00
|
|
|
"proof_main_verification_key.json"
|
2024-01-18 08:54:21 +00:00
|
|
|
|
2024-01-18 12:50:54 +00:00
|
|
|
function G1ToStruct(point) {
|
|
|
|
return {
|
|
|
|
x: point[0],
|
2024-01-22 15:43:11 +00:00
|
|
|
y: point[1],
|
2024-01-18 12:50:54 +00:00
|
|
|
}
|
2024-01-18 08:54:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 12:50:54 +00:00
|
|
|
function G2ToStruct(point) {
|
|
|
|
return {
|
2024-02-20 16:16:49 +00:00
|
|
|
x: { real: point[0][0], imag: point[0][1] },
|
|
|
|
y: { real: point[1][0], imag: point[1][1] },
|
2024-01-18 12:50:54 +00:00
|
|
|
}
|
2024-01-18 08:54:21 +00:00
|
|
|
}
|
2024-01-05 11:27:53 +00:00
|
|
|
|
2024-01-10 14:12:18 +00:00
|
|
|
function loadProof(name) {
|
2024-01-23 13:03:37 +00:00
|
|
|
const path = `${BASE_PATH}/${name}/${PROOF_FILE_NAME}`
|
|
|
|
const proof = JSON.parse(fs.readFileSync(path))
|
2024-01-18 12:50:54 +00:00
|
|
|
return {
|
2024-01-22 15:43:11 +00:00
|
|
|
a: G1ToStruct(proof["pi_a"]),
|
|
|
|
b: G2ToStruct(proof["pi_b"]),
|
|
|
|
c: G1ToStruct(proof["pi_c"]),
|
2024-01-18 12:50:54 +00:00
|
|
|
}
|
2024-01-05 11:27:53 +00:00
|
|
|
}
|
|
|
|
|
2024-01-22 15:43:03 +00:00
|
|
|
function loadPublicInput(name) {
|
2024-01-23 13:03:37 +00:00
|
|
|
const path = `${BASE_PATH}/${name}/${PUBLIC_INPUT_FILE_NAME}`
|
|
|
|
const input = JSON.parse(fs.readFileSync(path))
|
2024-01-22 15:43:03 +00:00
|
|
|
return input
|
|
|
|
}
|
|
|
|
|
2024-01-30 05:36:27 +00:00
|
|
|
function loadZkeyHash(name) {
|
|
|
|
const path = `${BASE_PATH}/${name}/${ZKEY_HASH_FILE_NAME}`
|
|
|
|
const input = JSON.parse(fs.readFileSync(path))
|
|
|
|
return input
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:38:47 +00:00
|
|
|
function loadVerificationKey(name) {
|
2024-01-23 13:03:37 +00:00
|
|
|
const path = `${BASE_PATH}/${name}/${VERIFICATION_KEY_FILE_NAME}`
|
|
|
|
const key = JSON.parse(fs.readFileSync(path))
|
2024-01-23 11:38:47 +00:00
|
|
|
return {
|
|
|
|
alpha1: G1ToStruct(key["vk_alpha_1"]),
|
|
|
|
beta2: G2ToStruct(key["vk_beta_2"]),
|
|
|
|
gamma2: G2ToStruct(key["vk_gamma_2"]),
|
|
|
|
delta2: G2ToStruct(key["vk_delta_2"]),
|
2024-01-23 12:05:27 +00:00
|
|
|
ic: key["IC"].map(G1ToStruct),
|
2024-01-23 11:38:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 05:36:27 +00:00
|
|
|
module.exports = { loadProof, loadPublicInput, loadVerificationKey, loadZkeyHash }
|