La master private key o Master Private Key is a 256-bit key generated from a seed phrase that allows the creation of an infinite number of keys in one deterministic wallet or HD wallet. It is a private key main which is unique to each purse, and which is stored as the root or start of said wallet. From the Master Private Key the Master Public Key o Master Public Key. Then a whole set of private keys (Xpriv) is also generated from the master private key. And with them you can manage the different addresses associated with the wallet.
Simply put, the Master Private Key starts the whole deterministic wallet and from it the Master Public Key. But not only that, they also derive all the private keys (Xpriv) that are needed to manage the balance found in the different addresses of the wallet.
They must understand an HD wallet as a tree. New branches can emerge from each branch. Well, every node of these branches allows to generate a Master Private Key. This key will allow them to generate public and private keys of all the branches that are generated from that node. However, it cannot create the keys from the other parallel or previous nodes.
That is, in this way a Master Private Key can be used to limit the use of the same seed. The Master Private Key of node 0 has control over all the addresses that can be generated. But you can create keys that you can control, but between them they cannot be controlled.
You must never give or reveal the Master Private Key to anyone. Unless you want that person / machine to have access to all the funds of the addresses that are generated from that key.
Function of the Master Private Key in HD wallets
The implementation of Bitcoin hierarchical deterministic wallets, also known as HD wallets, were created in order to improve security and allow the simplification of the recovery process of the funds available in them. Although they were also developed in order to make possible the generation and obtaining of several keys that start from the same root or seed. Eliminating the need to randomly generate multiple addresses with private keys, like old wallets did.
This type of wallets, described in the 32 BIP, have a tree structure where a main key (the Master Private Key) gives rise to a sequence of keys derived from it, from which other sets of keys are derived. If we represent this as a descending line, it could be said that the Master Private Key it plays the role of father and that the sequence of keys generated in the first place will be its daughters. After that set of keys, the new generated keys could be seen as grandchildren and so on.
HD wallets use the algorithm HMAC-SHA512 to generate a hash that derives the Master Private Key starting from a single seed. Then, from the master private key the CMaster Public wash through a mathematical process of multiplication of normal elliptic curve. Likewise, from the same hash derived from the algorithm, a chain code is created that allows the generation of new keys derived from the master keys. That is, from the Master Private Key The private keys (Xpriv) that manage the addresses and their funds will be created, and from the master public key the public keys (Xpub) will be derived from where the addresses are generated, but they are not managed.
And since all this data is generated starting from the same seed, it is possible to recover it. It is even possible to recreate the wallet again on any device just by using said seed.
Importance of the Master Private Key
To be able to back up, export or import a wallet, or restore it in the worst case. All this is possible thanks to the implementation of HD wallets and their descending structure. Where the Master private key It fulfills an important function, since this derives all the sets of keys that allow managing the wallet.
As all the information in the HD wallet is derived deterministically and hierarchically from the seed, and later, from the Master Private Key, it is possible to recreate the entire wallet in any other compatible wallet or device starting only from the seed. In complete assurance that the Master Private Key And all the keys derived from it, be it hundreds, thousands or millions, will also be restored. And with them, of course, all the funds that were stored.
So you can think of this tree structure as if the top of a tree is the Master Private Key, from which an infinite number of private keys (Xpriv) are derived in descending order. Therefore, each one of those derived private keys can be recovered simply by having the Master Private Key. But the process cannot be done in reverse. That is, it cannot be recovered by starting from a secondary private key.
Identification of the Master Private Keys and their derived keys
The descending structure on an HD wallet is infinite, so it can be as deep as desired. Each key derived from the Master Private Key can have 4 billion derived keys. But also, each of these keys can have another 4 billion more, and so on. So there can be an infinite number of descendants.
So to identify the master keys and derived keys in an HD wallet, a path description is used. Which allows observing each level of the offspring separated by the / symbol (bar). This makes it easy to navigate the tree structure of the wallet. For example, all secondary private keys derived from the Master Private Key, which begin with the letter m (lowercase), so they will be reflected as m / x / and / z /… / according to their level of descent.
If we have the first secondary private key (daughter) derived from the master private key (father), it is reflected as m / 0. Whereas if we have a private key derived from the secondary (granddaughter), it is reflected as m / 0/1. The entire downline of the Master Private Key it meets these parameters, which are read from right to left until reaching the master private key.