wallet

package
v1.0.0-alpha.29 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeymanagerConfigFileName for the keymanager used by the wallet: direct, derived, or remote.
	KeymanagerConfigFileName = "keymanageropts.json"
	// HashedPasswordFileName for the wallet.
	HashedPasswordFileName = "hash"
	// DirectoryPermissions for directories created under the wallet path.
	DirectoryPermissions = os.ModePerm
	// NewWalletPasswordPromptText for wallet creation.
	NewWalletPasswordPromptText = "New wallet password"
	// WalletPasswordPromptText for wallet unlocking.
	WalletPasswordPromptText = "Wallet password"
	// ConfirmPasswordPromptText for confirming a wallet password.
	ConfirmPasswordPromptText = "Confirm password"

	// CheckExistsErrMsg for when there is an error while checking for a wallet
	CheckExistsErrMsg = "could not check if wallet exists"
	// CheckValidityErrMsg for when there is an error while checking wallet validity
	CheckValidityErrMsg = "could not check if wallet is valid"
	// InvalidWalletErrMsg for when a directory does not contain a valid wallet
	InvalidWalletErrMsg = "directory does not contain valid wallet"
)

Variables

View Source
var (
	// ErrNoWalletFound signifies there was no wallet directory found on-disk.
	ErrNoWalletFound = errors.New(
		"no wallet found at path, please create a new wallet using `./prysm.sh validator wallet-v2 create`",
	)
	// ErrWalletExists is an error returned when a wallet already exists in the path provided.
	ErrWalletExists = errors.New("you already have a wallet at the specified path. You can " +
		"edit your wallet configuration by running ./prysm.sh validator wallet-v2 edit-config",
	)
	// KeymanagerKindSelections as friendly text.
	KeymanagerKindSelections = map[v2keymanager.Kind]string{
		v2keymanager.Derived: "HD Wallet (Recommended)",
		v2keymanager.Direct:  "Non-HD Wallet (Most Basic)",
		v2keymanager.Remote:  "Remote Signing Wallet (Advanced)",
	}
	// ValidateExistingPass checks that an input cannot be empty.
	ValidateExistingPass = func(input string) error {
		if input == "" {
			return errors.New("password input cannot be empty")
		}
		return nil
	}
)

Functions

func Exists

func Exists(walletDir string) (bool, error)

Exists checks if directory at walletDir exists

func IsValid

func IsValid(walletDir string) (bool, error)

IsValid checks if a folder contains a single key directory such as `derived`, `remote` or `direct`. Returns true if one of those subdirectories exist, false otherwise.

Types

type Config

type Config struct {
	WalletDir      string
	KeymanagerKind v2keymanager.Kind
	WalletPassword string
}

Config to open a wallet programmatically.

type Wallet

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

Wallet is a primitive in Prysm's v2 account management which has the capability of creating new accounts, reading existing accounts, and providing secure access to eth2 secrets depending on an associated keymanager (either direct, derived, or remote signing enabled).

func New

func New(cfg *Config) *Wallet

New creates a struct from config values.

func OpenWallet

func OpenWallet(ctx context.Context, cfg *Config) (*Wallet, error)

OpenWallet instantiates a wallet from a specified path. It checks the type of keymanager associated with the wallet by reading files in the wallet path, if applicable. If a wallet does not exist, returns an appropriate error.

func OpenWalletOrElseCli

func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context) (*Wallet, error)) (*Wallet, error)

OpenWalletOrElseCli tries to open the wallet and if it fails or no wallet is found, invokes a callback function.

func (*Wallet) AccountsDir

func (w *Wallet) AccountsDir() string

AccountsDir for the wallet.

func (*Wallet) FileNameAtPath

func (w *Wallet) FileNameAtPath(ctx context.Context, filePath string, fileName string) (string, error)

FileNameAtPath return the full file name for the requested file. It allows for finding the file with a regex pattern.

func (*Wallet) InitializeKeymanager

func (w *Wallet) InitializeKeymanager(
	ctx context.Context,
	skipMnemonicConfirm bool,
) (v2keymanager.IKeymanager, error)

InitializeKeymanager reads a keymanager config from disk at the wallet path, unmarshals it based on the wallet's keymanager kind, and returns its value.

func (*Wallet) KeymanagerKind

func (w *Wallet) KeymanagerKind() v2keymanager.Kind

KeymanagerKind used by the wallet.

func (*Wallet) LockWalletConfigFile

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

LockWalletConfigFile lock read and write to wallet file in order to prevent two validators from using the same keys.

func (*Wallet) Password

func (w *Wallet) Password() string

Password for the wallet.

func (*Wallet) ReadEncryptedSeedFromDisk

func (w *Wallet) ReadEncryptedSeedFromDisk(ctx context.Context) (io.ReadCloser, error)

ReadEncryptedSeedFromDisk reads the encrypted wallet seed configuration from within the wallet path.

func (*Wallet) ReadFileAtPath

func (w *Wallet) ReadFileAtPath(ctx context.Context, filePath string, fileName string) ([]byte, error)

ReadFileAtPath within the wallet directory given the desired path and filename.

func (*Wallet) ReadKeymanagerConfigFromDisk

func (w *Wallet) ReadKeymanagerConfigFromDisk(ctx context.Context) (io.ReadCloser, error)

ReadKeymanagerConfigFromDisk opens a keymanager config file for reading if it exists at the wallet path.

func (*Wallet) SaveHashedPassword

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

SaveHashedPassword to disk for the wallet.

func (*Wallet) SaveWallet

func (w *Wallet) SaveWallet() error

SaveWallet persists the wallet's directories to disk.

func (*Wallet) SetPassword

func (w *Wallet) SetPassword(newPass string)

SetPassword sets a new password for the wallet.

func (*Wallet) UnlockWalletConfigFile

func (w *Wallet) UnlockWalletConfigFile() error

UnlockWalletConfigFile unlock wallet file. should be called before client is closing in order to remove the file lock.

func (*Wallet) WriteEncryptedSeedToDisk

func (w *Wallet) WriteEncryptedSeedToDisk(ctx context.Context, encoded []byte) error

WriteEncryptedSeedToDisk writes the encrypted wallet seed configuration within the wallet path.

func (*Wallet) WriteFileAtPath

func (w *Wallet) WriteFileAtPath(ctx context.Context, filePath string, fileName string, data []byte) error

WriteFileAtPath within the wallet directory given the desired path, filename, and raw data.

func (*Wallet) WriteKeymanagerConfigToDisk

func (w *Wallet) WriteKeymanagerConfigToDisk(ctx context.Context, encoded []byte) error

WriteKeymanagerConfigToDisk takes an encoded keymanager config file and writes it to the wallet path.

Jump to

Keyboard shortcuts

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