#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import ecdsa
import base58
import hashlib


# ref : https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
# ref :https://davanum.wordpress.com/2014/03/17/generating-a-bitcoin-private-key-and-address/


def privkeytopubkey(privk):
    sk = ecdsa.SigningKey.from_string(privk, curve=ecdsa.SECP256k1)
    pubk = b'\04' + sk.verifying_key.to_string()
    return pubk


def pubkeytoaddr(pubk):
    hash1 = hashlib.sha256(pubk).digest()
    hash2 = hashlib.new('ripemd160', data=hash1).digest()
    addr = base58.b58encode_check(hash2)
    return addr


if __name__ == '__main__':
    privkey = bytes.fromhex('18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725')

    pubkey = privkeytopubkey(privkey)
    print('pubkey: {}'.format(pubkey.hex()))

    addr = pubkeytoaddr(pubkey)
    print('addr: {}'.format(addr))

@@ -83,16 +83,33 @@
 ashlib%0A%0A
+import unittest%0A%0A
 %0A# ref :
@@ -605,16 +605,26 @@
 e_check(
+b'%5Cx00' + 
 hash2)%0A 
@@ -644,33 +644,158 @@
 r%0A%0A%0A
-if __name__ == '__main__'
+def privkeytoaddr(privk):%0A    pubk = privkeytopubkey(privk)%0A    addr = pubkeytoaddr(pubk)%0A    return addr%0A%0A%0Aclass PrivKeyToAddrTest(unittest.TestCase)
 :%0A  
@@ -888,17 +888,16 @@
 21725')%0A
-%0A
     pubk
@@ -905,93 +905,429 @@
 y = 
-privkeytopubkey(privkey)%0A    print('pubkey: %7B%7D'.format(pubkey.hex()))%0A%0A    addr = pub
+'0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6'%0A    addr = '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'%0A%0A%0A    def test_privkeytopubkey(self):%0A        self.assertEqual(%0A            privkeytopubkey(self.privkey).hex().lower(), %0A            self.pubkey.lower()%0A        )%0A%0A    def test_privkeytoaddr(self):%0A        self.assertEqual(%0A            priv
 keyt
@@ -1336,47 +1336,100 @@
 ddr(
-pub
+self.priv
 key)
+,
 %0A    
-print('addr: %7B%7D'.format(addr)
+        self.addr%0A        )%0A%0A%0Aif __name__ == '__main__':%0A    unittest.main(
 )%0A

update bitcoinaddr.py