evmutils

package
v2.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: Apache-2.0 Imports: 15 Imported by: 31

Documentation

Index

Constants

View Source
const (
	ZXAddressLength    = 22
	ZXAddrPrefixLength = 2
	ZXAddrSuffixLength = 20
	ZXAddrPrefix       = "ZX"
)
View Source
const (
	AddressLength = 20
)

Variables

View Source
var (
	BlankHash = make([]byte, hashLength)
	ZeroHash  = Keccak256(nil)
)

Functions

func EVMIntToHashBytes

func EVMIntToHashBytes(i *Int) [hashLength]byte

EVMIntToHashBytes returns the absolute value of x as a big-endian fixed length byte slice.

func FromHex

func FromHex(s string) ([]byte, error)

FromHex convert hex string to bytes @param s @return []byte @return error

func GetDataFrom

func GetDataFrom(src []byte, offset uint64, size uint64) []byte

GetDataFrom get data from src @param src @param offset @param size @return []byte

func Has0xPrefix

func Has0xPrefix(str string) bool

Has0xPrefix check if the string has 0x prefix @param str @return bool

func Keccak256

func Keccak256(data []byte) []byte

Keccak256 keccak256 hash @param data @return []byte

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func LeftPaddingSlice

func LeftPaddingSlice(src []byte, toSize int) []byte

LeftPaddingSlice left padding @param src @param toSize @return []byte

func MarshalPublicKey added in v2.3.0

func MarshalPublicKey(pk crypto.PublicKey) (pkBytes []byte, err error)

MarshalPublicKey serialize pk to bytes

func MinI

func MinI(i, j int64) int64

MinI returns the minimum of i and j. @param i @param j @return int64

func RightPaddingSlice

func RightPaddingSlice(src []byte, toSize int) []byte

RightPaddingSlice right padding @param src @param toSize @return []byte

func ZXAddress added in v2.2.0

func ZXAddress(data []byte) (string, error)

ZXAddress computes the address of the given public key in Zhi Xin Lian format @param data @return string @return error

func ZXAddressFromCertificatePEM added in v2.1.1

func ZXAddressFromCertificatePEM(certPEM []byte) (string, error)

ZXAddressFromCertificatePEM computes the address in Zhi Xin Lian format from a certificate PEM

func ZXAddressFromCertificatePath added in v2.1.1

func ZXAddressFromCertificatePath(certPath string) (string, error)

ZXAddressFromCertificatePath computes the address in Zhi Xin Lian format from a certificate file path

func ZXAddressFromPublicKey added in v2.1.1

func ZXAddressFromPublicKey(pk crypto.PublicKey) (string, error)

ZXAddressFromPublicKey computes the address of the given public key object in Zhi Xin Lian format

func ZXAddressFromPublicKeyDER added in v2.1.1

func ZXAddressFromPublicKeyDER(pkDER []byte) (string, error)

ZXAddressFromPublicKeyDER computes the address in Zhi Xin Lian format from a public key DER

func ZXAddressFromPublicKeyPEM added in v2.1.1

func ZXAddressFromPublicKeyPEM(pkPEM []byte) (string, error)

ZXAddressFromPublicKeyPEM computes the address in Zhi Xin Lian format from a public key PEM

Types

type Address

type Address [AddressLength]byte

Address is the 20 byte address of an Ethereum account.

func BigToAddress

func BigToAddress(b *Int) Address

BigToAddress math.bigInt to evm address

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress any byte set to an evm address

func HexToAddress

func HexToAddress(s string) (Address, error)

HexToAddress direct convert hex to an evm address,直接将十六进制字符串转换为Address类型

func MakeHexToAddress added in v2.3.0

func MakeHexToAddress(s string) (Address, error)

MakeHexToAddress 基于十六进制数据,经过Hash计算获得一个EVM地址 @param s @return Address @return error

func StringToAddress

func StringToAddress(s string) (Address, error)

StringToAddress any string make an evm address

func (*Address) SetBytes

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

SetBytes sets the address to the value of b. @param b

func (*Address) String added in v2.3.0

func (a *Address) String() string

String returns the hex string representation of the address. @return string

type Int

type Int struct {
	*big.Int
}

Int is a 256-bit integer.

func BytesDataToEVMIntHash

func BytesDataToEVMIntHash(data []byte) *Int

BytesDataToEVMIntHash fixed length bytes

func EthHashBytesToEVMInt

func EthHashBytesToEVMInt(hash [hashLength]byte) (*Int, error)

EthHashBytesToEVMInt EVMIntToHashBytes reverse

func FromBigInt

func FromBigInt(i *big.Int) *Int

FromBigInt returns a new Int. @param i @return *Int

func FromDecimalString

func FromDecimalString(s string) *Int

FromDecimalString from fmt data Int.String()

func FromHexString

func FromHexString(s string) *Int

FromHexString from fmt data hex.encodeToString([]byte(Int.AsStringKey))

func FromString

func FromString(ss string) *Int

FromString from fmt data Int.AsStringKey

func HashBytesToEVMInt

func HashBytesToEVMInt(hash []byte) (*Int, error)

HashBytesToEVMInt byte to bigInt

func MakeAddress

func MakeAddress(data []byte) *Int

MakeAddress any byte make an evm.Int

func MakeAddressFromHex

func MakeAddressFromHex(str string) (*Int, error)

MakeAddressFromHex any hex str make an evm.Int

func MakeAddressFromString

func MakeAddressFromString(str string) (*Int, error)

MakeAddressFromString any str make an evm.Int

func MinInt

func MinInt(i, j *Int) *Int

MinInt returns the minimum of i and j. @param i @param j @return *Int

func New

func New(i int64) *Int

New returns a new Int. @param i @return *Int

func (*Int) Add

func (i *Int) Add(y *Int) *Int

Add adds y to i and returns i. @param y @return *Int

func (*Int) AddMod

func (i *Int) AddMod(y *Int, m *Int) *Int

AddMod adds y to i and returns i. @param y @param m @return *Int

func (*Int) And

func (i *Int) And(y *Int) *Int

And returns the bitwise AND of i and y. @param y @return *Int

func (*Int) AsStringKey

func (i *Int) AsStringKey() string

AsStringKey returns the string key of the Int. @return string

func (*Int) ByteAt

func (i *Int) ByteAt(n int) byte

ByteAt returns the nth byte of i. @param n @return byte

func (Int) Clone

func (i Int) Clone() *Int

Clone returns a copy of the Int. @return *Int

func (*Int) Div

func (i *Int) Div(y *Int) *Int

Div divides i by y and returns i. @param y @return *Int

func (*Int) EQ

func (i *Int) EQ(y *Int) bool

EQ returns true if i == y. @param y @return bool

func (*Int) Exp

func (i *Int) Exp(e *Int) *Int

Exp calculates i**e mod m and returns i. @param e @return *Int

func (*Int) GT

func (i *Int) GT(y *Int) bool

GT returns true if i > y. @param y @return bool

func (*Int) GetSigned

func (i *Int) GetSigned() *Int

GetSigned returns the signed value of the Int. @return *Int

func (*Int) IsZero

func (i *Int) IsZero() bool

IsZero returns true if i == 0. @return bool

func (*Int) LT

func (i *Int) LT(y *Int) bool

LT returns true if i < y. @param y @return bool

func (*Int) Mod

func (i *Int) Mod(m *Int) *Int

Mod returns the unsigned remainder of i/y. @param m @return *Int

func (*Int) Mul

func (i *Int) Mul(y *Int) *Int

Mul multiplies i by y and returns i. @param y @return *Int

func (*Int) MulMod

func (i *Int) MulMod(y *Int, m *Int) *Int

MulMod multiplies i by y and returns i. @param y @param m @return *Int

func (*Int) Not

func (i *Int) Not(y *Int) *Int

Not returns the bitwise NOT of i. @param y @return *Int

func (*Int) Or

func (i *Int) Or(y *Int) *Int

Or returns the bitwise OR of i and y. @param y @return *Int

func (*Int) SAR

func (i *Int) SAR(n uint64) *Int

SAR shifts i right by n bits. @param n @return *Int

func (*Int) SDiv

func (i *Int) SDiv(y *Int) *Int

SDiv divides i by y and returns i. @param y @return *Int

func (*Int) SGT

func (i *Int) SGT(y *Int) bool

SGT returns true if i > y. @param y @return bool

func (*Int) SHL

func (i *Int) SHL(n uint64) *Int

SHL shifts i left by n bits. @param n @return *Int

func (*Int) SHR

func (i *Int) SHR(n uint64) *Int

SHR shifts i right by n bits. @param n @return *Int

func (*Int) SLT

func (i *Int) SLT(y *Int) bool

SLT returns true if i < y. @param y @return bool

func (*Int) SMod

func (i *Int) SMod(m *Int) *Int

SMod returns the signed remainder of i/y. @param m @return *Int

func (*Int) SignExtend

func (i *Int) SignExtend(baseBytes *Int) *Int

SignExtend extends the length of the signed integer i by given number of bytes. @param baseBytes @return *Int

func (*Int) Sub

func (i *Int) Sub(y *Int) *Int

Sub subtracts y from i and returns i. @param y @return *Int

func (*Int) XOr

func (i *Int) XOr(y *Int) *Int

XOr returns the bitwise XOR of i and y. @param y @return *Int

Directories

Path Synopsis
abi

Jump to

Keyboard shortcuts

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