-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
25 lines (18 loc) · 838 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import hashlib, ecdsa, base58, utils
import random
def privateKeyToWif(key_hex):
return base58.b58encode(0x80, key_hex.encode())
def privateKeyToPublicKey(s):
sk = ecdsa.SigningKey.from_string(s.encode(), curve=ecdsa.SECP256k1)
vk = sk.verifying_key
return ('\04' + sk.verifying_key.to_string()).encode('hex')
def pubKeyToAddr(s):
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(s.encode()).digest())
return base58.b58encode(0, ripemd160.digest())
def keyToAddr(s):
return pubKeyToAddr(privateKeyToPublicKey(s))
# Warning: this random function is not cryptographically strong and is just for example
private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)])
print (privateKeyToWif(private_key))
print (keyToAddr(private_key))