<p>The method for deriving child keys from extended keys is specified in <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow noreferrer">BIP 32</a>.</p>

<p>Note that the specific derivation paths for xpubs, ypubs, and zpubs are not defined by BIP 32 but rather are constructions created by Electrum and SatoshiLabs. These have a specific meaning described in <a href="https://github.com/satoshilabs/slips/blob/master/slip-0132.md" rel="nofollow noreferrer">SLIP 132</a>. Their encoding is the same as described for xpubs in BIP 32 but with a different prefix byte.</p>

CC BY-SA 4.0
2019-08-20T17:04:18.320Z
I'm looking for a clearly defined and documented, step-by-step procedure that will take ypub6Ww3ibxVfGzLrAH1PNcjyAWenMTbbAosGNB6VvmSEgytSER9azLDWCxoJwW7Ke7icmizBMXrzBx9979FfaHxHcrArf3zbeJJJUZPf663zsP and successfully derive 37VucYSaXLCAsxYyAPfbSi9eh4iEcbShgf as the payment address indicated by the derivation path of m/49'/0'/0'/0/0. The above test data was computed using Ian Coleman's BIP39 tool with the 12 word seed of "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
EAWF Bob
CC BY-SA 4.0
2022-04-10T16:13:54.250Z
Please consider this question closed as I found the answer [here](https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key). Much appreciation to those who replied.
EAWF Bob
CC BY-SA 4.0
2019-06-11T07:55:40.287Z
2019-06-11T07:55:40.287Z
Ava Chow
<p>I'm trying to understand the HD wallet payment derivation procedure, so assume:</p>

<ul>
<li>Ownership of a Bitcoin HD Wallet on an external smart device</li>
<li>Exported account level extended public key (xpub....) from the first account.</li>
<li>Derivation Path "m/44'/0'/0'/0/0"</li>
</ul>

<p>What is the step-by-step procedure that one would use to derive a valid bitcoin payment address that can be confirmed with the external wallet?</p>

<p>The process, according to <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#public-parent-key--public-child-key" rel="nofollow noreferrer">BIP32 - Child key derivation (CKD) functions</a>, seems simple and straight-forward enough that it should be able to be written as a single function in any programming language with two processes: Base58 and HMAC-SHA512, which are such standard functions that I don't believe that it's necessary to install a platform tool and a bloated spaghetti code library to perform the derivation.</p>

<p>UPDATE 20190718:</p>

<p>Here's what I've been able to cobble together from various sources. PHP code and reference source for the derivation process:</p>

<pre><code>&lt;?php

  // https://iancoleman.io/bip39/ - Downloaded and used offline.
  // Bip39 Test Mnemonic: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about

 $Pub = "xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";

 $Index = "00000000";

 $ExtPubKey = bin2hex(base58_decode($Pub));

 $Type = substr($ExtPubKey,0,8);

 $Depth = substr($ExtPubKey,8,2);

 $Fingerprint = substr($ExtPubKey,10,8);

 $Account = substr($ExtPubKey,18,8);

 $ParentChainCode = substr($ExtPubKey,26,64);

 $ParentPublicKey = substr($ExtPubKey,90,66);

 $PubChecksum = substr($ExtPubKey,-8);

 $PublicKey = hash_hmac('sha512',$ParentChainCode,$ParentPublicKey.$Index);

 $PublicKey = "04".$PublicKey;

 $PublicKeyHash = hash('ripemd160',hash('sha256',$PublicKey,False));

 $BaseAddress = "00".$PublicKeyHash;

 $PreChecksum = hash('sha256',hash('sha256',$BaseAddress));

 $Checksum = substr($PreChecksum,0,8);

 $Address = $BaseAddress.$Checksum;

 $PaymentAddress = base58_encode(hex2bin($Address));

 echo "Payment Address: $PaymentAddress\n";

?&gt;

</code></pre>

<p>I'm using xpub to prove that the procedure works. Ultimately would like to be able to derive for ypub and zpub.</p>

<p>It seems like I'm just missing something important, like maybe variable typing, maybe binary something...I'm at a loss.</p>

<p>I've been told by Andreas that there's something about adding two numbers together, but I'm not finding the reference to it.</p>

<p>One source referenced something about elliptic curve and a mystical variable "G" but with no explanation.</p>

<p>According to BIP32, this process is supposed to be really easy.</p>

<p>Any assistance would be appreciated. TIA.</p>

CC BY-SA 4.0
2022-04-07T17:43:43.730Z
There are hundreds of open-source projects that do exactly this. Dozens that are trusted by experts, used in mainstream production by millions. Step through, parsing these libraries rather than expecting others to walk you through the process.
HansBKK
<address-generation><bip32-hd-wallets><bip44>
Procedure for Deriving Payment Addresses
EAWF Bob
# Procedure for Deriving Payment Addresses

(Asked by: username_0 on 2019-06-10)

I'm trying to understand the HD wallet payment derivation procedure, so assume:

* Ownership of a Bitcoin HD Wallet on an external smart device
* Exported account level extended public key (xpub....) from the first account.
* Derivation Path "m/44'/0'/0'/0/0"

What is the step-by-step procedure that one would use to derive a valid bitcoin payment address that can be confirmed with the external wallet?

The process, according to [BIP32 - Child key derivation (CKD) functions](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#public-parent-key--public-child-key), seems simple and straight-forward enough that it should be able to be written as a single function in any programming language with two processes: Base58 and HMAC-SHA512, which are such standard functions that I don't believe that it's necessary to install a platform tool and a bloated spaghetti code library to perform the derivation.

UPDATE 20190718:

Here's what I've been able to cobble together from various sources. PHP code and reference source for the derivation process:

```
<?php

  // https://iancoleman.io/bip39/ - Downloaded and used offline.
  // Bip39 Test Mnemonic: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about

 $Pub = "xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";

 $Index = "00000000";

 $ExtPubKey = bin2hex(base58_decode($Pub));

 $Type = substr($ExtPubKey,0,8);

 $Depth = substr($ExtPubKey,8,2);

 $Fingerprint = substr($ExtPubKey,10,8);

 $Account = substr($ExtPubKey,18,8);

 $ParentChainCode = substr($ExtPubKey,26,64);

 $ParentPublicKey = substr($ExtPubKey,90,66);

 $PubChecksum = substr($ExtPubKey,-8);

 $PublicKey = hash_hmac('sha512',$ParentChainCode,$ParentPublicKey.$Index);

 $PublicKey = "04".$PublicKey;

 $PublicKeyHash = hash('ripemd160',hash('sha256',$PublicKey,False));

 $BaseAddress = "00".$PublicKeyHash;

 $PreChecksum = hash('sha256',hash('sha256',$BaseAddress));

 $Checksum = substr($PreChecksum,0,8);

 $Address = $BaseAddress.$Checksum;

 $PaymentAddress = base58_encode(hex2bin($Address));

 echo "Payment Address: $PaymentAddress\n";

?>

```

I'm using xpub to prove that the procedure works. Ultimately would like to be able to derive for ypub and zpub.

It seems like I'm just missing something important, like maybe variable typing, maybe binary something...I'm at a loss.

I've been told by Andreas that there's something about adding two numbers together, but I'm not finding the reference to it.

One source referenced something about elliptic curve and a mystical variable "G" but with no explanation.

According to BIP32, this process is supposed to be really easy.

Any assistance would be appreciated. TIA.

**Tags:** address-generation, bip32-hd-wallets, bip44

> **Comments:**
> **username_1**: There are hundreds of open-source projects that do exactly this. Dozens that are trusted by experts, used in mainstream production by millions. Step through, parsing these libraries rather than expecting others to walk you through the process.  

---

## 1 answers

### Answer by username_2 on 2019-06-11. Score: 0

The method for deriving child keys from extended keys is specified in [BIP 32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki).

Note that the specific derivation paths for xpubs, ypubs, and zpubs are not defined by BIP 32 but rather are constructions created by Electrum and SatoshiLabs. These have a specific meaning described in [SLIP 132](https://github.com/satoshilabs/slips/blob/master/slip-0132.md). Their encoding is the same as described for xpubs in BIP 32 but with a different prefix byte.

> **Comments:**
> **username_0**: I'm looking for a clearly defined and documented, step-by-step procedure that will take ypub6Ww3ibxVfGzLrAH1PNcjyAWenMTbbAosGNB6VvmSEgytSER9azLDWCxoJwW7Ke7icmizBMXrzBx9979FfaHxHcrArf3zbeJJJUZPf663zsP and successfully derive 37VucYSaXLCAsxYyAPfbSi9eh4iEcbShgf as the payment address indicated by the derivation path of m/49'/0'/0'/0/0. The above test data was computed using Ian Coleman's BIP39 tool with the 12 word seed of "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"  
> **username_0**: Please consider this question closed as I found the answer [here](https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key). Much appreciation to those who replied.  

---

