<blockquote>
  <p>Given the XPub and an address, can I write an algorithm to say whether or not that public key was derived from that XPub and consequently belongs to the same user?</p>
</blockquote>

<p>[Edit: my terminology was off, answer edited substantially to be correct]</p>

<p>Given the xpub and an address, you would indeed be able to discern whether the two are related. </p>

<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#Extended_keys" rel="nofollow noreferrer">BIP32</a> is the specification that describes hierarchical deterministic (HD) wallets. To extend a parent public key, it is combined with the chain code and the index, then hashed through HMAC-SHA512. The hash output is split in two, and the 'left half of the hash' is added to the parent public key, to produce the child public key. </p>

<p>So by knowing the xpub (parent public key + chaincode), you can write an algorithm to determine if the two addresses have a parent/child relationship, and you would be able to find additional child addresses.</p>

<p>Without the xpub, remember that BIP32 derived keys are otherwise indistinguishable from any other keys. So you can not just look at an arbitrary address and know with certainty how it was derived. </p>

CC BY-SA 3.0
2018-04-03T02:07:59.060Z
The xpub includes the chaincode.
Pieter Wuille
CC BY-SA 3.0
2018-04-03T02:22:27.720Z
@PieterWuille my mistake, I've edited my answer to be more correct
chytrik
CC BY-SA 3.0
2018-01-16T21:13:51.417Z
2018-04-03T02:21:41.803Z
2018-04-03T02:21:41.803Z
chytrik
<p>Given the XPub and an address, can I write an algorithm to say whether or not that public key was derived from that XPub and consequently belongs to the same user?</p>

CC BY-SA 3.0
2018-01-16T03:21:29.247Z
You'll need to clarify your question, what do you mean by *"all of the addresses on the blockchain"*? An xpub can generate child pub keys: an example use case would be a business's server providing payment addresses to customers, without requiring any private keys to be stored on that server.
chytrik
CC BY-SA 3.0
2018-01-16T13:26:11.283Z
@chytrik Hey made some clarifications, thanks for the comment
Kyle Graham
<blockchain><bitcoin-core><xpub>
How do I use the XPub to generate the Public addresses
Kyle Graham
# How do I use the XPub to generate the Public addresses

(Asked by: username_0 on 2018-01-16)

Given the XPub and an address, can I write an algorithm to say whether or not that public key was derived from that XPub and consequently belongs to the same user?

**Tags:** blockchain, bitcoin-core, xpub

> **Comments:**
> **username_1**: You'll need to clarify your question, what do you mean by *"all of the addresses on the blockchain"*? An xpub can generate child pub keys: an example use case would be a business's server providing payment addresses to customers, without requiring any private keys to be stored on that server.  
> **username_0**: @username_1 Hey made some clarifications, thanks for the comment  

---

## 1 answers

### Answer by username_1 on 2018-01-16. Score: 2

> Given the XPub and an address, can I write an algorithm to say whether or not that public key was derived from that XPub and consequently belongs to the same user?

[Edit: my terminology was off, answer edited substantially to be correct]

Given the xpub and an address, you would indeed be able to discern whether the two are related.

[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#Extended_keys) is the specification that describes hierarchical deterministic (HD) wallets. To extend a parent public key, it is combined with the chain code and the index, then hashed through HMAC-SHA512. The hash output is split in two, and the 'left half of the hash' is added to the parent public key, to produce the child public key.

So by knowing the xpub (parent public key + chaincode), you can write an algorithm to determine if the two addresses have a parent/child relationship, and you would be able to find additional child addresses.

Without the xpub, remember that BIP32 derived keys are otherwise indistinguishable from any other keys. So you can not just look at an arbitrary address and know with certainty how it was derived.

> **Comments:**
> **username_2**: The xpub includes the chaincode.  
> **username_1**: @username_2 my mistake, I've edited my answer to be more correct  

---

