The relationship between the seed phrase and the private key

ethers.jsmnemonicprivate-keypublic-keywallets

Using ethers, I can easily generate a public key (wallet address), private key, and seed phrase:

function makeWallet(params) {
    const wallet = ethers.Wallet.createRandom();
    return [wallet.address, wallet.mnemonic.phrase, wallet.privateKey];
}

Question:

What is the relationship between the mnemonic phrase, the private key, and the address? I cad divide the question into 3 sub-parts:

  • Given a wallet address, and a mnemonic key, is it possible to compute the private key?
  • Given a wallet address, and a private key, is it possible to compute the mnemonic key?
  • Given a mnemonic key and/or private key, is it possible to compute the wallet address?

Best Answer

Given a wallet address, and a mnemonic key, is it possible to compute the private key?

If you have the mnemonic, it's possible to compute a number of private keys, and their corresponding addresses.

Given a wallet address, and a private key, is it possible to compute the mnemonic key?

No.

Given a mnemonic key and/or private key, is it possible to compute the wallet address?

Yes, given a private key, it is possible to compute the wallet address corresponding to it. Mnemonic is not necessary.

This is the usual flow of wallets: Private key => Public key => Address. The arrow "=>" represents the direction of the one-way function. Then people used a lot of wallets, i.e. they had to manage a lot of private keys, and hence it led to creation of the BIP-32, BIP-39 standards, which describes mnemonic and how one can deterministically generate lot of private keys from it. So user just needs to hold mnemonic for any number of wallets (private keys).

This site can be helpful for playing around: https://iancoleman.io/bip39/

In ethers.js there is a thing called HDNode that allows to handle lot of wallets with just a single mnemonic. If interested, you may check it out here: https://docs.ethers.io/v5/api/utils/hdnode/