ethutil

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 17 Imported by: 0

README

ethutil

ethutil

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//bytes of "\x19Ethereum Signed Message:\n32"
	SIGN_PREFIX_STANDARD []byte = []byte("\u0019Ethereum Signed Message:\n32")

	//bytes of "\x19\x01"
	SIGN_PREFIX_HEX1901 []byte = []byte("\u0019\u0001")
)

Functions

func AddressToHex

func AddressToHex(addr common.Address) string

func BigIntToBytes

func BigIntToBytes(i *big.Int) []byte

func Byte32ToBytes

func Byte32ToBytes(bs [32]byte) []byte

func BytesToHex

func BytesToHex(buf []byte) string

func CalcSignVByChainId

func CalcSignVByChainId(chainID *big.Int, v uint8) int64

func DeriveChainId

func DeriveChainId(v *big.Int) *big.Int

deriveChainId derives the chain id from the given v parameter

func ECDSAPrivateKeyToHex

func ECDSAPrivateKeyToHex(prv *ecdsa.PrivateKey) string

ecdsa私钥指针转私钥字符串

func Ecrecover

func Ecrecover(digestHash []byte, signature []byte) string

获取签名地址

func GetAddress

func GetAddress(privateKey string) string

根据私钥获取地址

func GetContractAbi

func GetContractAbi(abiJson string) *abi.ABI

获取合约abi对象

func GetEthClientWithHeader

func GetEthClientWithHeader(endpoint string, key string, val string) (*ethclient.Client, error)

func GetEthStandardHex

func GetEthStandardHex(hex string) string

将16进制字符串转换为eth标准的16进制形式字符串(统一小写)

func GetInfuraEthClientUseJWT

func GetInfuraEthClientUseJWT(endpoint string, token string) (*ethclient.Client, error)

func GetInfuraEthClientUseSecret

func GetInfuraEthClientUseSecret(endpoint string, secret string) (*ethclient.Client, error)

func GetRawTxHash

func GetRawTxHash(tx *types.Transaction) string

获取已签名交易的txhash

func GetTxFrom

func GetTxFrom(tx *types.Transaction, chainID *big.Int) string

获取交易from地址

func HexToAddress

func HexToAddress(addr string) common.Address

func HexToBytes

func HexToBytes(hexStr string) []byte

func HexToECDSAPrivateKey

func HexToECDSAPrivateKey(privateKey string) *ecdsa.PrivateKey

私钥字符串转ecdsa私钥指针

func Int32ToBytes

func Int32ToBytes(i int64) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntToBytes

func IntToBytes(i int) []byte

func IsValidAddressHex

func IsValidAddressHex(hex string) bool

判断是否是有效的地址16进制字符串

func IsValidPrivateKeyHex

func IsValidPrivateKeyHex(hex string) bool

是否是有效的私钥16进制字符串

func JoinSignature

func JoinSignature(sign *Signature) string

将签名转换为16进制字符串

func Keccak256

func Keccak256(data []byte) []byte

计算数据的Keccak256值

func NewTx

func NewTx(nonce uint64, to string, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Transaction

生成新交易(未签名)

func PackFuncArgs

func PackFuncArgs(datas *[]AbiParam) *[]byte

打包调用合约方法用的参数

func PackSignArgs

func PackSignArgs(datas *[]AbiParam) *[]byte

打包签名用的参数

func PubkeyToAddress

func PubkeyToAddress(pubkey *ecdsa.PublicKey) string

func RestoreSignV

func RestoreSignV(chainID *big.Int, v int64) uint8

还原签名中的V,总是返回0||1

func SendRawTx

func SendRawTx(client *ethclient.Client, tx *types.Transaction) error

发送已签名的tx

func SignTx

func SignTx(prv *ecdsa.PrivateKey, tx *types.Transaction, chainID *big.Int) *types.Transaction

签名交易

func VerifySignature

func VerifySignature(address string, digestHash, signature []byte) bool

验证签名

Types

type AbiParam

type AbiParam struct {
	Type string
	Data []byte
}

type Signature

type Signature struct {
	R []byte
	S []byte
	V uint8
}

签名

func ExtractEcdsaSignature

func ExtractEcdsaSignature(signHex string) *Signature

16进制字符串转换为签名

func SignMessage

func SignMessage(digestHash []byte, prv *ecdsa.PrivateKey) *Signature

签名消息 The produced signature is in the [R || S || V] format where V is 0 or 1.

func SignOriginDatas

func SignOriginDatas(prv *ecdsa.PrivateKey, prefix []byte, params *[]AbiParam) *Signature

签名原始参数

Jump to

Keyboard shortcuts

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