Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPassphrase = errors.New("invalid passphrase")
ErrInvalidPassphrase is returned when a decryption operation receives a bad passphrase.
var ErrNotSupported = errors.New("not supported")
ErrNotSupported is returned when an operation is requested from an account backend that it does not support.
var ErrUnknownAccount = errors.New("unknown account")
ErrUnknownAccount is returned for any requested operation for which no backend provides the specified account.
var ErrUnknownWallet = errors.New("unknown wallet")
ErrUnknownWallet is returned for any requested operation for which no backend provides the specified wallet.
var ErrWalletAlreadyOpen = errors.New("wallet already open")
ErrWalletAlreadyOpen is returned if a wallet is attempted to be opened the second time.
var ErrWalletClosed = errors.New("wallet closed")
ErrWalletClosed is returned if a wallet is attempted to be opened the secodn time.
Functions ¶
func NewAuthNeededError ¶
NewAuthNeededError creates a new authentication error with the extra details about the needed fields set.
Types ¶
type Account ¶
type Account struct { Address common.Address `json:"address"` // Ethereum account address derived from the key URL URL `json:"url"` // Optional resource locator within a backend }
Account represents an justitia account located at a specific location defined by the optional URL field.
type AuthNeededError ¶
type AuthNeededError struct {
Needed string // Extra authentication the user needs to provide
}
AuthNeededError is returned by backends for signing requests where the user is required to provide further authentication before signing can succeed.
This usually means either that a password needs to be supplied, or perhaps a one time PIN code displayed by some hardware device.
func (*AuthNeededError) Error ¶
func (err *AuthNeededError) Error() string
Error implements the standard error interface.
type Backend ¶
type Backend interface { // Wallets retrieves the list of wallets the backend is currently aware of. // // The returned wallets are not opened by default. For software HD wallets this // means that no base seeds are decrypted, and for hardware wallets that no actual // connection is established. // // The resulting wallet list will be sorted alphabetically based on its internal // URL assigned by the backend. Since wallets (especially hardware) may come and // go, the same wallet might appear at a different positions in the list during // subsequent retrievals. Wallets() []Wallet }
Backend is a "wallet provider" that may contain a batch of accounts they can sign transactions with and upon request, do so.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is an overarching account manager that can communicate with various backends for signing transactions.
func NewManager ¶
NewManager creates a generic account manager to sign transaction via various supported backends.
func (*Manager) Backends ¶
Backends retrieves the backend(s) with the given type from the account manager.
func (*Manager) Find ¶
Find attempts to locate the wallet corresponding to a specific account. Since accounts can be dynamically added to and removed from wallets, this method has a linear runtime in the number of wallets.
type URL ¶
type URL struct { Scheme string // Protocol scheme to identify a capable account backend Path string // Path for the backend to identify a unique entity }
func (URL) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface.
func (URL) TerminalString ¶
TerminalString implements the log.TerminalStringer interface.
func (*URL) UnmarshalJSON ¶
UnmarshalJSON parses url.
type Wallet ¶
type Wallet interface { // URL retrieves the canonical path under which this wallet is reachable. It is // user by upper layers to define a sorting order over all wallets from multiple // backends. URL() URL // Status returns a textual status to aid the user in the current state of the // wallet. It also returns an error indicating any failure the wallet might have // encountered. Status() (string, error) // Open initializes access to a wallet instance. It is not meant to unlock or // decrypt account keys, rather simply to establish a connection to hardware // wallets and/or to access derivation seeds. // // The passphrase parameter may or may not be used by the implementation of a // particular wallet instance. The reason there is no passwordless open method // is to strive towards a uniform wallet handling, oblivious to the different // backend providers. // // Please note, if you open a wallet, you must close it to release any allocated // resources (especially important when working with hardware wallets). Open(passphrase string) error // Close releases any resources held by an open wallet instance. Close() error // Accounts retrieves the list of signing accounts the wallet is currently aware // of. For hierarchical deterministic wallets, the list will not be exhaustive, // rather only contain the accounts explicitly pinned during account derivation. Accounts() []Account // Contains returns whether an account is part of this particular wallet or not. Contains(account Account) bool // SignHash requests the wallet to sign the given hash. // // It looks up the account specified either solely via its address contained within, // or optionally with the aid of any location metadata from the embedded URL field. // // If the wallet requires additional authentication to sign the request (e.g. // a password to decrypt the account, or a PIN code o verify the transaction), // an AuthNeededError instance will be returned, containing infos for the user // about which fields or actions are needed. The user may retry by providing // the needed details via SignHashWithPassphrase, or by other means (e.g. unlock // the account in a keystore). SignHash(account Account, hash []byte) ([]byte, error) // SignTx requests the wallet to sign the given transaction. // // It looks up the account specified either solely via its address contained within, // or optionally with the aid of any location metadata from the embedded URL field. // // If the wallet requires additional authentication to sign the request (e.g. // a password to decrypt the account, or a PIN code to verify the transaction), // an AuthNeededError instance will be returned, containing infos for the user // about which fields or actions are needed. The user may retry by providing // the needed details via SignTxWithPassphrase, or by other means (e.g. unlock // the account in a keystore). SignTx(account Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) // SignHashWithPassphrase requests the wallet to sign the given hash with the // given passphrase as extra authentication information. // // It looks up the account specified either solely via its address contained within, // or optionally with the aid of any location metadata from the embedded URL field. SignHashWithPassphrase(account Account, passphrase string, hash []byte) ([]byte, error) // SignTxWithPassphrase requests the wallet to sign the given transaction, with the // given passphrase as extra authentication information. // // It looks up the account specified either solely via its address contained within, // or optionally with the aid of any location metadata from the embedded URL field. SignTxWithPassphrase(account Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) }
type WalletEvent ¶
type WalletEvent struct { Wallet Wallet // Wallet instance arrived or departed Kind WalletEventType // Event type that happened in the system }
WalletEvent is an event fired by an account backend when a wallet arrival or departure is detected.
type WalletEventType ¶
type WalletEventType int
WalletEventType represents the different event types that can be fired by the wallet subscription subsystem.
const ( // WalletArrived is fired when a new wallet is detected either via USB or via // a filesystem event in the keystore. WalletArrived WalletEventType = iota // WalletOpened is fired when a wallet is successfully opened with the purpose // of starting any background processes such as automatic key derivation. WalletOpened // WalletDropped WalletDropped )