0

The scenario is this:

User has a cold storage wallet and will import their cold storage xpub into Bitcoin Core using getdescriptorinfo and importmulti. User wants to only use the keys associated with the imported xpub as a watch-only wallet and wants to exclude all existing keys in the wallet so as to avoid getting an address not associated with their xpub when calling getnewaddress or getrawchangeaddress.

Would the best way to go about this be to create a blank wallet first with:

createwallet "Cold Storage", disable_private_keys: true, blank: true?

Or is there a simpler way to specify which addresses are generated when calling getnewaddress?

2 Answers 2

2

Yes, you will want to create a new wallet and specify true for disable_private_keys. It is not necessary to specify blank as disable_private_keys will already ensure that no private keys will be generated or imported and as such, the newly created wallet will be blank anyways.

You can then import xpubs, public keys, and addresses into Bitcoin Core using importmulti. By setting "keypool":true for every public key, the keys will be added to Bitcoin Core's keypool and allow you to use getnewaddress to get addresses. Additionally, for change keys, specifying "internal":true will mark change keys as change and allow you to use getrawchangeaddress, fundrawtransaction, and walletcreatefundedpsbt more easily.

However, be careful when importing an xpub that you use the correct derivation paths. If the child keys that you will eventually be using are derived using hardened derivation, you cannot import an xpub as hardened child keys can only be derived from the master private key. In that case, you will have to import each key by itself, which can also be done using importmulti.

0
0

User has a cold storage wallet. User wants to import their xpub into Bitcoin Core and only use the keys associated with the imported xpub as a watch-only wallet.

You must pay attention about the xpub you are talking about and how bitcore core handle HD wallet.
If you already got an xpub, it means it has been generated and derivated from a mnemonic(most likely seed phrase BIP39) with a specific path (BIP44 for xpub -> legacy, BIP49 for ypub -> segwit compatible p2sh(p2wpkh)).

If you restore an xpub which follows BIP44 in electrum for instance no worries. However you simply can't do it in bitcoin core as their derivation path are specific to BIP32 if I'm correct (or their own choice see list) and not BIP44. It means if you got btcs within the xpub following BIP44 you will not find them in bitcoin core and if you use bitcore core new address from your xpub and import it to another wallet you probably won't detect your btc.

Also note that when talking about extended public key for export/import, by convention it's about an extended public keys after harden derivation.

Regarding your initial question, I suggestion to play around rpc and read its commands as you can definitively do it, but stay aware about wallet interoperability...

3
  • I understand how to import a BIP84 or BIP44 xpub and derive the keys correctly, my question is how to properly clear the wallet so the keypool does not clash with my imported keys or at least ensure I derive the Cold Storage address on demand. So that when I call getnewaddress I will be guaranteed to get one of my cold storage addresses. Its a lot to experiment with and I am building an app so want to make sure I do it 100% correctly. I will edit the original question to clarify.
    – Fontaine
    May 10, 2019 at 15:02
  • This is not an answer to the question; OP asks about importmulti which can (albeit in a roundabout way) import any kind of derivation. May 10, 2019 at 17:01
  • Was not aim to solve OP's question, just a little "heads-up" about wallet interoperability.. perhaps I should have simply avoid this ^^
    – onepix
    May 11, 2019 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.