Derive the Public Master Directorate and the BTC address of the seed phrase using the electrum wallet
As an enthusiastic of digital assets, it is essential to understand how Bitcoin wallets store and manage their private keys. In this article, we will explore a Python code that takes a standard seed phrase as an entrance and issues the root key or the public key XPUB used by an electrum wallet.
What is a seed phrase?
A seed phrase is a series of words that serves as the private key for a Bitcoin wallet. It is generated using a complex mathematical formula and consists of multiple phrases, each with 25 characters (or less). The seed phrase is typically divided into four parts:
- First part: 25 characters phrase
- Second part: 26 characters phrase
- Third part: 27 characters phrase
- Fourth part: 33 Character phrase
Each part contains a couple of words separated by a colon (:) followed by two characters (0-9). For example, 34: 1a23b
Electrum wallet and seed phrases
Electrum is a popular bitcoin wallet software that uses a seed phrase to store the private key. The seed phrase is used to derive the public key XPUB.
Here is a general description of the process:
- Divide the seed phrase into four parts:
34: 1A23B,56: 2D45E83F,89: 5A6D7C4A1BY12: 34567890123456789012345678908
- Derive the public key XPUB for each party using a cryptographic algorithm (for example, ECDSA with SECP256K1)
- Combine the derived keys to form the root key or the public key XPUB
Python code
`Python
Import hashlib
Def derive_xpub_Key (Seed_phrase):

Seed phrase divided into four parts
Parts = [Seed_phrase [: 25], Seed_phrase [26:51], Seed_phrase [52:78], Seed_phrase [79: 104]]]]
Initialize an empty list to store public keys Masters XPUB
xpub_keys = []
Iterer on each part of the seed phrase
For part in the parties:
Derive the public key XPUB using ECDSA with SECP256K1
Key = hashlib.sha256 (part.encode ()). Digest ()
Add the key referred to the list of public keys master xpub
xpub_keys.append (key)
Combine the keys derived in a single chain
root_key = '' .Join (xpub_keys)
Rot_Key return
Example use:
SEED_PHRASE = "34: 1A23B56: 2D45E83F89: 5A6D7C4A1B12: 3456789012345678901234567890"
root_key = derive_xpub_key (sement_phrase)
print (root_key)
emerges the root key or the Public key XPUB
`
Note: This code assumes that the seed phrase is provided as a chain. In practice, you may want to consider using a safer method to store and recover the seed phrase, such as encrypting it with a password or using a hardware safety module (HSM).
I hope this Python code will help you obtain the teacher’s public key and the BTC address of the seed phrase of an electrum wallet!
