Documentation
¶
Index ¶
- Variables
- func All[T any](slice []T, f func(T) bool) bool
- func BigIntArrToFeltArr(bigArr []*big.Int) []*felt.Felt
- func BigIntToFelt(bigNum *big.Int) *felt.Felt
- func BigToHex(in *big.Int) string
- func ByteArrFeltToString(arr []*felt.Felt) (string, error)
- func BytesToBig(bytesVal []byte) *big.Int
- func ComputeFact(programHash *big.Int, programOutputs []*big.Int) *big.Int
- func ETHToWei(eth float64) *felt.Felt
- func FeltArrToBigIntArr(f []*felt.Felt) []*big.Int
- func FeltArrToStringArr(f []*felt.Felt) []string
- func FeltToBigInt(f *felt.Felt) *big.Int
- func FillHexWithZeroes(hex string) string
- func Filter[T any](slice []T, f func(T) bool) []T
- func Flatten[T any](sl ...[]T) []T
- func FmtKecBytes(in *big.Int, rolen int) (buf []byte)
- func GetAndUnmarshalJSONFromMap[T any](aMap map[string]json.RawMessage, key string) (result T, err error)
- func GetSelectorFromName(funcName string) *big.Int
- func GetSelectorFromNameFelt(funcName string) *felt.Felt
- func HexArrToBNArr(hexArr []string) []*big.Int
- func HexArrToFelt(hexArr []string) ([]*felt.Felt, error)
- func HexToBN(hexString string) *big.Int
- func HexToBytes(hexString string) ([]byte, error)
- func HexToFelt(hexVal string) (*felt.Felt, error)
- func HexToShortStr(hexStr string) string
- func HexToU256Felt(hexStr string) ([]*felt.Felt, error)
- func Keccak256(data ...[]byte) []byte
- func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2
- func MaskBits(mask, wordSize int, slice []byte) (ret []byte)
- func RemoveFieldFromJSON(jsonData *[]byte, field string) error
- func SNValToBN(str string) *big.Int
- func SplitFactStr(fact string) (fact_low, fact_high string, err error)
- func StrToBig(str string) *big.Int
- func StrToHex(str string) string
- func StringToByteArrFelt(s string) ([]*felt.Felt, error)
- func TestHexArrToFelt(t testing.TB, hexArr []string) []*felt.Felt
- func TestHexToFelt(t testing.TB, hex string) *felt.Felt
- func TestUnmarshalJSONFileToType[T any](t testing.TB, filePath, subfield string) *T
- func U256FeltToHex(u256 []*felt.Felt) (string, error)
- func UTF8StrToBig(str string) *big.Int
- func Uint64ToFelt(num uint64) *felt.Felt
- func UnmarshalJSONFileToType[T any](filePath, subfield string) (*T, error)
- func UnwrapJSON(data map[string]any, tag string) (map[string]any, error)
- func WeiToETH(wei *felt.Felt) float64
- type KeccakState
Constants ¶
This section is empty.
Variables ¶
var RANDOM_FELT = new(felt.Felt).SetUint64(3735928559) //nolint:mnd
Just a random felt variable to use when needed. The value is "0xdeadbeef"
Functions ¶
func BigIntArrToFeltArr ¶
BigIntArrToFeltArr converts an array of big.Int objects to an array of Felt objects.
Parameters:
- bigArr: the array of big.Int objects to convert
Returns:
- []*felt.Felt: the array of Felt objects
func BigIntToFelt ¶
BigIntToFelt converts a big integer to a felt.Felt.
Parameters:
- bigNum: the big integer to convert
Returns:
- *felt.Felt: the converted value
func BigToHex ¶
BigToHex converts a big integer to its hexadecimal representation.
Parameters:
- in: the big integer to be converted
Returns:
- string: the hexadecimal representation
func ByteArrFeltToString ¶
ByteArrFeltToString converts array of Felts to string. The input array of felts will be of the format
[number of felts with 31 characters in length, 31 byte felts..., pending word with max size of 30 bytes, pending words bytes size]
For further explanation, refer the article
Parameters:
- []*felt.Felt: the array of felt.Felt objects
Returns:
s: string/bytearray
error: an error, if any
func BytesToBig ¶
BytesToBig converts a byte slice to a big.Int.
Parameters:
- bytesVal: the byte slice to be converted
Returns:
- *big.Int: the converted value
func ComputeFact ¶
ComputeFact computes the factorial of a given number.
Parameters:
- programHash: a pointer to a big.Int representing the program hash
- programOutputs: a slice of pointers to big.Int representing the program outputs
Returns:
- *big.Int: a pointer to a big.Int representing the computed factorial
func FeltArrToBigIntArr ¶
FeltArrToBigIntArr converts an array of Felt objects to an array of big.Int objects.
Parameters:
- f: the array of Felt objects to convert
Returns:
- []*big.Int: the array of big.Int objects
func FeltArrToStringArr ¶
FeltArrToStringArr converts an array of Felt objects to an array of string objects.
Parameters:
- f: the array of Felt objects to convert
Returns:
- []string: the array of string objects
func FeltToBigInt ¶
FeltToBigInt converts a Felt value to a *big.Int.
Parameters:
- f: the Felt value to convert
Returns:
- *big.Int: the converted value
func FillHexWithZeroes ¶ added in v0.12.0
FillHexWithZeroes normalises a hex string to have a '0x' prefix and pads it with leading zeros to a total length of 66 characters (including the '0x' prefix).
func Filter ¶
Filter filters a slice of type T using the given predicate, returning a new slice with the elements that match the predicate
func Flatten ¶
func Flatten[T any](sl ...[]T) []T
Flatten flattens a slice of slices into a single slice
func FmtKecBytes ¶
FmtKecBytes formats the given big.Int as a byte slice (Keccak hash) with a specified length.
The function appends the bytes of the big.Int to a buffer and returns it. If the length of the buffer is less than the specified length, the function pads the buffer with zeros.
Parameters:
- in: the big.Int to be formatted
- rolen: the length of the buffer
Returns: buf: the formatted buffer
func GetAndUnmarshalJSONFromMap ¶
func GetAndUnmarshalJSONFromMap[T any](aMap map[string]json.RawMessage, key string) (result T, err error)
GetAndUnmarshalJSONFromMap retrieves and unmarshals a JSON value from a map into the specified type T.
Parameters:
- aMap: A map containing JSON raw messages
- key: The key to look up in the map
Returns:
- T: The unmarshaled value of type T
- error: An error if the key is not found or unmarshaling fails
func GetSelectorFromName ¶
GetSelectorFromName generates a selector from a given function name.
Parameters:
- funcName: the name of the function
Returns:
- *big.Int: the selector
func GetSelectorFromNameFelt ¶
GetSelectorFromNameFelt returns a *felt.Felt based on the given function name.
Parameters:
- funcName: the name of the function
Returns:
- *felt.Felt: the *felt.Felt
func HexArrToBNArr ¶
HexArrToBNArr converts a hexadecimal string array to a *big.Int array. Trim "0x" prefix(if exists)
Parameters:
- hexArr: the hexadecimal string array to be converted
Returns:
- *big.Int: the converted array
func HexArrToFelt ¶
HexArrToFelt converts an array of hexadecimal strings to an array of felt objects.
The function iterates over each element in the hexArr array and calls the HexToFelt function to convert each hexadecimal value to a felt object. If any error occurs during the conversion, the function will return nil and the corresponding error. Otherwise, it appends the converted felt object to the feltArr array. Finally, the function returns the feltArr array containing all the converted felt objects.
Parameters:
- hexArr: an array of strings representing hexadecimal values
Returns:
- []*felt.Felt: an array of *felt.Felt objects, or nil if there was
- error: an error if any
func HexToBN ¶
HexToBN converts a hexadecimal string to a big.Int. trim "0x" prefix(if exists)
Parameters:
- hexString: the hexadecimal string to be converted
Returns:
- *big.Int: the converted value
func HexToBytes ¶
HexToBytes converts a hexadecimal string to a byte slice. trim "0x" prefix(if exists)
Parameters:
- hexString: the hexadecimal string to be converted
Returns:
- []byte: the converted value
- error: an error if any
func HexToFelt ¶
HexToFelt converts a hexadecimal string to a *felt.Felt object.
Parameters:
- hexVal: the input hexadecimal string to be converted.
Returns:
- *felt.Felt: a *felt.Felt object
- error: if conversion fails
func HexToShortStr ¶
HexToShortStr converts a hexadecimal string to a short string (Starknet) representation.
Parameters:
- hexStr: the hexadecimal string to convert to a short string
Returns:
- string: a short string
func HexToU256Felt ¶
HexToU256Felt converts a hexadecimal string to a Cairo u256 representation. The Cairo u256 is represented as two felt.Felt values:
- The first felt.Felt contains the 128 least significant bits (low part)
- The second felt.Felt contains the 128 most significant bits (high part)
Parameters:
- hexStr: the hexadecimal string to convert to a Cairo u256
Returns:
- []*felt.Felt: a slice containing two felt.Felt values [low, high]
- error: if conversion fails
func Keccak256 ¶
Keccak256 returns the Keccak-256 hash of the input data. (ref: https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto.go)
Parameters:
- data: a variadic parameter of type []byte representing the input data
Returns:
- []byte: a 32-byte hash output
func Map ¶
func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2
Map maps a slice of type T1 to a slice of type T2 using the given function
func MaskBits ¶
MaskBits masks (excess) bits in a slice of bytes based on the given mask and wordSize.
Parameters:
- mask: an integer representing the number of bits to mask
- wordSize: an integer representing the size of each word in bits
- slice: a slice of bytes to mask
Returns:
- ret: a slice of bytes with the masked bits
func RemoveFieldFromJSON ¶
RemoveFieldFromJSON removes a field from a JSON bytes slice.
Parameters:
- jsonData: pointer to the JSON data
- field: string field to remove, it must be a direct child of the JSON object
Returns:
- error: error if any
func SNValToBN ¶
SNValToBN converts a given string to a *big.Int by checking if the string contains "0x" prefix. used in string conversions when interfacing with the APIs
Parameters:
- str: a string to be converted to *big.Int
Returns:
- *big.Int: a pointer to a big.Int representing the converted value
func SplitFactStr ¶
SplitFactStr splits a given fact, with maximum 256 bits size, into two parts (felts): fact_low and fact_high.
The function takes a fact string as input and converts it to a big number using the HexToBN function. It then converts the big number to bytes using the Bytes method. If the length of the bytes is less than 32, it pads the bytes with zeros using the bytes.Repeat method. The padded bytes are then appended to the original bytes. The function then extracts the low part of the bytes by taking the last 16 bytes and converts it to a big number using the BytesToBig function. It also extracts the high part of the bytes by taking the first 16 bytes and converts it to a big number using the BytesToBig function. Finally, it converts the low and high big numbers to hexadecimal strings using the BigToHex function and returns them.
Parameters:
- fact: The fact string to be split
Return types:
- fact_low: The low part of the fact string in hexadecimal format
- fact_high: The high part of the fact string in hexadecimal format
- err: An error if any
func StrToBig ¶
StrToBig generates a *big.Int from a string representation.
Parameters:
- str: The string to convert to a *big.Int
Returns:
- *big.Int: a pointer to a big.Int representing the converted value
func StrToHex ¶
StrToBig generates a hexadecimal from a string/number representation.
Parameters:
- str: The string to convert to a hexadecimal
Returns:
- hex: a string representing the converted value
func StringToByteArrFelt ¶
StringToByteArrFelt converts string to array of Felt objects. The returned array of felts will be of the format
[number of felts with 31 characters in length, 31 byte felts..., pending word with max size of 30 bytes, pending words bytes size]
For further explanation, refer the article
Parameters:
- s: string/bytearray to convert
Returns:
[]*felt.Felt: the array of felt.Felt objects
error: an error, if any
func TestHexArrToFelt ¶
TestHexArrToFelt generates a slice of *felt.Felt from a slice of strings representing hexadecimal values.
Parameters:
- t: A testing.TB interface used for test logging and error reporting
- hexArr: A slice of strings representing hexadecimal values
Returns:
- []*felt.Felt: a slice of *felt.Felt
func TestHexToFelt ¶
TestHexToFelt generates a felt.Felt from a hexadecimal string.
Parameters:
- t: the testing.TB object for test logging and reporting
- hex: the hexadecimal string to convert to a felt.Felt
Returns:
- *felt.Felt: the generated felt.Felt object
func TestUnmarshalJSONFileToType ¶
TestUnmarshalJSONFileToType reads a JSON file at the given path and unmarshals it into the specified type T. If any error occurs during file reading or unmarshalling, it fails the test.
Parameters:
- t: testing.TB interface for test logging and error reporting
- filePath: string path to the JSON file
- subfield: string subfield to unmarshal from the JSON file
Returns:
- T: the unmarshalled data of type T
func U256FeltToHex ¶
U256FeltToHex converts a Cairo u256 representation (two felt.Felt values) back to a hexadecimal string. The Cairo u256 is represented as two felt.Felt values:
- The first felt.Felt contains the 128 least significant bits (low part)
- The second felt.Felt contains the 128 most significant bits (high part)
Parameters:
- u256: a slice containing two felt.Felt values [low, high]
Returns:
- string: the hexadecimal representation of the combined value
- error: if conversion fails
func UTF8StrToBig ¶
UTF8StrToBig converts a UTF-8 string to a big integer.
Parameters:
- str: The UTF-8 string to convert to a big integer
Returns:
- *big.Int: a pointer to a big.Int representing the converted value
func Uint64ToFelt ¶
Uint64ToFelt generates a new *felt.Felt from a given uint64 number.
Parameters:
- num: the uint64 number to convert to a *felt.Felt
Returns:
- *felt.Felt: a *felt.Felt
func UnmarshalJSONFileToType ¶
UnmarshalJSONFileToType reads a JSON file at the given path and unmarshals it into the specified type T. If any error occurs during file reading or unmarshalling, it returns an error.
Parameters:
- filePath: string path to the JSON file
- subfield: string subfield to unmarshal from the JSON file
Returns:
- *T: pointer to the unmarshalled data of type T
- error: error if file reading or unmarshalling fails
Types ¶
type KeccakState ¶
KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.
func NewKeccakState ¶
func NewKeccakState() KeccakState
NewKeccakState returns a new instance of KeccakState. (ref: https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto.go)
Parameters:
none
Returns:
- KeccakState: a new instance of KeccakState