ethwallet

package
v1.39.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: LGPL-3.0, MIT Imports: 19 Imported by: 11

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

This section is empty.

Functions

func DefaultBaseDerivationPath

func DefaultBaseDerivationPath() accounts.DerivationPath

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.

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(hexPrivateKey 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(hexPrivateKey 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) DeriveFromAccountIndex added in v1.38.6

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

func (*Wallet) DeriveFromPath added in v1.38.6

func (w *Wallet) DeriveFromPath(derivationPath string) (*Wallet, common.Address, error)

func (*Wallet) GetBalance added in v1.16.0

func (w *Wallet) GetBalance(ctx context.Context, optBlockNum ...*big.Int) (*big.Int, error)

func (*Wallet) GetNonce added in v1.17.0

func (w *Wallet) GetNonce(ctx context.Context) (uint64, error)

func (*Wallet) GetProvider

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

func (*Wallet) GetTransactionCount added in v1.38.6

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

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

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

func (*Wallet) PublicKeyHex

func (w *Wallet) PublicKeyHex() string

func (*Wallet) SendTransaction added in v1.3.6

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

func (*Wallet) SendTransactionWithLogger added in v1.39.1

func (w *Wallet) SendTransactionWithLogger(ctx context.Context, signedTxn *types.Transaction, log ethtxn.Logger) (*types.Transaction, ethtxn.WaitReceipt, error)

SendTransactionWithLogger sends a signed transaction and optionally logs request/response details.

func (*Wallet) SetProvider

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

func (*Wallet) SignData added in v1.20.24

func (w *Wallet) SignData(data []byte) ([]byte, error)

SignData signs a message with the wallet's private key.

This is the same as SignMessage, but it does not add the EIP-191 prefix. Please be careful with this method as it can be used to sign arbitrary data, but its helpful for signing typed data as defined by EIP-712.

func (*Wallet) SignMessage

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

SignMessage signs a message with EIP-191 prefix with the wallet's private key.

This is the same as SignData, but it adds the prefix "Ethereum Signed Message:\n" to the message and encodes the length of the message in the prefix. In case the message already has the prefix, it will not be added again.

func (*Wallet) SignTransaction added in v1.38.6

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

func (*Wallet) SignTx deprecated

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

Deprecated: use SignTransaction instead

func (*Wallet) SignTypedData added in v1.30.0

func (w *Wallet) SignTypedData(typedData *ethcoder.TypedData) ([]byte, []byte, error)

SignTypedData signs a typed data with EIP-712 prefix with the wallet's private key. It returns the signature and the digest of the typed data.

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 {
	RandomWalletEntropyBitSize int
	DerivationPath             string
}

func DefaultWalletOptions

func DefaultWalletOptions() WalletOptions

Jump to

Keyboard shortcuts

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