Documentation ¶
Overview ¶
Package hexutil implements hex encoding with 0x prefix. This encoding is used by the Ethereum RPC API to transport binary data in JSON payloads.
Encoding Rules ¶
All hex data must have prefix "0x".
For byte slices, the hex data must be of even length. An empty byte slice encodes as "0x".
Integers are encoded using the least amount of digits (no leading zero digits). Their encoding may be of uneven length. The number zero encodes as "0x0".
Index ¶
- Constants
- Variables
- func Decode(input string) ([]byte, error)
- func DecodeBig(input string) (*big.Int, error)
- func DecodeUint64(input string) (uint64, error)
- func EIP55Hex(data []byte) string
- func Encode(b []byte) string
- func EncodeUint64(i uint64) string
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func Keccak256(data ...[]byte) []byte
- func MessageHash(msg string) []byte
- func MustDecode(input string) []byte
- func MustDecodeBig(input string) *big.Int
- func MustDecodeUint64(input string) uint64
- func MustParseBig256(s string) *big.Int
- func NewKeccak256() hash.Hash
- func NewKeccak512() hash.Hash
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ParseBig256(s string) (*big.Int, bool)
- func ParseEthSignature(signature string) (r string, s string, v string)
- func ReadBits(bigint *big.Int, buf []byte)
- func ToEth(balance *big.Int) *big.Float
- type Address
- type Hash
- type HexOrDecimal256
Constants ¶
const ( // HashLength is the expected length of the hash HashLength = 32 // AddressLength is the expected length of the address AddressLength = 20 )
Lengths of hashes and addresses in bytes.
Variables ¶
var ( Big1 = big.NewInt(1) Big0 = big.NewInt(0) )
var ( ErrEmptyString = &decError{"empty hex string"} ErrSyntax = &decError{"invalid hex string"} ErrMissingPrefix = &decError{"hex string without 0x prefix"} ErrOddLength = &decError{"hex string of odd length"} ErrEmptyNumber = &decError{"hex string \"0x\""} ErrLeadingZero = &decError{"hex number with leading zero digits"} ErrUint64Range = &decError{"hex number > 64 bits"} ErrUintRange = &decError{"hex number is bigger than uint bits"} ErrBig256Range = &decError{"hex number > 256 bits"} )
Errors
Functions ¶
func DecodeBig ¶
DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.
func DecodeUint64 ¶
DecodeUint64 decodes a hex string with 0x prefix as a quantity.
func EncodeUint64 ¶
EncodeUint64 encodes i as a hex string with 0x prefix.
func FromECDSAPub ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func MessageHash ¶
generates th sha3 hash of given message according to Ethereum format eth_sign calculated the signature over keccak256("\x19Ethereum Signed Message:\n" + len(givenMessage) + givenMessage))) this gives context to a signature and prevents signing of transactions.
func MustDecode ¶
MustDecode decodes a hex string with 0x prefix. It panics for invalid input.
func MustDecodeBig ¶
MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
func MustDecodeUint64 ¶
MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
func MustParseBig256 ¶
MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func ParseBig256 ¶
ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
func ParseEthSignature ¶
ParseEthSignature parses s as a hexadecimal encoded signature for given message and returns, s, r and v values
Types ¶
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an Ethereum account.
func BytesToAddress ¶
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func PubkeyToAddress ¶
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
type HexOrDecimal256 ¶
HexOrDecimal256 marshals big.Int as hex or decimal.
Directories ¶
Path | Synopsis |
---|---|
Package abi implements the Ethereum ABI (Application Binary Interface).
|
Package abi implements the Ethereum ABI (Application Binary Interface). |
Package common contains various helper functions.
|
Package common contains various helper functions. |
math
Package math provides integer math utilities.
|
Package math provides integer math utilities. |
bn256
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
bn256/cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
bn256/google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
secp256k1
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |