So, when you set up a new wallet on Sparrow, you get two master public keys: the xpub and zpub. Recently, someone accidentally used the xpub instead of the zpub to make a watch-only wallet in Bluewallet. (You can check out the related discussion here.) The user then sent some funds to this watch-only wallet created with the xpub and wanted to know how to get the funds back.
I was thinking of telling him to create a new wallet using the same seed phrase on Sparrow or Electrum and choose the "Legacy" option this time. But I wanted to test it first to see if it actually works. To my surprise, it didn’t work.
Here’s what I found:
Sparrow shows only segwit addresses, but it has both master public keys for that seed phrase.
Xpub:
Zpub:
You can swap these master public keys using a Bitcoin Extended Public Key Converter, and that part is fine. But how do you recover the funds sent to the addresses made from the xpub?
If you import that seed phrase into Electrum and pick "Legacy" as the script type, you’ll end up with this xpub.
Understanding master public keys in Sparrow
4 replies 342 views
humbleledgerLegendary
Posts: 1027 · Reputation: 6554
#2Nov 22, 2018, 12:40 AM
For such problems, I'd use Ian Coleman's site:
I'm no expert on manual xpub/zpub handling, but I'd try importing the private key first.
Charles-Tim wrote it down better under here:
There has been a way I do recover such coins if possible I am in such situation.
I input the above seed phrase on iancoleman BIP39 tool. It will generate this m/84'/0'/0'/0/0 bc1qnjrn2yzc0tswkse335an00eslax4xu78svqfmy 030889282c9000b81edf4fd8ff1ab8c671b8bd0bf2ac255099ebcac55c5a193e23 L26FLhhEzwXYQncePSMXZ2AHhmDraKSpATMgRzukq2oMbEP4jSBi. You understood that. No need for further explanation.
Take the private key and import it on Electrum.
L26FLhhEzwXYQncePSMXZ2AHhmDraKSpATMgRzukq2oMbEP4jSBi
It will generate this address: 1FGePHwdHJW65V5wgUGZF4RmrZtcLXtZG8
Which is the address that is first generated by this public key.
xpub6CD4powCKnww5mvQPcmQyghbMvZHTy4q2BLZ55kjkr1YTP2Rte4Zanwq3Rv4nHdQvY1mMTB37bP QLWrDQgceT1TcB2MuQ5FKgaKtqUGfCro
So you can import the private key one after the other to recover the coins. It will likely be on the first address.
You can even convert the seed phrase to the equivalent BIP44 on Electrum. nc50lc has a post on it. If I see it, I will edit this post. Or nc50lc or anyone that saw the post can post about it below.
This will not work.
The legacy address you generated on m/44'/0'/0'/0/0 is same as the address generated with importing the seed phrase on electrum and selecting "Legacy" as the script type.
I am looking for the address generated from the xpub displayed by Sparrow. That's 1FGePHwdHJW65V5wgUGZF4RmrZtcLXtZG8.
This works. Thank you.
I could find another solution too.
I exported the master private key from the wallet file. Then I converted the zpub to xpub using electrum console and imported the resulting key. In this way, it's not required to import individual private keys one by one.
The master privtate key I got from the wallet file was as follows.
And below is the command I used in electrum console.
I don't really understand the use of the xpub displayed by Sparrow for a segwit wallet.
I think that can only lead to confusion.
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#5Nov 22, 2018, 12:41 PM
That's because other wallets do not utilize the "z" or other extended key formats like Bitcoin Core.
Those wallet have some mechanism to identify which derivation path to get to that extended key and the script type to use,
In Bitcoin Core and Sparrow, they use "descriptors".
In Sparrow, it can be seen in "Edit wallet output descriptor" button:
From that, your example wallet uses "wpkh" (P2WPKH) script type and the derivation path of m/84h/0h/0h from master private key to that extended public key.
Wallets supporting descriptors utilizes that.
For the recovery of that particular case when the user simply imported the xpub resulting with legacy HD watch-only wallet, you don't need a third-party tool nor command to recover it;
When importing to Electrum during script type selection screen:
Tick "legacy (p2pkh)", then edit the derivation path below from m/44h/0h/0h to m/84h/0h/0h to match the derivation path in your descriptor.
Then finalize the wallet creation process and the xpub and the legacy addresses of the improperly imported watch-only wallet should match.