Mnemonic Store#

class rizemind.mnemonic.store.MnemonicStore(keystore_dir=PosixPath('/home/runner/.rzmnd/keystore'))[source]#

Bases: object

Manages the secure storage of BIP39 mnemonic phrases.

exists(account_name: str) bool[source]#

Checks if a keystore for an account name exists.

Parameters:

account_name – The name of the account.

Returns:

True if the keystore file exists, False otherwise.

generate(words=24) str[source]#

Generates a new BIP39 mnemonic phrase.

Parameters:

words – The number of words in the mnemonic (e.g., 12, 15, 18, 21, 24).

Returns:

A new mnemonic phrase.

get_keystore_dir() Path[source]#

Returns the keystore directory path.

get_keystore_file(account_name: str) Path[source]#

Returns the path to an account’s keystore file.

Parameters:

account_name – The name of the account.

Returns:

The keystore file path for the given account.

list_accounts() list[str][source]#

Lists all available account names from the keystore directory.

Returns:

A sorted list of account names.

load(account_name: str, passphrase: str) str[source]#

Loads and decrypts a mnemonic from a keystore file.

Parameters:
  • account_name – The name of the account to load.

  • passphrase – The passphrase to decrypt the mnemonic.

Returns:

The decrypted mnemonic phrase.

Raises:
  • FileNotFoundError – If the keystore for the account does not exist.

  • ValueError – If decryption fails due to an incorrect passphrase or corrupted data.

save(account_name: str, passphrase: str, mnemonic: str) Path[source]#

Encrypts and saves a mnemonic to a keystore file.

Parameters:
  • account_name – The name of the account to save.

  • passphrase – The passphrase to encrypt the mnemonic.

  • mnemonic – The mnemonic phrase to save.

Returns:

The path to the newly created keystore file.