You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
871 B

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
}