How do I export an xpub from Bitcoin Core for use in BTCPayServer?

2

I'm using Bitcoin Core 0.17, and using bitcoin-cli getaddressinfo method to extract xpub for a given address.

This xpub is 66 characters long, and I'm using BTCPayServer which needs this xpub and I've to select one of the following address type corresponding to this:

  • P2WPKH
  • P2SH-P2WPKH
  • P2PKH

What I'm trying to do : I'm trying to link my wallet to BTCPayServer, in order to do so their admin panel needs an input for xpub and it also asks to specify the exact format of that xpub/derivation scheme. I don't want to use a wallet like electrum so I'm creating my own private keys through bitcoin-cli

enter image description here

WhoIsNinja

Posted 2019-09-01T03:26:08.400

Reputation: 123

1Maybe first explain what you're trying to do.Pieter Wuille 2019-09-01T06:25:01.003

I've edited my question, added screenshot where this information is to be inputWhoIsNinja 2019-09-01T06:51:49.753

Answers

4

This is not currently possible, as Bitcoin Core uses hardened BIP32 derivation to compute keys and addresses. This derivation scheme does not have a usable xpub that lets you derive the same keys publicly.

For more background, an xpub (or extended public key) is a string defined by BIP32. Every xpub has a corresponding xprv (extended private key). From the xpub one can derive a large number of child public keys, whose private keys can be derived from the corresponding xprv. This permits watching a large number of addresses without explicitly transferring all public keys.

The downside is that the xpub derivation scheme has a weakness: if an attacker knows the private key of any of the child keys and the xpub, he can compute the private key of all child keys. Because of this corcern, Bitcoin Core does not currently support xpub-compatible key derivation.

This will likely change in a future version with the introduction of descriptor wallets, which are far more flexible in specifying what keys and addresses belong to the wallet.

Pieter Wuille

Posted 2019-09-01T03:26:08.400

Reputation: 54 032

understood, that makes sense. so now, if I still want to link it to my bitcoin-cli generated xpub. What's the best way to convert that 66 char xpub to one of the desired formats using a tool or wallet ? (I understand it will be less secure)WhoIsNinja 2019-09-02T02:59:40.463

2You can't convert it. This functionality is simply not possible; the keys generated by Bitcoin Core cannot be predicted by an xpub. You can use other wallet software, however.Pieter Wuille 2019-09-02T03:10:03.043