UNPKG

snarkjs

Version:

zkSNARKs implementation in JavaScript

47 lines (37 loc) 1.56 kB
/* Copyright 2018 0KIMS association. This file is part of snarkJS. snarkJS is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. snarkJS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with snarkJS. If not, see <https://www.gnu.org/licenses/>. */ import { utils } from "ffjavascript"; const { unstringifyBigInts} = utils; function p256(n) { let nstr = n.toString(16); while (nstr.length < 64) nstr = "0"+nstr; nstr = `"0x${nstr}"`; return nstr; } export default async function groth16ExportSolidityCallData(_proof, _pub) { const proof = unstringifyBigInts(_proof); const pub = unstringifyBigInts(_pub); let inputs = ""; for (let i=0; i<pub.length; i++) { if (inputs != "") inputs = inputs + ","; inputs = inputs + p256(pub[i]); } let S; S=`[${p256(proof.pi_a[0])}, ${p256(proof.pi_a[1])}],` + `[[${p256(proof.pi_b[0][1])}, ${p256(proof.pi_b[0][0])}],[${p256(proof.pi_b[1][1])}, ${p256(proof.pi_b[1][0])}]],` + `[${p256(proof.pi_c[0])}, ${p256(proof.pi_c[1])}],` + `[${inputs}]`; return S; }