const bn128 = require("snarkjs").bn128; const bigInt = require("snarkjs").bigInt; const blake2b = require('blake2b'); const assert = require("assert"); const F = bn128.Fr; const SEED = "poseidon"; const NROUNDSF = 8; const NROUNDSP = 57; const T = 6; function getPseudoRandom(seed, n) { const res = []; let input = Buffer.from(seed); let h = blake2b(32).update(input).digest() while (res.length { if (typeof seed === "undefined") seed = SEED; if (typeof nRounds === "undefined") nRounds = NROUNDSF + NROUNDSP; if (typeof t === "undefined") t = T; let nonce = "0000"; let cmatrix = getPseudoRandom(seed+"_matrix_"+nonce, t*2); while (!allDifferent(cmatrix)) { nonce = (Number(nonce)+1)+""; while(nonce.length<4) nonce = "0"+nonce; cmatrix = getPseudoRandom(seed+"_matrix_"+nonce, t*2); } const M = new Array(t); for (let i=0; i { if (typeof seed === "undefined") seed = SEED; if (typeof nRounds === "undefined") nRounds = NROUNDSF + NROUNDSP; if (typeof t === "undefined") t = T; const cts = getPseudoRandom(seed+"_constants", nRounds); return cts; }; function ark(state, c) { for (let j=0; j { if (typeof seed === "undefined") seed = SEED; if (typeof nRoundsF === "undefined") nRoundsF = NROUNDSF; if (typeof nRoundsP === "undefined") nRoundsP = NROUNDSP; if (typeof t === "undefined") t = T; assert(nRoundsF % 2 == 0); const C = exports.getConstants(t, seed, nRoundsF + nRoundsP); const M = exports.getMatrix(t, seed, nRoundsF + nRoundsP); return function(inputs) { let state = []; assert(inputs.length < t); assert(inputs.length > 0); for (let i=0; i= nRoundsF/2 + nRoundsP)) { for (let j=0; j