Python Bitcoin Address Generator Compressed Keys

15.12.2020
Python Bitcoin Address Generator Compressed Keys Rating: 7,4/10 5907 reviews

Jul 16, 2018 What we get is 17JsmEygbbEUEpvt4PFtYaTeSqfb9ki1F1, a compressed Bitcoin wallet address. The wallet key generation process can be split into four steps: creating a public key with ECDSA; encrypting the key with SHA-256 and RIPEMD-160; calculating the checksum with double SHA-256; encoding the key with Base58.

bitwalletrecover.py - recover compressed private keys from your bitcoin wallet. Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
  • I wanted to learn how to create a Bitcoin wallet in code. I used as reference this guide which has code examples in JavaScript. I wrote my implementation in Python. Here is the resulting code: #!.
  • Bitcoin Key Compression Tool. This tool converts between compressed and uncompressed bitcoin keys. The main purpose is as a diagnostic tool.
bitwalletrecover.py
importre
importhashlib
importbase58
frompycoin.ecdsaimportgenerator_secp256k1, public_pair_for_secret_exponent
defbytetohex(byteStr):
return'.join( [ '%02X'%xforxinbyteStr ] ).strip()
litecoin= [b'x30', b'xb0']
bitcoin= [b'x00', b'x80']
cointype=litecoin
walletHandle=open('C:/Users/alex/Downloads/litecoin-0.8.5.1-win32-setup/data/wallet.dat', 'rb')
wallet=walletHandle.read()
privKeys=set(re.findall(b'x70x6Fx6Fx6C(.{52})', wallet))
print('Found %d privKeys'%len(privKeys))
forkeyinprivKeys:
key=key[20:]
public_x, public_y=public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16))
compressed_public_key=bytes.fromhex('%02x%064x'% (2+ (public_y&1), public_x))
#https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
m=hashlib.new('ripemd160')
m.update(hashlib.sha256(compressed_public_key).digest())
ripe=m.digest() # Step 2 & 3
extRipe=cointype[0] +ripe# Step 4
chksum=hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7
addr=extRipe+chksum# Step 8
print('Address:', base58.b58encode(addr))
# compressed wallet import format http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development
key=cointype[1] +key+b'x01'
chksum=hashlib.sha256(hashlib.sha256(key).digest()).digest()[:4]
addr=key+chksum# Step 8
print('Private Key:', base58.b58encode(addr),'n')
walletHandle.close()
Keys
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Bitcoin Wallet Address Generator

This is a simple Bitcoin wallet address generator coded in Python 3.It generates a Private Key in different formats (hex, wif and compressed wif) and corresponding Public Addresses, raw, P2WPKH addresses starting with prefix 1, P2SH addresses starting with prefix 3 as part of Segwit soft fork and Bech32 addresses with prefix bc1 P2WPKH and P2WSH.

Installation

Usage

Example 1
Output:
Example 2

Python Bitcoin Address Generator Compressed Keys Generator

Output:

Authors

Python Bitcoin Address Generator Compressed Keys Download

Pedro Fortes and others who contribute.

License

Python Bitcoin Address Generator Compressed Keys Download

This software is distributed under the terms of the MIT License.See the file 'LICENSE' in the root directory of the present distribution, or http://opensource.org/licenses/MIT. /medal-of-honor-2010-serial-key-generator.html.