<p>The format you use depends on how you need to use the private key. Your code produces a raw hex private key, without formatting.</p>

<pre><code>$ node index.js
mnemonic: thunder purchase pave tower lecture upgrade supreme half kid fitness tray shove
addrnodePublicKey: 02ceb48796223dc3777fe210a2034059b5e39b3743e59d62f75ef07a32f8440caf
addernodePrivateKey: 310fe2e677a3ad28acb91d2645bb33882f015ab11e59dce9d2a72905979e3cb6
</code></pre>

<h2>Raw Private Key</h2>

<p>A private key (in bitcoin, i.e. <code>ECDSA SECP256K1</code>) is a 32 byte number between <code>0x1</code> and <code>0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140</code>.</p>

<p>For example:</p>

<p><code>0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D</code></p>

<h2>Wallet Input Format (WIF)</h2>

<p>However, wallet software typically uses the <strong>Wallet Input Format (WIF)</strong> to make it easier to copy over. It uses <code>base58check</code> encoding so it avoids ambiguous characters (like 0 and O), it is shorter, and includes a checksum in case of typos. For example:</p>

<p><code>5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ</code></p>

<h3>WIF Conversion</h3>

<p>The process of converting a raw private key to WIF is outline here: <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Wallet_import_format</a>:</p>

<ul>
<li><p>Take a private key</p>

<p><code>0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D</code></p></li>
<li><p>Add a 0x80 byte in front of it for mainnet addresses or 0xef for testnet addresses. Also add a 0x01 byte at the end if the private key will correspond to a compressed public key</p>

<p><code>800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D</code></p></li>
<li><p>Perform SHA-256 hash on the extended key</p>

<p><code>8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592</code></p></li>
<li><p>Perform SHA-256 hash on result of SHA-256 hash</p>

<p><code>507A5B8DFED0FC6FE8801743720CEDEC06AA5C6FCA72B07C49964492FB98A714</code></p></li>
<li><p>Take the first 4 bytes of the second SHA-256 hash, this is the checksum</p>

<p><code>507A5B8D</code></p></li>
<li><p>Add the 4 checksum bytes from point 5 at the end of the extended key from point 2</p>

<p><code>800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D</code></p></li>
<li><p>Convert the result from a byte string into a base58 string using Base58Check encoding. This is the Wallet Import Format</p>

<p><code>5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ</code></p></li>
</ul>

<p><strong>Potential node.js resources:</strong></p>

<ul>
<li><a href="https://github.com/bitcoinjs/bs58check" rel="nofollow noreferrer">https://github.com/bitcoinjs/bs58check</a></li>
<li><a href="https://www.npmjs.com/package/create-hash" rel="nofollow noreferrer">https://www.npmjs.com/package/create-hash</a></li>
</ul>

CC BY-SA 4.0
2018-09-14T01:02:37.040Z
```% echo 0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D | bx base58check-encode -v 128```
**5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ**
skaht
CC BY-SA 4.0
2018-09-14T01:03:31.283Z
```% echo 0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D01 | bx base58check-encode -v 128```
**KwdMAjGmerYanjeui5SHS7JkmpZvVipYvB2LJGU1ZxJwYvP98617**
skaht
CC BY-SA 4.0
2018-09-12T19:19:00.637Z
2018-09-12T19:19:00.637Z
JBaczuk
<p>Somewhere I answered this already, but coldn't find it anymore... I was confused on the different keys as well, and created <a href="https://i.sstatic.net/IKfmu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IKfmu.png" alt="this graphic"></a> to have a clearer picture:</p>

CC BY-SA 4.0
2018-09-13T19:52:34.603Z
2018-09-13T19:52:34.603Z
pebwindkraft
<p>I wasn't aware of a private key format, however numerous stackoverflow posts hint towards a formatting of some kind</p>

<p><a href="https://bitcoin.stackexchange.com/questions/46443/format-of-private-key">Format of private key</a></p>

<p><a href="https://bitcoin.stackexchange.com/questions/23247/which-private-key-format-is-this">Which private key format is this?</a></p>

<p><a href="https://bitcoin.stackexchange.com/questions/21859/what-encoding-or-format-is-the-private-key-in-dumpprivkey">What encoding or format is the private key in Dumpprivkey?</a></p>

<p>And looking at <a href="https://iancoleman.io/bip39/" rel="nofollow noreferrer">iancoleman/bip39's website</a>, indeed the private key changes as you change the coin, implying that there is at least a format that takes into account version bytes.</p>

<p>However, using <a href="https://github.com/cryptocoinjs/hdkey/blob/master/lib/hdkey.js" rel="nofollow noreferrer">hdkey</a> in js I am unable to reproduce this format, or even the "32-byte big-endian secret parameter" Pieter Wuille describes in the last example.</p>

<pre><code>var bip39 = require('bip39');
var hdkey = require('hdkey');    

const mnemonic = 'thunder purchase pave tower lecture upgrade supreme half kid fitness tray shove'
const seed = bip39.mnemonicToSeed(mnemonic); //creates seed buffer
console.log('mnemonic: ' + mnemonic);

const root = hdkey.fromMasterSeed(seed);
const masterPrivateKey = root.privateKey.toString('hex');

const addrnode = root.derive("m/0'/0");
console.log('addrnodePublicKey: '+ addrnode._publicKey.toString('hex'))
console.log('addernodePrivateKey: ' + addrnode._privateKey.toString('hex'))
</code></pre>

<p>What is the detailed private key format? What does it consist of, how do you derive it from a standard private key? What is it used for compared to the unformatted private key? </p>

<wallet><private-key><wallet-import-format><private-key-format>
What is the private key format?
arshbot
# What is the private key format?

(Asked by: username_0 on 2018-09-12)

I wasn't aware of a private key format, however numerous stackoverflow posts hint towards a formatting of some kind

[Format of private key](https://bitcoin.stackexchange.com/questions/46443/format-of-private-key)

[Which private key format is this?](https://bitcoin.stackexchange.com/questions/23247/which-private-key-format-is-this)

[What encoding or format is the private key in Dumpprivkey?](https://bitcoin.stackexchange.com/questions/21859/what-encoding-or-format-is-the-private-key-in-dumpprivkey)

And looking at [iancoleman/bip39's website](https://iancoleman.io/bip39/), indeed the private key changes as you change the coin, implying that there is at least a format that takes into account version bytes.

However, using [hdkey](https://github.com/cryptocoinjs/hdkey/blob/master/lib/hdkey.js) in js I am unable to reproduce this format, or even the "32-byte big-endian secret parameter" Pieter Wuille describes in the last example.

```
var bip39 = require('bip39');
var hdkey = require('hdkey');    

const mnemonic = 'thunder purchase pave tower lecture upgrade supreme half kid fitness tray shove'
const seed = bip39.mnemonicToSeed(mnemonic); //creates seed buffer
console.log('mnemonic: ' + mnemonic);

const root = hdkey.fromMasterSeed(seed);
const masterPrivateKey = root.privateKey.toString('hex');

const addrnode = root.derive("m/0'/0");
console.log('addrnodePublicKey: '+ addrnode._publicKey.toString('hex'))
console.log('addernodePrivateKey: ' + addrnode._privateKey.toString('hex'))

```

What is the detailed private key format? What does it consist of, how do you derive it from a standard private key? What is it used for compared to the unformatted private key?

**Tags:** wallet, private-key, wallet-import-format, private-key-format


---

## 2 answers

### Answer by username_1 on 2018-09-12. Score: 3

The format you use depends on how you need to use the private key. Your code produces a raw hex private key, without formatting.

```
$ node index.js
mnemonic: thunder purchase pave tower lecture upgrade supreme half kid fitness tray shove
addrnodePublicKey: 02ceb48796223dc3777fe210a2034059b5e39b3743e59d62f75ef07a32f8440caf
addernodePrivateKey: 310fe2e677a3ad28acb91d2645bb33882f015ab11e59dce9d2a72905979e3cb6

```

## Raw Private Key

A private key (in bitcoin, i.e. `ECDSA SECP256K1`) is a 32 byte number between `0x1` and `0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140`.

For example:

`0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D`

## Wallet Input Format (WIF)

However, wallet software typically uses the **Wallet Input Format (WIF)** to make it easier to copy over. It uses `base58check` encoding so it avoids ambiguous characters (like 0 and O), it is shorter, and includes a checksum in case of typos. For example:

`5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ`

### WIF Conversion

The process of converting a raw private key to WIF is outline here: <https://en.bitcoin.it/wiki/Wallet_import_format>:

* Take a private key

  `0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D`
* Add a 0x80 byte in front of it for mainnet addresses or 0xef for testnet addresses. Also add a 0x01 byte at the end if the private key will correspond to a compressed public key

  `800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D`
* Perform SHA-256 hash on the extended key

  `8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592`
* Perform SHA-256 hash on result of SHA-256 hash

  `507A5B8DFED0FC6FE8801743720CEDEC06AA5C6FCA72B07C49964492FB98A714`
* Take the first 4 bytes of the second SHA-256 hash, this is the checksum

  `507A5B8D`
* Add the 4 checksum bytes from point 5 at the end of the extended key from point 2

  `800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D`
* Convert the result from a byte string into a base58 string using Base58Check encoding. This is the Wallet Import Format

  `5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ`

**Potential node.js resources:**

* <https://github.com/bitcoinjs/bs58check>
* <https://www.npmjs.com/package/create-hash>

> **Comments:**
> **username_2**: ```% echo 0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D | bx base58check-encode -v 128``` **5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ**  
> **username_2**: ```% echo 0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D01 | bx base58check-encode -v 128``` **KwdMAjGmerYanjeui5SHS7JkmpZvVipYvB2LJGU1ZxJwYvP98617**  

---

### Answer by username_3 on 2018-09-13. Score: 2

Somewhere I answered this already, but coldn't find it anymore... I was confused on the different keys as well, and created [![this graphic](https://i.sstatic.net/IKfmu.png)](https://i.sstatic.net/IKfmu.png) to have a clearer picture:


---

