mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 19:36:44 +01:00
Add HashGlobalInputs for ZKInputs
Add HashGlobalInputs for ZKInputs compatible with js & circom circuits version.
Compatible with hermeznetwork/commonjs at version: c6a1448db5bae4cda839ce36c1f35d8defccc9cd
(c6a1448db5)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
)
|
||||
|
||||
// SwapEndianness swaps the order of the bytes in the slice.
|
||||
@@ -19,3 +21,18 @@ func SwapEndianness(b []byte) []byte {
|
||||
func EthAddrToBigInt(a ethCommon.Address) *big.Int {
|
||||
return new(big.Int).SetBytes(a.Bytes())
|
||||
}
|
||||
|
||||
// BJJFromStringWithChecksum parses a hex string in Hermez format (which has
|
||||
// the Hermez checksum at the last byte, and is encoded in BigEndian) and
|
||||
// returns the corresponding *babyjub.PublicKey. This method is not part of the
|
||||
// spec, is used for importing javascript test vectors data.
|
||||
func BJJFromStringWithChecksum(s string) (*babyjub.PublicKey, error) {
|
||||
b, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkBytes := SwapEndianness(b)
|
||||
var pkComp babyjub.PublicKeyComp
|
||||
copy(pkComp[:], pkBytes[:])
|
||||
return pkComp.Decompress()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user