btclib_wallet.mnemonic package

Submodules

btclib_wallet.mnemonic.bip39 module

The BIP32 master key of a BIP39 mnemonic.

https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki.

The sentence, its entropy and its seed are bip39_slip39.bip39’s; what is here is the step BIP39 hands to BIP32, the seed becoming a root extended private key.

btclib_wallet.mnemonic.bip39.mxprv_from_mnemonic(mnemonic: Mnemonic, passphrase: str | None = None, network: str = 'mainnet', verify_checksum: bool = True) → str[source]

Return BIP32 root master extended private key from BIP39 mnemonic.

The seed is bip39_slip39.bip39.seed_from_mnemonic’s, None being the empty passphrase, and a refusal of that function’s leaves as bip39_slip39’s own class.

btclib_wallet.mnemonic.electrum module

The master keys of an Electrum mnemonic.

The sentence, its version and its seed are bip39_slip39.electrum’s. What is here is what Electrum derives from them: the BIP32 master key a versioned mnemonic names, and the master public key of a pre-2.0 one.

btclib_wallet.mnemonic.electrum.mxprv_from_mnemonic(mnemonic: Mnemonic, passphrase: str | None = None, network: str = 'mainnet') → str[source]

Return BIP32 master extended private key from Electrum mnemonic.

The derivation path is “m” for a “standard” mnemonic and “m/0h” for a “segwit” one. The version is bip39_slip39.electrum.version_from_mnemonic’s and the seed bip39_slip39.electrum.seed_from_mnemonic’s, None being the empty passphrase; a refusal of either leaves as bip39_slip39’s own class.

btclib_wallet.mnemonic.electrum.old_master_pub_key_from_mnemonic(mnemonic: Mnemonic, passphrase: str | None = None) → str[source]

Return the pre-2.0 Electrum master public key, as Electrum writes it.

Electrum’s Old_KeyStore.mpk_from_seed: the uncompressed SEC point of the stretched key with its 04 prefix cut off, so 128 hex characters of x and then y. That string is what a pre-2.0 wallet file holds under “master_public_key”, which is what makes it the value a vector can be taken from. The stretched key is bip39_slip39.electrum.old_master_prv_key_from_mnemonic’s, which refuses a passphrase: the pre-2.0 scheme has none.

btclib_wallet.mnemonic.slip39 module

The BIP32 master key of a set of SLIP-0039 shares.

https://github.com/satoshilabs/slips/blob/master/slip-0039.md.

The shares and the master secret they recover are bip39_slip39.slip39’s. SLIP-0039 backs up the BIP32 seed itself, so the master secret is handed straight to rootxprv_from_seed.

btclib_wallet.mnemonic.slip39.mxprv_from_mnemonics(mnemonics: Sequence[Mnemonic], passphrase: str | None = None, network: str = 'mainnet') → str[source]

Return BIP32 root master extended private key from SLIP-0039 shares.

The master secret is the BIP32 seed, so there is no stretching step between the two: SLIP-0039 backs up the seed itself.

None is the empty passphrase; any other value is handed on to be checked, so a falsy one of another type is refused rather than read as the empty passphrase. A refusal of bip39_slip39.slip39.master_secret_from_mnemonics leaves as bip39_slip39’s own class.

Module contents

Module btclib_wallet.mnemonic.

The master key of a BIP39, SLIP39 or Electrum mnemonic, one module per scheme. The schemes themselves – entropy, sentence and seed – are bip39_slip39’s, and what is here is where a seed meets BIP32: bip39.mxprv_from_mnemonic, slip39.mxprv_from_mnemonics, electrum.mxprv_from_mnemonic and electrum.old_master_pub_key_from_mnemonic.

The modules are named here because none is exported by importing the package alone: import btclib_wallet.mnemonic followed by btclib_wallet.mnemonic.bip39.mxprv_from_mnemonic(…) raises AttributeError until something else in the process happens to import the submodule.