3
3
"""
4
4
5
5
import hashlib
6
-
6
+ from fallback import RIPEMD160Hash
7
7
from debug import logger
8
8
from pyelliptic import arithmetic
9
9
@@ -15,21 +15,20 @@ def calculateBitcoinAddressFromPubkey(pubkey):
15
15
' function was passed a pubkey that was'
16
16
' %i bytes long rather than 65.' , len (pubkey ))
17
17
return "error"
18
- ripe = hashlib .new ('ripemd160' )
19
18
sha = hashlib .new ('sha256' )
20
19
sha .update (pubkey )
21
- ripe . update (sha .digest ())
22
- ripeWithProdnetPrefix = '\x00 ' + ripe .digest ()
20
+ ripe = RIPEMD160Hash (sha .digest ())
21
+ ripeWithProdnetPrefix = b '\x00 ' + ripe .digest ()
23
22
24
23
checksum = hashlib .sha256 (hashlib .sha256 (
25
24
ripeWithProdnetPrefix ).digest ()).digest ()[:4 ]
26
25
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
27
26
numberOfZeroBytesOnBinaryBitcoinAddress = 0
28
- while binaryBitcoinAddress [ 0 ] == '\x00 ' :
27
+ while binaryBitcoinAddress . startswith ( b '\x00 ') :
29
28
numberOfZeroBytesOnBinaryBitcoinAddress += 1
30
29
binaryBitcoinAddress = binaryBitcoinAddress [1 :]
31
30
base58encoded = arithmetic .changebase (binaryBitcoinAddress , 256 , 58 )
32
- return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
31
+ return b "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
33
32
34
33
35
34
def calculateTestnetAddressFromPubkey (pubkey ):
@@ -39,18 +38,17 @@ def calculateTestnetAddressFromPubkey(pubkey):
39
38
' function was passed a pubkey that was'
40
39
' %i bytes long rather than 65.' , len (pubkey ))
41
40
return "error"
42
- ripe = hashlib .new ('ripemd160' )
43
41
sha = hashlib .new ('sha256' )
44
42
sha .update (pubkey )
45
- ripe . update (sha .digest ())
46
- ripeWithProdnetPrefix = '\x6F ' + ripe .digest ()
43
+ ripe = RIPEMD160Hash (sha .digest ())
44
+ ripeWithProdnetPrefix = b '\x6F ' + ripe .digest ()
47
45
48
46
checksum = hashlib .sha256 (hashlib .sha256 (
49
47
ripeWithProdnetPrefix ).digest ()).digest ()[:4 ]
50
48
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
51
49
numberOfZeroBytesOnBinaryBitcoinAddress = 0
52
- while binaryBitcoinAddress [ 0 ] == '\x00 ' :
50
+ while binaryBitcoinAddress . startswith ( b '\x00 ') :
53
51
numberOfZeroBytesOnBinaryBitcoinAddress += 1
54
52
binaryBitcoinAddress = binaryBitcoinAddress [1 :]
55
53
base58encoded = arithmetic .changebase (binaryBitcoinAddress , 256 , 58 )
56
- return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
54
+ return b "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
0 commit comments