bittensor_wallet.keyfile

Contents

bittensor_wallet.keyfile#

ask_password(validation_required)

Prompts the user to enter a password for key encryption.

decrypt_keyfile_data(keyfile_data[, ...])

Decrypts the passed keyfile data using ansible vault.

deserialize_keypair_from_keyfile_data(...)

Deserializes Keypair object from passed keyfile data.

encrypt_keyfile_data(keyfile_data[, password])

Encrypts the passed keyfile data using ansible vault.

get_coldkey_password_from_environment(...)

get_password_from_environment(env_var_name)

Retrieves the cold key password from the environment variables.

keyfile_data_encryption_method(keyfile_data)

Returns type of encryption method as a string.

keyfile_data_is_encrypted(keyfile_data)

Returns true if the keyfile data is encrypted.

keyfile_data_is_encrypted_ansible(keyfile_data)

Returns true if the keyfile data is ansible encrypted.

keyfile_data_is_encrypted_legacy(keyfile_data)

Returns true if the keyfile data is legacy encrypted.

keyfile_data_is_encrypted_nacl(keyfile_data)

Returns true if the keyfile data is NaCl encrypted.

legacy_encrypt_keyfile_data(keyfile_data[, ...])

legacy_encrypt_keyfile_data.

serialized_keypair_to_keyfile_data(keypair)

Serializes keypair object into keyfile data.

validate_password(password)

Validates the password against a password policy.

Keyfile([path, name, should_save_to_env])

Module Contents#

Functions Details

class bittensor_wallet.keyfile.Keyfile(path=None, name=None, should_save_to_env=False)

Bases: object

check_and_update_encryption(print_result=True, no_prompt=False)

Check the version of keyfile and update if needed.

Parameters:
  • print_result (bool) – If True, prints the result of the encryption check.

  • no_prompt (bool) – If True, skips user prompts during the update process.

Returns:

True if the keyfile was successfully updated to the latest encryption method.

data

Returns the keyfile data under path.

decrypt(password=None)

Decrypts the file under the path.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

encrypt(password=None)

Encrypts the file under the path.

Parameters:

password (Option<String>) – The password used to encrypt the data. If None, asks for user input.

env_var_name()

Returns local environment variable key name based on Keyfile path.

exists_on_device()

Returns True if the file exists on the device.

Returns:

True if the file is readable.

get_keypair(password=None)

Returns the keypair from path, decrypts data if the file is encrypted.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

Returns:

The Keypair loaded from the file.

is_encrypted()

Returns True if the file under path is encrypted.

Returns:

True if the file is encrypted.

is_readable()

Returns True if the file under path is readable.

is_writable()

Returns True if the file under path is writable.

Returns:

True if the file is writable.

keypair

Returns the keypair from path, decrypts data if the file is encrypted.

make_dirs()

Creates directories for the path if they do not exist.

path

Returns the wallet path.

remove_password_from_env()

Removes the password associated with the Keyfile from the local environment.

save_password_to_env(password=None)

Saves the key’s password to the associated local environment variable.

Parameters:

password (Option<String>) – The password to save. If None, asks for user input.

Returns:

The base64-encoded encrypted password.

set_keypair(keypair, encrypt=True, overwrite=False, password=None)

Writes the keypair to the file and optionally encrypts data.

Parameters:
  • keypair (Keypair) – The keypair object to be stored.

  • encrypt (bool) – If True, encrypts the keyfile data.

  • overwrite (bool) – If True, overwrites existing file without prompting.

  • password (Option<String>) – The password used to encrypt the data. If None, asks for user input.

bittensor_wallet.keyfile.ask_password(validation_required)

Prompts the user to enter a password for key encryption.

Parameters:

validation_required (bool) – If True, validates the password against policy requirements.

Returns:

The valid password entered by the user.

bittensor_wallet.keyfile.decrypt_keyfile_data(keyfile_data, password=None, password_env_var=None)

Decrypts the passed keyfile data using ansible vault.

Parameters:
  • keyfile_data – The bytes to decrypt.

  • password (str) – The password used to decrypt the data. If None, asks for user input.

  • coldkey_name (str) – The name of the cold key. If provided, retrieves the password from environment variables.

Returns:

The decrypted data.

bittensor_wallet.keyfile.deserialize_keypair_from_keyfile_data(keyfile_data)

Deserializes Keypair object from passed keyfile data.

Parameters:

keyfile_data (PyBytes) – The keyfile data to be loaded.

Returns:

The Keypair loaded from bytes.

Raises:

KeyFileError – The passed pybytes cannot construct a keypair object.

bittensor_wallet.keyfile.encrypt_keyfile_data(keyfile_data, password=None)

Encrypts the passed keyfile data using ansible vault.

Parameters:
  • keyfile_data (bytes) – The bytes to encrypt.

  • password (str) – The password used to encrypt the data. If None, asks for user input.

Returns:

The encrypted data.

bittensor_wallet.keyfile.get_coldkey_password_from_environment(env_var_name)
bittensor_wallet.keyfile.get_password_from_environment(env_var_name)

Retrieves the cold key password from the environment variables.

Parameters:

coldkey_name – The name of the cold key.

Returns:

Option<String> - The password retrieved from the environment variables, or None if not found.

bittensor_wallet.keyfile.keyfile_data_encryption_method(keyfile_data)

Returns type of encryption method as a string.

Parameters:

keyfile_data (bytes) – Bytes to validate.

Returns:

A string representing the name of encryption method.

Return type:

(str)

bittensor_wallet.keyfile.keyfile_data_is_encrypted(keyfile_data)

Returns true if the keyfile data is encrypted.

Parameters:

keyfile_data (bytes) – The bytes to validate.

Returns:

true if the data is encrypted.

Return type:

is_encrypted (bool)

bittensor_wallet.keyfile.keyfile_data_is_encrypted_ansible(keyfile_data)

Returns true if the keyfile data is ansible encrypted.

Parameters:

validate. (keyfile_data - The bytes to)

Returns:

is_ansible - True if the data is ansible encrypted.

bittensor_wallet.keyfile.keyfile_data_is_encrypted_legacy(keyfile_data)

Returns true if the keyfile data is legacy encrypted.

Parameters:

validate. (keyfile_data - The bytes to)

Returns:

is_legacy - true if the data is legacy encrypted.

bittensor_wallet.keyfile.keyfile_data_is_encrypted_nacl(keyfile_data)

Returns true if the keyfile data is NaCl encrypted.

Parameters:

validate (keyfile_data - Bytes to)

Returns:

is_nacl - true if the data is ansible encrypted.

bittensor_wallet.keyfile.legacy_encrypt_keyfile_data(keyfile_data, password=None)

legacy_encrypt_keyfile_data.

Parameters:
  • keyfile_data (bytes) – Bytes of data from the keyfile.

  • password (str) – Optional string that represents the password.

Returns:

The encrypted keyfile data in bytes.

bittensor_wallet.keyfile.serialized_keypair_to_keyfile_data(keypair)

Serializes keypair object into keyfile data.

Parameters:

keypair (Keypair) – The keypair object to be serialized.

Returns:

Serialized keypair data.

bittensor_wallet.keyfile.validate_password(password)

Validates the password against a password policy.

Parameters:

password (str) – The password to verify.

Returns:

True if the password meets validity requirements.

Classes Details

class bittensor_wallet.keyfile.Keyfile(path=None, name=None, should_save_to_env=False)

Bases: object

check_and_update_encryption(print_result=True, no_prompt=False)

Check the version of keyfile and update if needed.

Parameters:
  • print_result (bool) – If True, prints the result of the encryption check.

  • no_prompt (bool) – If True, skips user prompts during the update process.

Returns:

True if the keyfile was successfully updated to the latest encryption method.

decrypt(password=None)

Decrypts the file under the path.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

encrypt(password=None)

Encrypts the file under the path.

Parameters:

password (Option<String>) – The password used to encrypt the data. If None, asks for user input.

env_var_name()

Returns local environment variable key name based on Keyfile path.

exists_on_device()

Returns True if the file exists on the device.

Returns:

True if the file is readable.

get_keypair(password=None)

Returns the keypair from path, decrypts data if the file is encrypted.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

Returns:

The Keypair loaded from the file.

is_encrypted()

Returns True if the file under path is encrypted.

Returns:

True if the file is encrypted.

is_readable()

Returns True if the file under path is readable.

is_writable()

Returns True if the file under path is writable.

Returns:

True if the file is writable.

make_dirs()

Creates directories for the path if they do not exist.

set_keypair(keypair, encrypt=True, overwrite=False, password=None)

Writes the keypair to the file and optionally encrypts data.

Parameters:
  • keypair (Keypair) – The keypair object to be stored.

  • encrypt (bool) – If True, encrypts the keyfile data.

  • overwrite (bool) – If True, overwrites existing file without prompting.

  • password (Option<String>) – The password used to encrypt the data. If None, asks for user input.

data

Returns the keyfile data under path.

check_and_update_encryption(print_result=True, no_prompt=False)

Check the version of keyfile and update if needed.

Parameters:
  • print_result (bool) – If True, prints the result of the encryption check.

  • no_prompt (bool) – If True, skips user prompts during the update process.

Returns:

True if the keyfile was successfully updated to the latest encryption method.

data

Returns the keyfile data under path.

decrypt(password=None)

Decrypts the file under the path.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

encrypt(password=None)

Encrypts the file under the path.

Parameters:

password (Option<String>) – The password used to encrypt the data. If None, asks for user input.

env_var_name()

Returns local environment variable key name based on Keyfile path.

exists_on_device()

Returns True if the file exists on the device.

Returns:

True if the file is readable.

get_keypair(password=None)

Returns the keypair from path, decrypts data if the file is encrypted.

Parameters:

password (Option<String>) – The password used to decrypt the data. If None, asks for user input.

Returns:

The Keypair loaded from the file.

is_encrypted()

Returns True if the file under path is encrypted.

Returns:

True if the file is encrypted.

is_readable()

Returns True if the file under path is readable.

is_writable()

Returns True if the file under path is writable.

Returns:

True if the file is writable.

keypair

Returns the keypair from path, decrypts data if the file is encrypted.

make_dirs()

Creates directories for the path if they do not exist.

path

Returns the wallet path.

remove_password_from_env()

Removes the password associated with the Keyfile from the local environment.

save_password_to_env(password=None)

Saves the key’s password to the associated local environment variable.

Parameters:

password (Option<String>) – The password to save. If None, asks for user input.

Returns:

The base64-encoded encrypted password.

set_keypair(keypair, encrypt=True, overwrite=False, password=None)

Writes the keypair to the file and optionally encrypts data.

Parameters:
  • keypair (Keypair) – The keypair object to be stored.

  • encrypt (bool) – If True, encrypts the keyfile data.

  • overwrite (bool) – If True, overwrites existing file without prompting.

  • password (Option<String>) – The password used to encrypt the data. If None, asks for user input.