ethwallet

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: LGPL-3.0, MIT Imports: 18 Imported by: 10

README

ethwallet

inspired by the work of Miguel Mota at github.com/miguelmota/go-ethereum-hdwallet and Richard Moore at github.com/ethers-io/ethers.js

Documentation

Index

Constants

View Source
const (
	EntropyBitSize12WordMnemonic = 128
	EntropyBitSize24WordMnemonic = 256
)

Entropy bit size constants for 12 and 24 word mnemonics

Variables

View Source
var DefaultBaseDerivationPath = accounts.DefaultBaseDerivationPath

DefaultBaseDerivationPath is the base path from which custom derivation endpoints are incremented. As such, the first account will be at m/44'/60'/0'/0/0, the second at m/44'/60'/0'/0/1, etc.

View Source
var DefaultWalletOptions = WalletOptions{
	DerivationPath:             "m/44'/60'/0'/0/0",
	RandomWalletEntropyBitSize: EntropyBitSize12WordMnemonic,
}

Functions

func EntropyToMnemonic

func EntropyToMnemonic(entropy []byte) (string, error)

func IsValid191Signature added in v1.12.9

func IsValid191Signature(address common.Address, message, signature []byte) (bool, error)

func IsValidEOASignature added in v1.5.0

func IsValidEOASignature(address common.Address, digest, signature []byte) (bool, error)

func IsValidMnemonic

func IsValidMnemonic(mnemonic string) bool

func MnemonicToEntropy

func MnemonicToEntropy(mnemonic string) ([]byte, error)

func NewSeedFromMnemonic

func NewSeedFromMnemonic(mnemonic string) ([]byte, error)

NewSeedFromMnemonic returns a BIP-39 seed based on a BIP-39 mnemonic.

func ParseDerivationPath

func ParseDerivationPath(path string) (accounts.DerivationPath, error)

ParseDerivationPath parses the derivation path in string format into []uint32

func RandomEntropy

func RandomEntropy(bitSize ...int) ([]byte, error)

func RandomSeed

func RandomSeed() ([]byte, error)

RandomSeed returns a randomly generated BIP-39 seed.

func RecoverAddress added in v1.5.0

func RecoverAddress(message, signature []byte) (common.Address, error)

func RecoverAddressFromDigest added in v1.5.0

func RecoverAddressFromDigest(digest, signature []byte) (common.Address, error)

func ValidateEthereumSignature

func ValidateEthereumSignature(address string, message []byte, signatureHex string) (bool, error)

Validate the public key address of a signed message

Types

type HDNode

type HDNode struct {
	// contains filtered or unexported fields
}

func NewHDNodeFromEntropy

func NewHDNodeFromEntropy(entropy []byte, path *accounts.DerivationPath) (*HDNode, error)

func NewHDNodeFromMnemonic

func NewHDNodeFromMnemonic(mnemonic string, path *accounts.DerivationPath) (*HDNode, error)

func NewHDNodeFromPrivateKey added in v1.3.5

func NewHDNodeFromPrivateKey(privateKey string) (*HDNode, error)

func NewHDNodeFromRandomEntropy

func NewHDNodeFromRandomEntropy(bitSize int, path *accounts.DerivationPath) (*HDNode, error)

func (*HDNode) Address

func (h *HDNode) Address() common.Address

func (*HDNode) Clone

func (h *HDNode) Clone() (*HDNode, error)

func (*HDNode) DerivationPath

func (h *HDNode) DerivationPath() accounts.DerivationPath

func (*HDNode) DeriveAccountIndex

func (h *HDNode) DeriveAccountIndex(accountIndex uint32) error

func (*HDNode) DerivePath

func (h *HDNode) DerivePath(derivationPath accounts.DerivationPath) error

func (*HDNode) DerivePathFromString

func (h *HDNode) DerivePathFromString(path string) error

func (*HDNode) Entropy

func (h *HDNode) Entropy() []byte

func (*HDNode) Mnemonic

func (h *HDNode) Mnemonic() string

func (*HDNode) PrivateKey

func (h *HDNode) PrivateKey() *ecdsa.PrivateKey

func (*HDNode) PublicKey

func (h *HDNode) PublicKey() *ecdsa.PublicKey

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

func NewWalletFromHDNode

func NewWalletFromHDNode(hdnode *HDNode, optPath ...accounts.DerivationPath) (*Wallet, error)

func NewWalletFromMnemonic

func NewWalletFromMnemonic(mnemonic string, optPath ...string) (*Wallet, error)

func NewWalletFromPrivateKey added in v1.3.5

func NewWalletFromPrivateKey(key string) (*Wallet, error)

func NewWalletFromRandomEntropy

func NewWalletFromRandomEntropy(options ...WalletOptions) (*Wallet, error)

func (*Wallet) Address

func (w *Wallet) Address() common.Address

func (*Wallet) Clone

func (w *Wallet) Clone() (*Wallet, error)

func (*Wallet) DeriveAccountIndex

func (w *Wallet) DeriveAccountIndex(accountIndex uint32) (*Wallet, common.Address, error)

func (*Wallet) DerivePath

func (w *Wallet) DerivePath(path accounts.DerivationPath) (*Wallet, common.Address, error)

func (*Wallet) DerivePathFromString

func (w *Wallet) DerivePathFromString(path string) (*Wallet, common.Address, error)

func (*Wallet) GetProvider

func (w *Wallet) GetProvider() *ethrpc.Provider

func (*Wallet) HDNode

func (w *Wallet) HDNode() *HDNode

func (*Wallet) IsValidSignature added in v1.5.0

func (w *Wallet) IsValidSignature(msg, sig []byte) (bool, error)

func (*Wallet) IsValidSignatureOfDigest added in v1.5.0

func (w *Wallet) IsValidSignatureOfDigest(digest, sig []byte) (bool, error)

func (*Wallet) NewTransaction added in v1.3.6

func (w *Wallet) NewTransaction(ctx context.Context, txnRequest *ethtxn.TransactionRequest) (*types.Transaction, error)

func (*Wallet) PrivateKey

func (w *Wallet) PrivateKey() *ecdsa.PrivateKey

func (*Wallet) PrivateKeyHex

func (w *Wallet) PrivateKeyHex() string

func (*Wallet) Provider

func (w *Wallet) Provider() *WalletProvider

func (*Wallet) PublicKey

func (w *Wallet) PublicKey() *ecdsa.PublicKey

func (*Wallet) PublicKeyHex

func (w *Wallet) PublicKeyHex() string

func (*Wallet) SelfDeriveAccountIndex

func (w *Wallet) SelfDeriveAccountIndex(accountIndex uint32) (common.Address, error)

func (*Wallet) SelfDerivePath

func (w *Wallet) SelfDerivePath(path accounts.DerivationPath) (common.Address, error)

func (*Wallet) SelfDerivePathFromString

func (w *Wallet) SelfDerivePathFromString(path string) (common.Address, error)

func (*Wallet) SendTransaction added in v1.3.6

func (w *Wallet) SendTransaction(ctx context.Context, signedTx *types.Transaction) (*types.Transaction, ethtxn.WaitReceipt, error)

func (*Wallet) SetProvider

func (w *Wallet) SetProvider(provider *ethrpc.Provider)

func (*Wallet) SignMessage

func (w *Wallet) SignMessage(message []byte) ([]byte, error)

func (*Wallet) SignTx

func (w *Wallet) SignTx(tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)

func (*Wallet) Transactor

func (w *Wallet) Transactor(ctx context.Context) (*bind.TransactOpts, error)

func (*Wallet) TransactorForChainID added in v1.6.0

func (w *Wallet) TransactorForChainID(chainID *big.Int) (*bind.TransactOpts, error)

type WalletOptions

type WalletOptions struct {
	DerivationPath             string
	RandomWalletEntropyBitSize int
}

type WalletProvider

type WalletProvider struct {
	// contains filtered or unexported fields
}

WalletProvider is a helper to query the provider in context of the wallet address

func (*WalletProvider) Backend

func (w *WalletProvider) Backend() *ethrpc.Provider

func (*WalletProvider) GetEtherBalanceAt

func (w *WalletProvider) GetEtherBalanceAt(ctx context.Context, blockNumber *big.Int) (*big.Int, error)

func (*WalletProvider) GetTransactionCount

func (w *WalletProvider) GetTransactionCount(ctx context.Context) (uint64, error)

func (*WalletProvider) NewTransactor

func (w *WalletProvider) NewTransactor(ctx context.Context) (*bind.TransactOpts, error)

Jump to

Keyboard shortcuts

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