usbwallet

package
v0.0.0-...-2597ab7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package usbwallet abstracts functionality provided by go-ethereum's usbwallet package, providing fully managed access to hardware wallets.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAmbiguousDerivation is returned when account derivation is attempted
	// while multiple devices are connected but no non-zero expected address is
	// provided.
	ErrAmbiguousDerivation = errors.New("ambiguous account derivation")
	// ErrNoWalletsOpen is returned when account derivation is attempted but no
	// devices are open.
	ErrNoWalletsOpen = errors.New("no wallets open")
)

Functions

This section is empty.

Types

type Type

type Type int

Type defines a type of USB wallet.

const (
	UnknownWalletType Type = iota
	Ledger
)

Available wallet Types.

type Wallet

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

A Wallet manages hardware wallets connected over USB. As it manages device events concurrently, any errors are reported on a channel accessible via the Err() method.

func New

func New(hub *usbwallet.Hub, t Type, basePath accounts.DerivationPath) *Wallet

New creates a new Wallet backed by the Hub, connected to the specific Type of hardware.

func NewLedger

func NewLedger() (*Wallet, error)

NewLedger is equivalent to calling New() with parameters specific to Ledger devices.

func (*Wallet) Close

func (w *Wallet) Close() error

Close stops all device management and frees resources, also closing the Err() channel and unblocking all Wait() calls with sync.ErrToggleClosed.

func (*Wallet) Err

func (w *Wallet) Err() <-chan error

Err returns the channel on which all errors are reported. Errors are not fatal to the Wallet.

func (*Wallet) SignerFn

func (w *Wallet) SignerFn(index uint32, expectedAddr *common.Address, chainID *big.Int) (bind.SignerFn, common.Address, error)

SignerFn returns a SignerFn for use in a bind.TransactOpts. Unlike Metamask, the account index is 0-based. As the Wallet can manage more that one hardware device, the expected address removes ambiguity but MAY be nil (or a pointer to the zero address) i.f.f. there is only a single USB device connected.

Although a SignerFn accepts a types.Transaction, which itself contains a chain ID, the returned function is bound to a pre-specified chain for added security.

func (*Wallet) Wait

func (w *Wallet) Wait(ctx context.Context) error

Wait blocks until at least one hardware device is connected and ready to sign signable things. In the case of a Ledger device, this means that not only is the device unlocked, but its Ethereum app is open.

Jump to

Keyboard shortcuts

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