wallet

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: GPL-3.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// KeymanagerConfigFileName for the keymanager used by the wallet: imported, derived, remote, or web3signer.
	KeymanagerConfigFileName = "keymanageropts.json"
	// NewWalletPasswordPromptText for wallet creation.
	NewWalletPasswordPromptText = "New wallet password"
	// PasswordPromptText for wallet unlocking.
	PasswordPromptText = "Wallet password"
	// ConfirmPasswordPromptText for confirming a wallet password.
	ConfirmPasswordPromptText = "Confirm password"
	// DefaultWalletPasswordFile used to store a wallet password with appropriate permissions
	// if a user signs up via the Prysm web UI via RPC.
	DefaultWalletPasswordFile = "walletpassword.txt"
	// 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. You can create a new wallet with `validator wallet create`. " +
			"If you already did, perhaps you created a wallet in a custom directory, which you can specify using " +
			"`--wallet-dir=/path/to/my/wallet`",
	)
	// KeymanagerKindSelections as friendly text.
	KeymanagerKindSelections = map[keymanager.Kind]string{
		keymanager.Local:      "Imported Wallet (Recommended)",
		keymanager.Derived:    "HD Wallet",
		keymanager.Web3Signer: "Consensys Web3Signer (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 InputPassword

func InputPassword(
	cliCtx *cli.Context,
	passwordFileFlag *cli.StringFlag,
	promptText string,
	confirmPassword bool,
	passwordValidator func(input string) error,
) (string, error)

InputPassword prompts for a password and optionally for password confirmation. The password is validated according to custom rules.

func IsValid

func IsValid(walletDir string) (bool, error)

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

Types

type Config

type Config struct {
	WalletDir      string
	KeymanagerKind keymanager.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 account management which has the capability of creating new accounts, reading existing accounts, and providing secure access to Ethereum proof of stake secrets depending on an associated keymanager (either imported, derived, or remote signing enabled).

func New

func New(cfg *Config) *Wallet

New creates a struct from config values.

func NewWalletForWeb3Signer

func NewWalletForWeb3Signer() *Wallet

NewWalletForWeb3Signer returns a new wallet for web3 signer which is temporary and not stored locally.

func OpenWallet

func OpenWallet(_ 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(_ context.Context, filePath, 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, cfg iface.InitKeymanagerConfig) (keymanager.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() keymanager.Kind

KeymanagerKind used by the wallet.

func (*Wallet) Password

func (w *Wallet) Password() string

Password for the wallet.

func (*Wallet) ReadFileAtPath

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

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

func (*Wallet) ReadKeymanagerConfigFromDisk

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

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

func (*Wallet) SaveWallet

func (w *Wallet) SaveWallet() error

SaveWallet persists the wallet's directories to disk.

func (*Wallet) WriteFileAtPath

func (w *Wallet) WriteFileAtPath(_ context.Context, filePath, 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(_ 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