pub trait PoseidonHasher<F: PrimeField> {
    // Required method
    fn hash(&mut self, inputs: &[F]) -> Result<F, PoseidonError>;
}

Required Methods§

source

fn hash(&mut self, inputs: &[F]) -> Result<F, PoseidonError>

Calculates a Poseidon hash for the given input of prime fields and returns the result as a prime field.

Examples

Example with two simple big-endian byte inputs (converted to prime fields) and BN254-based parameters provided by the library.

use light_poseidon::{Poseidon, PoseidonHasher, parameters::bn254_x5};
use ark_bn254::Fr;
use ark_ff::{BigInteger, PrimeField};

let mut poseidon = Poseidon::<Fr>::new_circom(2).unwrap();

let input1 = Fr::from_be_bytes_mod_order(&[1u8; 32]);
let input2 = Fr::from_be_bytes_mod_order(&[2u8; 32]);

let hash = poseidon.hash(&[input1, input2]).unwrap();

// Do something with `hash`.

Implementors§