fixtures

package
v0.0.0-...-bb1a4e7 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

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

View Source
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

View Source
var (
	Big1 = big.NewInt(1)
	Big0 = big.NewInt(0)
)
View Source
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 Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecodeBig

func DecodeBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

DecodeUint64 decodes a hex string with 0x prefix as a quantity.

func EIP55Hex

func EIP55Hex(data []byte) string

Hex returns an EIP55-compliant hex string representation of the address.

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeUint64

func EncodeUint64(i uint64) string

EncodeUint64 encodes i as a hex string with 0x prefix.

func FromECDSAPub

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func MessageHash

func MessageHash(msg string) []byte

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

func MustDecode(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func MustDecodeBig

func MustDecodeBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustDecodeUint64

func MustDecodeUint64(input string) uint64

MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustParseBig256

func MustParseBig256(s string) *big.Int

MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.

func NewKeccak256

func NewKeccak256() hash.Hash

NewKeccak256 creates a new Keccak-256 hash.

func NewKeccak512

func NewKeccak512() hash.Hash

NewKeccak512 creates a new Keccak-512 hash.

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.

func ParseBig256

func ParseBig256(s string) (*big.Int, bool)

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

func ParseEthSignature(signature string) (r string, s string, v string)

ParseEthSignature parses s as a hexadecimal encoded signature for given message and returns, s, r and v values

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func ToEth

func ToEth(balance *big.Int) *big.Float

Types

type Address

type Address [AddressLength]byte

Address represents the 20 byte address of an Ethereum account.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) Address

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

UnsafeBytes gets the string representation of the underlying address.

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

type HexOrDecimal256

type HexOrDecimal256 big.Int

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.

Jump to

Keyboard shortcuts

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