mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-01 18:30:56 +00:00
no need to use byteindex/iterbytes anymore
This commit is contained in:
parent
f2a52400c3
commit
a9291e89c5
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user