Author

Topic: Problem importing p2wpkh private key into mobile wallet - bluewallet (Read 213 times)

HCP
legendary
Activity: 2086
Merit: 4363
The old "legacy" format Bitcoin Core wallets will just scan all 3 variants of an imported WIF key... I'm not sure what happens with the new descriptor wallets, but given that you can specify the script type in the descriptor, it's possible it may only scan the one you specify (again, not 100% as I haven't played with descriptor wallets very much, and I think can also import WIFs into descriptor wallets).

Mycelium just does all 3 and you can "tap" on the screen to swap between Legacy, Nested and Native Segwit etc.

Electrum will only do one type per wallet file for HD wallets...  but for imported key wallets, you can mix and match... if you want to scan all three, you just put the private key in three times, once with each prefix.
legendary
Activity: 2268
Merit: 18771
If not, how does the wallet know which address format I want to recover? The same private key can be used for all three address formats. As HCP found, if all addresses are empty, the app will recover the legacy address? But what if all or 2/3 have inputs, what then?
The possible options are that you specify which type of address you want to recover such as you do with Electrum, that it scans for one or more active addresses as is partially the case here with BlueWallet, or it just imports only a single type of address, as I believe is the case with blockchain.com web wallets only importing legacy addresses.

In terms of when 2 out of 3 have been used (this will be a very niche case), then looking at the code I linked above BlueWallet won't find them all. It first scans for an active P2WPKH address, and if found, imports that one. Only if the P2WPKH address is unused will it then scan for a P2SH-P2WPKH address, and only if that is also unused will it then scan for a P2PKH address.
legendary
Activity: 3472
Merit: 10611
I haven't experimented with too many alternative wallets, but do they all offer you an option to click on the type of address you want to recover? As in legacy, nested segwit, and native segwit.

If not, how does the wallet know which address format I want to recover? The same private key can be used for all three address formats. As HCP found, if all addresses are empty, the app will recover the legacy address? But what if all or 2/3 have inputs, what then?
I haven't tried that many wallets either but the handful I've seen didn't have any option to import a single key, they only accept mnemonics and derive all keys on demand in a tabbed design. For example you ask for a new address it shows a new page with 3 tabs each showing a different address type with a different derivation path for p2pkh, p2wpkh-p2sh and p2wpkh.
legendary
Activity: 2730
Merit: 7065
Note that the use of prefixes ("p2pkh:", "p2wpkh-p2sh:", and "p2wpkh:") is, as far as I'm aware, an Electrum only thing.

I'm not aware of any other wallets that actually require or use the prefixes like this.
I haven't experimented with too many alternative wallets, but do they all offer you an option to click on the type of address you want to recover? As in legacy, nested segwit, and native segwit.

If not, how does the wallet know which address format I want to recover? The same private key can be used for all three address formats. As HCP found, if all addresses are empty, the app will recover the legacy address? But what if all or 2/3 have inputs, what then?
HCP
legendary
Activity: 2086
Merit: 4363
The private key starts with "p2wpkh:" and when I import it into electrum, it works and it shows me the correct public key.
Note that the use of prefixes ("p2pkh:", "p2wpkh-p2sh:", and "p2wpkh:") is, as far as I'm aware, an Electrum only thing.

I'm not aware of any other wallets that actually require or use the prefixes like this.
legendary
Activity: 1092
Merit: 1125
If I remember correctly, when you import a private key in to BlueWallet it scans all the relevant addresses looking for which one has been used, and then imports that one. If it finds none of them have been used, it defaults to the nested segwit (P2SH-P2WPKH) address, which will start with a 3.

Have you ever used this vanity address? It might be that you need to send some funds to it before you can import it to BlueWallet.

Edit: Just had a look through the code and it looks like I'm right, except it will default to a legacy address beginning with a 1 if it finds no used addresses. You can see the code here if you are interested: https://github.com/BlueWallet/BlueWallet/blob/master/class/wallet-import.js#L250-L268

Thank you so much man !
Ive tried importing several different addresses with and without the "p2wpkh:" prefix but it always imported the wrong address.
I sent a small amount to the address yesterday and just now tried it again and it imported the correct one!
Can't thank you enough since it took quite a while to generate and I would have been so sad if I couldn't use it as my daily wallet which it was meant for Tongue

edit: if anyone is curious, this is the address which took me about a day to find on three computers running simultaniously:
bc1qsam00000rymzeeyfwh7f3vcmc5y79fsqam5rc2
legendary
Activity: 2268
Merit: 18771
If I remember correctly, when you import a private key in to BlueWallet it scans all the relevant addresses looking for which one has been used, and then imports that one. If it finds none of them have been used, it defaults to the nested segwit (P2SH-P2WPKH) address, which will start with a 3.

Have you ever used this vanity address? It might be that you need to send some funds to it before you can import it to BlueWallet.

Edit: Just had a look through the code and it looks like I'm right, except it will default to a legacy address beginning with a 1 if it finds no used addresses. You can see the code here if you are interested: https://github.com/BlueWallet/BlueWallet/blob/master/class/wallet-import.js#L250-L268
legendary
Activity: 1092
Merit: 1125
I created a vanity bitcoin address (bc1q...) and just came to realize that I can not import the given private key into my mobile wallet which is weird because blue wallet offers segwit addresses.

The private key starts with "p2wpkh:" and when I import it into electrum, it works and it shows me the correct public key.

However if I try importing the whole key into bluewallet or any other mobile iOS wallet I have tried so far, it never works.
If I leave the "p2wpkh:" out, it just imports a different address. I am not too familiar with the different address types and I couldn't find a solution on the forum or on google so far..

If anyone had the same problem or could tell me how to import my private key correctly, I would really appreciate it!
Jump to: