Documentation ¶
Index ¶
- Constants
- Variables
- func BigEndianBitsToBigInt(bits []bool) *big.Int
- func CheckBigIntInField(a *big.Int) bool
- func InitHashScheme(f func([]*big.Int, *big.Int) (*big.Int, error))
- func NewBigIntFromHashBytes(b []byte) (*big.Int, error)
- func ReverseByteOrder(b []byte) []byte
- func SetBitBigEndian(bitmap []byte, n uint)
- func TestBit(bitmap []byte, n uint) bool
- func TestBitBigEndian(bitmap []byte, n uint) bool
- func ToSecureKey(key []byte) (*big.Int, error)
- type Byte32
- type Hash
- func HandlingElemsAndByte32(flagArray uint32, elems []Byte32) (*Hash, error)
- func HashElems(fst, snd *big.Int, elems ...*big.Int) (*Hash, error)
- func HashElemsWithDomain(domain, fst, snd *big.Int, elems ...*big.Int) (*Hash, error)
- func NewHashFromBigInt(b *big.Int) *Hash
- func NewHashFromBytes(b []byte) *Hash
- func NewHashFromCheckedBytes(b []byte) (*Hash, error)
- func NewHashFromString(s string) (*Hash, error)
Constants ¶
const ( HASH_DOMAIN_ELEMS_BASE = 256 HASH_DOMAIN_BYTE32 = 2 * HASH_DOMAIN_ELEMS_BASE )
const HashByteLen = 32
HashByteLen is the length of the Hash byte array
Variables ¶
var BigOne = big.NewInt(1)
var BigZero = big.NewInt(0)
var HashZero = Hash{}
var Q *big.Int
Functions ¶
func BigEndianBitsToBigInt ¶
func CheckBigIntInField ¶
CheckBigIntInField checks if given *big.Int fits in a Field Q element
func NewBigIntFromHashBytes ¶
NewBigIntFromHashBytes returns a *big.Int from a byte array, swapping the endianness in the process. This is the intended method to get a *big.Int from a byte array that previously has ben generated by the Hash.Bytes() method.
func ReverseByteOrder ¶
ReverseByteOrder swaps the order of the bytes in the slice.
func SetBitBigEndian ¶
SetBitBigEndian sets the bit n in the bitmap to 1, in Big Endian.
func TestBitBigEndian ¶
TestBitBigEndian tests whether the bit n in bitmap is 1, in Big Endian.
Types ¶
type Byte32 ¶
type Byte32 [32]byte
func NewByte32FromBytes ¶
same action as common.Hash (truncate bytes longer than 32 bytes FROM beginning, and padding 0 at the beginning for shorter bytes)
func NewByte32FromBytesPaddingZero ¶
create bytes32 with zeropadding to shorter bytes, or truncate it
func ToSecureKeyBytes ¶ added in v0.2.0
ToSecureKeyBytes turn the byte key into a 32-byte "secured" key, which represented a big-endian integer
type Hash ¶
type Hash [HashByteLen]byte
Hash is the generic type to store the hash in the MerkleTree, encoded in little endian
func HandlingElemsAndByte32 ¶ added in v0.6.0
HandlingElemsAndByte32 hash an arry mixed with field and byte32 elements, turn each byte32 into field elements first then calculate the hash with HashElems
func HashElems ¶
HashElems call HashElemsWithDomain with a domain of HASH_DOMAIN_ELEMS_BASE(256)*<element counts>
func HashElemsWithDomain ¶ added in v0.6.0
HashElemsWithDomain performs a recursive poseidon hash over the array of ElemBytes, each hash reduce 2 fieds into one, with a specified domain field which would be used in every recursiving call
func NewHashFromBigInt ¶
NewHashFromBigInt returns a *Hash representation of the given *big.Int
func NewHashFromBytes ¶
NewHashFromBytes returns a *Hash from a byte array considered to be a represent of big-endian integer, it swapping the endianness in the process.
func NewHashFromCheckedBytes ¶ added in v0.2.0
NewHashFromCheckedBytes is the intended method to get a *Hash from a byte array that previously has ben generated by the Hash.Bytes() method. so it check the size of bytes to be expected length
func NewHashFromString ¶
NewHashFromString returns a *Hash representation of the given decimal string
func (*Hash) Bytes ¶
Bytes returns the byte representation of the *Hash in big-endian encoding. The function converts the byte order from little endian to big endian.
func (Hash) MarshalText ¶
MarshalText implements the marshaler for the Hash type
func (*Hash) UnmarshalText ¶
UnmarshalText implements the unmarshaler for the Hash type