bittensor.mock.keyfile_mock#

Classes#

MockKeyfile

Defines an interface to a mocked keyfile object (nothing is created on device) keypair is treated as non encrypted and the data is just the string version.

Module Contents#

class bittensor.mock.keyfile_mock.MockKeyfile(path)[source]#

Bases: bittensor.keyfile

Defines an interface to a mocked keyfile object (nothing is created on device) keypair is treated as non encrypted and the data is just the string version.

Parameters:

path (str)

_mock_keypair#
_mock_data#
__str__()[source]#
__repr__()[source]#
property keypair: bittensor.Keypair#

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

Returns:

The keypair stored under the path.

Return type:

keypair (bittensor.Keypair)

Raises:

KeyFileError – Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.

property data: bytes#

Returns the keyfile data under path.

Returns:

The keyfile data stored under the path.

Return type:

keyfile_data (bytes)

Raises:

KeyFileError – Raised if the file does not exist, is not readable, or writable.

property keyfile_data: bytes#

Returns the keyfile data under path.

Returns:

The keyfile data stored under the path.

Return type:

keyfile_data (bytes)

Raises:

KeyFileError – Raised if the file does not exist, is not readable, or writable.

set_keypair(keypair, encrypt=True, overwrite=False, password=None)[source]#

Writes the keypair to the file and optionally encrypts data.

Parameters:
  • keypair (bittensor.Keypair) – The keypair to store under the path.

  • encrypt (bool, optional) – If True, encrypts the file under the path. Default is True.

  • overwrite (bool, optional) – If True, forces overwrite of the current file. Default is False.

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

Raises:

KeyFileError – Raised if the file does not exist, is not readable, writable, or if the password is incorrect.

get_keypair(password=None)[source]#

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

Parameters:

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

Returns:

The keypair stored under the path.

Return type:

keypair (bittensor.Keypair)

Raises:

KeyFileError – Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.

make_dirs()[source]#

Creates directories for the path if they do not exist.

exists_on_device()[source]#

Returns True if the file exists on the device.

Returns:

True if the file is on the device.

Return type:

on_device (bool)

is_readable()[source]#

Returns True if the file under path is readable.

Returns:

True if the file is readable.

Return type:

readable (bool)

is_writable()[source]#

Returns True if the file under path is writable.

Returns:

True if the file is writable.

Return type:

writable (bool)

is_encrypted()[source]#

Returns True if the file under path is encrypted.

Returns:

True if the file is encrypted.

Return type:

encrypted (bool)

encrypt(password=None)[source]#

Encrypts the file under the path.

Parameters:

password (str, optional) – The password for encryption. If None, asks for user input.

Raises:

KeyFileError – Raised if the file does not exist, is not readable, or writable.

decrypt(password=None)[source]#

Decrypts the file under the path.

Parameters:

password (str, optional) – The password for decryption. If None, asks for user input.

Raises:

KeyFileError – Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.