Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Mia Chloe on November 24, 2023, 11:47:11 AM



Title: How do I go about this?
Post by: Mia Chloe on November 24, 2023, 11:47:11 AM
Using mnemonic phrases also known as seed phrase to generate private keys for a wallet is normal during wallet creation.however I been wanting to try generating a private key by myself from the seed phrase outside the wallet software. I tried using the seed from  an HD wallet of BIP-32 standard But am having a hard time getting the right algorithm for generation of the master key and chain code .
How do I go about this pls?


Title: Re: How do I go about this?
Post by: Charles-Tim on November 24, 2023, 11:55:33 AM
For the generation of the master keys and child keys:

Use https://iancoleman.io/bip39/ offline, not online. You can use it to generate the keys and addresses from seed phrase.

For offline usage:
Use the html on a word editor: https://github.com/iancoleman/bip39/releases/latest/

For security reasons, use it offline on a word editor.


Title: Re: How do I go about this?
Post by: Zaguru12 on November 24, 2023, 12:04:01 PM
Here is a little guide by blue Snow on how to generate your master  private key from seed phrase (https://bitcointalk.org/index.php?topic=5288888.0). Make sure you are doing it offline.

Although I don’t know why you wish to generate the master private key from the seed phrase but in case of back up there is no point of backing up the master private key even though it will recover the same address as the seed phrase will do but seed phrase back is more convenient than the key.


Title: Re: How do I go about this?
Post by: Mia Chloe on November 24, 2023, 12:09:08 PM
For the generation of the master keys and child keys:

Use https://iancoleman.io/bip39/ offline, not online. You can use it to generate the keys and addresses from seed phrase.

For offline usage:
Use the html on a word editor: https://github.com/iancoleman/bip39/releases/latest/

For security reasons, use it offline on a word editor.
Thanks alot Charles Tim and Zaguru12
Is there a similar script I can run on phyton?


Title: Re: How do I go about this?
Post by: Charles-Tim on November 24, 2023, 12:33:17 PM
Is there a similar script I can run on phyton?
I do not know much about this. You can wait for other reputed members and see what they will reply. Let me quote nc50lc so that he can see this thread. I believe he will have something good to reply.


Title: Re: How do I go about this?
Post by: seek3r on November 27, 2023, 04:01:13 PM
For the generation of the master keys and child keys:

Use https://iancoleman.io/bip39/ offline, not online. You can use it to generate the keys and addresses from seed phrase.

For offline usage:
Use the html on a word editor: https://github.com/iancoleman/bip39/releases/latest/

For security reasons, use it offline on a word editor.
Thanks alot Charles Tim and Zaguru12
Is there a similar script I can run on phyton?


It is possible to run this on python aswell. You have to use mnemonic library for the BIP39 functionalities and the bip32utils library for the BIP32 key derivation.

Create a new mnemonic phrase with the mnemonic library. The individual passphrase is optional.
Code:
from mnemonic import Mnemonic

mnemo = Mnemonic("english")
words = mnemo.generate(strength=128)  # 128, 160, 192, 224, 256 bits
seed = mnemo.to_seed(words, passphrase="INSERT_PASSPHRASE_HERE")
print("Mnemonic:", words)
print("Seed:", seed.hex())

Now use the bip32utils library to derrive the masterkey and the child keys:
Code:
from bip32utils import BIP32Key

master_key = BIP32Key.fromEntropy(seed)
child_key = master_key.ChildKey(44 + BIP32Key.HARDENED) \
                        .ChildKey(0 + BIP32Key.HARDENED) \
                        .ChildKey(0 + BIP32Key.HARDENED) \
                        .ChildKey(0).ChildKey(0)

print("Master Key:", master_key.ExtendedKey())
print("Child Key:", child_key.Address())

I have used "m/44'/0'/0'/0/0" as derivation path since this path is widely used by many wallets and allows a structured way to generate multiple addresses.


Title: Re: How do I go about this?
Post by: Mia Chloe on November 27, 2023, 04:31:20 PM
For the generation of the master keys and child keys:

Use https://iancoleman.io/bip39/ offline, not online. You can use it to generate the keys and addresses from seed phrase.

For offline usage:
Use the html on a word editor: https://github.com/iancoleman/bip39/releases/latest/

For security reasons, use it offline on a word editor.
Thanks alot Charles Tim and Zaguru12
Is there a similar script I can run on phyton?


It is possible to run this on python aswell. You have to use mnemonic library for the BIP39 functionalities and the bip32utils library for the BIP32 key derivation.

Create a new mnemonic phrase with the mnemonic library. The individual passphrase is optional.
Code:
from mnemonic import Mnemonic

mnemo = Mnemonic("english")
words = mnemo.generate(strength=128)  # 128, 160, 192, 224, 256 bits
seed = mnemo.to_seed(words, passphrase="INSERT_PASSPHRASE_HERE")
print("Mnemonic:", words)
print("Seed:", seed.hex())

Now use the bip32utils library to derrive the masterkey and the child keys:
Code:
from bip32utils import BIP32Key

master_key = BIP32Key.fromEntropy(seed)
child_key = master_key.ChildKey(44 + BIP32Key.HARDENED) \
                        .ChildKey(0 + BIP32Key.HARDENED) \
                        .ChildKey(0 + BIP32Key.HARDENED) \
                        .ChildKey(0).ChildKey(0)

print("Master Key:", master_key.ExtendedKey())
print("Child Key:", child_key.Address())

I have used "m/44'/0'/0'/0/0" as derivation path since this path is widely used by many wallets and allows a structured way to generate multiple addresses.

Thanks a lot seek3r although I was able to use Charles-Tim help which was very very easy to use I would definitely use this phyton script also .


Title: Re: How do I go about this?
Post by: NotATether on November 28, 2023, 12:52:21 PM
Thanks a lot seek3r although I was able to use Charles-Tim help which was very very easy to use I would definitely use this phyton script also .

I do not recommend directly using private keys which are derived from the seed phrase for holding bitcoins because there is a change that you might mess up the generation process which leads to the coins becoming inaccessible. This should be done only for learning purposes. (As you hopefully already know).