wallet

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntropyBits              = 256
	FileMode                 = 0600
	DefaultNodeKeyPath       = "m/44'/60'/0'/0/%d"
	LedgerLiveNodeKeyPath    = "m/44'/60'/%d/0/0"
	MyEtherWalletNodeKeyPath = "m/44'/60'/0'/%d"
)

Config

Variables

This section is empty.

Functions

func GenerateNewMnemonic added in v0.2.3

func GenerateNewMnemonic() (string, error)

Generate a new random mnemonic and seed

Types

type AddressManager

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

Simple class to wrap the node's address file

func NewAddressManager

func NewAddressManager(path string) *AddressManager

Creates a new address manager

func (*AddressManager) GetAddress

func (m *AddressManager) GetAddress() (common.Address, bool)

Get the cached address

func (*AddressManager) LoadAddress

func (m *AddressManager) LoadAddress() (common.Address, bool, error)

Gets the address saved on disk. Returns false if the address file doesn't exist.

func (*AddressManager) SetAddress added in v0.2.3

func (m *AddressManager) SetAddress(newAddress common.Address)

Sets the node address without saving it to disk

func (*AddressManager) SetAndSaveAddress

func (m *AddressManager) SetAndSaveAddress(newAddress common.Address) error

Sets the node address and saves it to disk

type IWalletManager

type IWalletManager interface {
	// The type of wallet
	GetType() types.WalletType

	// The wallet address
	GetAddress() (common.Address, error)

	// A transactor that can sign transactions
	GetTransactor() (*bind.TransactOpts, error)

	// Sign a message with the wallet's private key
	SignMessage(message []byte) ([]byte, error)

	// Sign a transaction with the wallet's private key
	SignTransaction(serializedTx []byte) ([]byte, error)

	// Serialize the wallet data as JSON
	SerializeData() (string, error)
}

Interface for wallet managers

type LocalWalletManager

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

Simple class to wrap a node's local wallet keystore. Note that this does *not* manage the wallet data file on disk, though it does manage the legacy keystore used by some integrations.

func NewLocalWalletManager

func NewLocalWalletManager(chainID uint) *LocalWalletManager

Creates a new wallet manager for local wallets

func (*LocalWalletManager) GenerateValidatorKey

func (m *LocalWalletManager) GenerateValidatorKey(path string) ([]byte, error)

Generate the validator key with the provided path, using the wallet's seed as the root

func (*LocalWalletManager) GetAddress

func (m *LocalWalletManager) GetAddress() (common.Address, error)

Get the pubkey of the loaded node wallet, or false if one isn't loaded yet

func (*LocalWalletManager) GetEthKeystore

func (m *LocalWalletManager) GetEthKeystore(password string) ([]byte, error)

Get the legacy keystore in Geth format

func (*LocalWalletManager) GetPrivateKey

func (m *LocalWalletManager) GetPrivateKey() *ecdsa.PrivateKey

Get the private key if it's been loaded

func (*LocalWalletManager) GetTransactor

func (m *LocalWalletManager) GetTransactor() (*bind.TransactOpts, error)

Get the transactor for the wallet

func (*LocalWalletManager) GetType

Get the type of this wallet manager

func (*LocalWalletManager) InitializeKeystore

func (m *LocalWalletManager) InitializeKeystore(derivationPath string, walletIndex uint, mnemonic string, password string) (*sharedtypes.LocalWalletData, error)

Initialize a new keystore from a mnemonic and derivation info, derive the corresponding key, and load it all up

func (*LocalWalletManager) LoadWallet

func (m *LocalWalletManager) LoadWallet(data *sharedtypes.LocalWalletData, password string) error

Load the node wallet's private key from the keystore

func (*LocalWalletManager) SerializeData

func (m *LocalWalletManager) SerializeData() (string, error)

Serialize the wallet data as JSON

func (*LocalWalletManager) SignMessage

func (m *LocalWalletManager) SignMessage(message []byte) ([]byte, error)

Signs a message with the node wallet's private key

func (*LocalWalletManager) SignTransaction

func (m *LocalWalletManager) SignTransaction(serializedTx []byte) ([]byte, error)

Signs a transaction with the node wallet's private key

func (*LocalWalletManager) VerifyPassword

func (m *LocalWalletManager) VerifyPassword(password string) (bool, error)

Verifies that the provided password is correct for this wallet's keystore

type PasswordManager

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

Simple class to wrap the node's password file

func NewPasswordManager

func NewPasswordManager(path string) *PasswordManager

Creates a new password manager

func (*PasswordManager) DeletePassword

func (m *PasswordManager) DeletePassword() error

Delete the password from disk

func (*PasswordManager) GetPasswordFromDisk

func (m *PasswordManager) GetPasswordFromDisk() (string, bool, error)

Gets the password saved on disk. Returns nil if the password file doesn't exist.

func (*PasswordManager) SavePassword

func (m *PasswordManager) SavePassword(password string) error

Save the password to disk

type Wallet

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

Wallet

func NewWallet

func NewWallet(log *log.ColorLogger, walletDataPath string, walletAddressPath string, passwordFilePath string, chainID uint) (*Wallet, error)

Create new wallet

func TestRecovery

func TestRecovery(derivationPath string, walletIndex uint, mnemonic string, chainID uint) (*Wallet, error)

Recover a wallet keystore from a mnemonic - only used for testing mnemonics

func (*Wallet) CreateNewLocalWallet

func (w *Wallet) CreateNewLocalWallet(derivationPath string, walletIndex uint, password string, savePassword bool) (string, error)

Initialize the wallet from a random seed

func (*Wallet) DeletePassword

func (w *Wallet) DeletePassword() error

Delete the wallet password from disk, but retain it in memory if a local keystore is already loaded

func (*Wallet) GenerateValidatorKey

func (w *Wallet) GenerateValidatorKey(path string) ([]byte, error)

Generate a BLS validator key from the provided path, using the node wallet's seed as a basis

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() (common.Address, bool)

Get the node address, if one is loaded

func (*Wallet) GetEthKeystore

func (w *Wallet) GetEthKeystore(password string) ([]byte, error)

Get the node account private key bytes

func (*Wallet) GetNodePrivateKeyBytes

func (w *Wallet) GetNodePrivateKeyBytes() ([]byte, error)

Get the node account private key bytes

func (*Wallet) GetPassword

func (w *Wallet) GetPassword() (string, bool, error)

Retrieves the wallet's password

func (*Wallet) GetStatus

func (w *Wallet) GetStatus() (sharedtypes.WalletStatus, error)

Gets the status of the wallet and its artifacts

func (*Wallet) GetTransactor

func (w *Wallet) GetTransactor() (*bind.TransactOpts, error)

Get the transactor that can sign transactions

func (*Wallet) MasqueradeAsAddress

func (w *Wallet) MasqueradeAsAddress(newAddress common.Address) error

Masquerade as another node address, running all node functions as that address (in read only moe)

func (*Wallet) Recover

func (w *Wallet) Recover(derivationPath string, walletIndex uint, mnemonic string, password string, savePassword bool, testMode bool) error

Recover a local wallet from a mnemonic

func (*Wallet) RestoreAddressToWallet

func (w *Wallet) RestoreAddressToWallet() error

End masquerading as another node address, and use the wallet's address (returning to read/write mode)

func (*Wallet) SerializeData

func (w *Wallet) SerializeData() (string, error)

Serialize the wallet data as JSON

func (*Wallet) SetPassword

func (w *Wallet) SetPassword(password string, save bool) error

Attempts to load the wallet keystore with the provided password if not set

func (*Wallet) SignMessage

func (w *Wallet) SignMessage(message []byte) ([]byte, error)

Sign a message with the wallet's private key

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(serializedTx []byte) ([]byte, error)

Sign a transaction with the wallet's private key

Jump to

Keyboard shortcuts

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