Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 2.05 KB

can_not_get_mnemoic_from_private_key.md

File metadata and controls

33 lines (25 loc) · 2.05 KB

You're correct that it's generally straightforward to derive a private key from a mnemonic phrase, but the reverse process (deriving a mnemonic from a private key) is not typically possible or standardized. Here's why:

  1. Mnemonic to Private Key:

    • This is a one-way process defined by standards like BIP39 (Bitcoin Improvement Proposal 39).
    • The mnemonic phrase contains more information than just the private key. It includes a checksum and potentially additional metadata.
    • The process involves:
      1. Converting the mnemonic words to a binary seed.
      2. Using this seed to generate the master private key.
      3. Deriving child keys if needed (for HD wallets).
  2. Private Key to Mnemonic:

    • This is not standardly possible because:
      • The private key doesn't contain the additional information present in the mnemonic (like the checksum).
      • Multiple different mnemonics could potentially generate the same private key.
      • The mnemonic creation process involves randomness that isn't captured in the private key alone.

For the cryptocurrencies you mentioned (Ethereum, Bitcoin, Cosmos, Solana):

  • Ethereum: As you showed, libraries like eth_account can derive keys from mnemonics but not vice versa.
  • Bitcoin: Libraries like bitcoinlib work similarly.
  • Cosmos: The cosmos-sdk follows the same principle.
  • Solana: Tools like @solana/web3.js also derive keys from mnemonics but not the reverse.

In practice, if you need to "recover" a mnemonic-like representation from a private key, you would typically:

  1. Generate a new mnemonic.
  2. Derive its corresponding private key.
  3. Replace this derived private key with your actual private key.

This creates a new, valid mnemonic-private key pair, but it's not recovering the original mnemonic. It's creating a new one that happens to produce the same private key.

Remember, for security reasons, it's generally recommended to start with a mnemonic and derive keys from it, rather than starting with raw private keys.