accounts

package
v0.4.0-alpha3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2018 License: Apache-2.0 Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const (
	HomeConfigDir       = ".sonm"
	DefaultKeystorePath = "keystore"
)

Variables

View Source
var (
	ErrWalletNoAccount = errors.New("Wallet does not have any account")
	ErrWalletNotOpen   = errors.New("Wallet is not open")
	ErrWalletIsEmpty   = errors.New("Keystore does not have any wallets")
)

Functions

func GetDefaultKeyStoreDir

func GetDefaultKeyStoreDir() (string, error)

func LoadKeys

func LoadKeys(keystore, passphrase string, options ...Option) (*ecdsa.PrivateKey, error)

todo: move this code onto (c *EthConfig) LoadKey(options ...Option)

Types

type EthConfig

type EthConfig struct {
	Passphrase string `required:"false" default:"" yaml:"pass_phrase"`
	Keystore   string `required:"false" default:"" yaml:"key_store"`
}

func (*EthConfig) LoadKey

func (c *EthConfig) LoadKey(options ...Option) (*ecdsa.PrivateKey, error)

type Identity

type Identity interface {
	// GetPrivateKey return *ecdsa.PrivateKey, it include PublicKey and ethereum Address shortly
	GetPrivateKey() (*ecdsa.PrivateKey, error)

	// New creates new account in keystore.
	// Do not open created account.
	New(passphrase string) error

	// Open opens loaded account
	Open(passphrase string) error

	// Import imports existing account from given json and pass-phrase
	Import(json []byte, passphrase string) error

	// ImportECDSA imports existing account from given private key and pass-phrase
	ImportECDSA(key *ecdsa.PrivateKey, passphrase string) error
}

Identity interface uses for auth and detect all objects in network source implementation going to go-ethereum accounting its need to be storing wallets in one dir and opened it by passphrase

func NewIdentity

func NewIdentity(keydir string) Identity

NewIdentity creates new identity instance which operates given key storage dir

type KeyOpener

type KeyOpener interface {
	// GetPassPhraser return PassPhraser interface
	// that provides pass phrase for loaded keys
	GetPassPhraser() PassPhraser
	// OpenKeystore opens key storage.
	// Bool param is true if keystore did not exist and was created.
	OpenKeystore() (bool, error)
	// GetKey returns private key from opened storage
	GetKey() (*ecdsa.PrivateKey, error)
}

KeyOpener is interface for loading Eth keys

func DefaultKeyOpener

func DefaultKeyOpener(p Printer, keyDir, passPhrase string) (KeyOpener, error)

DefaultKeyOpener return KeyOpener configured for using with pre-defined pass-phrase or retrieve pass-phrase interactively

func NewKeyOpener

func NewKeyOpener(keyDir string, pf PassPhraser) KeyOpener

NewKeyOpener returns KeyOpener that able to open keys

type KeyStorager

type KeyStorager interface {
	// KeyStore returns path to key store
	KeyStore() string
	// PassPhrase returns passphrase for keystore
	PassPhrase() string
}

KeyStorager interface describe an item that must know something about a path to the keystore and a passphrase

type KeystoreConfig added in v0.4.1

type KeystoreConfig struct {
	KeyDir      string            `yaml:"key_store" required:"true"`
	PassPhrases map[string]string `yaml:"pass_phrases"`
}

type MultiKeystore added in v0.4.1

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

func NewMultiKeystore added in v0.4.1

func NewMultiKeystore(cfg *KeystoreConfig, pf PassPhraser) (*MultiKeystore, error)

func (*MultiKeystore) Generate added in v0.4.1

func (m *MultiKeystore) Generate() (*ecdsa.PrivateKey, error)

Generate creates new key into keystore

func (*MultiKeystore) GenerateWithPassword added in v0.4.1

func (m *MultiKeystore) GenerateWithPassword(pass string) (*ecdsa.PrivateKey, error)

GenerateWithPassword generates new key with given pass-phrase

func (*MultiKeystore) GetDefault added in v0.4.1

func (m *MultiKeystore) GetDefault() (*ecdsa.PrivateKey, error)

GetDefault returns default key for the keystore

func (*MultiKeystore) GetDefaultAddress added in v0.4.1

func (m *MultiKeystore) GetDefaultAddress() (common.Address, error)

func (*MultiKeystore) GetKeyByAddress added in v0.4.1

func (m *MultiKeystore) GetKeyByAddress(addr common.Address) (*ecdsa.PrivateKey, error)

GetKeyByAddress loads and decrypts key form keystore (if present)

func (*MultiKeystore) GetKeyWithPass added in v0.4.1

func (m *MultiKeystore) GetKeyWithPass(addr common.Address, pass string) (*ecdsa.PrivateKey, error)

func (*MultiKeystore) List added in v0.4.1

func (m *MultiKeystore) List() []accounts.Account

List returns list of accounts addresses into keystore

func (*MultiKeystore) SetDefault added in v0.4.1

func (m *MultiKeystore) SetDefault(addr common.Address) error

SetDefault marks key as default for keystore

type Option

type Option func(o *options)

func Silent

func Silent() Option

type PassPhraser

type PassPhraser interface {
	GetPassPhrase() (string, error)
}

PassPhraser is interface for retrieving pass phrase for Eth keys

If you want to retrieve pass phrases reader different ways (e.g: from file, from env variables, interactively from terminal) you must implement PassPhraser reader a different way and pass it to KeyOpener instance

func NewInteractivePassPhraser

func NewInteractivePassPhraser() PassPhraser

NewInteractivePassPhraser implements PassPhraser that prompts user for pass-phrase and read it from terminal's Stdin

func NewStaticPassPhraser

func NewStaticPassPhraser(p string) PassPhraser

type Printer

type Printer interface {
	Printf(format string, i ...interface{})
}

Printer interface describe anything that can print something somehow on a something.

func NewFmtPrinter

func NewFmtPrinter() Printer

func NewSilentPrinter

func NewSilentPrinter() Printer

NewSilentPrinter returns new printer which can prints nothing

Jump to

Keyboard shortcuts

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