utils

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ZeroAddr is all 0s
	ZeroAddr common.Address
	// ZeroAddrHex is string of 20 0s
	ZeroAddrHex = Addr2Hex(ZeroAddr)
	// ZeroBigInt is big.NewInt(0)
	ZeroBigInt = big.NewInt(0)
	// ZeroHash is all 0s
	ZeroHash common.Hash
	// HashLength is the expected length of the hash
	HashLength = 32
)

Functions

func Addr2Hex

func Addr2Hex(a common.Address) string

Addr2Hex returns hex without 0x

func Addr2Hex0x

func Addr2Hex0x(a common.Address) string

func ArrayBytes2Hex0x

func ArrayBytes2Hex0x(in [][]byte) []string

func ArrayHex2Hash

func ArrayHex2Hash(in []string) [][32]byte

func Byte32ToBits

func Byte32ToBits(api frontend.API, b32 Bytes32, frSize int) []frontend.Variable

func Byte32ToFrBits

func Byte32ToFrBits(b32 [2]*big.Int, frSize int) []uint

func Bytes2Addr

func Bytes2Addr(b []byte) common.Address

Bytes2Addr returns Address from b Addr.Bytes() does the reverse

func Bytes2AddrHex

func Bytes2AddrHex(b []byte) string

Bytes2AddrHex returns hex without 0x

func Bytes2AddrHex0x

func Bytes2AddrHex0x(b []byte) string

func Bytes2Hash

func Bytes2Hash(b []byte) common.Hash

Bytes2Hash converts bytes to Hash

func Bytes2Hex

func Bytes2Hex(b []byte) string

Bytes2Hex returns hex string without 0x prefix

func Bytes2Hex0x

func Bytes2Hex0x(b []byte) string

func DecomposeBits

func DecomposeBits(data *big.Int, length int) []uint

DecomposeBits returns little endian bits of data

func FlipByGroups

func FlipByGroups[T any](in []T, groupSize int) []T

FlipByGroups flips the order of the groups of groupSize. e.g. [1,2,3,4,5,6] with groupSize 2 is flipped to [5,6,3,4,1,2]

func FormatAddrHex

func FormatAddrHex(s string) string

FormatAddrHex formats a string into standard Addr string

func GetHexArray

func GetHexArray(hexStr string, maxLen int) (res []frontend.Variable)

func Hex2Addr

func Hex2Addr(s string) common.Address

Hex2Addr accepts hex string with or without 0x prefix and return Address

func Hex2BigInt

func Hex2BigInt(s string) *big.Int

func Hex2Bytes

func Hex2Bytes(s string) (b []byte)

Hex2Bytes supports hex string with or without 0x prefix Calls hex.DecodeString directly and ignore err similar to ec.FromHex but better

func Hex2Hash

func Hex2Hash(s string) common.Hash

Hex2Hash accepts hex string with or without 0x prefix and return Hash

func IsValidTxHash

func IsValidTxHash(txHash string) bool

IsValidTxHash verifies whether a string can represent a valid hash or not.

func MiMCBlockPad0

func MiMCBlockPad0(data []byte, blockSize int) []byte

MiMCBlockPad0 pad 0 into miMC block up to specific block size in Big-Endian

func PackBitsToInt

func PackBitsToInt(bits []uint) []*big.Int

func Pad20Bytes

func Pad20Bytes(in []byte) []byte

if in is 20 bytes, return directly. otherwise return a new []byte w/ len 20, left pad 0x00..[in] if len(in)>20, panic

func Pad32Bytes

func Pad32Bytes(in []byte) []byte

func ParseBytes32

func ParseBytes32(data []byte, frSize int) [2]*big.Int

ParseBytes32 decomposes data (big endian) into little endian bits then recomposes the result into two big ints in the form of {lo, hi}

func Recompose32ByteToNibbles

func Recompose32ByteToNibbles(api frontend.API, trunk []frontend.Variable) [64]frontend.Variable

func Recompose6BytesToNibbles

func Recompose6BytesToNibbles(api frontend.API, d frontend.Variable) [12]frontend.Variable

func RecomposeSDKByte32ToNibble

func RecomposeSDKByte32ToNibble(api frontend.API, b32 Bytes32) [64]frontend.Variable

func Reverse

func Reverse[S ~[]E, E any](s S) S

func Strings2bytes

func Strings2bytes(rs []string) (ret [][]byte)

Types

type Bytes32

type Bytes32 struct {
	Val [2]frontend.Variable
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL