diff --git a/tests/device_tests/test_zerosig.py b/tests/device_tests/test_zerosig.py index 0e1393b80d..2a518830db 100644 --- a/tests/device_tests/test_zerosig.py +++ b/tests/device_tests/test_zerosig.py @@ -25,13 +25,6 @@ import common from trezorlib import messages as proto -if sys.version_info < (3,): - def byteindex(data, index): - return ord(data[index]) -else: - def byteindex(data, index): - return data[index] - TXHASH_d5f65e = binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882') @@ -63,7 +56,7 @@ class TestZeroSig(common.TrezorTest): tx = self.client.call(msg) - siglen = byteindex(tx.serialized_tx, 44) + siglen = tx.serialized_tx[44] print(siglen) if siglen < 67: print("!!!!", n) @@ -89,7 +82,7 @@ class TestZeroSig(common.TrezorTest): ) (signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) - siglen = byteindex(serialized_tx, 44) + siglen = serialized_tx[44] # TREZOR must strip leading zero from signature self.assertEqual(siglen, 67) @@ -112,7 +105,7 @@ class TestZeroSig(common.TrezorTest): ) (signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) - siglen = byteindex(serialized_tx, 44) + siglen = serialized_tx[44] # TREZOR must strip leading zero from signature self.assertEqual(siglen, 66) diff --git a/trezorlib/ckd_public.py b/trezorlib/ckd_public.py index 1aee54e4f3..4ee2244d09 100644 --- a/trezorlib/ckd_public.py +++ b/trezorlib/ckd_public.py @@ -32,20 +32,13 @@ from . import messages as proto PRIME_DERIVATION_FLAG = 0x80000000 -if sys.version_info < (3,): - def byteindex(data, index): - return ord(data[index]) -else: - def byteindex(data, index): - return data[index] - def point_to_pubkey(point): order = SECP256k1.order x_str = number_to_string(point.x(), order) y_str = number_to_string(point.y(), order) vk = x_str + y_str - return struct.pack('B', (byteindex(vk, 63) & 1) + 2) + vk[0:32] # To compressed key + return struct.pack('B', vk[63] & 1 + 2) + vk[0:32] # To compressed key def sec_to_public_pair(pubkey): @@ -152,7 +145,7 @@ def deserialize(xpub): node.chain_code = data[13:45] key = data[45:-4] - if byteindex(key, 0) == 0: + if key[0] == 0: node.private_key = key[1:] else: node.public_key = key diff --git a/trezorlib/tools.py b/trezorlib/tools.py index 4ff3b50e86..9f874d4b5c 100644 --- a/trezorlib/tools.py +++ b/trezorlib/tools.py @@ -22,17 +22,6 @@ import binascii import struct import sys -if sys.version_info < (3,): - def byteindex(data, index): - return ord(data[index]) - - def iterbytes(data): - return (ord(char) for char in data) -else: - def byteindex(data, index): - return data[index] - iterbytes = iter - def Hash(data): return hashlib.sha256(hashlib.sha256(data).digest()).digest() @@ -52,8 +41,8 @@ def hash_160_to_bc_address(h160, address_type): def compress_pubkey(public_key): - if byteindex(public_key, 0) == 4: - return bytes((byteindex(public_key, 64) & 1) + 2) + public_key[1:33] + if public_key[0] == 4: + return bytes(public_key[64] & 1 + 2) + public_key[1:33] raise ValueError("Pubkey is already compressed") @@ -73,7 +62,7 @@ def b58encode(v): """ encode v, which is a string of bytes, to base58.""" long_value = 0 - for c in iterbytes(v): + for c in v: long_value = long_value * 256 + c result = '' @@ -86,7 +75,7 @@ def b58encode(v): # Bitcoin does a little leading-zero-compression: # leading 0-bytes in the input become leading-1s nPad = 0 - for c in iterbytes(v): + for c in v: if c == 0: nPad += 1 else: