from binascii import unhexlify hexlify import hashlib from base58 impo

 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
from binascii import unhexlify, hexlify
import hashlib
from base58 import b58encode
from secp256k1 import PrivateKey
from pycoin.symbols.btc import network as btc_network
wif = '5J2CbVdUaaQ3xR7fB9A9G5HnCN6uzMX152w2P9weonXp3qRepUp'
pk_hex = hexlify(btc_network.parse.wif(wif).secret_exponent().to_bytes(32, byteorder='big'))
pk_bytes = unhexlify(pk_hex)
pubkey = PrivateKey(pk_bytes).pubkey
pub_bytes = pubkey.serialize(True)
ripe_hash = hashlib.new('ripemd160')
ripe_hash.update(pub_bytes)
ripe_hex = ripe_hash.hexdigest()
print('ripe hex', ripe_hex)
ext_hex = pub_comp + ripe_hex[:8]
print('ext hex', ext_hex)
b58 = b58encode(unhexlify(ext_hex))
addr = 'EOS' + b58
print(addr)