edgecase_datafeed1552020-07-20
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.14492020-05-28bitcoinb27618deae05910f529240cc6960aeb87f017b12d302327253ee893825ce2bd46321001HtwyqFWNVDoSEVqZwjBRRAV2oEsi8aQXr13MfGs39pR5aEK4iKdoLjVYXKwi6Y3uyPqRecipe_for_generating_a_Bitcoin_address_#2stjohn_piano2020-07-19no
Contents
- 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_a_Bitcoin_transaction_with_two_outputsedgecase85bitcoin_functions_2.pybitcoin_functions_2.py653f38ebab7f7c176ce7925364b5916c32b8e97ab5d4c00a66b990a0b6e0074c
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 script that generates a standard Bitcoin address from a private key.
asset_of_another_articleEdgecase_Bitcoin_Storage_Toolset_version_2edgecase148generate_bitcoin_address_4.pygenerate_bitcoin_address_4.pyf8fad8e3c31555b9ff309d52fca360a9e22ea0f8b3689bfa9fc8e6370339f456
Asset: A Python implementation of SHA256. Author unknown.
asset_of_another_articleReading_and_verifying_a_standard_raw_bitcoin_transactionedgecase51pypy_sha256.pypypy_sha256.py2bbd4a83b69625e2f7ece5201475af2803f0ea11f3815c83d8afab3773d8f47b
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:
recipe_for_generating_entropy_bytes_using_dice_2 :
articleRecipe_for_generating_entropy_bytes_using_dice_#2edgecase151Recipe for generating entropy bytes using dice #2
Previous version of this recipe:
articleRecipe_for_generating_a_Bitcoin_addressedgecase69Recipe for generating a Bitcoin address
The code used in this recipe has been run in Python 2.7.5 on CentOS 7.6 and in Python 2.7.13 on Mac OS X 10.6.8. It should run successfully in Python 2.7.x.
Recipe
Initial conditions:
- You must already have a Bitcoin private key (ideally 32 bytes, but can be fewer). A 32-byte private key will be 64 hex characters. Hex characters consist of the ten digit characters "0123456789" and the lower-case alphabetical characters "abcdef".
Example Bitcoin private key:
15e7e195332b0aa8a684dc3be1f29dd04daa0a5434c11a8b9e6ad180df076ae4
1) Create a work directory.
2) Browse to the Assets section of this article and download all the linked assets.
List of assets:
- bitcoin_functions_2.py
- bjorn_edstrom_ripemd160.py
- ecdsa-0.10.tar.gz
- generate_bitcoin_address_4.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 will produce a new directory named "ecdsa-0.10" in the work directory. The directory "ecdsa-0.10" will contain a directory named "ecdsa". Copy the "ecdsa" directory into the work directory.
5) Open the file generate_bitcoin_address_4.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". By default, it is already set to this value.
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_4.py
The output should contain the Bitcoin address that corresponds to your private key.
Example
I've used the example private key shown earlier.
aineko:work stjohnpiano$ python generate_bitcoin_address_4.py
### START GENERATION OF BITCOIN ADDRESS
Private key (hex bytes): 15e7e195332b0aa8a684dc3be1f29dd04daa0a5434c11a8b9e6ad180df076ae4
Private key (32 hex bytes): 15e7e195332b0aa8a684dc3be1f29dd04daa0a5434c11a8b9e6ad180df076ae4
Private key (WIF): 5Hyw8omWJ9NxPXDzk6unt8kM28oanScP4msfUvt3L9nPt8wZdVf
Bitcoin address: 14gLgyVBiK7i7gtPLLYcVCAKfBuj1rL9JT
### END GENERATION OF BITCOIN ADDRESS
iQIcBAABCgAGBQJfFWA6AAoJECL1OzZgiBhwfyEQAJt3Es8jKr3v4chaQJfB1BxB
jDMfYB7Ms1H0k5Mj3uGaqcbyHN4Y/eAxrOYTeu82113sQT78xjSVFsz9VMfQ7RW7
jwVKHawJwfUb8s/7GB6HjlgkkFtZ5VO/+nE3bd8v8HbffhJ+ZH24UKVgAyD07cSN
ihxfjzW1Uq5U62PCwKFL/CgHiZBpRuaoBFm+clgE/jpi4TgCFXkxn2WRrO5eUHQD
1uBrG4h9A7UqyPig6OnBz/OIRJtL9IxQnSzlDd/P+PfLiW8y3SaIkbW9JfZlIssc
UNAOf3/+jvIBf+XbusCjpmD/cDoLx+KsoLpsLRXt9Oi4a1pFDZMbPtSZKN+d3mBk
CdbXmniwr3BwLhf5ao8UJZX3mmDFlKdLyNvvkl6KJA2u7jMO0cynpCv5FTSaQjVC
QcgpM+6V8SyVcNFbXapwLA+EvDz+xVprp9Z5psekRWlewI878n8UW4yfpKnk4ZDI
fF9o5rMTAfvQRe1W6nDhoRL+zZExEIs7Wwg/Jlq91/iLBEoytUI2udNLS5OTkPyQ
ubZzHfKM8+f6HD66bjiXxZrgpIqPWONFXFDb2o3fKCoRY6PrIwWNc+k3x6nI2fLY
FY6mLxzNc70WHKsiLtOQGvv0KGnwnWFf23yk4SLhwQ67kq3MSG0QYfbmLKkxowrw
cJx2dQaoXui22hnKfDSq
=nqVj