All you need to know about HD wallets, xpub, ypub and zpub
Every cryptocurrency wallet is composed of a public address and a private key. These keys are just a string of random numbers. The public address can be shared with other people and they can use it to send funds to it. The private key should never be shared, as the owner of the private key has access to the funds and can send them to other wallets.
Originally, a new private key and public key was generated every time funds were to be sent to a Bitcoin wallet. This made it increasingly difficult to back up the wallet information, as users had to back up their Bitcoin wallets every time they received funds in them. Over time there were many attempts to improve this system, but the real breakthrough came with BIP32 (Bitcoin Improvement Proposal), which marked the creation of the Hierarchical Deterministic Wallets. An HD Wallet automatically generates a structure of child private and public keys. This structure is hierarchical, as the name suggests since these keys are obtained from a single master – parent- seed (see image below). This solved the issue of users having to keep generating their own wallets. It also makes it easy to back up and restore backups, with the use of this single seed.
What is an Xpub?
Every child key pair generated can define an XPub (Extended Public Key). As the name suggests, an Xpub doesn’t contain information about private keys, but only public ones. This means that an Xpub will not give you access to the funds in a wallet, but it can be used to view the child wallet’s addresses, transactions, and balances. You can think of it as a read-only view of a wallet. Although the Xpub doesn’t give you spending abilities, only the possibility to view a wallet’s information, it’s highly risky to share the key with anyone.
What are Ypub and Zpub?
After the adoption of SegWit, theBIP49 standard was introduced giving origin to the Ypub. A Ypub key is the same as an Xpub key, but it follows the new standard and has an address type P2SH-P2WPKH. Ypub is for backward-compatible SegWit Wallets.
After the Xpub and Ypub, the newest Public Extended Key is called Zpub. Just as its predecessor the Zpub follows the BIP49 standard, but the address type is P2WPKH. Zpub is for native compatible SegWit wallets.
An easy way to differentiate between Xpubs, Ypubs and Zpubs is that Xpubs addresses always start with “1”, the Ypub addresses always start with “3”, whilst Zpub addresses always start with “bc1”.
Create and view an Xpub, Ypub and Zpub key with Crypto APIs
Two other endpoints allow you to get the Change and Receive addresses associated with the Xpub specified in the query.