Add initial structure of BatchBuilder

This commit is contained in:
arnaucube
2020-08-03 18:24:51 +02:00
parent dd1901709c
commit f3cfba1bbe
5 changed files with 193 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"math/big"
eth "github.com/ethereum/go-ethereum/common"
"github.com/iden3/go-iden3-crypto/poseidon"
cryptoUtils "github.com/iden3/go-iden3-crypto/utils"
)
@@ -65,6 +66,16 @@ func (l *Leaf) BigInts() ([5]*big.Int, error) {
return e, nil
}
// Value returns the value of the Leaf, which is the Poseidon hash of its *big.Int representation
func (l *Leaf) Value() (*big.Int, error) {
toHash := [poseidon.T]*big.Int{}
lBI := l.BigInts()
copy(toHash[:], lBI[:])
v, err := poseidon.Hash(toHash)
return v, err
}
// LeafFromBigInts returns a Leaf from a [5]*big.Int
func LeafFromBigInts(e [5]*big.Int) (*Leaf, error) {
if !cryptoUtils.CheckBigIntArrayInField(e[:]) {