edgecase_datafeed692018-11-14
This is the date at the time of creation of this datafeed article. A checkpoint article containing a hash of this datafeed article may be created on this date or at a later date.6272018-10-01bitcoin8b53df721231f95e4e1843a74fd560fcfd6512d2e258ba1a2fc0472a8230b46754390433jEsi2kqFwMtagFqBuHuzCeYPVdDkR8zP1DaAgMor4bZiAuLgZWdz4W5RkoYVQFvDKpRecipe_for_generating_a_Bitcoin_addressstjohn_piano2018-11-14no
Parts
- Description
- Assets
- Notes
- Recipe
- Example
Description
This recipe describes a method of generating a standard Bitcoin address from a private key.
Assets
Asset: A library of functions for handling standard Bitcoin data types.
asset_of_another_articleCreating_and_signing_a_standard_raw_Bitcoin_transaction:_Iteration_#2edgecase63bitcoin_functions.pybitcoin_functions.pye6d2c81e26c5dc0171a4489e78e5457c58559bc4a76bf5147e63224323672c1a
Asset: An implementation of RIPEMD-160, written by B_j_o:r_n_ E_d_s_t_r_o:m_.
asset_of_another_articleReading_and_verifying_a_standard_raw_bitcoin_transactionedgecase51bjorn_edstrom_ripemd160.pybjorn_edstrom_ripemd160.pya5ca6eb289989861e30806ff7e39165622bd366a1c6cd5edd2dbd7dfc4877666
Asset: A Python implementation of ECDSA cryptography, written by Peter Pearson.
asset_of_another_articleReading_and_verifying_a_standard_raw_bitcoin_transactionedgecase51ecdsa-0.10.tar.gzecdsa-0.10.tar.gz67dae9e1af2b0fd71bc9a378654f7dc89211c1c5aee71e160f8cfce1fa6d6980
Asset: A Python implementation of SHA256.
asset_of_another_articleReading_and_verifying_a_standard_raw_bitcoin_transactionedgecase51pypy_sha256.pypypy_sha256.py2bbd4a83b69625e2f7ece5201475af2803f0ea11f3815c83d8afab3773d8f47b
Asset: A script that generates a standard Bitcoin address from a private key.
asset_of_another_articleCreating_and_signing_a_standard_raw_Bitcoin_transaction:_Iteration_#2edgecase63generate_bitcoin_address_3.pygenerate_bitcoin_address_3.pyb18c438fe479095eff17702c52968309351b6e5f9d147758ce5924b116f5a8ef
Notes
My working definition of a standard address:
- An uncompressed single-signature Pay-To-Public-Key-Hash (P2PKH) address.
Standard addresses start with the character '1'.
This recipe assumes that you have already generated a private key (32 bytes). The following article describes one way to do this:
articleRecipe_for_generating_entropy_bytes_using_diceedgecase67Recipe for generating entropy bytes using dice
This recipe was originally published in the article
articleCreating_and_signing_a_standard_raw_Bitcoin_transaction:_Iteration_#2edgecase63Creating and signing a standard raw Bitcoin transaction: Iteration #2
, in the section Recipes For Using Various Downloadable Assets, in the part "Recipe 2: generate_bitcoin_address_3.py". The recipe shown here has been edited for republication.
Recipe
Initial conditions:
- You must have Python 2.7.x installed on your computer. These code assets were developed / tested under Python 2.7.13 running on Mac OS X 10.6.8 (Snow Leopard), and should run successfully on other versions of Python 2.7.
- You must already have a Bitcoin private key (ideally 32 bytes). A 32-byte private key will be 64 hex characters long. When used as a control value in this recipe, it must be a 64-character string that consists only of hex characters (the ten digit characters "0123456789" and the lower-case alphabetical characters "abcdef").
1) Create a work directory.
2) Browse to the Assets part of this article and download all the linked assets. List of assets:
- bitcoin_functions.py
- bjorn_edstrom_ripemd160.py
- ecdsa-0.10.tar.gz
- generate_bitcoin_address_3.py
- pypy_sha256.py
3) Move these assets into the work directory.
4) Unpack the zipped tape archive file ecdsa-0.10.tar.gz. This can be done by opening a terminal, changing directory to the work directory, and running the following command:
tar -zxvf ecdsa-0.10.tar.gz
This unpacking should produce a new directory named "ecdsa-0.10" in the work directory. The directory "ecdsa-0.10" should contain a directory named "ecdsa". Copy the "ecdsa" directory into the work directory.
5) Open the file generate_bitcoin_address_3.py in a text editor. Scroll to lines 71-77, which should be the section of text that lies between
##### START CONTROLS
and
##### END CONTROLS
6) Set the variable private_key_type to "hex_bytes".
7) Set the variable private_key_hex_bytes to be the private key.
8) Open a terminal and change directory to the work directory.
9) Run the following command:
python generate_bitcoin_address_3.py
The output should contain the Bitcoin address that corresponds to your private key.
Example
aineko:work stjohnpiano$ python generate_bitcoin_address_3.py
### START GENERATION OF BITCOIN ADDRESS
Private key (hex bytes): a26e15954d2dafcee70eeaaa084eab8a4c1a30b0f71a42be4d8da20123bff121
Private key (32 hex bytes): a26e15954d2dafcee70eeaaa084eab8a4c1a30b0f71a42be4d8da20123bff121
Private key (WIF): 5K3pdySk3c2jz3i7jiULrMZN5JSUSEEF1M1bbetRRVAbE2vdEv9
Bitcoin address: 1AGygbyEFYduWkkmZbbvirgS9kuBBMLJCP
### END GENERATION OF BITCOIN ADDRESS
iQIcBAABCgAGBQJb7AJzAAoJECL1OzZgiBhw+lsP/AmPimwqvPybQ2Z0+cN9FdLx
htZ2KLk3Ji1PLnLwpoNYF5aSZc41SlVtSS7aIfT0lyK8JPTwgb/EmYYlvz9jKti5
NkmBnGnTBMF28WNCt4fU1IQrU6WMvYAcfUhLW2UlmVIh0Cp5axpwbFOd7OADN2gY
s5qfVOf72NCyTkXA28DjBAu6rwEc+7QmMWxNvtSGWK3MTwacDEl/gZcR+HX/G+YG
/cwWBFnA7ecvw0E/4iIEzRBaNHlxIwIrFIqgRfdSeY2WTfr9lRx4fNFmhljH+Mdj
hmDXnGwVKv4YEFjkWyQ50HFAREeuuIRnMpKRKnDpV4xhPlGmWkXGqLCQ74enmccw
Dm7+r0BFDaE+1hUjLgpy8+v/3CLttmMzOXjduHJ5EE9gaSimNQmWUei6q+RqmSzq
Juo0VFAVwoxWus3WQ+cKMicSs5deOjMt3Gg2aTs9B6FEz0gSq6dIUAmZay9UsEe+
oIFpJAJpMhOVlVE6azTUEzZYIJ1LKrG+kX7pnPGn9EfMjBy1KaJYEy3VDazkid7n
TvQ/6UZh7c2zF+s+0venPBJk92mb8AqVWoES7oOHRt8gZBXrvL3fB6YI6YJYDFN4
ahNIidnqm57cEI9L3feifCMxpEWaOi2qw01vlH93LQYAoC1MNxLTqFRaGBXyZZJA
cdEUQifVFYiywO0/QbbQ
=To+Q