Documentation
¶
Index ¶
- Constants
- Variables
- func BigPow(a, b int64) *big.Int
- func CalTxHash(tx string) ([]byte, error)
- func CalcSignHash(data []byte, addPrefix bool) []byte
- func CheckAuthList(authList []*EthAuthorization) error
- func Decode(input string) ([]byte, error)
- func EIP712Hash(typedData TypedData) string
- func EIP712HashWithTypedDataHash(domainSeparatorHex, typedDataHashHex string) string
- func EIP712ParamsHash(typedData TypedData) string
- func EcRecover(signature, message string, addPrefix bool) (string, error)
- func EcRecoverAuthorization(tx EthAuthorization) (string, error)
- func EcRecoverBytes(signature, message []byte, addPrefix bool) (string, error)
- func EcRecoverPubKey(signature, message string, addPrefix bool) (*btcec.PublicKey, error)
- func EcRecoverPubKeyBytes(signature, message []byte, addPrefix bool) ([]byte, error)
- func FromHex(s string) []byte
- func GenEip1559TxWithSig(unsignedRawTx string, chainID, R, S, V *big.Int) (string, error)
- func GenEip7702TxWithSig(unsignedRawTx string, chainID, R, S, V *big.Int) (string, error)
- func GenLegacyTxWithSig(unsignedRawTx string, chainID, R, S, V *big.Int) (string, error)
- func GenTxWithSig(txType int, chainId, unsignedRawTx, r, s, v string) (string, error)
- func GenUnsignedEip1559Tx(tx *types.Transaction, chainId *big.Int) (string, error)
- func GenUnsignedEip7702Tx(tx *types.Transaction, authList []*EthAuthorization, chainId *big.Int) (string, error)
- func GenUnsignedTx(evmTx *EVMTx) (string, error)
- func GenerateEIP1559Tx(rlpStr string) (*types.Transaction, error)
- func GenerateSignAuthHash(address []byte, nonce *big.Int, chainId *big.Int) ([]byte, error)
- func GetNewAddress(pubKey *btcec.PublicKey) string
- func GetNewAddressBytes(pubKey *btcec.PublicKey) []byte
- func HasHexPrefix(str string) bool
- func Hex2Bytes(str string) []byte
- func IsEthHexAddress(s string) bool
- func IsHex(str string) bool
- func IsHexAddress(s string) bool
- func NewEip1559Transaction(chainId *big.Int, nonce uint64, maxPriorityFeePerGas *big.Int, ...) *types.Transaction
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func PubKeyToAddr(publicKey []byte) (string, error)
- func ReadBits(bigint *big.Int, buf []byte)
- func SignEip1559Tx(chainId *big.Int, tx *types.Transaction, prvKey *ecdsa.PrivateKey) ([]byte, error)
- func SignEip7702Tx(tx *types.Transaction, authList []*EthAuthorization, chainId *big.Int, ...) ([]byte, error)
- func SignEthTypeMessage(message string, prvKey *btcec.PrivateKey, addPrefix bool) (string, error)
- func SignLegacyTx(tx *EthTransaction, chainId *big.Int, prvKey *btcec.PrivateKey) ([]byte, error)
- func SignTx(evmTx *EVMTx, privateKey *btcec.PrivateKey) (string, error)
- func TypedDataAndHash(typedData TypedData) ([]byte, string, error)
- func U256(x *big.Int) *big.Int
- func U256Bytes(n *big.Int) []byte
- func ValidateAddress(s string) bool
- func VerifySignMsg(signature, message, address string, addPrefix bool) error
- type AccessList
- type AccessTuple
- type Address
- type DynamicFeeTx
- type EVMTx
- type Eip1559Transaction
- type Eip1559TransactionVRS
- type Eip7702Transaction
- type Eip7702TransactionVRS
- type EthAuthorization
- type EthTransaction
- func (tx *EthTransaction) GenUnsignedTx(chainId *big.Int) string
- func (tx *EthTransaction) GetSigningHash(chainId *big.Int) (string, string, error)
- func (tx *EthTransaction) Hash() (string, error)
- func (tx *EthTransaction) SignTransaction(chainId *big.Int, prvKey *btcec.PrivateKey) string
- func (tx *EthTransaction) SignedTx(chainId *big.Int, sig *SignatureData) string
- func (tx *EthTransaction) UnSignedTx(chainId *big.Int) string
- type Hash
- type NameValueType
- type SignatureData
- func NewSignatureData(msgHash []byte, publicKey string, r, s *big.Int) (*SignatureData, error)
- func SignAsRecoverable(value []byte, prvKey *btcec.PrivateKey) *SignatureData
- func SignMessage(message []byte, prvKey *btcec.PrivateKey) *SignatureData
- func SignMessageEIP1559(message []byte, prvKey *btcec.PrivateKey) (*SignatureData, error)
- type Type
- type TypePriority
- type TypedData
- func (typedData *TypedData) Dependencies(primaryType string, found []string) []string
- func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) ([]byte, error)
- func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)
- func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes
- func (typedData *TypedData) Format() ([]*NameValueType, error)
- func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) ([]byte, error)
- func (typedData *TypedData) Map() map[string]interface{}
- func (typedData *TypedData) TypeHash(primaryType string) []byte
- type TypedDataDomain
- type TypedDataMessage
- type Types
Constants ¶
const ( AuthorizationTxType = 0x04 AuthorizationTxTypeMagic = 0x05 )
const (
AddressLength = 20
)
const (
DynamicFeeTxType = 0x02
)
Variables ¶
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"} ErrUint64Range = &decError{"hex number > 64 bits"} )
Errors
var (
ErrInvalidParam = errors.New("invalid param")
)
Functions ¶
func CalcSignHash ¶
func CheckAuthList ¶
func CheckAuthList(authList []*EthAuthorization) error
func EIP712Hash ¶
func EIP712ParamsHash ¶
func EcRecoverAuthorization ¶
func EcRecoverAuthorization(tx EthAuthorization) (string, error)
func EcRecoverBytes ¶
func EcRecoverPubKey ¶
func EcRecoverPubKeyBytes ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func GenEip1559TxWithSig ¶
func GenEip7702TxWithSig ¶
func GenLegacyTxWithSig ¶
func GenTxWithSig ¶
func GenUnsignedEip1559Tx ¶
func GenUnsignedEip7702Tx ¶
func GenUnsignedEip7702Tx(tx *types.Transaction, authList []*EthAuthorization, chainId *big.Int) (string, error)
func GenUnsignedTx ¶
func GenerateEIP1559Tx ¶
func GenerateEIP1559Tx(rlpStr string) (*types.Transaction, error)
func GenerateSignAuthHash ¶
func GetNewAddress ¶
func GetNewAddressBytes ¶
func HasHexPrefix ¶
func IsEthHexAddress ¶
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
func NewEip1559Transaction ¶
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func PubKeyToAddr ¶
func ReadBits ¶
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 SignEip1559Tx ¶
func SignEip1559Tx(chainId *big.Int, tx *types.Transaction, prvKey *ecdsa.PrivateKey) ([]byte, error)
func SignEip7702Tx ¶
func SignEip7702Tx(tx *types.Transaction, authList []*EthAuthorization, chainId *big.Int, prvKey *btcec.PrivateKey) ([]byte, error)
func SignEthTypeMessage ¶
func SignLegacyTx ¶
func SignLegacyTx(tx *EthTransaction, chainId *big.Int, prvKey *btcec.PrivateKey) ([]byte, error)
func TypedDataAndHash ¶
TypedDataAndHash is a helper function that calculates a hash for typed data conforming to EIP-712. This hash can then be safely used to calculate a signature.
See https://eips.ethereum.org/EIPS/eip-712 for the full specification.
This gives context to the signed typed data and prevents signing of transactions.
func U256Bytes ¶
U256Bytes converts a big Int into a 256bit EVM number. This operation is destructive.
func ValidateAddress ¶
func VerifySignMsg ¶
Types ¶
type AccessList ¶
type AccessList []AccessTuple
type AccessTuple ¶
type AccessTuple struct {
Address []byte `json:"address" gencodec:"required"`
StorageKeys []Hash `json:"storageKeys" gencodec:"required"`
}
AccessTuple is the element type of an access list.
type Address ¶
type Address [20]byte
Address represents the 20 byte address of an Ethereum account.
func BigToAddress ¶
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
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.
type DynamicFeeTx ¶
type DynamicFeeTx struct {
ChainID *big.Int `json:"chainId"`
Nonce uint64 `json:"nonce"`
GasTipCap *big.Int `json:"gasTipCap"` // a.k.a. maxPriorityFeePerGas
GasFeeCap *big.Int `json:"gasFeeCap"` // a.k.a. maxFeePerGas
Gas uint64 `json:"gas"`
To *Address `json:"to"` // nil means contract creation
Value *big.Int `json:"value"`
Data []byte `json:"data"`
AccessList AccessList
// Signature values
V *big.Int `json:"v" gencodec:"required"`
R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s" gencodec:"required"`
}
DynamicFeeTx represents an EIP-1559 transaction.
func NewEthDynamicFeeTx ¶
func (*DynamicFeeTx) Hash ¶
func (tx *DynamicFeeTx) Hash() (string, error)
func (*DynamicFeeTx) SignTransaction ¶
func (tx *DynamicFeeTx) SignTransaction(prvKey *btcec.PrivateKey) (string, error)
type EVMTx ¶
type EVMTx struct {
TxType int
ChainId *big.Int
Tx *EthTransaction
Tx1559 *types.Transaction
AuthorizationList []*EthAuthorization
}
type Eip1559Transaction ¶
type Eip1559Transaction struct {
ChainId *big.Int `json:"chainId"`
Nonce uint64 `json:"nonce"`
GasTipCap *big.Int `json:"gasTipCap"`
GasFeeCap *big.Int `json:"gasFeeCap"`
Gas uint64 `json:"gas"`
To *common.Address `json:"to" rlp:"nil"` // nil for contract creation
Value *big.Int `json:"value"`
Data []byte `json:"data"`
AccessList types.AccessList `json:"accessList"`
}
type Eip1559TransactionVRS ¶
type Eip1559TransactionVRS struct {
ChainId *big.Int `json:"chainId"`
Nonce uint64 `json:"nonce"`
GasTipCap *big.Int `json:"gasTipCap"`
GasFeeCap *big.Int `json:"gasFeeCap"`
Gas uint64 `json:"gas"`
To *common.Address `json:"to" rlp:"nil"` // nil for contract creation
Value *big.Int `json:"value"`
Data []byte `json:"data"`
AccessList types.AccessList `json:"accessList"`
V *big.Int
R *big.Int
S *big.Int
}
type Eip7702Transaction ¶
type Eip7702Transaction struct {
ChainId *big.Int `json:"chainId"`
Nonce uint64 `json:"nonce"`
GasTipCap *big.Int `json:"gasTipCap"`
GasFeeCap *big.Int `json:"gasFeeCap"`
Gas uint64 `json:"gas"`
To *common.Address `json:"to" rlp:"nil"`
Value *big.Int `json:"value"`
Data []byte `json:"data"`
AccessList types.AccessList `json:"accessList"`
AuthorizationList []*EthAuthorization `json:"authorizationList"`
}
type Eip7702TransactionVRS ¶
type Eip7702TransactionVRS struct {
ChainId *big.Int `json:"chainId"`
Nonce uint64 `json:"nonce"`
GasTipCap *big.Int `json:"gasTipCap"`
GasFeeCap *big.Int `json:"gasFeeCap"`
Gas uint64 `json:"gas"`
To *common.Address `json:"to" rlp:"nil"`
Value *big.Int `json:"value"`
Data []byte `json:"data"`
AccessList types.AccessList `json:"accessList"`
AuthorizationList []*EthAuthorization `json:"authorizationList"`
V *big.Int
R *big.Int
S *big.Int
}
type EthAuthorization ¶
type EthAuthorization struct {
ChainId *big.Int `json:"chainId"`
Address []byte `json:"address"`
Nonce *big.Int `json:"nonce"`
YParity *big.Int `json:"yParit"`
R *big.Int `json:"r"`
S *big.Int `json:"s"`
}
func NewEthAuthorization ¶
func NewEthAuthorization(nonce, chainid, yParity, r, s *big.Int, address []byte) *EthAuthorization
func SignAuthorization ¶
func SignAuthorization(tx EthAuthorization, prvKey *btcec.PrivateKey) (EthAuthorization, error)
type EthTransaction ¶
type EthTransaction struct {
Nonce *big.Int `json:"nonce"`
GasPrice *big.Int `json:"gasPrice"`
GasLimit *big.Int `json:"gas"`
To []byte `json:"to"`
Value *big.Int `json:"value"`
Data []byte `json:"data"`
// Signature values
V *big.Int `json:"v"`
R *big.Int `json:"r"`
S *big.Int `json:"s"`
}
func NewEthTransaction ¶
func NewEthTransaction(nonce, gasLimit, gasPrice, value *big.Int, to, data string) *EthTransaction
func NewTransactionFromRaw ¶
func NewTransactionFromRaw(raw string) (*EthTransaction, error)
func (*EthTransaction) GenUnsignedTx ¶
func (tx *EthTransaction) GenUnsignedTx(chainId *big.Int) string
func (*EthTransaction) GetSigningHash ¶
func (*EthTransaction) Hash ¶
func (tx *EthTransaction) Hash() (string, error)
func (*EthTransaction) SignTransaction ¶
func (tx *EthTransaction) SignTransaction(chainId *big.Int, prvKey *btcec.PrivateKey) string
func (*EthTransaction) SignedTx ¶
func (tx *EthTransaction) SignedTx(chainId *big.Int, sig *SignatureData) string
func (*EthTransaction) UnSignedTx ¶
func (tx *EthTransaction) UnSignedTx(chainId *big.Int) string
type NameValueType ¶
type NameValueType struct {
Name string `json:"name"`
Value interface{} `json:"value"`
Typ string `json:"type"`
}
NameValueType is a very simple struct with Name, Value and Type. It's meant for simple json structures used to communicate signing-info about typed data with the UI
func (*NameValueType) Pprint ¶
func (nvt *NameValueType) Pprint(depth int) string
Pprint returns a pretty-printed version of nvt
type SignatureData ¶
func NewSignatureData ¶
func SignAsRecoverable ¶
func SignAsRecoverable(value []byte, prvKey *btcec.PrivateKey) *SignatureData
func SignMessage ¶
func SignMessage(message []byte, prvKey *btcec.PrivateKey) *SignatureData
func SignMessageEIP1559 ¶
func SignMessageEIP1559(message []byte, prvKey *btcec.PrivateKey) (*SignatureData, error)
func (SignatureData) ToBytes ¶
func (sd SignatureData) ToBytes() []byte
func (*SignatureData) ToHex ¶
func (sd *SignatureData) ToHex() string
type TypePriority ¶
type TypedData ¶
type TypedData struct {
Types Types `json:"types"`
PrimaryType string `json:"primaryType"`
Domain TypedDataDomain `json:"domain"`
Message TypedDataMessage `json:"message"`
}
func (*TypedData) Dependencies ¶
Dependencies returns an array of custom types ordered by their hierarchical reference tree
func (*TypedData) EncodeData ¶
func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) ([]byte, error)
EncodeData generates the following encoding: `enc(value₁) ‖ enc(value₂) ‖ … ‖ enc(valueₙ)`
each encoded member is 32-byte long
func (*TypedData) EncodePrimitiveValue ¶
func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)
EncodePrimitiveValue deals with the primitive values found while searching through the typed data
func (*TypedData) EncodeType ¶
EncodeType generates the following encoding: `name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")"`
each member is written as `type ‖ " " ‖ name` encodings cascade down and are sorted by name
func (*TypedData) Format ¶
func (typedData *TypedData) Format() ([]*NameValueType, error)
Format returns a representation of typedData, which can be easily displayed by a user-interface without in-depth knowledge about 712 rules
func (*TypedData) HashStruct ¶
func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) ([]byte, error)
HashStruct generates a keccak256 hash of the encoding of the provided data
type TypedDataDomain ¶
type TypedDataDomain struct {
Name string `json:"name"`
Version string `json:"version"`
ChainId *big.Int `json:"chainId"`
VerifyingContract string `json:"verifyingContract"`
Salt string `json:"salt"`
}
func (*TypedDataDomain) Map ¶
func (domain *TypedDataDomain) Map() map[string]interface{}
Map is a helper function to generate a map version of the domain
type TypedDataMessage ¶
type TypedDataMessage = map[string]interface{}