Created
November 19, 2012 23:37
-
-
Save natedaiger/4114875 to your computer and use it in GitHub Desktop.
deterministic bitcoin address generator...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I FOUND THIS HERE: | |
# | |
# https://bitcointalk.org/index.php?action=printpage;topic=84238.0 | |
import ecdsa | |
secp256k1curve = ecdsa.ellipticcurve.CurveFp(115792089237316195423570985008687907853269984665640564039457584007908834671663, 0, 7) | |
secp256k1point = ecdsa.ellipticcurve.Point(secp256k1curve, 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798, 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141) | |
secp256k1 = ecdsa.curves.Curve('secp256k1', secp256k1curve, secp256k1point, (1, 3, 132, 0, 10)) | |
#-------------------------------------- | |
import binascii | |
import hashlib | |
import json | |
def json_dump_for(phrase, count, start=1): | |
print json.dumps(deterministic_addresses(phrase, count, start)) | |
def print_addresses_for(phrase, count): | |
addresses = deterministic_addresses(phrase, count) | |
for (i, address) in addresses: | |
print "{}: {}".format(i, address) | |
def deterministic_addresses(phrase, count, start=1): | |
end = start + count | |
return [(i, addy_from_phrase(phrase + str(i))) for i in range(start, end)] | |
def addy_from_phrase(phrase): | |
pk = int(sha256_of_phrase(phrase), 16) | |
return addy_from_int(pk) | |
def sha256_of_phrase(phrase): | |
return hashlib.sha256(phrase).hexdigest() | |
def addy_from_int(pk): | |
pko = ecdsa.SigningKey.from_secret_exponent(pk, secp256k1) | |
pubkey = binascii.hexlify(pko.get_verifying_key().to_string()) | |
pubkey2 = hashlib.sha256(binascii.unhexlify('04' + pubkey)).hexdigest() | |
pubkey3 = hashlib.new('ripemd160', binascii.unhexlify(pubkey2)).hexdigest() | |
pubkey4 = hashlib.sha256(binascii.unhexlify('00' + pubkey3)).hexdigest() | |
pubkey5 = hashlib.sha256(binascii.unhexlify(pubkey4)).hexdigest() | |
pubkey6 = pubkey3 + pubkey5[:8] | |
pubnum = int(pubkey6, 16) | |
pubnumlist = [] | |
while pubnum != 0: | |
pubnumlist.append(pubnum % 58) | |
pubnum /= 58 | |
address = '' | |
for l in ['123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'[x] for x in pubnumlist]: | |
address = l + address | |
return '1' + address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment