33"""
44
55import hashlib
6-
6+ from fallback import RIPEMD160Hash
77from debug import logger
88from pyelliptic import arithmetic
99
@@ -15,21 +15,20 @@ def calculateBitcoinAddressFromPubkey(pubkey):
1515 ' function was passed a pubkey that was'
1616 ' %i bytes long rather than 65.' , len (pubkey ))
1717 return "error"
18- ripe = hashlib .new ('ripemd160' )
1918 sha = hashlib .new ('sha256' )
2019 sha .update (pubkey )
21- ripe . update (sha .digest ())
22- ripeWithProdnetPrefix = '\x00 ' + ripe .digest ()
20+ ripe = RIPEMD160Hash (sha .digest ())
21+ ripeWithProdnetPrefix = b '\x00 ' + ripe .digest ()
2322
2423 checksum = hashlib .sha256 (hashlib .sha256 (
2524 ripeWithProdnetPrefix ).digest ()).digest ()[:4 ]
2625 binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
2726 numberOfZeroBytesOnBinaryBitcoinAddress = 0
28- while binaryBitcoinAddress [ 0 ] == '\x00 ' :
27+ while binaryBitcoinAddress . startswith ( b '\x00 ') :
2928 numberOfZeroBytesOnBinaryBitcoinAddress += 1
3029 binaryBitcoinAddress = binaryBitcoinAddress [1 :]
3130 base58encoded = arithmetic .changebase (binaryBitcoinAddress , 256 , 58 )
32- return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
31+ return b "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
3332
3433
3534def calculateTestnetAddressFromPubkey (pubkey ):
@@ -39,18 +38,17 @@ def calculateTestnetAddressFromPubkey(pubkey):
3938 ' function was passed a pubkey that was'
4039 ' %i bytes long rather than 65.' , len (pubkey ))
4140 return "error"
42- ripe = hashlib .new ('ripemd160' )
4341 sha = hashlib .new ('sha256' )
4442 sha .update (pubkey )
45- ripe . update (sha .digest ())
46- ripeWithProdnetPrefix = '\x6F ' + ripe .digest ()
43+ ripe = RIPEMD160Hash (sha .digest ())
44+ ripeWithProdnetPrefix = b '\x6F ' + ripe .digest ()
4745
4846 checksum = hashlib .sha256 (hashlib .sha256 (
4947 ripeWithProdnetPrefix ).digest ()).digest ()[:4 ]
5048 binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
5149 numberOfZeroBytesOnBinaryBitcoinAddress = 0
52- while binaryBitcoinAddress [ 0 ] == '\x00 ' :
50+ while binaryBitcoinAddress . startswith ( b '\x00 ') :
5351 numberOfZeroBytesOnBinaryBitcoinAddress += 1
5452 binaryBitcoinAddress = binaryBitcoinAddress [1 :]
5553 base58encoded = arithmetic .changebase (binaryBitcoinAddress , 256 , 58 )
56- return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
54+ return b "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
0 commit comments