types

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 2 Imported by: 101

README

go-eth2-wallet-types

Tag License GoDoc Travis CI codecov.io

Go library containing wallet-related types such as wallet, accout and store.

** Please note that this library uses standards that are not yet final, and as such may result in changes that alter public and private keys. Do not use this library for production use just yet **

Table of Contents

Install

go-eth2-wallet-types is a standard Go module which can be installed with:

go get github.com/wealdtech/go-eth2-wallet-types

Usage

go-eth2-wallet-types is used as part of go-eth2-wallet: please see documentation there for details.

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2019 Weald Technology Trading Ltd

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	// ID provides the ID for the account.
	ID() uuid.UUID

	// Name provides the name for the account.
	Name() string

	// PublicKey provides the public key for the account.
	PublicKey() e2types.PublicKey

	// Path provides the path for the account.
	// Can be empty if the account is not derived from a path.
	Path() string

	// Lock locks the account.  A locked account cannot sign.
	Lock()

	// Unlock unlocks the account.  An unlocked account can sign.
	Unlock([]byte) error

	// IsUnlocked returns true if the account is unlocked.
	IsUnlocked() bool

	// Sign signs data with the account.
	Sign(data []byte) (e2types.Signature, error)
}

Account is the interface for all Ethereum 2 accounts.

type AccountMetadata

type AccountMetadata interface {
	// WalletID provides the ID for the wallet.
	WalletID() uuid.UUID

	// ID provides the ID for the account.
	ID() uuid.UUID

	// Name provides the name for the account.
	Name() string
}

AccountMetadata provides metadata for an account. It is used for various accounting purposes, for example to ensure that no two accounts with the same name exist in a single wallet.

type AccountPrivateKeyProvider

type AccountPrivateKeyProvider interface {
	// PrivateKey provides the private key for the account.
	PrivateKey() (e2types.PrivateKey, error)
}

AccountPrivateKeyProvider is the interface for accounts that can provide a private key.

type Encryptor

type Encryptor interface {
	// Name() provides the name of the encryptor
	Name() string

	// Version() provides the version of the encryptor
	Version() uint

	// Encrypt encrypts a byte array with its encryption mechanism and key
	Encrypt(data []byte, key []byte) (map[string]interface{}, error)

	// Decrypt encrypts a byte array with its encryption mechanism and key
	Decrypt(data map[string]interface{}, key []byte) ([]byte, error)
}

Encryptor is the interface for encrypting and decrypting sensitive information in wallets.

type Store

type Store interface {
	// Name provides the name of the store
	Name() string

	// StoreWallet stores wallet data.  It will fail if it cannot store the data.
	StoreWallet(walletID uuid.UUID, walletName string, data []byte) error

	// RetrieveWallet retrieves wallet data for all wallets.
	RetrieveWallets() <-chan []byte

	// RetrieveWallet retrieves wallet data for a wallet with a given name.
	// It will fail if it cannot retrieve the data.
	RetrieveWallet(walletName string) ([]byte, error)

	// RetrieveWalletByID retrieves wallet data for a wallet with a given ID.
	// It will fail if it cannot retrieve the data.
	RetrieveWalletByID(walletID uuid.UUID) ([]byte, error)

	// StoreAccount stores account data.  It will fail if it cannot store the data.
	StoreAccount(walletID uuid.UUID, accountID uuid.UUID, data []byte) error

	// RetrieveAccounts retrieves account information for all accounts.
	RetrieveAccounts(walletID uuid.UUID) <-chan []byte

	// RetrieveAccount retrieves account data for a wallet with a given ID.
	// It will fail if it cannot retrieve the data.
	RetrieveAccount(walletID uuid.UUID, accountID uuid.UUID) ([]byte, error)

	// StoreAccountsIndex stores the index of accounts for a given wallet.
	StoreAccountsIndex(walletID uuid.UUID, data []byte) error

	// RetrieveAccountsIndex retrieves the index of accounts for a given wallet.
	RetrieveAccountsIndex(walletID uuid.UUID) ([]byte, error)
}

Store is the interface for wallet stores. It is used to store and access data provided by wallets, both wallets themselves as well as keys inside the wallets.

type StoreLocationProvider

type StoreLocationProvider interface {
	Location() string
}

StoreLocationProvider provides the location of the store.

type StoreProvider

type StoreProvider interface {
	// Store returns the store.
	Store() Store
}

StoreProvider is the interface provides a store.

type Wallet

type Wallet interface {
	// ID provides the ID for the wallet.
	ID() uuid.UUID

	// Name provides the name for the wallet.
	Name() string

	// Type provides the type of the wallet.
	Type() string

	// Version provides the version of the wallet.
	Version() uint

	// Lock locks the wallet.  A locked account cannot create new accounts.
	Lock()

	// Unlock unlocks the wallet.  An unlocked account can create new accounts.
	Unlock([]byte) error

	// IsUnlocked returns true if the wallet is unlocked.
	IsUnlocked() bool

	// CreateAccount creates a new account in the wallet.
	// The only rule for names is that they cannot start with an underscore (_) character.
	// This will error if an account with the name already exists.
	CreateAccount(name string, passphrase []byte) (Account, error)

	// Accounts provides all accounts in the wallet.
	Accounts() <-chan Account

	// AccountByID provides a single account from the wallet given its ID.
	// This will error if the account is not found.
	AccountByID(id uuid.UUID) (Account, error)

	// AccountByName provides a single account from the wallet given its name.
	// This will error if the account is not found.
	AccountByName(name string) (Account, error)
}

Wallet is the interface for wallets. A wallet contains one or more accounts. Each account has its own security mechanism.

type WalletAccountImporter

type WalletAccountImporter interface {
	// ImportAccount creates a new account in the wallet from an existing private key.
	// The only rule for names is that they cannot start with an underscore (_) character.
	// This will error if an account with the name already exists.
	ImportAccount(name string, key []byte, passphrase []byte) (Account, error)
}

WalletAccountImporter is the interface for wallets that can import accounts.

type WalletExporter

type WalletExporter interface {
	// Export exports the entire wallet, protected by an additional passphrase.
	Export(passphrase []byte) ([]byte, error)
}

WalletExporter is the interface for wallets that can export themselves.

type WalletKeyProvider

type WalletKeyProvider interface {
	// Key returns the wallet's key.
	Key() ([]byte, error)
}

WalletKeyProvider is the interface for wallets that can provide a key.

Jump to

Keyboard shortcuts

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