bip38_no_ec

Module for BIP38 encryption/decryption. Reference: https://github.com/bitcoin/bips/blob/master/bip-0038.mediawiki

class Bip38NoEcConst

Bases: object

Class container for BIP38 no EC constants.

ENC_KEY_BYTE_LEN: int = 39
ENC_KEY_PREFIX: bytes = b'\x01B'
FLAGBYTE_COMPRESSED: bytes = b'\xe0'
FLAGBYTE_UNCOMPRESSED: bytes = b'\xc0'
SCRYPT_KEY_LEN: int = 64
SCRYPT_N: int = 16384
SCRYPT_P: int = 8
SCRYPT_R: int = 8
class Bip38NoEcEncrypter

Bases: object

BIP38 encrypter class. It encrypts a private key using the algorithm specified in BIP38 without EC multiplication.

static Encrypt(priv_key: Union[bytes, IPrivateKey], passphrase: str, pub_key_mode: P2PKHPubKeyModes) str

Encrypt the specified private key.

Parameters:
  • priv_key (bytes or IPrivateKey) – Private key bytes or object

  • passphrase (str) – Passphrase

  • pub_key_mode (Bip38PubKeyModes) – Public key mode

Returns:

Encrypted private key

Return type:

str

Raises:
  • TypeError – If the private key is not a Secp256k1PrivateKey

  • ValueError – If the private key bytes are not valid

class Bip38NoEcDecrypter

Bases: object

BIP38 decrypter class. It decrypts a private key using the algorithm specified in BIP38 without EC multiplication.

static Decrypt(priv_key_enc: str, passphrase: str) Tuple[bytes, P2PKHPubKeyModes]

Decrypt the specified private key.

Parameters:
  • priv_key_enc (str) – Encrypted private key bytes

  • passphrase (str) – Passphrase

Returns:

Decrypted private key (index 0), public key mode (index 1)

Return type:

tuple[bytes, Bip38PubKeyModes]

Raises:
  • Base58ChecksumError – If base58 checksum is not valid

  • ValueError – If the encrypted key is not valid