package merkletree import ( "math/big" "github.com/iden3/go-iden3-crypto/poseidon" ) // HashElems performs a poseidon hash over the array of ElemBytes, currently we // are using 2 elements. Uses poseidon.Hash to be compatible with the circom // circuits implementations. func HashElems(elems ...*big.Int) (*Hash, error) { poseidonHash, err := poseidon.Hash(elems) if err != nil { return nil, err } return NewHashFromBigInt(poseidonHash), nil } // HashElemsKey performs a poseidon hash over the array of ElemBytes, currently // we are using 2 elements. func HashElemsKey(key *big.Int, elems ...*big.Int) (*Hash, error) { if key == nil { key = new(big.Int).SetInt64(0) } bi := make([]*big.Int, 3) copy(bi[:], elems) bi[2] = key poseidonHash, err := poseidon.Hash(bi) if err != nil { return nil, err } return NewHashFromBigInt(poseidonHash), nil }