Firstly, what is HD wallet:
I've always seen people confuse HD wallet to hardware wallet...some of us might know it but for the newbies and those that does not
i think this should explain little...
HD => Hierarchical Deterministic Wallet .
HW => Hardware Wallet .
HD wallet [Hierarchical Deterministic wallet] is a type of wallet that generates its private keys
and addresses from a single seed .
Thus, a single seed can generate a master private key which can also generate an extended master public key(i.e the master private key generate a master public key) now with the master private key, new child private keys and public keys can be generated. Hence, with the master public keys, new child public keys can be generated which doesn't need a private key
A brief illustration on how it works:when you create a wallet you generate a seed ~ 64 random bytes which go through the HMAC hash function to generate a Master extended private key,
the Master extended private key is still having the master private key but the reason it's uses the word "extended" as the keyword is because it contains the private key and the
chaincode,both the private key and the chaincode is use in the generation of child keys in their corresponding indexes(0,1,2.....).
Thus, this private key(i.e the private key in our master extended private key or extended key) is being use to generate the master public key, to create child public keys it needs to go through the HMAC hash along with the chain code in the master private key and this form a extended public key ( i.e master public key + chain code).
In summary, we have an an extended private key or extended key ( private key and chaincode) to create child keys(private and public ),extended public key ( public key and chain code) to create child public keys.
The extended keys (private and public) can create two types of child keys which are
* Non-Hardened or Normal => both exended keys can generate same public keys whcih means you can stil use the only the extended public key to generate the child keys...
it index range from 0d0 to 0d2147483647 [in decimal]... same as 0 to 2147483647
it index range from 0x0 to 0x7fffffff [in hex(base16)].. hex is a short for hexadecimal
*Hardened=> to create these child keys there is need for private key unlike
normal where you can generate public child keys only without the need of extended private key
it index ranges from 0d2147483648 to 0d4294967295[in decimal]
it index ranges from 0x80000000 to 0xffffffff[in hex]
Each address has it's own private keys which means it's all derived from an extended private key,
the extended private key can be called ( “xprv”/“yprv”/“zprv”) but this depends on the address type since your wallet needs to generate a particular type of address you choose/need .
Extended Private Key (xprv,yprv,zprv)
address that starts with 1--Legacy (P2PKH) => extended private key (“xprv”)
address that starts with 3 --Wrapped Segwit (Nested-P2WPKH) => extended private key (“yprv”)
address that starts with bc1--Segwit (P2WPKH)=>extended private key (“zprv”)...
Extended Public Key (xpub,ypub,zpub)
address that starts with 1--Legacy (P2PKH) => extended public key (“xpub”)
address that starts with 3 --Wrapped Segwit (Nested-P2WPKH) => extended public key (“ypub”)
address that starts with bc1--Segwit (P2WPKH)=> extended public key (“zpub”)...
Now you can choose to recover your Segwit HD wallet anytime if you have the zprv by just importing it to a new wallet, if you tried to use a single private key you will only be importing a single address which is not going to form an HD wallet.
On the other hand, you can import your zpub on a different wallet to create a view only wallet(watch only wallet),watch only wallet is a wallet shows all your available funds, addresses and transactions but inform of a view only mode, to make any transaction(output) happen you need the private key to sign the ownership of the public key
Note:* "The keys (and addresses, respectively) can be layered to hierarchical structure where each upper level determines the lower one."
* "Hardware wallets (HW) internally use an
HD key derivation to produce private keys, public keys and corresponding public addresses"
Source:
https://learnmeabitcoin.com/technical/keys/hd-wallets/#hmac-sha512-toolyou can learn more from the source above
I'm also open to any addition and correction...your corrections are welcome.