nectar.wallet module

class nectar.wallet.Wallet(blockchain_instance: Any | None = None, *args: Any, **kwargs: Any)

Bases: object

The wallet is meant to maintain access to private keys for your accounts. It either uses manually provided private keys or uses a SQLite database managed by storage.py.

Parameters:
  • rpc (Rpc) – RPC connection to a Hive node

  • keys (array, dict, str) – Predefine the wif keys to shortcut the wallet database

Three wallet operation modes are possible:

  • Wallet Database: Here, nectar loads the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call nectar.hive.Hive without the keys parameter

  • Providing Keys: Here, you can provide the keys for your accounts manually. All you need to do is add the wif keys for the accounts you want to use as a simple array using the keys parameter to nectar.hive.Hive.

  • Force keys: This more is for advanced users and requires that you know what you are doing. Here, the keys parameter is a dictionary that overwrite the active, owner, posting or memo keys for any account. This mode is only used for foreign signatures!

A new wallet can be created by using:

from nectar import Hive
hive = Hive()
hive.wallet.wipe(True)
hive.wallet.create("supersecret-passphrase")

This will raise nectar.exceptions.WalletExists if you already have a wallet installed.

The wallet can be unlocked for signing using

from nectar import Hive
hive = Hive()
hive.wallet.unlock("supersecret-passphrase")

A private key can be added by using the addPrivateKey() method that is available after unlocking the wallet with the correct passphrase:

from nectar import Hive
hive = Hive()
hive.wallet.unlock("supersecret-passphrase")
hive.wallet.addPrivateKey("5xxxxxxxxxxxxxxxxxxxx")

Note

The private key has to be either in hexadecimal or in wallet import format (wif) (starting with a 5).

addPrivateKey(wif: str) None

Add a private key to the wallet database

Parameters:

wif (str) – Private key

changePassphrase(new_pwd: str) None

Change the passphrase for the wallet database

create(pwd: str) None

Alias for newWallet()

Parameters:

pwd (str) – Passphrase for the created wallet

created() bool

Do we have a wallet database already?

getAccount(pub: str) Dict[str, Any] | None

Get the account data for a public key (first account found for this public key)

Parameters:

pub (str) – Public key

getAccountFromPrivateKey(wif: str) str | None

Obtain account name from private key

getAccountFromPublicKey(pub: str) str | None

Obtain the first account name from public key

Parameters:

pub (str) – Public key

Note: this returns only the first account with the given key. To get all accounts associated with a given public key, use getAccountsFromPublicKey().

getAccounts() List[Dict[str, Any]]

Return all accounts installed in the wallet database

getAccountsFromPublicKey(pub: str) Generator[str, None, None]

Obtain all account names associated with a public key

Parameters:

pub (str) – Public key

getActiveKeyForAccount(name: str) str | None

Obtain owner Active Key for an account from the wallet database

getActiveKeysForAccount(name: str) List[str] | None

Obtain list of all owner Active Keys for an account from the wallet database

getAllAccounts(pub: str) Generator[Dict[str, Any], None, None]

Get the account data for a public key (all accounts found for this public key)

Parameters:

pub (str) – Public key

getKeyForAccount(name: str, key_type: str) str | None

Obtain key_type Private Key for an account from the wallet database

Parameters:
  • name (str) – Account name

  • key_type (str) – key type, has to be one of “owner”, “active”, “posting” or “memo”

getKeyType(account: Account | Dict[str, Any], pub: str) str | None

Get key type

Parameters:
  • account (Account, dict) – Account data

  • pub (str) – Public key

getKeysForAccount(name: str, key_type: str) List[str] | None

Obtain a List of key_type Private Keys for an account from the wallet database

Parameters:
  • name (str) – Account name

  • key_type (str) – key type, has to be one of “owner”, “active”, “posting” or “memo”

getMemoKeyForAccount(name: str) str | None

Obtain owner Memo Key for an account from the wallet database

getOwnerKeyForAccount(name: str) str | None

Obtain owner Private Key for an account from the wallet database

getOwnerKeysForAccount(name: str) List[str] | None

Obtain list of all owner Private Keys for an account from the wallet database

getPostingKeyForAccount(name: str) str | None

Obtain owner Posting Key for an account from the wallet database

getPostingKeysForAccount(name: str) List[str] | None

Obtain list of all owner Posting Keys for an account from the wallet database

getPrivateKeyForPublicKey(pub: str) str | None

Obtain the private key for a given public key

Parameters:

pub (str) – Public Key

getPublicKeys(current: bool = False) List[str]

Return all installed public keys :param bool current: If true, returns only keys for currently

connected blockchain

is_encrypted() bool

Is the key store encrypted?

lock() bool

Lock the wallet database

locked() bool

Is the wallet database locked?

newWallet(pwd: str) None

Create a new wallet database

Parameters:

pwd (str) – Passphrase for the created wallet

property prefix: str
privatekey(key: str) PrivateKey
publickey_from_wif(wif: str) str
removeAccount(account: str) None

Remove all keys associated with a given account

Parameters:

account (str) – name of account to be removed

removePrivateKeyFromPublicKey(pub: str) None

Remove a key from the wallet database

Parameters:

pub (str) – Public key

property rpc: Any
setKeys(loadkeys: Dict[str, Any] | List[Any] | set | str) None

This method is strictly only for in memory keys that are passed to Wallet with the keys argument

unlock(pwd: str) bool | None

Unlock the wallet database

unlocked() bool

Is the wallet database unlocked?

wipe(sure: bool = False) None