<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CodeShark</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CodeShark"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/CodeShark"/>
	<updated>2026-05-17T08:31:31Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63452</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63452"/>
		<updated>2017-06-17T02:53:57Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please add a row for yourself to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr for help if you get caught in the anti-spam.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{AccJuly}} || it is a workable solution, provided it is activated before August 1 (and therefore BIP148-compatible)&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! rowspan=2 | Aff* &amp;lt;!-- Using one year before the the creation date of this page as the benchmark. Do not list yourself as affiliated with a project that you haven&#039;t made meaningful contributions to since then.  --&amp;gt;&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| Karl-Johan Alm || Core || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Bryan Bishop || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || Core || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || Core || {{Prefer}} || {{No}} || || {{Acceptable}} || {{No|LOL}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || Core || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || c-lightning || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{AccJuly}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Thaddeus Dryja || lit || {{Prefer}} || {{No}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || Core || {{Prefer}} || {{Deficient}} || {{Prefer}} || {{Deficient}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || BIP 68/112 || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{No|LOL}} || {{No|Nope}}&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || Core || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || Core || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{AccJuly}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Laolu &amp;quot;roasbeef&amp;quot; Osuntokun || lnd || {{Prefer}} || || || || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavol &amp;quot;stick&amp;quot; Rusnak || Trezor || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || c-lightning || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Gregory Sanders || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Paul Sztorc ||  || {{Prefer}} || {{Deficient}} || {{Wanting}} || {{AccJuly}} || {{Evaluating}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || Core || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || Core || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Warren Togami || Elements || {{Prefer}} || {{Prefer}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Leo Wandersleb || Mycelium || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || Core || {{Prefer}} || || || || {{No}} ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;affiliation&amp;quot; is an optional field for the company or project the individual is associated with, that most qualifies the person to comment on the matter and is not meant as a company or project endorsement of the individual&#039;s position.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;When adding companies below, sources for each position MUST be provided.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Company &lt;br /&gt;
! rowspan=2 | Service&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| Abra || wallet || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitcoin India || exchange/miner || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| BitcoinReminder.com || service || {{Prefer}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;&amp;gt;[https://bitcoinreminder.com/informations/poli BitcoinReminder.com&#039;s position on scaling proposals]&amp;lt;/ref&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;/&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;/&amp;gt; || {{Weak}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;/&amp;gt; || {{No|LOL}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;/&amp;gt; || {{No}}&amp;lt;ref name=&amp;quot;bitcoinreminder_com&amp;quot;/&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Bitfinex || exchange || {{Acceptable}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitfury || miner || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Acceptable}} || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitmain || miner || {{AccJuly}}&amp;lt;ref name=&amp;quot;bitmain&amp;quot;&amp;gt;[https://blog.bitmain.com/en/uahf-contingency-plan-uasf-bip148/ Bitmain&#039;s plot against BIP148]&amp;lt;/ref&amp;gt; || {{No}} || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;bitmain&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitonic/BL3P.eu || exchange || {{Prefer}}&amp;lt;ref name=&amp;quot;bitonic&amp;quot;&amp;gt;[https://bitonic.nl/en/news/138/our-position-on-scaling-proposals Bitonic&#039;s position on scaling proposals]&amp;lt;/ref&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;bitonic&amp;quot;/&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;bitonic&amp;quot;/&amp;gt; || {{Weak}}&amp;lt;ref name=&amp;quot;bitonic&amp;quot;/&amp;gt; || {{No|LOL}}&amp;lt;ref name=&amp;quot;bitonic&amp;quot;/&amp;gt; || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Bitpay || wallet || {{Prefer}}&amp;lt;ref name=&amp;quot;bccore_swadoption&amp;quot;/&amp;gt; || {{No}} || || {{Prefer}} || {{Prefer}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitrated || || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitrefill || merchant || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitsquare || exchange || {{Prefer}} || {{Prefer}}&amp;lt;ref name=&amp;quot;bitsquare&amp;quot;&amp;gt;[https://forum.bitsquare.io/t/bitsquare-will-support-uasf-bitcoin-not-bitmaincoin/2265 Bitsquare will support UASF Bitcoin not BitMainCoin]&amp;lt;/ref&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;bitsquare&amp;quot;/&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitstamp || exchange || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bittylicious || exchange || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref&amp;gt;[https://twitter.com/Bittylicious_/status/867305106668224513 Bittylicious answer on Twitter]&amp;lt;/ref&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Blockchain.info || wallet || {{Acceptable}}&amp;lt;ref name=&amp;quot;bccore_swadoption&amp;quot;/&amp;gt; || || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; || &lt;br /&gt;
|-&lt;br /&gt;
| blockonomics || || {{Prefer}} || {{Prefer}}&amp;lt;ref&amp;gt;[https://twitter.com/blockonomics_co/status/851738251509497856 blockonomics announcement on Twitter]&amp;lt;/ref&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Bustabit|| gambling || {{Prefer}}&amp;lt;ref name=&amp;quot;bustabit&amp;quot;&amp;gt;[https://www.bustabit.com/statement-on-forks Bustabit Statement on Bitcoin Forks]&amp;lt;/ref&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;bustabit&amp;quot;/&amp;gt; || || || {{AccJuly}}&amp;lt;ref name=&amp;quot;bustabit&amp;quot;/&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Ciphrex || wallet / dev stack || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Coinbase || wallet || {{Acceptable}}&amp;lt;ref name=&amp;quot;bccore_swadoption&amp;quot;/&amp;gt; || || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; || &lt;br /&gt;
|-&lt;br /&gt;
| CoinGate || exchange || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| CoinJar || wallet || || {{Evaluating}}&amp;lt;ref&amp;gt;[https://twitter.com/GetCoinJar/status/875581525730787329 CoinJar answer on Twitter]&amp;lt;/ref&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Coinkite || || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| coinomi || wallet || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| DigitalBitbox || wallet(hardware) || {{Prefer}} || {{Acceptable}} || {{Prefer}}|| || ||&lt;br /&gt;
|-&lt;br /&gt;
| Electrum || wallet || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Kraken || exchange || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| LightningASIC || miner || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| OneHash || betting || {{Prefer}}&amp;lt;ref&amp;gt;[https://blog.onehash.com/sick-of-presidential-election-3f1a2defbbbf OneHash, &amp;quot;Sick of presidential election ?!&amp;quot;]&amp;lt;/ref&amp;gt; || || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Slushpool || miner || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Vaultoro || exchange || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Acceptable}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || {{AccJuly}} || {{AccJuly}}&amp;lt;ref name=&amp;quot;silbert&amp;quot; /&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| Walltime || || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Xapo || wallet || {{Prefer}}&amp;lt;ref name=&amp;quot;coindance&amp;quot; /&amp;gt; || || || {{Prefer}} || {{Prefer}}&amp;lt;ref&amp;gt;[https://twitter.com/tedmrogers/status/867362691370954752 Tweet by president of Xapo]&amp;lt;/ref&amp;gt; || &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;bccore_swadoption&amp;quot;&amp;gt;[https://bitcoincore.org/en/segwit_adoption/ Bitcoin Core&#039;s Segwit adoption list]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;coindance&amp;quot;&amp;gt;[https://coin.dance/poli Coin Dance, &amp;quot;Global Bitcoin Political Support &amp;amp; Public Opinion&amp;quot;]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;silbert&amp;quot;&amp;gt;[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77 Digital Currency Group, &amp;quot;Bitcoin Scaling Agreement at Consensus 2017&amp;quot;]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63415</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63415"/>
		<updated>2017-06-16T01:32:37Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please add a row for yourself to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr for help if you get caught in the anti-spam.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{AccJuly}} || it is a workable solution, provided it is activated before August 1 (and therefore BIP148-compatible)&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 colspan=2 | Developer &amp;amp; affiliation* &amp;lt;!-- Using one year before the the creation date of this page as the benchmark. Do not list yourself as affiliated with a project that you haven&#039;t made meaningful contributions to since then.  --&amp;gt;&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| Karl-Johan Alm || Core || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Bryan Bishop || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || Core || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || Core || {{Prefer}} || {{No}} || || {{Acceptable}} || {{No|LOL}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || Core || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{Evaluating}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || Core || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{AccJuly}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Thaddeus Dryja || lit || {{Prefer}} || {{No}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || Core || {{Prefer}} || {{Deficient}} || {{Prefer}} || {{Deficient}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || BIP 68/112 || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{No|LOL}} || {{No|Nope}}&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || Core || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || Core || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{AccJuly}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavol &amp;quot;stick&amp;quot; Rusnak || Trezor || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || c-lightning || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Gregory Sanders || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || Core || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || Core || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Warren Togami || Elements || {{Prefer}} || {{Prefer}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Leo Wandersleb || Mycelium || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || Core || {{Prefer}} || || || || {{No}} ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;affiliation&amp;quot; is an optional field for the company or project the individual is associated with, that most qualifies the person to comment on the matter and is not meant as a company or project endorsement of the individual&#039;s position.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 colspan=2 | Company &lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| Bitfury || miner || {{Prefer}}[https://coin.dance/poli] || {{Acceptable}} || || || {{AccJuly}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitsquare || exchange || {{Prefer}} || {{Prefer}}[https://forum.bitsquare.io/t/bitsquare-will-support-uasf-bitcoin-not-bitmaincoin/2265] || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Coinbase || wallet || {{Prefer}}[https://bitcoincore.org/en/segwit_adoption/] || {{Evaluating}} || {{Weak}}  ||  || {{AccJuly}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  || &lt;br /&gt;
|-&lt;br /&gt;
| Xapo || wallet || {{Prefer}}[https://coin.dance/poli] || {{Evaluating}} ||  ||  || {{AccJuly}}[https://twitter.com/tedmrogers/status/867362691370954752]  || &lt;br /&gt;
|-&lt;br /&gt;
| Blockchain.info || wallet || {{Prefer}}[https://bitcoincore.org/en/segwit_adoption/]  || {{Evaluating}} || {{Weak}} ||  || {{AccJuly}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  || &lt;br /&gt;
|-&lt;br /&gt;
| Kraken || exchange || {{Prefer}}[https://coin.dance/poli] || {{Acceptable}}  || ||  || {{AccJuly}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitstamp|| exchange  || {{Prefer}}[https://coin.dance/poli] || {{Acceptable}}  || ||  || {{Acceptable}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitfinex|| exchange  || {{Prefer}}[https://coin.dance/poli] || {{Acceptable}}  || ||  || {{Acceptable}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitonic/BL3P.eu || exchange || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No|LOL}} || {{No}} &amp;lt;!-- rep on slack said they will provide a source June 16th --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Bitpay|| wallet || {{Prefer}}[https://bitcoincore.org/en/segwit_adoption/] || {{No}} || ||  || {{Prefer}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Localbitcoins|| exchange || {{Prefer}}[https://bitcoincore.org/en/segwit_adoption/] || {{Acceptable}} || {{Weak}} ||  || {{AccJuly}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Poloniex|| exchange || {{Prefer}}[https://coin.dance/poli] || {{Wanting}} || ||  || {{AccJuly}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Bitmain|| miner || {{No}} || {{No}} || ||  || {{Prefer}} ||&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| Vaultoro|| gold exchange || {{Prefer}}[https://coin.dance/poli] || {{Acceptable}}  || ||  || {{Acceptable}}[https://medium.com/@DCGco/bitcoin-scaling-agreement-at-consensus-2017-133521fe9a77]  ||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63358</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63358"/>
		<updated>2017-06-14T06:10:05Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please add a row for yourself to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr for help if you get caught in the anti-spam.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{AccJuly}} || it is a workable solution, provided it is activated before August 1 (and therefore BIP148-compatible)&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 colspan=2 | Developer &amp;amp; affiliation* &amp;lt;!-- Using one year before the the creation date of this page as the benchmark. Do not list yourself as affiliated with a project that you haven&#039;t made meaningful contributions to since then.  --&amp;gt;&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || Core || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Bryan Bishop || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || Core || {{Prefer}} || {{No}} || || {{Acceptable}} || {{No|LOL}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || Core || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || Core || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || Core || {{Prefer}} || {{Deficient}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || Core || {{Prefer}} || {{Deficient}} || {{Prefer}} || {{Deficient}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || BIP 68/112 || {{Prefer}} || {{Prefer}} || {{No}} || {{AccJuly}} || {{No|LOL}} || {{No|Nope}}&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || Core || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || Core || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || Core || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavol &amp;quot;stick&amp;quot; Rusnak || Trezor || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || c-lightning || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Gregory Sanders || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || Core || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || Core || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || Core || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Warren Togami || Elements || {{Prefer}} || {{Prefer}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || Core || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| flix1 || || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{Deficient}} || {{Evaluating}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Leo Wandersleb || Mycelium || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || Core || {{Prefer}} || || || || {{No}} ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;affiliation&amp;quot; is an optional field for the company or project the individual is associated with, that most qualifies the person to comment on the matter and is not meant as a company or project endorsement of the individual&#039;s position.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63136</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63136"/>
		<updated>2017-06-10T09:57:06Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please edit your row (add one if you&#039;re missing) to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr to give it access.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Deficient}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Gregory Sanders || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || {{Wanting}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} ||  || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{Evaluating}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63135</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63135"/>
		<updated>2017-06-10T09:55:04Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please edit your row (add one if you&#039;re missing) to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr to give it access.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Deficient}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Gregory Sanders || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || {{Wanting}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} ||  || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{Evaluating}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62820</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62820"/>
		<updated>2017-06-05T11:31:18Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{Weak}} || {{Acceptable}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Acceptable}} || {{Evaluating}} || {{No}} || {{Evaluating}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{No}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || {{Prefer}} || {{Wanting}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || || ||&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62819</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62819"/>
		<updated>2017-06-05T10:24:44Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{Weak}} || {{Acceptable}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Prefer}} || {{Evaluating}} || {{Weak}} || {{Evaluating}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{No}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || {{Prefer}} || {{Wanting}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || || ||&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62800</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62800"/>
		<updated>2017-06-04T04:39:28Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Yes}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Prefer}} || {{Yes}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Yes}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{Weak}} || {{Yes}} || {{No}} || {{Yes}}&lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Prefer}} || {{Evaluating}} || {{Yes}} || {{Evaluating}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{No}} || {{Yes}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Yes}} || {{Yes}} || || ||&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62799</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=62799"/>
		<updated>2017-06-04T04:35:15Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Yes}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Prefer}} || {{Yes}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Yes}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{Weak}} || {{Yes}} || {{No}} || {{Yes}}&lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{No}} || {{Yes}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Yes}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pieter Wuille || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Yes}} || {{Yes}} || || ||&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=41624</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=41624"/>
		<updated>2013-10-09T10:12:43Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Implementations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
* [25 May 2013] Added test vectors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Accepted&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes [[Deterministic Wallet|hierarchical determinstic wallets]] (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall denote the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: private and public.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n or k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 0, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n or K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is the point at infinity, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external [[keychain]] is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
For more detailed information about these (such as intermediate values and other representations), see [[BIP_0032_TestVectors]]&lt;br /&gt;
&lt;br /&gt;
Test vector 1&lt;br /&gt;
&lt;br /&gt;
  Master (hex): 000102030405060708090a0b0c0d0e0f&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi&lt;br /&gt;
  * [Chain m/0&#039;]&lt;br /&gt;
    * ext pub: xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw&lt;br /&gt;
    * ext prv: xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7&lt;br /&gt;
  * [Chain m/0&#039;/1]&lt;br /&gt;
    * ext pub: xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ&lt;br /&gt;
    * ext prv: xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;]&lt;br /&gt;
    * ext pub: xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5&lt;br /&gt;
    * ext prv: xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV&lt;br /&gt;
    * ext prv: xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2/1000000000]&lt;br /&gt;
    * ext pub: xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy&lt;br /&gt;
    * ext prv: xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76&lt;br /&gt;
&lt;br /&gt;
Test vector 2&lt;br /&gt;
&lt;br /&gt;
  Master (hex): fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U&lt;br /&gt;
  * [Chain m/0]&lt;br /&gt;
    * ext pub: xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH&lt;br /&gt;
    * ext prv: xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt&lt;br /&gt;
  * [Chain m/0/2147483647&#039;]&lt;br /&gt;
    * ext pub: xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a&lt;br /&gt;
    * ext prv: xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1]&lt;br /&gt;
    * ext pub: xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon&lt;br /&gt;
    * ext prv: xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;]&lt;br /&gt;
    * ext pub: xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL&lt;br /&gt;
    * ext prv: xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt&lt;br /&gt;
    * ext prv: xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j&lt;br /&gt;
&lt;br /&gt;
==Implementations==&lt;br /&gt;
&lt;br /&gt;
A Python implementation is available at https://github.com/richardkiss/pycoin&lt;br /&gt;
&lt;br /&gt;
A Java implementation is available at https://github.com/bitsofproof/supernode/blob/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java&lt;br /&gt;
&lt;br /&gt;
A C++ implementation is available at https://github.com/CodeShark/CoinClasses/tree/master/tests/hdwallets&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=41599</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=41599"/>
		<updated>2013-10-08T10:48:13Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
* [25 May 2013] Added test vectors&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Accepted&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes [[Deterministic Wallet|hierarchical determinstic wallets]] (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall denote the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: private and public.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n or k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = 0, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n or K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is the point at infinity, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external [[keychain]] is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
For more detailed information about these (such as intermediate values and other representations), see [[BIP_0032_TestVectors]]&lt;br /&gt;
&lt;br /&gt;
Test vector 1&lt;br /&gt;
&lt;br /&gt;
  Master (hex): 000102030405060708090a0b0c0d0e0f&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi&lt;br /&gt;
  * [Chain m/0&#039;]&lt;br /&gt;
    * ext pub: xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw&lt;br /&gt;
    * ext prv: xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7&lt;br /&gt;
  * [Chain m/0&#039;/1]&lt;br /&gt;
    * ext pub: xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ&lt;br /&gt;
    * ext prv: xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;]&lt;br /&gt;
    * ext pub: xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5&lt;br /&gt;
    * ext prv: xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV&lt;br /&gt;
    * ext prv: xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334&lt;br /&gt;
  * [Chain m/0&#039;/1/2&#039;/2/1000000000]&lt;br /&gt;
    * ext pub: xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy&lt;br /&gt;
    * ext prv: xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76&lt;br /&gt;
&lt;br /&gt;
Test vector 2&lt;br /&gt;
&lt;br /&gt;
  Master (hex): fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542&lt;br /&gt;
  * [Chain m]&lt;br /&gt;
    * ext pub: xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB&lt;br /&gt;
    * ext prv: xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U&lt;br /&gt;
  * [Chain m/0]&lt;br /&gt;
    * ext pub: xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH&lt;br /&gt;
    * ext prv: xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt&lt;br /&gt;
  * [Chain m/0/2147483647&#039;]&lt;br /&gt;
    * ext pub: xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a&lt;br /&gt;
    * ext prv: xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1]&lt;br /&gt;
    * ext pub: xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon&lt;br /&gt;
    * ext prv: xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;]&lt;br /&gt;
    * ext pub: xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL&lt;br /&gt;
    * ext prv: xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc&lt;br /&gt;
  * [Chain m/0/2147483647&#039;/1/2147483646&#039;/2]&lt;br /&gt;
    * ext pub: xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt&lt;br /&gt;
    * ext prv: xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j&lt;br /&gt;
&lt;br /&gt;
==Implementations==&lt;br /&gt;
&lt;br /&gt;
A Python implementation is available at https://github.com/richardkiss/pycoin&lt;br /&gt;
&lt;br /&gt;
A Java implementation is available at https://github.com/bitsofproof/supernode/blob/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java&lt;br /&gt;
&lt;br /&gt;
A C++ implementation is available at https://github.com/CodeShark/CoinClasses/tree/master/tests&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40544</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40544"/>
		<updated>2013-08-28T09:19:06Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* pong */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sources:&lt;br /&gt;
* [[Original Bitcoin client]] source&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[Getwork]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For ECDSA the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Scripting]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totaling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xfd || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffff || 3 || 0xfd followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffffffff || 5 || 0xfe followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xff followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used.  This protocol and structure supports IPv6, &#039;&#039;&#039;but note that the original client currently only supports IPv4 networking&#039;&#039;&#039;. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402)&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supports IPv4 and only reads the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:10.0.0.1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unix_time#Notable.C2.A0events.C2.A0in.C2.A0Unix.C2.A0time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || net_addr || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| version &amp;gt;= 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || net_addr || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [[BIP_0014|User Agent]] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [[BIP 0037]], since version &amp;gt;= 70001&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE. This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;version&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + net_addr)[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash if found in the node&#039;s main chain, the list of it&#039;s children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients (specifically the Satoshi client) will gladly provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the blockchain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients (specifically the Satoshi client) will gladly provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_specification#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;getdata&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Transaction data format version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Always locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_specification#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_specification#Block_Headers|block_header]][] || [[Protocol_specification#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with identifying potential nodes in the network. The response to receiving this message is to transmit an addr message with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
It is specified in [[BIP_0035|BIP 35]]. Since [[BIP_0037|BIP 37]], only transactions matching the filter are replied.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message is used for [[IP Transactions]], to ask the peer if it accepts such transactions and allow it to look at the content of the order.&lt;br /&gt;
&lt;br /&gt;
It contains a CWalletTx object&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CMerkleTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashBlock&lt;br /&gt;
|-&lt;br /&gt;
| ? || vMerkleBranch&lt;br /&gt;
|-&lt;br /&gt;
| ? || nIndex&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CWalletTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || vtxPrev&lt;br /&gt;
|-&lt;br /&gt;
| ? || mapValue&lt;br /&gt;
|-&lt;br /&gt;
| ? || vOrderForm&lt;br /&gt;
|-&lt;br /&gt;
| ? || fTimeReceivedIsTxTime&lt;br /&gt;
|-&lt;br /&gt;
| ? || nTimeReceived&lt;br /&gt;
|-&lt;br /&gt;
| ? || fFromMe&lt;br /&gt;
|-&lt;br /&gt;
| ? || fSpent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
Confirms an order has been submitted. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the transaction&lt;br /&gt;
|-&lt;br /&gt;
| ? || wallet_entry || CWalletTx || Same payload as checkorder&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
Generic reply for [[IP Transactions]]&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || reply || uint32_t || reply code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Possible values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || SUCCESS || The IP Transaction can proceed (&#039;&#039;checkorder&#039;&#039;), or has been accepted (&#039;&#039;submitorder&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || WALLET_ERROR || AcceptWalletTransaction() failed&lt;br /&gt;
|-&lt;br /&gt;
| 2 || DENIED || IP Transactions are not accepted by this node&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || random nonce&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== pong ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;pong&#039;&#039; message is sent in response to a &#039;&#039;ping&#039;&#039; message. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || nonce from ping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [[BIP 0037]].&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || var_str || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || var_str || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a var_str to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be canceled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int&amp;gt; || All alert IDs contained in this set should be canceled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
== Wireshark dissector ==&lt;br /&gt;
A dissector for wireshark is being developed at https://github.com/blueCommand/bitcoin-dissector&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40543</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40543"/>
		<updated>2013-08-28T09:17:00Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Message types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sources:&lt;br /&gt;
* [[Original Bitcoin client]] source&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[Getwork]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For ECDSA the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Scripting]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totaling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xfd || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffff || 3 || 0xfd followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffffffff || 5 || 0xfe followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xff followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used.  This protocol and structure supports IPv6, &#039;&#039;&#039;but note that the original client currently only supports IPv4 networking&#039;&#039;&#039;. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402)&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supports IPv4 and only reads the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:10.0.0.1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unix_time#Notable.C2.A0events.C2.A0in.C2.A0Unix.C2.A0time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || net_addr || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| version &amp;gt;= 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || net_addr || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [[BIP_0014|User Agent]] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [[BIP 0037]], since version &amp;gt;= 70001&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE. This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;version&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + net_addr)[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash if found in the node&#039;s main chain, the list of it&#039;s children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients (specifically the Satoshi client) will gladly provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the blockchain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients (specifically the Satoshi client) will gladly provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_specification#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;getdata&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Transaction data format version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Always locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_specification#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_specification#Block_Headers|block_header]][] || [[Protocol_specification#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with identifying potential nodes in the network. The response to receiving this message is to transmit an addr message with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
It is specified in [[BIP_0035|BIP 35]]. Since [[BIP_0037|BIP 37]], only transactions matching the filter are replied.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message is used for [[IP Transactions]], to ask the peer if it accepts such transactions and allow it to look at the content of the order.&lt;br /&gt;
&lt;br /&gt;
It contains a CWalletTx object&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CMerkleTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashBlock&lt;br /&gt;
|-&lt;br /&gt;
| ? || vMerkleBranch&lt;br /&gt;
|-&lt;br /&gt;
| ? || nIndex&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CWalletTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || vtxPrev&lt;br /&gt;
|-&lt;br /&gt;
| ? || mapValue&lt;br /&gt;
|-&lt;br /&gt;
| ? || vOrderForm&lt;br /&gt;
|-&lt;br /&gt;
| ? || fTimeReceivedIsTxTime&lt;br /&gt;
|-&lt;br /&gt;
| ? || nTimeReceived&lt;br /&gt;
|-&lt;br /&gt;
| ? || fFromMe&lt;br /&gt;
|-&lt;br /&gt;
| ? || fSpent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
Confirms an order has been submitted. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the transaction&lt;br /&gt;
|-&lt;br /&gt;
| ? || wallet_entry || CWalletTx || Same payload as checkorder&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
Generic reply for [[IP Transactions]]&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || reply || uint32_t || reply code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Possible values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || SUCCESS || The IP Transaction can proceed (&#039;&#039;checkorder&#039;&#039;), or has been accepted (&#039;&#039;submitorder&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || WALLET_ERROR || AcceptWalletTransaction() failed&lt;br /&gt;
|-&lt;br /&gt;
| 2 || DENIED || IP Transactions are not accepted by this node&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || random nonce&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== pong ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;pong&#039;&#039; message is sent in response to a &amp;quot;ping&amp;quot; message. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || nonce from ping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [[BIP 0037]].&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || var_str || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || var_str || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a var_str to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be canceled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int&amp;gt; || All alert IDs contained in this set should be canceled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
== Wireshark dissector ==&lt;br /&gt;
A dissector for wireshark is being developed at https://github.com/blueCommand/bitcoin-dissector&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40542</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40542"/>
		<updated>2013-08-28T09:13:17Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* ping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sources:&lt;br /&gt;
* [[Original Bitcoin client]] source&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[Getwork]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For ECDSA the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Scripting]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totaling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xfd || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffff || 3 || 0xfd followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffffffff || 5 || 0xfe followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xff followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used.  This protocol and structure supports IPv6, &#039;&#039;&#039;but note that the original client currently only supports IPv4 networking&#039;&#039;&#039;. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402)&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supports IPv4 and only reads the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:10.0.0.1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unix_time#Notable.C2.A0events.C2.A0in.C2.A0Unix.C2.A0time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || net_addr || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| version &amp;gt;= 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || net_addr || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [[BIP_0014|User Agent]] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [[BIP 0037]], since version &amp;gt;= 70001&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE. This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;version&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + net_addr)[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash if found in the node&#039;s main chain, the list of it&#039;s children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients (specifically the Satoshi client) will gladly provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the blockchain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients (specifically the Satoshi client) will gladly provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_specification#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;getdata&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Transaction data format version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Always locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_specification#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_specification#Block_Headers|block_header]][] || [[Protocol_specification#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with identifying potential nodes in the network. The response to receiving this message is to transmit an addr message with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
It is specified in [[BIP_0035|BIP 35]]. Since [[BIP_0037|BIP 37]], only transactions matching the filter are replied.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message is used for [[IP Transactions]], to ask the peer if it accepts such transactions and allow it to look at the content of the order.&lt;br /&gt;
&lt;br /&gt;
It contains a CWalletTx object&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CMerkleTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashBlock&lt;br /&gt;
|-&lt;br /&gt;
| ? || vMerkleBranch&lt;br /&gt;
|-&lt;br /&gt;
| ? || nIndex&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CWalletTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || vtxPrev&lt;br /&gt;
|-&lt;br /&gt;
| ? || mapValue&lt;br /&gt;
|-&lt;br /&gt;
| ? || vOrderForm&lt;br /&gt;
|-&lt;br /&gt;
| ? || fTimeReceivedIsTxTime&lt;br /&gt;
|-&lt;br /&gt;
| ? || nTimeReceived&lt;br /&gt;
|-&lt;br /&gt;
| ? || fFromMe&lt;br /&gt;
|-&lt;br /&gt;
| ? || fSpent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
Confirms an order has been submitted. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the transaction&lt;br /&gt;
|-&lt;br /&gt;
| ? || wallet_entry || CWalletTx || Same payload as checkorder&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
Generic reply for [[IP Transactions]]&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || reply || uint32_t || reply code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Possible values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || SUCCESS || The IP Transaction can proceed (&#039;&#039;checkorder&#039;&#039;), or has been accepted (&#039;&#039;submitorder&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || WALLET_ERROR || AcceptWalletTransaction() failed&lt;br /&gt;
|-&lt;br /&gt;
| 2 || DENIED || IP Transactions are not accepted by this node&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || random nonce&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [[BIP 0037]].&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || var_str || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || var_str || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a var_str to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be canceled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int&amp;gt; || All alert IDs contained in this set should be canceled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
== Wireshark dissector ==&lt;br /&gt;
A dissector for wireshark is being developed at https://github.com/blueCommand/bitcoin-dissector&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40249</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=40249"/>
		<updated>2013-08-17T18:49:14Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Message types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sources:&lt;br /&gt;
* [[Original Bitcoin client]] source&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[Getwork]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For ECDSA the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Scripting]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totaling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xfd || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffff || 3 || 0xfd followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xffffffff || 5 || 0xfe followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xff followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT has also CVarInt class which implements even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used.  This protocol and structure supports IPv6, &#039;&#039;&#039;but note that the original client currently only supports IPv4 networking&#039;&#039;&#039;. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402)&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supports IPv4 and only reads the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:10.0.0.1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unix_time#Notable.C2.A0events.C2.A0in.C2.A0Unix.C2.A0time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || net_addr || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| version &amp;gt;= 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || net_addr || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [[BIP_0014|User Agent]] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [[BIP 0037]], since version &amp;gt;= 70001&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE. This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;version&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + net_addr)[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum payload length: 1.8 Megabytes or 50000 entries):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash if found in the node&#039;s main chain, the list of it&#039;s children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients (specifically the Satoshi client) will gladly provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the blockchain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients (specifically the Satoshi client) will gladly provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_specification#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_specification#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;getdata&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Transaction data format version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Always locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_specification#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_specification#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_specification#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_specification#Block_Headers|block_header]][] || [[Protocol_specification#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with identifying potential nodes in the network. The response to receiving this message is to transmit an addr message with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message is used for [[IP Transactions]], to ask the peer if it accepts such transactions and allow it to look at the content of the order.&lt;br /&gt;
&lt;br /&gt;
It contains a CWalletTx object&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CMerkleTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashBlock&lt;br /&gt;
|-&lt;br /&gt;
| ? || vMerkleBranch&lt;br /&gt;
|-&lt;br /&gt;
| ? || nIndex&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields from CWalletTx&lt;br /&gt;
|-&lt;br /&gt;
| ? || vtxPrev&lt;br /&gt;
|-&lt;br /&gt;
| ? || mapValue&lt;br /&gt;
|-&lt;br /&gt;
| ? || vOrderForm&lt;br /&gt;
|-&lt;br /&gt;
| ? || fTimeReceivedIsTxTime&lt;br /&gt;
|-&lt;br /&gt;
| ? || nTimeReceived&lt;br /&gt;
|-&lt;br /&gt;
| ? || fFromMe&lt;br /&gt;
|-&lt;br /&gt;
| ? || fSpent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
Confirms an order has been submitted. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the transaction&lt;br /&gt;
|-&lt;br /&gt;
| ? || wallet_entry || CWalletTx || Same payload as checkorder&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
Generic reply for [[IP Transactions]]&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || reply || uint32_t || reply code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Possible values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || SUCCESS || The IP Transaction can proceed (&#039;&#039;checkorder&#039;&#039;), or has been accepted (&#039;&#039;submitorder&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || WALLET_ERROR || AcceptWalletTransaction() failed&lt;br /&gt;
|-&lt;br /&gt;
| 2 || DENIED || IP Transactions are not accepted by this node&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [[BIP 0037]].&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || var_str || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || var_str || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a var_str to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be canceled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int&amp;gt; || All alert IDs contained in this set should be canceled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
== Wireshark dissector ==&lt;br /&gt;
A dissector for wireshark is being developed at https://github.com/blueCommand/bitcoin-dissector&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=List_of_address_prefixes&amp;diff=39019</id>
		<title>List of address prefixes</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=List_of_address_prefixes&amp;diff=39019"/>
		<updated>2013-06-30T09:18:09Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Blockchain-based currencies use addresses, which are a [[Base58Check encoding]] of some hash, typically that of a public key. The encoding includes a version byte, which affects the first character in the address. The following is a list of some prefixes which are in use.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Initial byte(s)&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
!Example&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;12CPLrAUPvhVwjZqBgww3sLdEg4Z888R1j&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|F&lt;br /&gt;
|Friendly pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;Ff361bCr7k8aFHjseFxaYWaSpjfq9hVswD&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|L&lt;br /&gt;
|Litecoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;LhK2kQwiaAvhjWY799cZvMyYwnQAcxkarr&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;NATX6zEUNfxfvgVwz8qVnnw3hLhhYXhgQn&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|95&lt;br /&gt;
|f&lt;br /&gt;
|Fairbrix pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;fF6o8LeDAfswEpMbCW8BqaqmzMWS7TGgew&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|97&lt;br /&gt;
|g&lt;br /&gt;
|GeistGeld pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;gQ8YScyiMUTart6kUJpzhjPzAKfiYAwooc&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|105&lt;br /&gt;
|j&lt;br /&gt;
|i0coin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;jWmCr5cKeQjV4iyfUyipfLGwVML8MvXhF2&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;mkJ7Bf5chdfw61d1m7gnDVAQV3EQQAb8iz&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|125&lt;br /&gt;
|s&lt;br /&gt;
|Solidcoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;sXNaMoYBocjcQJRLK53dkaQ5mWuKfvHB9f&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|127&lt;br /&gt;
|t&lt;br /&gt;
|Tenebrix pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;tUK2EQTMF6cN6vuNEfJtVf1BMqarvEZJBL&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Bitcoin Private key (for uncompressed pubkey)&lt;br /&gt;
|&amp;lt;tt&amp;gt;5Htn3FzuH3b1X5VF2zLTsAQzBcyzkZNJsa2egXN8ZFJTCqQm3Rq&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|K or L&lt;br /&gt;
|Bitcoin Private key (for compressed pubkey)&lt;br /&gt;
|&amp;lt;tt&amp;gt;L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|138&lt;br /&gt;
|x&lt;br /&gt;
|ixcoin pubkey hash&lt;br /&gt;
|&amp;lt;tt&amp;gt;xoKDFH4uWpyzxUcCC5jCLFujRKayv3HHcV&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Testnet script hash&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|239&lt;br /&gt;
|9&lt;br /&gt;
|Testnet Private key (for uncompressed pubkey)&lt;br /&gt;
|&amp;lt;tt&amp;gt;91eWjgRmucdtYHpMdsHbn9h8UU8hdoMNSKj8p3QAj6VTLyBnjj6&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|239&lt;br /&gt;
|c&lt;br /&gt;
|Testnet Private key (for compressed pubkey)&lt;br /&gt;
|&amp;lt;tt&amp;gt;cNJFgo1driFnPcBdBX8BrJrpxchBWXwXCvNH5SoSkdcF6JXXwHMm&amp;lt;/tt&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|0x142, 0x143&lt;br /&gt;
|6P&lt;br /&gt;
|Encrypted private key ([[BIP 0038|BIP 38]])&lt;br /&gt;
|&amp;lt;tt&amp;gt; 6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg &amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that private keys for compressed and uncompressed bitcoin public keys use the same version byte. The reason for the compressed form starting with a different character is because a 0x01 byte is appended to the private key before base58 encoding.&lt;br /&gt;
&lt;br /&gt;
The following table shows the leading symbol(s) and address length(s) for 160 bit hashes for each of the possible decimal version values:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Address length&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|up to 34&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Q-Z, a-k, m-o&lt;br /&gt;
|33&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|o-z, 2&lt;br /&gt;
|33 or 34&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|2&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|2 or 3&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|5-6&lt;br /&gt;
|3&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
|3 or 4&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|4&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
|4 or 5&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|10-11&lt;br /&gt;
|5&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|5 or 6&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|13&lt;br /&gt;
|6&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|14&lt;br /&gt;
|6 or 7&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|15-16&lt;br /&gt;
|7&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|17&lt;br /&gt;
|7 or 8&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|18&lt;br /&gt;
|8&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|19&lt;br /&gt;
|8 or 9&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|20-21&lt;br /&gt;
|9&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|22&lt;br /&gt;
|9 or A&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|23&lt;br /&gt;
|A&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|A or B&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|25-26&lt;br /&gt;
|B&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|27&lt;br /&gt;
|B or C&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|C&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|29&lt;br /&gt;
|C or D&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|30-31&lt;br /&gt;
|D&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|D or E&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|33&lt;br /&gt;
|E&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|34&lt;br /&gt;
|E or F&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|35-36&lt;br /&gt;
|F&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|37&lt;br /&gt;
|F or G&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|38&lt;br /&gt;
|G&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|39&lt;br /&gt;
|G or H&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|40-41&lt;br /&gt;
|H&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|42&lt;br /&gt;
|H or J&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|43&lt;br /&gt;
|J&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|J or K&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|45-46&lt;br /&gt;
|K&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|47&lt;br /&gt;
|K or L&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|L&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|49&lt;br /&gt;
|L or M&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|50-51&lt;br /&gt;
|M&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|53&lt;br /&gt;
|N&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|54&lt;br /&gt;
|N or P&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|55-56&lt;br /&gt;
|P&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|57&lt;br /&gt;
|P or Q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|58&lt;br /&gt;
|Q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|59&lt;br /&gt;
|Q or R&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|60-61&lt;br /&gt;
|R&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|62&lt;br /&gt;
|R or S&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|63&lt;br /&gt;
|S&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|64&lt;br /&gt;
|S or T&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|65-66&lt;br /&gt;
|T&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|67&lt;br /&gt;
|T or U&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|68&lt;br /&gt;
|U&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|69&lt;br /&gt;
|U or V&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|70-71&lt;br /&gt;
|V&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|72&lt;br /&gt;
|V or W&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|73&lt;br /&gt;
|W&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|74&lt;br /&gt;
|W or X&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|75-76&lt;br /&gt;
|X&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|77&lt;br /&gt;
|X or Y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|78&lt;br /&gt;
|Y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|79&lt;br /&gt;
|Y or Z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|80-81&lt;br /&gt;
|Z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|82&lt;br /&gt;
|Z or a&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|83&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|84&lt;br /&gt;
|a or b&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|85&lt;br /&gt;
|b&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|86&lt;br /&gt;
|b or c&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|87-88&lt;br /&gt;
|c&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|89&lt;br /&gt;
|c or d&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|90&lt;br /&gt;
|d&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|91&lt;br /&gt;
|d or e&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|92-93&lt;br /&gt;
|e&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|94&lt;br /&gt;
|e or f&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|95&lt;br /&gt;
|f&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|96&lt;br /&gt;
|f or g&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|97-98&lt;br /&gt;
|g&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|99&lt;br /&gt;
|g or h&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|100&lt;br /&gt;
|h&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|101&lt;br /&gt;
|h or i&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|102-103&lt;br /&gt;
|i&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|104&lt;br /&gt;
|i or j&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|105&lt;br /&gt;
|j&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|106&lt;br /&gt;
|j or k&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|107-108&lt;br /&gt;
|k&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|109&lt;br /&gt;
|k or m&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|110&lt;br /&gt;
|m&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|112-113&lt;br /&gt;
|n&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|114&lt;br /&gt;
|n or o&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|115&lt;br /&gt;
|o&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|116&lt;br /&gt;
|o or p&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|117-118&lt;br /&gt;
|p&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|119&lt;br /&gt;
|p or q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|120&lt;br /&gt;
|q&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|121&lt;br /&gt;
|q or r&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|122-123&lt;br /&gt;
|r&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|124&lt;br /&gt;
|r or s&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|125&lt;br /&gt;
|s&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|126&lt;br /&gt;
|s or t&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|127-128&lt;br /&gt;
|t&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|129&lt;br /&gt;
|t or u&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|130&lt;br /&gt;
|u&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|131&lt;br /&gt;
|u or v&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|132-133&lt;br /&gt;
|v&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|134&lt;br /&gt;
|v or w&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|135&lt;br /&gt;
|w&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|136&lt;br /&gt;
|w or x&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|137-138&lt;br /&gt;
|x&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|139&lt;br /&gt;
|x or y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|140&lt;br /&gt;
|y&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|141&lt;br /&gt;
|y or z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|142-143&lt;br /&gt;
|z&lt;br /&gt;
|34&lt;br /&gt;
|-&lt;br /&gt;
|144&lt;br /&gt;
|z or 2&lt;br /&gt;
|34 or 35&lt;br /&gt;
|-&lt;br /&gt;
|145-255&lt;br /&gt;
|2&lt;br /&gt;
|35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[es:Lista de prefijos de direcciones]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37538</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37538"/>
		<updated>2013-05-04T22:50:30Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Conventions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall denote the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: private and public.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37537</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37537"/>
		<updated>2013-05-04T22:48:57Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Child key derivation functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: private and public.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37536</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37536"/>
		<updated>2013-05-04T22:45:16Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Child key derivation functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr;  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37535</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37535"/>
		<updated>2013-05-04T22:44:38Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Extended keys */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37534</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37534"/>
		<updated>2013-05-04T22:41:15Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
[Note: this has probability lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;.]&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37533</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37533"/>
		<updated>2013-05-04T22:38:58Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Public child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;), i) &amp;amp;rarr; (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;, c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; || I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;, i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k, c), i)*G = CKD&#039;((k*G, c), i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37532</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37532"/>
		<updated>2013-05-04T22:33:53Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes long.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37531</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37531"/>
		<updated>2013-05-04T22:33:33Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) [Note: The 0x00 pads the private key to make it 33 bytes.]&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37530</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37530"/>
		<updated>2013-05-04T22:33:16Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 pads the private key to make it 33 bytes)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37529</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37529"/>
		<updated>2013-05-04T22:31:49Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = &amp;amp;chi;(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37528</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37528"/>
		<updated>2013-05-04T22:31:07Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Conventions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
We shall represent the compressed form of point P by &amp;amp;chi;(P), which for secp256k1 will always be 33 bytes long.&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37527</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37527"/>
		<updated>2013-05-04T22:23:42Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Extended keys */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K = k*G and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37526</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37526"/>
		<updated>2013-05-04T21:54:36Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = 0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37525</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37525"/>
		<updated>2013-05-04T21:52:22Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Public child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=parity byte || x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key = c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data = parity byte || x coordinate(K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;,i), with K&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt; the extended public key corresponding to k&amp;lt;sub&amp;gt;ext&amp;lt;/sub&amp;gt;. Symbolically, CKD((k,c),i)*G = CKD&#039;((k*G,c),i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37524</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37524"/>
		<updated>2013-05-04T21:49:32Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=parity byte || x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(x,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(X,i), with X the extended public key corresponding to x. Symbolically, CKD(x,i)*G = CKD&#039;(x*G,i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37523</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37523"/>
		<updated>2013-05-04T21:48:48Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Private child key derivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=signed x coordinate(k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G) || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(x,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(X,i), with X the extended public key corresponding to x. Symbolically, CKD(x,i)*G = CKD&#039;(x*G,i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37522</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37522"/>
		<updated>2013-05-04T21:45:14Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Child key derivation functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bit unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G || i) (with K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; = k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G, EC multiplication)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(x,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(X,i), with X the extended public key corresponding to x. Symbolically, CKD(x,i)*G = CKD&#039;(x*G,i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37518</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37518"/>
		<updated>2013-05-04T21:05:07Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Child key derivation functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation functions===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bits unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G || i) (with K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; = k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G, EC multiplication)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(x,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(X,i), with X the extended public key corresponding to x. Symbolically, CKD(x,i)*G = CKD&#039;(x*G,i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37517</id>
		<title>BIP 0032</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0032&amp;diff=37517"/>
		<updated>2013-05-04T20:58:54Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: Clarification on the distinction between public and private derivation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;color:red&amp;quot;&amp;gt;&lt;br /&gt;
WARNING: please do not assume this specification is final.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RECENT CHANGES:&lt;br /&gt;
* [16 Apr 2013] Added private derivation for i &amp;gt;= 0x80000000 (less risk of parent private key leakage)&lt;br /&gt;
* [30 Apr 2013] Switched from multiplication by I_L to addition of I_L (faster, easier implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 32&lt;br /&gt;
  Title: Hierarchical Deterministic Wallets&lt;br /&gt;
  Author: Pieter Wuille&lt;br /&gt;
  Status: Draft&lt;br /&gt;
  Type: Informational&lt;br /&gt;
  Created: 11-02-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This document describes hierarchical determinstic wallets (or &amp;quot;HD Wallets&amp;quot;): wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.&lt;br /&gt;
&lt;br /&gt;
The specification is intended to set a standard for deterministic wallets that can be interchanged between different clients. Although the wallets described here have many features, not all are required by supporting clients.&lt;br /&gt;
&lt;br /&gt;
The specification consists of two parts. In a first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys. Still, these wallets are not intended to be shared and used on several systems simultaneously. They support hiding their private keys by using the wallet encrypt feature and not sharing the password, but such &amp;quot;neutered&amp;quot; wallets lose the power to generate public keys as well. &lt;br /&gt;
&lt;br /&gt;
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate a fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).&lt;br /&gt;
&lt;br /&gt;
However, deterministic wallets typically consist of a single &amp;quot;chain&amp;quot; of keypairs. The fact that there is only one chain means that sharing a wallet happens on an all-or-nothing basis. However, in some cases one only wants some (public) keys to be shared and recoverable. In the example of a webshop, the webserver does not need access to all public keys of the merchant&#039;s wallet; only to those addresses which are used to receive customer&#039;s payments, and not for example the change addresses that are generated when the merchant spends money. Hierarchical deterministic wallets allow such selective sharing by supporting multiple keypair chains, derived from a single root.&lt;br /&gt;
&lt;br /&gt;
==Specification: Key derivation==&lt;br /&gt;
&lt;br /&gt;
===Conventions===&lt;br /&gt;
&lt;br /&gt;
In the rest of this text we will assume the public key cryptography used in Bitcoin, namely elliptic curve cryptography using the field and curve parameters defined by secp256k1 (http://www.secg.org/index.php?action=secg,docs_secg). Variables below are either:&lt;br /&gt;
* integers modulo the order of the curve (referred to as n), serialized as 32 bytes, most significant byte first.&lt;br /&gt;
* coordinates of points on the curve, serialized as specified in SEC1 in compressed form: [0x02 or 0x03] + 32 byte x coordinate), where the header byte depends on the parity of the omitted y coordinate.&lt;br /&gt;
* byte sequences&lt;br /&gt;
&lt;br /&gt;
Addition (+) of two coordinates is defined as application of the EC group operation. Multiplication (*) of an integer and a coordinate is defined as repeated application of the EC group operation. The generator element of the curve is called G. The public key K corresponding to the private key k is calculated as k*G. We do not distinguish between numbers or coordinates and their serialization as byte sequences.&lt;br /&gt;
&lt;br /&gt;
===Extended keys===&lt;br /&gt;
&lt;br /&gt;
In what follows, we will define a function that derives a number of child keys from a parent key. In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.&lt;br /&gt;
&lt;br /&gt;
We represent an extended private key as (k,c), with k the normal private key, and c the chain code. An extended public key is represented as (K,c), with K the normal public key and c the chain code.&lt;br /&gt;
&lt;br /&gt;
===Child key derivation function===&lt;br /&gt;
&lt;br /&gt;
We allow for two different types of derivation: public and private.&lt;br /&gt;
* Private derivation: knowledge of the private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; is required to compute both k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; and K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Public derivation: knowledge of the public key K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; suffices to compute K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; (but not k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We define the private and public child key derivation functions:&lt;br /&gt;
* CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) →  (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined for both private and public derivation.&lt;br /&gt;
* CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), defined only for public derivation.&lt;br /&gt;
&lt;br /&gt;
We use the most significant bit of i to specify which type of derivation to use. i is encoded as a 32 bits unsigned integer, most significant byte first; &#039;||&#039; represents concatenation.&lt;br /&gt;
&lt;br /&gt;
====Private child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD((k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, private derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=0x00 || k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i) (The 0x00 makes sure the data being hashed aligns with the public version)&lt;br /&gt;
** If 0, public derivation is used: let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G || i) (with K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; = k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;*G, EC multiplication)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (mod n).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i (note that this has a chance lower than 1 in 2&amp;lt;sup&amp;gt;127&amp;lt;/sup&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
====Public child key derivation====&lt;br /&gt;
&lt;br /&gt;
To define CKD&#039;((K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i) → (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;):&lt;br /&gt;
* Check whether the highest bit (0x80000000) of i is set:&lt;br /&gt;
** If 1, return error&lt;br /&gt;
** If 0, let I = HMAC-SHA512(Key=c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;, Data=K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; || i)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = (I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; + k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;)*G = I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt;*G + K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; (EC operations).&lt;br /&gt;
* c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; ≥ n, the resulting key is invalid, and one should proceed with the next value for i.&lt;br /&gt;
&lt;br /&gt;
Note that the extended public key corresponding to the evaluation of CKD(x,i) with public derivation (so with i &amp;lt; 0x80000000) is identical to the evaluation of CKD&#039;(X,i), with X the extended public key corresponding to x. Symbolically, CKD(x,i)*G = CKD&#039;(x*G,i). This implies that CKD&#039; can be used to derive all public keys corresponding to the private keys that CKD would find. It cannot be used to retrieve the private keys, however.&lt;br /&gt;
&lt;br /&gt;
The HMAC-SHA512 function is specified in [http://tools.ietf.org/html/rfc4231 RFC 4231].&lt;br /&gt;
&lt;br /&gt;
===The key tree===&lt;br /&gt;
&lt;br /&gt;
The next step is cascading several CKD constructions to build a tree. We start with one root, the master extended key m. By evaluating CKD(m,i) for several values of i, we get a number of first-degree derivative nodes. As each of these is again an extended key, CKD can be applied to those as well. To shorten notation, we will write CKD(CKD(CKD(m,0x8000003),0x2),0x5) as m/3&#039;/2/5 now.&lt;br /&gt;
&lt;br /&gt;
Each leaf node in the tree corresponds to an actual keypair, while the internal nodes correspond to the collection of keypairs that descends from them. The chain codes of the leaf nodes are ignored, and only their embedded private or public key is used. Because of this construction, knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public keys allows reconstruction of all descendant public keys derived using public derivation.&lt;br /&gt;
&lt;br /&gt;
===Key identifiers===&lt;br /&gt;
&lt;br /&gt;
Extended keys can be identified by the Hash160 (RIPEMD160 after SHA256) of the serialized public key, ignoring the chain code. This corresponds exactly to the data used in traditional Bitcoin addresses. It is not advised to represent this data in base58 format though, as it may be interpreted as an address that way (and wallet software is not required to accept payment to the chain key itself).&lt;br /&gt;
&lt;br /&gt;
The first 32 bits of the identifier are called the fingerprint.&lt;br /&gt;
&lt;br /&gt;
===Serialization format===&lt;br /&gt;
&lt;br /&gt;
Extended public and private keys are serialized as follows:&lt;br /&gt;
* 4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private)&lt;br /&gt;
* 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... &lt;br /&gt;
* 4 bytes: the fingerprint of the parent&#039;s key (0x00000000 if master key)&lt;br /&gt;
* 4 bytes: child number. This is the number i in x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = x&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;/i, with x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; the key being serialized. This is encoded in MSB order. (0x00000000 if master key)&lt;br /&gt;
* 32 bytes: the chain code&lt;br /&gt;
* 33 bytes: the public key or private key data (0x02 + X or 0x03 + X for public keys, 0x00 + k for private keys)&lt;br /&gt;
&lt;br /&gt;
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of up to 112 characters. Because of the choice of the version bytes, the Base58 representation will start with &amp;quot;xprv&amp;quot; or &amp;quot;xpub&amp;quot; on mainnet, &amp;quot;tprv&amp;quot; or &amp;quot;tpub&amp;quot; on testnet.&lt;br /&gt;
&lt;br /&gt;
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions. Internally, the full 160-bit identifier could be used.&lt;br /&gt;
&lt;br /&gt;
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.&lt;br /&gt;
&lt;br /&gt;
===Master key generation===&lt;br /&gt;
&lt;br /&gt;
The total number of possible extended keypairs is almost 2^512, but the produced keys are only 256 bits long, and offer about half of that in terms of security. Therefore, master keys are not generated directly, but instead from a potentially short seed value.&lt;br /&gt;
&lt;br /&gt;
* Generate a seed S of a chosen length (at least 128 bits, but 256 is advised) from a (P)RNG.&lt;br /&gt;
* Calculate I = HMAC-SHA512(key=&amp;quot;Bitcoin seed&amp;quot;, msg=S)&lt;br /&gt;
* Split I into two 32-byte sequences, I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt;.&lt;br /&gt;
* Use I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; (mod n) as master secret key, and I&amp;lt;sub&amp;gt;R&amp;lt;/sub&amp;gt; as master chain code.&lt;br /&gt;
In case I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; is 0 or &amp;gt;=n, the master key is invalid.&lt;br /&gt;
&lt;br /&gt;
[[File:BIP32-derivation.png]]&lt;br /&gt;
&lt;br /&gt;
==Specification: Wallet structure==&lt;br /&gt;
&lt;br /&gt;
The previous sections specified key trees and their nodes. The next step is imposing a wallet structure on this tree. The layout defined in this section is a default only, though clients are encouraged to mimick it for compatibility, even if not all features are supported.&lt;br /&gt;
&lt;br /&gt;
An HDW is organized as several &#039;accounts&#039;. Accounts are numbered, the default account (&amp;quot;&amp;quot;) being number 0. Clients are not required to support more than one account - if not, they only use the default account.&lt;br /&gt;
&lt;br /&gt;
Each account is composed of two keypair chains: an internal and an external one. The external keychain is used to generate new public addresses, while the internal keychain is used for all other operations (change addresses, generation addresses, ..., anything that doesn&#039;t need to be communicated). Clients that do not support separate keychains for these should use the external one for everything.&lt;br /&gt;
&lt;br /&gt;
 * m/i&#039;/0/k corresponds to the k&#039;th keypair of the external chain of account number i of the HDW derived from master m.&lt;br /&gt;
 * m/i&#039;/1/k corresponds to the k&#039;th keypair of the internal chain of account number i of the HDW derived from master m.&lt;br /&gt;
&lt;br /&gt;
===Use cases===&lt;br /&gt;
&lt;br /&gt;
====Full wallet sharing: m====&lt;br /&gt;
&lt;br /&gt;
In cases where two systems need to access a single shared wallet, and both need to be able to perform spendings, one needs to share the master private extended key. Nodes can keep a pool of N look-ahead keys cached for external chains, to watch for incoming payments. The look-ahead for internal chains can be very small, as no gaps are to be expected here. An extra look-ahead could be active for the first unused account&#039;s chains - triggering the creation of a new account when used. Note that the name of the account will still need to be entered manually and cannot be synchronized via the block chain.&lt;br /&gt;
&lt;br /&gt;
====Audits: M====&lt;br /&gt;
&lt;br /&gt;
In case an auditor needs full access to the list of incoming and outgoing payments, one can share the master public extended key. This will allow the auditor to see all transactions from and to the wallet, in all accounts, but not a single secret key.&lt;br /&gt;
&lt;br /&gt;
====Per-office balances: m/i&#039;====&lt;br /&gt;
&lt;br /&gt;
When a business has several independent offices, they can all use wallets derived from a single master. This will allow the headquarters to maintain a super-wallet that sees all incoming and outgoing transactions of all offices, and even permit moving money between the offices.&lt;br /&gt;
&lt;br /&gt;
====Recurrent business-to-business transactions: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
In case two business partners often transfer money, one can use the extended public key for the external chain of a specific account (M/i&#039;/0) as a sort of &amp;quot;super address&amp;quot;, allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.&lt;br /&gt;
Such a mechanism could also be used by mining pool operators as variable payout address.&lt;br /&gt;
&lt;br /&gt;
====Unsecure money receiver: M/i&#039;/0====&lt;br /&gt;
&lt;br /&gt;
When an unsecure webserver is used to run an e-commerce site, it needs to know public addresses that be used to receive payments. The webserver only needs to know the public extended key of the external chain of a single account. This means someone illegally obtaining access to the webserver can at most see all incoming payments, but will not (trivially) be able to distinguish outgoing transactions, nor see payments received by other webservers if there are several ones.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
&lt;br /&gt;
To comply with this standard, a client must at least be able to import an extended public or private key, to give access to its direct descendants as wallet keys. The wallet structure (master/account/chain/subchain) presented in the second part of the specification is advisory only, but is suggested as a minimal structure for easy compatibility - even when no separate accounts or distinction between internal and external chains is made. However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
In addition to the expectations from the EC public-key cryptography itself:&lt;br /&gt;
* Given a public key K, an attacker cannot find the corresponding private key more efficiently than by solving the EC discrete logarithm problem (assumed to require 2&amp;lt;sup&amp;gt;128&amp;lt;/sup&amp;gt; group operations).&lt;br /&gt;
the intended security properties of this standard are:&lt;br /&gt;
* Given a child extended private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) and the integer i, an attacker cannot find the parent private key k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt; more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
* Given any number (2 &amp;lt;= N &amp;lt;= 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;-1) of (index, extended private key) tuples (i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), with distinct i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&#039;s, determining whether they are derived from a common parent extended private key (i.e., whether there exists a (p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) such that for each j in [0..N-1] CKD((p&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;),i&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)=(p&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;)), cannot be done more efficiently than a 2&amp;lt;sup&amp;gt;256&amp;lt;/sup&amp;gt; brute force of HMAC-SHA512.&lt;br /&gt;
Note however that the following properties does not exist:&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child public key (K&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;), it is hard to find i.&lt;br /&gt;
* Given a parent extended public key (K&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;,c&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;) and a child private key (k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;) using public derivation, it is hard to find k&amp;lt;sub&amp;gt;par&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Private and public keys must be kept safe as usual. Leaking a private key means access to coins - leaking a public key can mean loss of privacy.&lt;br /&gt;
&lt;br /&gt;
Somewhat more care must be taken regarding extended keys, as these correspond to an entire (sub)tree of keys. One weakness that may not be immediately obvious, is that knowledge of the extended public key + a private key descending from it is equivalent to knowing the extended private key (i.e., every private and public key) in case public derivation is used. This means that extended public keys must be treated more carefully than regular public keys. This is the reason why accounts at the first level of the default wallet layout use private derivation, so a leak of account-specific (or below) private key never risks compromising the master.&lt;br /&gt;
&lt;br /&gt;
We rely on resistance against (partial) preimages in HMAC-SHA512 to prevent I&amp;lt;sub&amp;gt;L&amp;lt;/sub&amp;gt; in key derivation and master key generation from being zero.&lt;br /&gt;
&lt;br /&gt;
==Test Vectors==&lt;br /&gt;
&lt;br /&gt;
I&#039;ll publish test vectors as soon as the specification is assumed to be final.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
&lt;br /&gt;
* Gregory Maxwell for the original idea of type-2 deterministic wallets, and many discussions about it.&lt;br /&gt;
* Alan Reiner for the implementation of this scheme in Armory, and the suggestions that followed from that.&lt;br /&gt;
* Mike Caldwell for the version bytes to obtain human-recognizable Base58 strings.&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Pooled_mining&amp;diff=36208</id>
		<title>Pooled mining</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Pooled_mining&amp;diff=36208"/>
		<updated>2013-03-18T21:15:50Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Luke-Jr&amp;#039;s approach (&amp;quot;Eligius&amp;quot;) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Pooled mining&#039;&#039;&#039; is a [[Mining|mining]] approach where multiple generating clients contribute to the generation of a block, and then split the block reward according the contributed processing power. Pooled mining effectively reduces the granularity of the block generation reward, spreading it out more smoothly over time.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
With increasing generation difficulty, mining with lower-performance devices can take a very long time before block generation, on average. For example, with a mining speed of 1000 Khps, at a difficulty of 14484 (which was in effect at the end of December, 2010), the average time to generate a block is almost 2 years. &lt;br /&gt;
&lt;br /&gt;
To provide a more smooth incentive to lower-performance miners, several pooled miners, using different approaches, have been created. With a mining pool, a lot of different people contribute to generating a block, and the reward is then split among them according to their processing contribution. This way, instead of waiting for years to generate 50btc in a block, a smaller miner may get a fraction of a bitcoin on a more regular basis.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;share&#039;&#039;&#039; is awarded by the mining pool to the clients who present a valid [[proof of work]] of the same type as the proof of work that is used for creating [[block|blocks]], but of lesser difficulty, so that it requires less time on average to generate.&lt;br /&gt;
&lt;br /&gt;
==Pooled mining approaches==&lt;br /&gt;
&lt;br /&gt;
The problem with pooled mining is that steps must be taken to prevent cheating by the clients and the server. Currently there are several different approaches used.&lt;br /&gt;
&lt;br /&gt;
===The slush approach===&lt;br /&gt;
&lt;br /&gt;
[[Bitcoin Pooled Mining]] (BPM), sometimes referred to as &amp;quot;slush&#039;s pool&amp;quot;, follows a score-based method.  Older shares (from beginning of the round) have lower weight than more recent shares, which reduces the motivation to cheat by switching between pools within a round.&lt;br /&gt;
&lt;br /&gt;
===The puddinpop approach===&lt;br /&gt;
&lt;br /&gt;
(As of February, 2011, there are no puddinpop pools running.)&lt;br /&gt;
&lt;br /&gt;
Another approach is the &#039;metahash&#039; technique, used by puddinpop&#039;s [[remote miner]]. Clients generate hashes, and also submit &#039;metahashes&#039;, which are hashes of a large chunk of generated hashes. The server checks that the metahashes are correct (in a round-robin fashion, picking up a metahash from a client that hasn&#039;t been checked on the longest), thus preventing clients from simply claiming that they have done work without actually doing it. The withholding of good blocks by the clients is prevented by the server&#039;s possession of the private key, just as in the previous approach. Rewards are distributed based on the number of metahashes submitted by the clients.&lt;br /&gt;
&lt;br /&gt;
The generated blocks contain multiple keys in the generation transaction, giving fractional bitcoin amounts to each key in proportion to their hashing contribution for that block.&lt;br /&gt;
&lt;br /&gt;
===The Pay-per-Share approach===&lt;br /&gt;
&lt;br /&gt;
The Pay-per-Share (PPS) approach, first described by [[BitPenny]], is to offer an instant flat payout for each share that is solved.  The payout is offered from the pool&#039;s existing balance and can therefore be withdrawn immediately, without waiting for a block to be solved or confirmed.  The possibility of cheating the miners by the pool operator and by timing attacks is thus completely eliminated. &lt;br /&gt;
&lt;br /&gt;
This method results in the least possible variance for miners while transferring all risk to the pool operator.  The resulting possibility of loss for the server is offset by setting a payout lower than the full expected value.&lt;br /&gt;
&lt;br /&gt;
===Luke-Jr&#039;s approach (&amp;quot;[[Eligius]]&amp;quot;)===&lt;br /&gt;
[[User:Luke-Jr|Luke]] came up with a third approach borrowing strengths from the earlier two.&lt;br /&gt;
Like slush&#039;s approach, miners submit proofs-of-work to earn shares.&lt;br /&gt;
Like puddinpop&#039;s approach, the pool pays out immediately via block generation.&lt;br /&gt;
When distributing block rewards, it is divided equally among all shares since the last valid block.&lt;br /&gt;
Unlike any preexisting pool approach, this means that the shares contributed toward stale blocks are recycled into the next block&#039;s shares.&lt;br /&gt;
In order to spare participating miners from transaction fees, rewards are only paid out if a miner has earned at least 0.67108864 BTC (400 [[Tonal Bitcoin|TBC]]). If the amount owed is less, it will be added to the earnings of a later block (which may then total over the threshold amount).&lt;br /&gt;
If a miner does not submit a share for over a week, the pool sends any balance remaining, regardless of its size.&lt;br /&gt;
&lt;br /&gt;
===The Triplemining approach===&lt;br /&gt;
The [[Triplemining]] approach is to bring together a medium-sized pool with no fees and clever redistribution of 1% of every found block to allow your share to grow more rapidly than on any other bitcoin mining pool. &lt;br /&gt;
&lt;br /&gt;
For every found block, Triplemining redistributes 1% of the profits to all minipool owners (people with 1 or more friends mining with them). The redistribution is connected to the shares found by the members of the minipool. So if the hash rate of the minipool members equals or is bigger than yours, the part in the redistribution will be equally bigger.&lt;br /&gt;
&lt;br /&gt;
===P2Pool approach===&lt;br /&gt;
&lt;br /&gt;
[[P2Pool]] mining nodes work on a chain of shares similar to Bitcoin’s blockchain. When a block is found, the reward is divided among the most recent shares in this share-blockchain. Like the puddinpop and Luke-Jr approaches, p2pool pays via generation.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
&lt;br /&gt;
The cooperative mining approach (slush and Luke-Jr) uses a lot less resources on the pool server, since rather than continuously checking metahashes, all that has to be checked is the validity of submitted shares. The number of shares sent can be adjusted by adjusting the artificial difficulty level.&lt;br /&gt;
&lt;br /&gt;
Further, the cooperative mining approach allows the clients to use existing miners without any modification, while the puddinpop approach requires the custom pool miner, which are as of now not as efficient on GPU mining as the existing GPU miners.&lt;br /&gt;
[[File:Smallgeneration.png|thumb|Puddinpop miners receive coins directly.]]&lt;br /&gt;
&lt;br /&gt;
Additionally, the puddinpop and Luke-Jr approaches of distributing the earnings by way of including precise sub-cent amounts in the generation transaction for the participants, results in the presence of sub-cent bitcoin amounts in your wallet, which are liable to disappear (as unnecessary fees) later due to a bug in old (before 0.3.21) bitcoin nodes. (E.g., if you have a transaction with 0.052 in your wallet, and you later send .05 to someone, your .002 will disappear.).&lt;br /&gt;
&lt;br /&gt;
Puddinpop and Luke-Jr miners receive coins directly, which eliminates the delay in receiving earnings that is required on slush-based mining servers. However, using some [[eWallet]] services for generated coin will cause those coins to be lost.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[:Category:Miners|Miners]]&lt;br /&gt;
* [[Poolservers]]&lt;br /&gt;
* [[Comparison of mining pools]]&lt;br /&gt;
* [[:Category:Pool Operators|Pool Operators]]&lt;br /&gt;
* [[Why a GPU mines faster than a CPU]]&lt;br /&gt;
* [[Why pooled mining]]&lt;br /&gt;
* [[Mining pool reward FAQ]]&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [http://btcserv.net BTCSERV.net - Bitcoin Pool]&lt;br /&gt;
* [http://21bitcoin.com/pool/ 21bitcoin mining pool, Chinese Interface]&lt;br /&gt;
* [http://mining.bitcoin.cz slush&#039;s mining pool]&lt;br /&gt;
* [http://www.bitcash.cz bitcash.cz - czech mining pool]&lt;br /&gt;
* [http://www.bitcoin.org/smf/index.php?topic=1458.0 puddinpop&#039;s mining pool thread]&lt;br /&gt;
* [http://blockexplorer.com/block/00000000000233334b157d901714baf59e5b9236227b2878844e52244da4195e example puddinpop block]&lt;br /&gt;
* [http://bitclockers.com bitclockers mining pool]&lt;br /&gt;
* [https://pool.itzod.ru pool.itzod.ru mining pool] &lt;br /&gt;
* [https://50btc.com 50btc.com mining pool] &lt;br /&gt;
* [http://forum.bitcoin.org/index.php?topic=18313 P2Pool forum]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Mining]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36204</id>
		<title>Base58Check encoding</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36204"/>
		<updated>2013-03-18T13:50:51Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Encoding a Bitcoin address */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A modified Base 58 [http://en.wikipedia.org/wiki/Binary-to-text_encoding binary-to-text encoding] known as &#039;&#039;&#039;Base58Check&#039;&#039;&#039; is used for encoding [[Bitcoin address]]es.&lt;br /&gt;
&lt;br /&gt;
More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.  A Bitcoin address is simply a Base58Check-encoded string with a 20-byte payload, the payload being the hash of the  [[public key]] associated with the address.&lt;br /&gt;
&lt;br /&gt;
The original Bitcoin client source code discusses the reasoning behind base58 encoding:&lt;br /&gt;
&lt;br /&gt;
base58.h:&lt;br /&gt;
 // Why base-58 instead of standard base-64 encoding?&lt;br /&gt;
 // - Don&#039;t want 0OIl characters that look the same in some fonts and&lt;br /&gt;
 //      could be used to create visually identical looking account numbers.&lt;br /&gt;
 // - A string with non-alphanumeric characters is not as easily accepted as an account number.&lt;br /&gt;
 // - E-mail usually won&#039;t line-break if there&#039;s no punctuation to break at.&lt;br /&gt;
 // - Doubleclicking selects the whole number as one word if it&#039;s all alphanumeric.&lt;br /&gt;
&lt;br /&gt;
==Features of Base58Check==&lt;br /&gt;
Base58Check has the following features:&lt;br /&gt;
* An arbitrarily sized payload.&lt;br /&gt;
* A set of 58 alphanumeric symbols consisting of easily distinguished uppercase and lowercase letters (0OIl are not used) &lt;br /&gt;
* One byte of version/application information.  Bitcoin addresses use 0x00 for this byte (future ones may use 0x05).&lt;br /&gt;
* Four bytes (32 bits) of SHA256-based error checking code.  This code can be used to automatically detect and possibly correct typographical errors.&lt;br /&gt;
* An extra step for preservation of leading zeroes in the data.&lt;br /&gt;
&lt;br /&gt;
==Creating a Base58Check string==&lt;br /&gt;
A Base58Check string is created from a version/application byte and payload as follows.&lt;br /&gt;
# Take the version/application byte and payload bytes, and concatenate them together (bytewise).&lt;br /&gt;
# Take the first four bytes of SHA256(SHA256(results of step 1))&lt;br /&gt;
# Concatenate the results of step 1 and the results of step 2 together (bytewise).&lt;br /&gt;
# Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below.  The result should be normalized to not have any leading base-58 zeroes (character &#039;1&#039;).&lt;br /&gt;
# The leading character &#039;1&#039;, which has a value of zero in base58, is reserved for representing an entire leading zero &#039;&#039;&#039;byte&#039;&#039;&#039;, as when it is in a leading position, has no value as a base-58 symbol.  There can be one or more leading &#039;1&#039;s when necessary to represent one or more leading zero bytes.  Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any).  Each leading zero byte shall be represented by its own character &#039;1&#039; in the final result.&lt;br /&gt;
# Concatenate the 1&#039;s from step 5 with the results of step 4.  &#039;&#039;&#039;This is the Base58Check result.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Encoding a Bitcoin address==&lt;br /&gt;
A Bitcoin address is based on any [[ECDSA]] [[secp256k1]] public/private [[key pair]].&lt;br /&gt;
&lt;br /&gt;
A Bitcoin address is the Base58Check encoding of the hash of the associated [[script]].  Specifically, it is Base58Check(version byte,[[RIPEMD160]]([[SHA256]]([[script]]))), with the following constraints:&lt;br /&gt;
* [[RIPEMD160]] and [[SHA256]] in this case are always exactly 20 and 32 unsigned bytes respectively.  These are big-endian (most significant byte first).  (Beware of [[bignumber]] implementations that clip leading 0x00 bytes, or prepend extra 0x00 bytes to indicate sign - your code must handle these cases properly or else you may generate valid-looking addresses which can be sent to, but cannot be spent from - which would lead to the permanent loss of coins.)&lt;br /&gt;
* version byte is 0x00 for pay-to-address, version byte is 0x05 for pay-to-script-hash.&lt;br /&gt;
&lt;br /&gt;
Bitcoin addresses that use the version byte 0x00 start with the digit &#039;1&#039;. Bitcoin addresses that use the version byte 0x05 start with the digit &#039;3&#039;.&lt;br /&gt;
&lt;br /&gt;
==Encoding a private key==&lt;br /&gt;
Base58Check encoding is also used for encoding [[private key]]s in the [[Wallet import format]].  This is formed exactly the same as a Bitcoin address, except that 0x80 is used for the version/application byte, and the payload is 32 bytes instead of 20 (a private key in Bitcoin is a single 32-byte unsigned big-endian integer).  Such encodings will always yield a 51-character string that starts with &#039;5&#039;, or more specifically, either &#039;5H&#039;, &#039;5J&#039;, or &#039;5K&#039;.&lt;br /&gt;
&lt;br /&gt;
==Base58 symbol chart==&lt;br /&gt;
The Base58 symbol chart used in Bitcoin is specific to the Bitcoin project and is not intended to be the same as any other Base58 implementation used outside the context of Bitcoin.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|9&lt;br /&gt;
|A&lt;br /&gt;
|10&lt;br /&gt;
|B&lt;br /&gt;
|11&lt;br /&gt;
|C&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|D&lt;br /&gt;
|13&lt;br /&gt;
|E&lt;br /&gt;
|14&lt;br /&gt;
|F&lt;br /&gt;
|15&lt;br /&gt;
|G&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|H&lt;br /&gt;
|17&lt;br /&gt;
|J&lt;br /&gt;
|18&lt;br /&gt;
|K&lt;br /&gt;
|19&lt;br /&gt;
|L&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|M&lt;br /&gt;
|21&lt;br /&gt;
|N&lt;br /&gt;
|22&lt;br /&gt;
|P&lt;br /&gt;
|23&lt;br /&gt;
|Q&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|R&lt;br /&gt;
|25&lt;br /&gt;
|S&lt;br /&gt;
|26&lt;br /&gt;
|T&lt;br /&gt;
|27&lt;br /&gt;
|U&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|V&lt;br /&gt;
|29&lt;br /&gt;
|W&lt;br /&gt;
|30&lt;br /&gt;
|X&lt;br /&gt;
|31&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|Z&lt;br /&gt;
|33&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|b&lt;br /&gt;
|35&lt;br /&gt;
|c&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|d&lt;br /&gt;
|37&lt;br /&gt;
|e&lt;br /&gt;
|38&lt;br /&gt;
|f&lt;br /&gt;
|39&lt;br /&gt;
|g&lt;br /&gt;
|-&lt;br /&gt;
|40&lt;br /&gt;
|h&lt;br /&gt;
|41&lt;br /&gt;
|i&lt;br /&gt;
|42&lt;br /&gt;
|j&lt;br /&gt;
|43&lt;br /&gt;
|k&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|m&lt;br /&gt;
|45&lt;br /&gt;
|n&lt;br /&gt;
|46&lt;br /&gt;
|o&lt;br /&gt;
|47&lt;br /&gt;
|p&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|q&lt;br /&gt;
|49&lt;br /&gt;
|r&lt;br /&gt;
|50&lt;br /&gt;
|s&lt;br /&gt;
|51&lt;br /&gt;
|t&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|u&lt;br /&gt;
|53&lt;br /&gt;
|v&lt;br /&gt;
|54&lt;br /&gt;
|w&lt;br /&gt;
|55&lt;br /&gt;
|x&lt;br /&gt;
|-&lt;br /&gt;
|56&lt;br /&gt;
|y&lt;br /&gt;
|57&lt;br /&gt;
|z&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The algorithm for encoding address_byte_string (consisting of 0x01 + hash + 4-byte_check_code) is&lt;br /&gt;
&lt;br /&gt;
    code_string = &amp;quot;123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&amp;quot;&lt;br /&gt;
    x = convert_bytes_to_big_integer(hash_result)&lt;br /&gt;
    &lt;br /&gt;
    output_string = &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    while(x &amp;gt; 0) &lt;br /&gt;
        {&lt;br /&gt;
            (x, remainder) = divide(x, 58)&lt;br /&gt;
            output_string.append(code_string[remainder])&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    repeat(number_of_leading_zero_bytes_in_hash)&lt;br /&gt;
        {&lt;br /&gt;
        output_string.append(code_string[0]);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    output_string.reverse();&lt;br /&gt;
&lt;br /&gt;
==Version bytes==&lt;br /&gt;
Here are some common version bytes:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|-&lt;br /&gt;
|21&lt;br /&gt;
|4&lt;br /&gt;
|Bitcoin (compact) public key (proposed)&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Private key&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Bitcoin testnet script hash&lt;br /&gt;
|}&lt;br /&gt;
[[List of address prefixes]] is a more complete list.&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/blob/master/src/base58.h &amp;quot;Satoshi&amp;quot; C++ codebase (encode/decode using BigNum library)]&lt;br /&gt;
* [https://gitorious.org/bitcoin/libblkmaker/blobs/master/base58.c libblkmaker C code (decode only, no external libraries needed)]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
&lt;br /&gt;
[[es:Codificación Base58Check]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36203</id>
		<title>Base58Check encoding</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36203"/>
		<updated>2013-03-18T13:50:28Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Encoding a Bitcoin address */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A modified Base 58 [http://en.wikipedia.org/wiki/Binary-to-text_encoding binary-to-text encoding] known as &#039;&#039;&#039;Base58Check&#039;&#039;&#039; is used for encoding [[Bitcoin address]]es.&lt;br /&gt;
&lt;br /&gt;
More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.  A Bitcoin address is simply a Base58Check-encoded string with a 20-byte payload, the payload being the hash of the  [[public key]] associated with the address.&lt;br /&gt;
&lt;br /&gt;
The original Bitcoin client source code discusses the reasoning behind base58 encoding:&lt;br /&gt;
&lt;br /&gt;
base58.h:&lt;br /&gt;
 // Why base-58 instead of standard base-64 encoding?&lt;br /&gt;
 // - Don&#039;t want 0OIl characters that look the same in some fonts and&lt;br /&gt;
 //      could be used to create visually identical looking account numbers.&lt;br /&gt;
 // - A string with non-alphanumeric characters is not as easily accepted as an account number.&lt;br /&gt;
 // - E-mail usually won&#039;t line-break if there&#039;s no punctuation to break at.&lt;br /&gt;
 // - Doubleclicking selects the whole number as one word if it&#039;s all alphanumeric.&lt;br /&gt;
&lt;br /&gt;
==Features of Base58Check==&lt;br /&gt;
Base58Check has the following features:&lt;br /&gt;
* An arbitrarily sized payload.&lt;br /&gt;
* A set of 58 alphanumeric symbols consisting of easily distinguished uppercase and lowercase letters (0OIl are not used) &lt;br /&gt;
* One byte of version/application information.  Bitcoin addresses use 0x00 for this byte (future ones may use 0x05).&lt;br /&gt;
* Four bytes (32 bits) of SHA256-based error checking code.  This code can be used to automatically detect and possibly correct typographical errors.&lt;br /&gt;
* An extra step for preservation of leading zeroes in the data.&lt;br /&gt;
&lt;br /&gt;
==Creating a Base58Check string==&lt;br /&gt;
A Base58Check string is created from a version/application byte and payload as follows.&lt;br /&gt;
# Take the version/application byte and payload bytes, and concatenate them together (bytewise).&lt;br /&gt;
# Take the first four bytes of SHA256(SHA256(results of step 1))&lt;br /&gt;
# Concatenate the results of step 1 and the results of step 2 together (bytewise).&lt;br /&gt;
# Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below.  The result should be normalized to not have any leading base-58 zeroes (character &#039;1&#039;).&lt;br /&gt;
# The leading character &#039;1&#039;, which has a value of zero in base58, is reserved for representing an entire leading zero &#039;&#039;&#039;byte&#039;&#039;&#039;, as when it is in a leading position, has no value as a base-58 symbol.  There can be one or more leading &#039;1&#039;s when necessary to represent one or more leading zero bytes.  Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any).  Each leading zero byte shall be represented by its own character &#039;1&#039; in the final result.&lt;br /&gt;
# Concatenate the 1&#039;s from step 5 with the results of step 4.  &#039;&#039;&#039;This is the Base58Check result.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Encoding a Bitcoin address==&lt;br /&gt;
A Bitcoin address is based on any [[ECDSA]] [[secp256k1]] public/private [[key pair]].&lt;br /&gt;
&lt;br /&gt;
A Bitcoin address is the Base58Check encoding of the hash of the associated [[script]].  Specifically, it is Base58Check(version byte,[[RIPEMD160]]([[SHA256]]([[script]]))), with the following constraints:&lt;br /&gt;
* [[RIPEMD160]] and [[SHA256]] in this case are always exactly 20 and 32 unsigned bytes respectively.  These are big-endian (most significant byte first).  (Beware of [[bignumber]] implementations that clip leading 0x00 bytes, or prepend extra 0x00 bytes to indicate sign - your code must handle these cases properly or else you may generate valid-looking addresses which can be sent to, but cannot be spent from - which would lead to the permanent loss of coins.)&lt;br /&gt;
* version byte is 0x00 for pay-to-address, version_byte is 0x05 for pay-to-script-hash.&lt;br /&gt;
&lt;br /&gt;
Bitcoin addresses that use the version byte 0x00 start with the digit &#039;1&#039;. Bitcoin addresses that use the version byte 0x05 start with the digit &#039;3&#039;.&lt;br /&gt;
&lt;br /&gt;
==Encoding a private key==&lt;br /&gt;
Base58Check encoding is also used for encoding [[private key]]s in the [[Wallet import format]].  This is formed exactly the same as a Bitcoin address, except that 0x80 is used for the version/application byte, and the payload is 32 bytes instead of 20 (a private key in Bitcoin is a single 32-byte unsigned big-endian integer).  Such encodings will always yield a 51-character string that starts with &#039;5&#039;, or more specifically, either &#039;5H&#039;, &#039;5J&#039;, or &#039;5K&#039;.&lt;br /&gt;
&lt;br /&gt;
==Base58 symbol chart==&lt;br /&gt;
The Base58 symbol chart used in Bitcoin is specific to the Bitcoin project and is not intended to be the same as any other Base58 implementation used outside the context of Bitcoin.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|9&lt;br /&gt;
|A&lt;br /&gt;
|10&lt;br /&gt;
|B&lt;br /&gt;
|11&lt;br /&gt;
|C&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|D&lt;br /&gt;
|13&lt;br /&gt;
|E&lt;br /&gt;
|14&lt;br /&gt;
|F&lt;br /&gt;
|15&lt;br /&gt;
|G&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|H&lt;br /&gt;
|17&lt;br /&gt;
|J&lt;br /&gt;
|18&lt;br /&gt;
|K&lt;br /&gt;
|19&lt;br /&gt;
|L&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|M&lt;br /&gt;
|21&lt;br /&gt;
|N&lt;br /&gt;
|22&lt;br /&gt;
|P&lt;br /&gt;
|23&lt;br /&gt;
|Q&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|R&lt;br /&gt;
|25&lt;br /&gt;
|S&lt;br /&gt;
|26&lt;br /&gt;
|T&lt;br /&gt;
|27&lt;br /&gt;
|U&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|V&lt;br /&gt;
|29&lt;br /&gt;
|W&lt;br /&gt;
|30&lt;br /&gt;
|X&lt;br /&gt;
|31&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|Z&lt;br /&gt;
|33&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|b&lt;br /&gt;
|35&lt;br /&gt;
|c&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|d&lt;br /&gt;
|37&lt;br /&gt;
|e&lt;br /&gt;
|38&lt;br /&gt;
|f&lt;br /&gt;
|39&lt;br /&gt;
|g&lt;br /&gt;
|-&lt;br /&gt;
|40&lt;br /&gt;
|h&lt;br /&gt;
|41&lt;br /&gt;
|i&lt;br /&gt;
|42&lt;br /&gt;
|j&lt;br /&gt;
|43&lt;br /&gt;
|k&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|m&lt;br /&gt;
|45&lt;br /&gt;
|n&lt;br /&gt;
|46&lt;br /&gt;
|o&lt;br /&gt;
|47&lt;br /&gt;
|p&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|q&lt;br /&gt;
|49&lt;br /&gt;
|r&lt;br /&gt;
|50&lt;br /&gt;
|s&lt;br /&gt;
|51&lt;br /&gt;
|t&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|u&lt;br /&gt;
|53&lt;br /&gt;
|v&lt;br /&gt;
|54&lt;br /&gt;
|w&lt;br /&gt;
|55&lt;br /&gt;
|x&lt;br /&gt;
|-&lt;br /&gt;
|56&lt;br /&gt;
|y&lt;br /&gt;
|57&lt;br /&gt;
|z&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The algorithm for encoding address_byte_string (consisting of 0x01 + hash + 4-byte_check_code) is&lt;br /&gt;
&lt;br /&gt;
    code_string = &amp;quot;123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&amp;quot;&lt;br /&gt;
    x = convert_bytes_to_big_integer(hash_result)&lt;br /&gt;
    &lt;br /&gt;
    output_string = &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    while(x &amp;gt; 0) &lt;br /&gt;
        {&lt;br /&gt;
            (x, remainder) = divide(x, 58)&lt;br /&gt;
            output_string.append(code_string[remainder])&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    repeat(number_of_leading_zero_bytes_in_hash)&lt;br /&gt;
        {&lt;br /&gt;
        output_string.append(code_string[0]);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    output_string.reverse();&lt;br /&gt;
&lt;br /&gt;
==Version bytes==&lt;br /&gt;
Here are some common version bytes:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|-&lt;br /&gt;
|21&lt;br /&gt;
|4&lt;br /&gt;
|Bitcoin (compact) public key (proposed)&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Private key&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Bitcoin testnet script hash&lt;br /&gt;
|}&lt;br /&gt;
[[List of address prefixes]] is a more complete list.&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/blob/master/src/base58.h &amp;quot;Satoshi&amp;quot; C++ codebase (encode/decode using BigNum library)]&lt;br /&gt;
* [https://gitorious.org/bitcoin/libblkmaker/blobs/master/base58.c libblkmaker C code (decode only, no external libraries needed)]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
&lt;br /&gt;
[[es:Codificación Base58Check]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36202</id>
		<title>Base58Check encoding</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36202"/>
		<updated>2013-03-18T13:47:24Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Encoding a Bitcoin address */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A modified Base 58 [http://en.wikipedia.org/wiki/Binary-to-text_encoding binary-to-text encoding] known as &#039;&#039;&#039;Base58Check&#039;&#039;&#039; is used for encoding [[Bitcoin address]]es.&lt;br /&gt;
&lt;br /&gt;
More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.  A Bitcoin address is simply a Base58Check-encoded string with a 20-byte payload, the payload being the hash of the  [[public key]] associated with the address.&lt;br /&gt;
&lt;br /&gt;
The original Bitcoin client source code discusses the reasoning behind base58 encoding:&lt;br /&gt;
&lt;br /&gt;
base58.h:&lt;br /&gt;
 // Why base-58 instead of standard base-64 encoding?&lt;br /&gt;
 // - Don&#039;t want 0OIl characters that look the same in some fonts and&lt;br /&gt;
 //      could be used to create visually identical looking account numbers.&lt;br /&gt;
 // - A string with non-alphanumeric characters is not as easily accepted as an account number.&lt;br /&gt;
 // - E-mail usually won&#039;t line-break if there&#039;s no punctuation to break at.&lt;br /&gt;
 // - Doubleclicking selects the whole number as one word if it&#039;s all alphanumeric.&lt;br /&gt;
&lt;br /&gt;
==Features of Base58Check==&lt;br /&gt;
Base58Check has the following features:&lt;br /&gt;
* An arbitrarily sized payload.&lt;br /&gt;
* A set of 58 alphanumeric symbols consisting of easily distinguished uppercase and lowercase letters (0OIl are not used) &lt;br /&gt;
* One byte of version/application information.  Bitcoin addresses use 0x00 for this byte (future ones may use 0x05).&lt;br /&gt;
* Four bytes (32 bits) of SHA256-based error checking code.  This code can be used to automatically detect and possibly correct typographical errors.&lt;br /&gt;
* An extra step for preservation of leading zeroes in the data.&lt;br /&gt;
&lt;br /&gt;
==Creating a Base58Check string==&lt;br /&gt;
A Base58Check string is created from a version/application byte and payload as follows.&lt;br /&gt;
# Take the version/application byte and payload bytes, and concatenate them together (bytewise).&lt;br /&gt;
# Take the first four bytes of SHA256(SHA256(results of step 1))&lt;br /&gt;
# Concatenate the results of step 1 and the results of step 2 together (bytewise).&lt;br /&gt;
# Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below.  The result should be normalized to not have any leading base-58 zeroes (character &#039;1&#039;).&lt;br /&gt;
# The leading character &#039;1&#039;, which has a value of zero in base58, is reserved for representing an entire leading zero &#039;&#039;&#039;byte&#039;&#039;&#039;, as when it is in a leading position, has no value as a base-58 symbol.  There can be one or more leading &#039;1&#039;s when necessary to represent one or more leading zero bytes.  Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any).  Each leading zero byte shall be represented by its own character &#039;1&#039; in the final result.&lt;br /&gt;
# Concatenate the 1&#039;s from step 5 with the results of step 4.  &#039;&#039;&#039;This is the Base58Check result.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Encoding a Bitcoin address==&lt;br /&gt;
A Bitcoin address is based on any [[ECDSA]] [[secp256k1]] public/private [[key pair]].&lt;br /&gt;
&lt;br /&gt;
A Bitcoin address is the Base58Check encoding of the hash of the associated [[script]].  Specifically, it is Base58Check(version_byte,[[RIPEMD160]]([[SHA256]]([[script]]))), with the following constraints:&lt;br /&gt;
* [[RIPEMD160]] and [[SHA256]] in this case are always exactly 20 and 32 unsigned bytes respectively.  These are big-endian (most significant byte first).  (Beware of [[bignumber]] implementations that clip leading 0x00 bytes, or prepend extra 0x00 bytes to indicate sign - your code must handle these cases properly or else you may generate valid-looking addresses which can be sent to, but cannot be spent from - which would lead to the permanent loss of coins.)&lt;br /&gt;
* version_byte is 0x00 for pay-to-address, version_byte is 0x05 for pay-to-script-hash.&lt;br /&gt;
&lt;br /&gt;
Bitcoin addresses that use the version byte 0x00 start with the digit &#039;1&#039;. Bitcoin addresses that use the version byte 0x05 start with the digit &#039;3&#039;.&lt;br /&gt;
&lt;br /&gt;
==Encoding a private key==&lt;br /&gt;
Base58Check encoding is also used for encoding [[private key]]s in the [[Wallet import format]].  This is formed exactly the same as a Bitcoin address, except that 0x80 is used for the version/application byte, and the payload is 32 bytes instead of 20 (a private key in Bitcoin is a single 32-byte unsigned big-endian integer).  Such encodings will always yield a 51-character string that starts with &#039;5&#039;, or more specifically, either &#039;5H&#039;, &#039;5J&#039;, or &#039;5K&#039;.&lt;br /&gt;
&lt;br /&gt;
==Base58 symbol chart==&lt;br /&gt;
The Base58 symbol chart used in Bitcoin is specific to the Bitcoin project and is not intended to be the same as any other Base58 implementation used outside the context of Bitcoin.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|9&lt;br /&gt;
|A&lt;br /&gt;
|10&lt;br /&gt;
|B&lt;br /&gt;
|11&lt;br /&gt;
|C&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|D&lt;br /&gt;
|13&lt;br /&gt;
|E&lt;br /&gt;
|14&lt;br /&gt;
|F&lt;br /&gt;
|15&lt;br /&gt;
|G&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|H&lt;br /&gt;
|17&lt;br /&gt;
|J&lt;br /&gt;
|18&lt;br /&gt;
|K&lt;br /&gt;
|19&lt;br /&gt;
|L&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|M&lt;br /&gt;
|21&lt;br /&gt;
|N&lt;br /&gt;
|22&lt;br /&gt;
|P&lt;br /&gt;
|23&lt;br /&gt;
|Q&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|R&lt;br /&gt;
|25&lt;br /&gt;
|S&lt;br /&gt;
|26&lt;br /&gt;
|T&lt;br /&gt;
|27&lt;br /&gt;
|U&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|V&lt;br /&gt;
|29&lt;br /&gt;
|W&lt;br /&gt;
|30&lt;br /&gt;
|X&lt;br /&gt;
|31&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|Z&lt;br /&gt;
|33&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|b&lt;br /&gt;
|35&lt;br /&gt;
|c&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|d&lt;br /&gt;
|37&lt;br /&gt;
|e&lt;br /&gt;
|38&lt;br /&gt;
|f&lt;br /&gt;
|39&lt;br /&gt;
|g&lt;br /&gt;
|-&lt;br /&gt;
|40&lt;br /&gt;
|h&lt;br /&gt;
|41&lt;br /&gt;
|i&lt;br /&gt;
|42&lt;br /&gt;
|j&lt;br /&gt;
|43&lt;br /&gt;
|k&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|m&lt;br /&gt;
|45&lt;br /&gt;
|n&lt;br /&gt;
|46&lt;br /&gt;
|o&lt;br /&gt;
|47&lt;br /&gt;
|p&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|q&lt;br /&gt;
|49&lt;br /&gt;
|r&lt;br /&gt;
|50&lt;br /&gt;
|s&lt;br /&gt;
|51&lt;br /&gt;
|t&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|u&lt;br /&gt;
|53&lt;br /&gt;
|v&lt;br /&gt;
|54&lt;br /&gt;
|w&lt;br /&gt;
|55&lt;br /&gt;
|x&lt;br /&gt;
|-&lt;br /&gt;
|56&lt;br /&gt;
|y&lt;br /&gt;
|57&lt;br /&gt;
|z&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The algorithm for encoding address_byte_string (consisting of 0x01 + hash + 4-byte_check_code) is&lt;br /&gt;
&lt;br /&gt;
    code_string = &amp;quot;123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&amp;quot;&lt;br /&gt;
    x = convert_bytes_to_big_integer(hash_result)&lt;br /&gt;
    &lt;br /&gt;
    output_string = &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    while(x &amp;gt; 0) &lt;br /&gt;
        {&lt;br /&gt;
            (x, remainder) = divide(x, 58)&lt;br /&gt;
            output_string.append(code_string[remainder])&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    repeat(number_of_leading_zero_bytes_in_hash)&lt;br /&gt;
        {&lt;br /&gt;
        output_string.append(code_string[0]);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    output_string.reverse();&lt;br /&gt;
&lt;br /&gt;
==Version bytes==&lt;br /&gt;
Here are some common version bytes:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|-&lt;br /&gt;
|21&lt;br /&gt;
|4&lt;br /&gt;
|Bitcoin (compact) public key (proposed)&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Private key&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Bitcoin testnet script hash&lt;br /&gt;
|}&lt;br /&gt;
[[List of address prefixes]] is a more complete list.&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/blob/master/src/base58.h &amp;quot;Satoshi&amp;quot; C++ codebase (encode/decode using BigNum library)]&lt;br /&gt;
* [https://gitorious.org/bitcoin/libblkmaker/blobs/master/base58.c libblkmaker C code (decode only, no external libraries needed)]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
&lt;br /&gt;
[[es:Codificación Base58Check]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36201</id>
		<title>Base58Check encoding</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36201"/>
		<updated>2013-03-18T13:46:43Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Encoding a Bitcoin address */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A modified Base 58 [http://en.wikipedia.org/wiki/Binary-to-text_encoding binary-to-text encoding] known as &#039;&#039;&#039;Base58Check&#039;&#039;&#039; is used for encoding [[Bitcoin address]]es.&lt;br /&gt;
&lt;br /&gt;
More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.  A Bitcoin address is simply a Base58Check-encoded string with a 20-byte payload, the payload being the hash of the  [[public key]] associated with the address.&lt;br /&gt;
&lt;br /&gt;
The original Bitcoin client source code discusses the reasoning behind base58 encoding:&lt;br /&gt;
&lt;br /&gt;
base58.h:&lt;br /&gt;
 // Why base-58 instead of standard base-64 encoding?&lt;br /&gt;
 // - Don&#039;t want 0OIl characters that look the same in some fonts and&lt;br /&gt;
 //      could be used to create visually identical looking account numbers.&lt;br /&gt;
 // - A string with non-alphanumeric characters is not as easily accepted as an account number.&lt;br /&gt;
 // - E-mail usually won&#039;t line-break if there&#039;s no punctuation to break at.&lt;br /&gt;
 // - Doubleclicking selects the whole number as one word if it&#039;s all alphanumeric.&lt;br /&gt;
&lt;br /&gt;
==Features of Base58Check==&lt;br /&gt;
Base58Check has the following features:&lt;br /&gt;
* An arbitrarily sized payload.&lt;br /&gt;
* A set of 58 alphanumeric symbols consisting of easily distinguished uppercase and lowercase letters (0OIl are not used) &lt;br /&gt;
* One byte of version/application information.  Bitcoin addresses use 0x00 for this byte (future ones may use 0x05).&lt;br /&gt;
* Four bytes (32 bits) of SHA256-based error checking code.  This code can be used to automatically detect and possibly correct typographical errors.&lt;br /&gt;
* An extra step for preservation of leading zeroes in the data.&lt;br /&gt;
&lt;br /&gt;
==Creating a Base58Check string==&lt;br /&gt;
A Base58Check string is created from a version/application byte and payload as follows.&lt;br /&gt;
# Take the version/application byte and payload bytes, and concatenate them together (bytewise).&lt;br /&gt;
# Take the first four bytes of SHA256(SHA256(results of step 1))&lt;br /&gt;
# Concatenate the results of step 1 and the results of step 2 together (bytewise).&lt;br /&gt;
# Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below.  The result should be normalized to not have any leading base-58 zeroes (character &#039;1&#039;).&lt;br /&gt;
# The leading character &#039;1&#039;, which has a value of zero in base58, is reserved for representing an entire leading zero &#039;&#039;&#039;byte&#039;&#039;&#039;, as when it is in a leading position, has no value as a base-58 symbol.  There can be one or more leading &#039;1&#039;s when necessary to represent one or more leading zero bytes.  Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any).  Each leading zero byte shall be represented by its own character &#039;1&#039; in the final result.&lt;br /&gt;
# Concatenate the 1&#039;s from step 5 with the results of step 4.  &#039;&#039;&#039;This is the Base58Check result.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Encoding a Bitcoin address==&lt;br /&gt;
A Bitcoin address is based on any [[ECDSA]] [[secp256k1]] public/private [[key pair]].&lt;br /&gt;
&lt;br /&gt;
A Bitcoin address is the Base58Check encoding of the hash of the associated [[script]].  Specifically, it is Base58Check(version_byte,[[RIPEMD160]]([[SHA256]]([[script]]))), with the following constraints:&lt;br /&gt;
* [[RIPEMD160]] and [[SHA256]] in this case are always exactly 20 and 32 unsigned bytes respectively.  These are big-endian (most significant byte first).  (Beware of [[bignumber]] implementations that clip leading 0x00 bytes, or prepend extra 0x00 bytes to indicate sign - your code must handle these cases properly or else you may generate valid-looking addresses which can be sent to, but cannot be spent from - which would lead to the permanent loss of coins.)&lt;br /&gt;
* version_byte is 0x00 for standard pay-to-address scripts, version_byte is 0x05 for pay-to-script-hash scripts.&lt;br /&gt;
&lt;br /&gt;
Bitcoin addresses that use the version byte 0x00 start with the digit &#039;1&#039;. Bitcoin addresses that use the version byte 0x05 start with the digit &#039;3&#039;.&lt;br /&gt;
&lt;br /&gt;
==Encoding a private key==&lt;br /&gt;
Base58Check encoding is also used for encoding [[private key]]s in the [[Wallet import format]].  This is formed exactly the same as a Bitcoin address, except that 0x80 is used for the version/application byte, and the payload is 32 bytes instead of 20 (a private key in Bitcoin is a single 32-byte unsigned big-endian integer).  Such encodings will always yield a 51-character string that starts with &#039;5&#039;, or more specifically, either &#039;5H&#039;, &#039;5J&#039;, or &#039;5K&#039;.&lt;br /&gt;
&lt;br /&gt;
==Base58 symbol chart==&lt;br /&gt;
The Base58 symbol chart used in Bitcoin is specific to the Bitcoin project and is not intended to be the same as any other Base58 implementation used outside the context of Bitcoin.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|9&lt;br /&gt;
|A&lt;br /&gt;
|10&lt;br /&gt;
|B&lt;br /&gt;
|11&lt;br /&gt;
|C&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|D&lt;br /&gt;
|13&lt;br /&gt;
|E&lt;br /&gt;
|14&lt;br /&gt;
|F&lt;br /&gt;
|15&lt;br /&gt;
|G&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|H&lt;br /&gt;
|17&lt;br /&gt;
|J&lt;br /&gt;
|18&lt;br /&gt;
|K&lt;br /&gt;
|19&lt;br /&gt;
|L&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|M&lt;br /&gt;
|21&lt;br /&gt;
|N&lt;br /&gt;
|22&lt;br /&gt;
|P&lt;br /&gt;
|23&lt;br /&gt;
|Q&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|R&lt;br /&gt;
|25&lt;br /&gt;
|S&lt;br /&gt;
|26&lt;br /&gt;
|T&lt;br /&gt;
|27&lt;br /&gt;
|U&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|V&lt;br /&gt;
|29&lt;br /&gt;
|W&lt;br /&gt;
|30&lt;br /&gt;
|X&lt;br /&gt;
|31&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|Z&lt;br /&gt;
|33&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|b&lt;br /&gt;
|35&lt;br /&gt;
|c&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|d&lt;br /&gt;
|37&lt;br /&gt;
|e&lt;br /&gt;
|38&lt;br /&gt;
|f&lt;br /&gt;
|39&lt;br /&gt;
|g&lt;br /&gt;
|-&lt;br /&gt;
|40&lt;br /&gt;
|h&lt;br /&gt;
|41&lt;br /&gt;
|i&lt;br /&gt;
|42&lt;br /&gt;
|j&lt;br /&gt;
|43&lt;br /&gt;
|k&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|m&lt;br /&gt;
|45&lt;br /&gt;
|n&lt;br /&gt;
|46&lt;br /&gt;
|o&lt;br /&gt;
|47&lt;br /&gt;
|p&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|q&lt;br /&gt;
|49&lt;br /&gt;
|r&lt;br /&gt;
|50&lt;br /&gt;
|s&lt;br /&gt;
|51&lt;br /&gt;
|t&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|u&lt;br /&gt;
|53&lt;br /&gt;
|v&lt;br /&gt;
|54&lt;br /&gt;
|w&lt;br /&gt;
|55&lt;br /&gt;
|x&lt;br /&gt;
|-&lt;br /&gt;
|56&lt;br /&gt;
|y&lt;br /&gt;
|57&lt;br /&gt;
|z&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The algorithm for encoding address_byte_string (consisting of 0x01 + hash + 4-byte_check_code) is&lt;br /&gt;
&lt;br /&gt;
    code_string = &amp;quot;123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&amp;quot;&lt;br /&gt;
    x = convert_bytes_to_big_integer(hash_result)&lt;br /&gt;
    &lt;br /&gt;
    output_string = &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    while(x &amp;gt; 0) &lt;br /&gt;
        {&lt;br /&gt;
            (x, remainder) = divide(x, 58)&lt;br /&gt;
            output_string.append(code_string[remainder])&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    repeat(number_of_leading_zero_bytes_in_hash)&lt;br /&gt;
        {&lt;br /&gt;
        output_string.append(code_string[0]);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    output_string.reverse();&lt;br /&gt;
&lt;br /&gt;
==Version bytes==&lt;br /&gt;
Here are some common version bytes:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|-&lt;br /&gt;
|21&lt;br /&gt;
|4&lt;br /&gt;
|Bitcoin (compact) public key (proposed)&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Private key&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Bitcoin testnet script hash&lt;br /&gt;
|}&lt;br /&gt;
[[List of address prefixes]] is a more complete list.&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/blob/master/src/base58.h &amp;quot;Satoshi&amp;quot; C++ codebase (encode/decode using BigNum library)]&lt;br /&gt;
* [https://gitorious.org/bitcoin/libblkmaker/blobs/master/base58.c libblkmaker C code (decode only, no external libraries needed)]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
&lt;br /&gt;
[[es:Codificación Base58Check]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36200</id>
		<title>Base58Check encoding</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Base58Check_encoding&amp;diff=36200"/>
		<updated>2013-03-18T13:42:23Z</updated>

		<summary type="html">&lt;p&gt;CodeShark: /* Encoding a Bitcoin address */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A modified Base 58 [http://en.wikipedia.org/wiki/Binary-to-text_encoding binary-to-text encoding] known as &#039;&#039;&#039;Base58Check&#039;&#039;&#039; is used for encoding [[Bitcoin address]]es.&lt;br /&gt;
&lt;br /&gt;
More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.  A Bitcoin address is simply a Base58Check-encoded string with a 20-byte payload, the payload being the hash of the  [[public key]] associated with the address.&lt;br /&gt;
&lt;br /&gt;
The original Bitcoin client source code discusses the reasoning behind base58 encoding:&lt;br /&gt;
&lt;br /&gt;
base58.h:&lt;br /&gt;
 // Why base-58 instead of standard base-64 encoding?&lt;br /&gt;
 // - Don&#039;t want 0OIl characters that look the same in some fonts and&lt;br /&gt;
 //      could be used to create visually identical looking account numbers.&lt;br /&gt;
 // - A string with non-alphanumeric characters is not as easily accepted as an account number.&lt;br /&gt;
 // - E-mail usually won&#039;t line-break if there&#039;s no punctuation to break at.&lt;br /&gt;
 // - Doubleclicking selects the whole number as one word if it&#039;s all alphanumeric.&lt;br /&gt;
&lt;br /&gt;
==Features of Base58Check==&lt;br /&gt;
Base58Check has the following features:&lt;br /&gt;
* An arbitrarily sized payload.&lt;br /&gt;
* A set of 58 alphanumeric symbols consisting of easily distinguished uppercase and lowercase letters (0OIl are not used) &lt;br /&gt;
* One byte of version/application information.  Bitcoin addresses use 0x00 for this byte (future ones may use 0x05).&lt;br /&gt;
* Four bytes (32 bits) of SHA256-based error checking code.  This code can be used to automatically detect and possibly correct typographical errors.&lt;br /&gt;
* An extra step for preservation of leading zeroes in the data.&lt;br /&gt;
&lt;br /&gt;
==Creating a Base58Check string==&lt;br /&gt;
A Base58Check string is created from a version/application byte and payload as follows.&lt;br /&gt;
# Take the version/application byte and payload bytes, and concatenate them together (bytewise).&lt;br /&gt;
# Take the first four bytes of SHA256(SHA256(results of step 1))&lt;br /&gt;
# Concatenate the results of step 1 and the results of step 2 together (bytewise).&lt;br /&gt;
# Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below.  The result should be normalized to not have any leading base-58 zeroes (character &#039;1&#039;).&lt;br /&gt;
# The leading character &#039;1&#039;, which has a value of zero in base58, is reserved for representing an entire leading zero &#039;&#039;&#039;byte&#039;&#039;&#039;, as when it is in a leading position, has no value as a base-58 symbol.  There can be one or more leading &#039;1&#039;s when necessary to represent one or more leading zero bytes.  Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any).  Each leading zero byte shall be represented by its own character &#039;1&#039; in the final result.&lt;br /&gt;
# Concatenate the 1&#039;s from step 5 with the results of step 4.  &#039;&#039;&#039;This is the Base58Check result.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Encoding a Bitcoin address==&lt;br /&gt;
A Bitcoin address is based on any [[ECDSA]] [[secp256k1]] public/private [[key pair]].&lt;br /&gt;
&lt;br /&gt;
A Bitcoin address is the Base58Check encoding of the hash of the associated [[script]].  Specifically, it is Base58Check(version_byte,[[RIPEMD160]]([[SHA256]]([[script]]))), with the following constraints:&lt;br /&gt;
* [[RIPEMD160]] and [[SHA256]] in this case are always exactly 20 and 32 unsigned bytes respectively.  These are big-endian (most significant byte first).  (Beware of [[bignumber]] implementations that clip leading 0x00 bytes, or prepend extra 0x00 bytes to indicate sign - your code must handle these cases properly or else you may generate valid-looking addresses which can be sent to, but cannot be spent from - which would lead to the permanent loss of coins.)&lt;br /&gt;
* 0 refers to the version/application byte.&lt;br /&gt;
&lt;br /&gt;
Bitcoin addresses that use the version byte 0x00 start with the digit &#039;1&#039;. Bitcoin addresses that use the version byte 0x05 start with the digit &#039;3&#039;.&lt;br /&gt;
&lt;br /&gt;
==Encoding a private key==&lt;br /&gt;
Base58Check encoding is also used for encoding [[private key]]s in the [[Wallet import format]].  This is formed exactly the same as a Bitcoin address, except that 0x80 is used for the version/application byte, and the payload is 32 bytes instead of 20 (a private key in Bitcoin is a single 32-byte unsigned big-endian integer).  Such encodings will always yield a 51-character string that starts with &#039;5&#039;, or more specifically, either &#039;5H&#039;, &#039;5J&#039;, or &#039;5K&#039;.&lt;br /&gt;
&lt;br /&gt;
==Base58 symbol chart==&lt;br /&gt;
The Base58 symbol chart used in Bitcoin is specific to the Bitcoin project and is not intended to be the same as any other Base58 implementation used outside the context of Bitcoin.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
!Value&lt;br /&gt;
!Character&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|1&lt;br /&gt;
|2&lt;br /&gt;
|2&lt;br /&gt;
|3&lt;br /&gt;
|3&lt;br /&gt;
|4&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|5&lt;br /&gt;
|5&lt;br /&gt;
|6&lt;br /&gt;
|6&lt;br /&gt;
|7&lt;br /&gt;
|7&lt;br /&gt;
|8&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
|9&lt;br /&gt;
|9&lt;br /&gt;
|A&lt;br /&gt;
|10&lt;br /&gt;
|B&lt;br /&gt;
|11&lt;br /&gt;
|C&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|D&lt;br /&gt;
|13&lt;br /&gt;
|E&lt;br /&gt;
|14&lt;br /&gt;
|F&lt;br /&gt;
|15&lt;br /&gt;
|G&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|H&lt;br /&gt;
|17&lt;br /&gt;
|J&lt;br /&gt;
|18&lt;br /&gt;
|K&lt;br /&gt;
|19&lt;br /&gt;
|L&lt;br /&gt;
|-&lt;br /&gt;
|20&lt;br /&gt;
|M&lt;br /&gt;
|21&lt;br /&gt;
|N&lt;br /&gt;
|22&lt;br /&gt;
|P&lt;br /&gt;
|23&lt;br /&gt;
|Q&lt;br /&gt;
|-&lt;br /&gt;
|24&lt;br /&gt;
|R&lt;br /&gt;
|25&lt;br /&gt;
|S&lt;br /&gt;
|26&lt;br /&gt;
|T&lt;br /&gt;
|27&lt;br /&gt;
|U&lt;br /&gt;
|-&lt;br /&gt;
|28&lt;br /&gt;
|V&lt;br /&gt;
|29&lt;br /&gt;
|W&lt;br /&gt;
|30&lt;br /&gt;
|X&lt;br /&gt;
|31&lt;br /&gt;
|Y&lt;br /&gt;
|-&lt;br /&gt;
|32&lt;br /&gt;
|Z&lt;br /&gt;
|33&lt;br /&gt;
|a&lt;br /&gt;
|34&lt;br /&gt;
|b&lt;br /&gt;
|35&lt;br /&gt;
|c&lt;br /&gt;
|-&lt;br /&gt;
|36&lt;br /&gt;
|d&lt;br /&gt;
|37&lt;br /&gt;
|e&lt;br /&gt;
|38&lt;br /&gt;
|f&lt;br /&gt;
|39&lt;br /&gt;
|g&lt;br /&gt;
|-&lt;br /&gt;
|40&lt;br /&gt;
|h&lt;br /&gt;
|41&lt;br /&gt;
|i&lt;br /&gt;
|42&lt;br /&gt;
|j&lt;br /&gt;
|43&lt;br /&gt;
|k&lt;br /&gt;
|-&lt;br /&gt;
|44&lt;br /&gt;
|m&lt;br /&gt;
|45&lt;br /&gt;
|n&lt;br /&gt;
|46&lt;br /&gt;
|o&lt;br /&gt;
|47&lt;br /&gt;
|p&lt;br /&gt;
|-&lt;br /&gt;
|48&lt;br /&gt;
|q&lt;br /&gt;
|49&lt;br /&gt;
|r&lt;br /&gt;
|50&lt;br /&gt;
|s&lt;br /&gt;
|51&lt;br /&gt;
|t&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|u&lt;br /&gt;
|53&lt;br /&gt;
|v&lt;br /&gt;
|54&lt;br /&gt;
|w&lt;br /&gt;
|55&lt;br /&gt;
|x&lt;br /&gt;
|-&lt;br /&gt;
|56&lt;br /&gt;
|y&lt;br /&gt;
|57&lt;br /&gt;
|z&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The algorithm for encoding address_byte_string (consisting of 0x01 + hash + 4-byte_check_code) is&lt;br /&gt;
&lt;br /&gt;
    code_string = &amp;quot;123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz&amp;quot;&lt;br /&gt;
    x = convert_bytes_to_big_integer(hash_result)&lt;br /&gt;
    &lt;br /&gt;
    output_string = &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    while(x &amp;gt; 0) &lt;br /&gt;
        {&lt;br /&gt;
            (x, remainder) = divide(x, 58)&lt;br /&gt;
            output_string.append(code_string[remainder])&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    repeat(number_of_leading_zero_bytes_in_hash)&lt;br /&gt;
        {&lt;br /&gt;
        output_string.append(code_string[0]);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    output_string.reverse();&lt;br /&gt;
&lt;br /&gt;
==Version bytes==&lt;br /&gt;
Here are some common version bytes:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!Decimal version&lt;br /&gt;
!Leading symbol&lt;br /&gt;
!Use&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
|1&lt;br /&gt;
|Bitcoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|3&lt;br /&gt;
|Bitcoin script hash&lt;br /&gt;
|-&lt;br /&gt;
|21&lt;br /&gt;
|4&lt;br /&gt;
|Bitcoin (compact) public key (proposed)&lt;br /&gt;
|-&lt;br /&gt;
|52&lt;br /&gt;
|M or N&lt;br /&gt;
|Namecoin pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|128&lt;br /&gt;
|5&lt;br /&gt;
|Private key&lt;br /&gt;
|-&lt;br /&gt;
|111&lt;br /&gt;
|m or n&lt;br /&gt;
|Bitcoin testnet pubkey hash&lt;br /&gt;
|-&lt;br /&gt;
|196&lt;br /&gt;
|2&lt;br /&gt;
|Bitcoin testnet script hash&lt;br /&gt;
|}&lt;br /&gt;
[[List of address prefixes]] is a more complete list.&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
* [https://github.com/bitcoin/bitcoin/blob/master/src/base58.h &amp;quot;Satoshi&amp;quot; C++ codebase (encode/decode using BigNum library)]&lt;br /&gt;
* [https://gitorious.org/bitcoin/libblkmaker/blobs/master/base58.c libblkmaker C code (decode only, no external libraries needed)]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
&lt;br /&gt;
[[es:Codificación Base58Check]]&lt;/div&gt;</summary>
		<author><name>CodeShark</name></author>
	</entry>
</feed>