<p>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.</p>

<p>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.</p>

<p>The downside is that the xpub derivation scheme has a weakness: if an attacker knows the private key of <em>any</em> 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.</p>

<p>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.</p>

CC BY-SA 4.0
2019-09-02T02:59:40.463Z
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
CC BY-SA 4.0
2019-09-02T03:10:03.043Z
You 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
CC BY-SA 4.0
2022-08-13T21:45:46.453Z
Time to update this answer? I think with `listdescriptors` RPC it's possible.
rustyx
CC BY-SA 4.0
2019-09-01T17:40:06.240Z
2019-09-01T17:40:06.240Z
Pieter Wuille
<p>I'm using Bitcoin Core 0.17, and using bitcoin-cli getaddressinfo method to extract xpub for a given address.</p>

<p>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:</p>

<ul>
<li>P2WPKH</li>
<li>P2SH-P2WPKH</li>
<li>P2PKH</li>
</ul>

<p>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</p>

<p><a href="https://i.sstatic.net/VwgZJ.png" rel="noreferrer"><img src="https://i.sstatic.net/VwgZJ.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-09-01T06:25:01.003Z
Maybe first explain what you're trying to do.
Pieter Wuille
CC BY-SA 4.0
2019-09-01T06:51:49.753Z
I've edited my question, added screenshot where this information is to be input
WhoIsNinja
<bitcoin-core><address><client>
How do I export an xpub from Bitcoin Core for use in BTCPayServer?
WhoIsNinja
# How do I export an xpub from Bitcoin Core for use in BTCPayServer?

(Asked by: username_0 on 2019-09-01)

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](https://i.sstatic.net/VwgZJ.png)](https://i.sstatic.net/VwgZJ.png)

**Tags:** bitcoin-core, address, client

> **Comments:**
> **username_1**: Maybe first explain what you're trying to do.  
> **username_0**: I've edited my question, added screenshot where this information is to be input  

---

## 1 answers

### Answer by username_1 on 2019-09-01. Score: 16 | Accepted answer

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.

> **Comments:**
> **username_0**: 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)  
> **username_1**: You 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.  
> **username_2**: Time to update this answer? I think with `listdescriptors` RPC it's possible.  

---

