types

package
v0.0.0-...-811d2bd Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength
	AddressLength = 20
	// AccPublicKeyLength
	AccPublicKeyLength = 33
	// AccPrivateKeyLength
	AccPrivateKeyLength = 32
	// P2pPublicKeyLength
	P2pPublicKeyLength = 32
	// P2pPrivateKeyLength
	P2pPrivateKeyLength = 64

	P2pAddressBech32Length = 44

	P2pSignatureLength = 64
)

Lengths of hashes and addresses in bytes.

Variables

This section is empty.

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func Encode

func Encode(b []byte) string

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

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 IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func VerifyP2pAddrBytes

func VerifyP2pAddrBytes(p2pPubkey []byte, p2pAddr string) bool

VerifyP2pAddrBytes verify whether P2P address matches public key

func VerifyP2pSignBytes

func VerifyP2pSignBytes(p2pPubkey []byte, signature []byte, message []byte) bool

VerifyP2pSignBytes verify the signature made by P2P key

func VerifyP2pSignString

func VerifyP2pSignString(p2pPubkey []byte, signature []byte, message string) bool

VerifyP2pSignString verify the signature made by P2P key

func VerifyWalletAddr

func VerifyWalletAddr(walletPubkey, walletAddr string) int

VerifyWalletAddr verify the wallet address and public key match

func VerifyWalletAddrBytes

func VerifyWalletAddrBytes(walletPubkey []byte, walletAddr string) int

VerifyWalletAddrBytes []byte version of VerifyWalletKey() for the pubkey format

func VerifyWalletSign

func VerifyWalletSign(walletPubkey, signature, message string) bool

VerifyWalletSign verify the signature by wallet key

func VerifyWalletSignBytes

func VerifyWalletSignBytes(walletPubkey []byte, signature []byte, message string) bool

VerifyWalletSignBytes []byte version of VerifyWalletKey() for pubkey and signature format

Types

type AccPrivKey

type AccPrivKey [AccPrivateKeyLength]byte

AccPrivKey account(wallet) private key

func BytesToAccPriveKey

func BytesToAccPriveKey(b []byte) AccPrivKey

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

func (AccPrivKey) Bytes

func (p AccPrivKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (AccPrivKey) PubKeyFromPrivKey

func (p AccPrivKey) PubKeyFromPrivKey() AccPubKey

PubKeyFromPrivKey generate a AccPubKey from the AccPrivKey

func (*AccPrivKey) SetBytes

func (p *AccPrivKey) 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.

func (AccPrivKey) Sign

func (p AccPrivKey) Sign(b []byte) ([]byte, error)

Sign secp256k1 sign since account(wallet) uses secp256k1 key pair

type AccPubKey

type AccPubKey [AccPublicKeyLength]byte

AccPubKey account(wallet) public key

func BytesToAccPubKey

func BytesToAccPubKey(b []byte) AccPubKey

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

func WalletPubkeyFromBech

func WalletPubkeyFromBech(str string) (AccPubKey, error)

WalletPubkeyFromBech create an AccPubKey from Bech of wallet pubkey

func (AccPubKey) Address

func (p AccPubKey) Address() Address

Address generate a wallet address from account public key

func (AccPubKey) Bytes

func (p AccPubKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*AccPubKey) SetBytes

func (p *AccPubKey) 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.

func (AccPubKey) ToBech

func (p AccPubKey) ToBech() (string, error)

type Address

type Address [AddressLength]byte

Address

func BigToAddress

func BigToAddress(b *big.Int) Address

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

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 P2pAddressFromBech

func P2pAddressFromBech(str string) (Address, error)

func WalletAddressFromBech

func WalletAddressFromBech(str string) (Address, error)

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

Bytes gets the string representation of the underlying address.

func (Address) Compare

func (a Address) Compare(b Address) int

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) P2pAddressToBech

func (a Address) P2pAddressToBech() (string, error)

func (Address) P2pPublicKeyToBech

func (a Address) P2pPublicKeyToBech() (string, error)

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.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (Address) ToBech

func (a Address) ToBech(hrp string) (string, error)

func (Address) WalletAddressToBech

func (a Address) WalletAddressToBech() (string, error)

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 HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Float64

func (h Hash) Float64() float64

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

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.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type P2pPrivKey

type P2pPrivKey [P2pPrivateKeyLength]byte

P2pPrivKey P2P address private key

func BytesToP2pPrivKey

func BytesToP2pPrivKey(b []byte) P2pPrivKey

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

func (P2pPrivKey) Address

func (p P2pPrivKey) Address() Address

Address generate an Address from a P2pPrivKey

func (P2pPrivKey) Bytes

func (p P2pPrivKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (P2pPrivKey) PubKey

func (p P2pPrivKey) PubKey() P2pPubKey

PubKey generate a P2pPubKey from a P2pPrivKey

func (*P2pPrivKey) SetBytes

func (p *P2pPrivKey) 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.

func (P2pPrivKey) Sign

func (p P2pPrivKey) Sign(b []byte) []byte

Sign p2p address uses ed25519 algo

type P2pPubKey

type P2pPubKey [P2pPublicKeyLength]byte

P2pPubKey P2P address public key

func BytesToP2pPubKey

func BytesToP2pPubKey(b []byte) P2pPubKey

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

func P2pPubKeyFromBech

func P2pPubKeyFromBech(str string) (P2pPubKey, error)

P2pPubKeyFromBech create a P2pPubKey from a Bech-encoded P2P public key

func (P2pPubKey) Address

func (p P2pPubKey) Address() Address

Address generate a P2P address from P2P public key

func (P2pPubKey) Bytes

func (p P2pPubKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*P2pPubKey) SetBytes

func (p *P2pPubKey) 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.

func (P2pPubKey) ToBech

func (p P2pPubKey) ToBech() (string, error)

ToBech the Bech format string

Jump to

Keyboard shortcuts

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