const Scalar = require("ffjavascript").Scalar; const blake2b = require("blake2b"); const assert = require("assert"); const ZqField = require("ffjavascript").ZqField; const utils = require("ffjavascript").utils; const F = new ZqField(Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617")); exports.F = F; 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; assert(t<=6); // Force the same matrix for all. t=6; 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