mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
trezorlib: remove Hash to btc_hash, prepare for moving it away from things
This commit is contained in:
parent
325312d11c
commit
b7c7190573
@ -110,7 +110,7 @@ class MyTxApiBitcoin(object):
|
||||
o.script_pubkey = b'\x76\xa9\x14' + pubkey + b'\x88\xac'
|
||||
|
||||
txser = self.serialize_tx(t)
|
||||
txhash = tools.Hash(txser)[::-1]
|
||||
txhash = tools.btc_hash(txser)[::-1]
|
||||
self.inputs.append(
|
||||
proto_types.TxInputType(
|
||||
address_n=self.client.expand_path("44'/0'/0'/0/%d" % idx),
|
||||
|
@ -1029,7 +1029,7 @@ class ProtocolMixin(object):
|
||||
if xprv[0:4] not in ('xprv', 'tprv'):
|
||||
raise ValueError("Unknown type of xprv")
|
||||
|
||||
if len(xprv) < 100 and len(xprv) > 112:
|
||||
if not 100 < len(xprv) < 112: # yes this is correct in Python
|
||||
raise ValueError("Invalid length of xprv")
|
||||
|
||||
node = proto.HDNodeType()
|
||||
@ -1038,7 +1038,7 @@ class ProtocolMixin(object):
|
||||
if data[90:92] != b'00':
|
||||
raise ValueError("Contain invalid private key")
|
||||
|
||||
checksum = binascii.hexlify(hashlib.sha256(hashlib.sha256(binascii.unhexlify(data[:156])).digest()).digest()[:4])
|
||||
checksum = binascii.hexlify(tools.btc_hash(binascii.unhexlify(data[:156]))[:4])
|
||||
if checksum != data[156:]:
|
||||
raise ValueError("Checksum doesn't match")
|
||||
|
||||
|
@ -126,14 +126,14 @@ def serialize(node, version=0x0488B21E):
|
||||
s += b'\x00' + node.private_key
|
||||
else:
|
||||
s += node.public_key
|
||||
s += tools.Hash(s)[:4]
|
||||
s += tools.btc_hash(s)[:4]
|
||||
return tools.b58encode(s)
|
||||
|
||||
|
||||
def deserialize(xpub):
|
||||
data = tools.b58decode(xpub, None)
|
||||
|
||||
if tools.Hash(data[:-4])[:4] != data[-4:]:
|
||||
if tools.btc_hash(data[:-4])[:4] != data[-4:]:
|
||||
raise ValueError("Checksum failed")
|
||||
|
||||
node = messages.HDNodeType()
|
||||
|
@ -35,7 +35,10 @@ def H_(x: int) -> int:
|
||||
return x | HARDENED_FLAG
|
||||
|
||||
|
||||
def Hash(data):
|
||||
def btc_hash(data):
|
||||
"""
|
||||
Double-SHA256 hash as used in BTC
|
||||
"""
|
||||
return hashlib.sha256(hashlib.sha256(data).digest()).digest()
|
||||
|
||||
|
||||
@ -47,7 +50,7 @@ def hash_160(public_key):
|
||||
|
||||
def hash_160_to_bc_address(h160, address_type):
|
||||
vh160 = struct.pack('<B', address_type) + h160
|
||||
h = Hash(vh160)
|
||||
h = btc_hash(vh160)
|
||||
addr = vh160 + h[0:4]
|
||||
return b58encode(addr)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user