Your bitcoin wallet can let you have many wallets within the same application and generate an endless amount of addresses. Understanding what xPubs and xPrivs are can help you understand how this happens.
xPub stands for Extended Public Key while xPrivs stands for Extended Private Key. Simply put, xPubs and xPrivs are the parent keys that can allow a wallet to mathematically produce billions of child keys that work as public keys and private keys within your wallet.
As a Bitcoin user, knowing about xPubs and xPrivs will help you to:
- Discover ways to unlock more out of your Bitcoin experience
- Understand how xPubs and xPrivs affect the security and privacy of your bitcoin
- Know why the best bitcoin wallets use this
xPubs and xPrivs have not always been around since the beginning of Bitcoin wallets, here is why they were introduced.
Bitcoin Before xPubs and xPrivs
The first bitcoin wallet, Bitcoin-Qt, had a key-management problem. It generated private keys at random which were all stored on the computer in a wallet.dat file.
While this worked, there was a flaw in that users could lose their bitcoin when they accidentally deleted the file or fell victim to malware. In the case that you encrypt this file and forget your wallet’s password, there is no way to recover your funds.
For your funds to be safe as a Bitcoin-Qt user, you had to make continual backups of the newer versions of the wallet.dat file every time you made a transaction. Still, there was no solution for losing your password.
To make this less cumbersome, Bitcoin Improvement Proposal 32 (BIP32) was devised to change how private keys are generated. In the proposal, instead of Bitcoin wallets needing to generate private keys at random for every transaction, a wallet can have one master key that can generate other keys from itself in a predefined way.
Having a determined way to generate private keys means that:
- You only need to backup one (master) private key
- You have the convenience of using the private keys across different wallet applications
Here’s how one parent private key can replace multiple private keys:
How xPubs and xPrivs Work
The key-pair concept is inseparable from Bitcoin, where private keys are meant to sign transactions and public keys, derived from private keys, are used to receive transactions.
When it comes to xPubs (Extended Public Keys) and xPrivs (Extended Private Key) they also serve as public keys and private keys, only in a morphed manner. Their “extendedness” gives them the ability to derive more child private keys and public keys. And just as in normal private keys and public keys, the extended public key is generated from an extended private key.
What’s more, all derived child keys can also derive their own future generations of grandchild keys. But even with continued derivation, all derived keys always carry the unique signature (like DNA) of their parent keys throughout their generation. It’s this family-tree-like derivation process that serves as the origin of a new breed of Bitcoin wallets, hierarchical deterministic wallets.
In hierarchical deterministic wallets (also called HD-wallets), a specific tree-path/branch is selected from which future child keys will be held in. And by having the parent keys, which are the xPub and xPriv, you can traverse through all branches to check for child keys.
The convenience of having a master key to derive all possible keys generated opened a new world in Bitcoin where users no longer have to make the decision between better privacy or easy backups.
xPubs and xPrivs in Action
You Can Have Many Accounts in One Wallet
By having a parent key that can generate many child keys, a wallet can derive child private keys and child public keys that serve as parent keys for new wallets within one main wallet.
As a user, you can find this useful if you wish to have multiple accounts within one wallet. You can use this to separate your financial concerns. For example, you could have an account for personal expenses, business, or even savings without needing to set up multiple bitcoin wallets.
Securing your Keys is Easier
Generating private keys at random meant you had many keys to backup. This is not the case with wallets that implement xPubs and xPrivs.
With parent keys that can deterministically generate child keys for all your wallet transactions, you’ll only have to backup one master key. This master key can be used to derive all other keys you previously generated to transact. Thus, you only need one backup to restore everything.
You Can Share Funds in One Bitcoin wallet
Since an xPriv can sign for transactions from any address generated by it, sharing it can allow other trusted parties to make payments on your behalf. For example, an organization can use the Master xPriv to give child keys to both the procurement and employee payments departments without giving either department the ability to spend each others’ funds.
With this in mind, sharing your xPriv should be done with extreme caution since anyone who holds your private key gains control over all your funds.
More Privacy for your Transactions
An xPub can generate multiple child public keys that can be used to receive funds. This is a simple way to improve privacy for Bitcoin transactions as it prevents linking transaction data together by reusing an address to receive unrelated transactions.
A Multi-Wallet Experience is Possible
xPriv and xPubs are the advancement in Bitcoin that allows users to use more than one wallet software application without creating multiple backups.
Using your wallet’s seed, any wallet application can derive both the xPub and the xPriv and recover coins that you previously received with another wallet.
Despite this, there is always a challenge when wallets use different schemes to derive keys. As a user you can benefit from checking for Bitcoin wallet compatibility before switching vendors.
Payments are Secure With Untrusted Parties
Since private keys have full control of your wallets, storing them on an Internet connected device to accept payments may be sub-optimal. Particularly, if you store your private keys on an unsecure payment processor to generate addresses, any breach can lead to the loss of your funds.
Instead, with an xpub you can generate multiple payment addresses without having to expose your private keys to potential threats.