Skip to content

Bitcoin

Bitcoin

https://karpathy.github.io/2021/06/21/blockchain/

Generating an Address

Download Addresses:

wget http://addresses.loyce.club/blockchair_bitcoin_addresses_and_balance_October_19_2020.tsv.gz -O - | gunzip 

Sort List:

cat blockchair_bitcoin_addresses_and_balance_LATEST.tsv | grep "^b" > bech32_bitcoin_addresses
cat blockchair_bitcoin_addresses_and_balance_LATEST.tsv | grep "^1" > p2pkh_bitcoin_addresses
cat blockchair_bitcoin_addresses_and_balance_LATEST.tsv | grep "^3" > p2sh_bitcoin_addresses

Check Address list against:
comm -12 Bitcoin_addresses_LATEST.txt <(cat mylist.txt | sort | uniq)

import hashlib
from cryptopals_lib import *

def key2address(public_key, version=b"\x00"):
	#Compress the Public Key
	bytes_public_key = publicKey.compressed()
	
	#Hash the Public Key with Sha256 then hash that output with ripemd160
	hashed_public_key = hashlib.new('ripemd160', hashlib.new('sha256', bytes_public_key).digest()).digest()

	#Version Information. \x00 for mainnet and \x6f for testnet
	#version = b"\x00"

	#Take the first 4 bytes of the double sha256 hashed publickey and version
	checksum = hashlib.new('sha256', hashlib.new('sha256', version + hashed_public_key).digest()).digest()[:4]

	# BASE58(Version || Hashed Output || Checksum)
	return b58encode(version + hashed_public_key + checksum)


#Generate Private Public Key pair
privateKey, publicKey = generate_KeyPair(secp256k1_Generator_Point)

print(key2address(publicKey))
#1Nn73LPMp8T1dJUixQYMZvEBcZpVNgHTCn

Sending a Transaction

import hashlib
from cryptopals_lib import *

#Generate From Address
from_privateKey, from_publicKey = generate_KeyPair(secp256k1_Generator_Point)
from_address = key2address(from_publicKey)

#Generate To Address
_, to_publicKey = generate_KeyPair(secp256k1_Generator_Point)

Signatures

Schorr_Signature