How to use the snarkjs.bn128.Fr function in snarkjs

To help you get started, we’ve selected a few snarkjs examples, based on popular ways it is used in public projects.

github iden3 / iden3js / src / crypto / poseidon.js View on Github external
const { bigInt, bn128 } = require('snarkjs');

const F = bn128.Fr;
// const Poseidon = require('../../node_modules/circomlib/src/poseidon.js');
const { poseidon } = require('circomlib');

function hash(arr) {
  const poseidonHash = poseidon.createHash(6, 8, 57);
  return poseidonHash(arr);
}

function multiHash(arr) {
  // TODO check bigints inside finite field

  let r = bigInt(0);
  for (let i = 0; i < arr.length; i += 5) {
    const fiveElems = [];
    for (let j = 0; j < 5; j++) {
      if (i + j < arr.length) {