1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

apps/wallet/sign_tx: fix sighash

This commit is contained in:
Jan Pochyla 2018-02-09 14:16:33 +01:00
parent 800c2c64c8
commit e888b6b967
3 changed files with 5 additions and 5 deletions

View File

@ -321,7 +321,7 @@ async def sign_tx(tx: SignTx, root):
tx, txi, ecdsa_hash_pubkey(key_sign_pub), get_hash_type(coin))
signature = ecdsa_sign(key_sign, bip143_hash)
witness = get_p2wpkh_witness(signature, key_sign_pub)
witness = get_p2wpkh_witness(coin, signature, key_sign_pub)
tx_ser.serialized_tx = witness
tx_ser.signature_index = i
@ -402,10 +402,10 @@ def get_tx_header(tx: SignTx, segwit=False):
return w_txi
def get_p2wpkh_witness(signature: bytes, pubkey: bytes):
def get_p2wpkh_witness(coin: CoinType, signature: bytes, pubkey: bytes):
w = bytearray_with_cap(1 + 5 + len(signature) + 1 + 5 + len(pubkey))
write_varint(w, 0x02) # num of segwit items, in P2WPKH it's always 2
append_signature_and_pubkey(w, pubkey, signature)
append_signature_and_pubkey(w, pubkey, signature, get_hash_type(coin))
return w

View File

@ -87,7 +87,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
# test data public key hash
# only for input 2 - input 1 is not segwit
result = bip143.preimage_hash(self.tx, self.inp2, unhexlify('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1'))
result = bip143.preimage_hash(self.tx, self.inp2, unhexlify('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1'), 0x01)
self.assertEqual(hexlify(result), b'c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670')

View File

@ -74,7 +74,7 @@ class TestSegwitBip143(unittest.TestCase):
bip143.add_output(txo_bin)
# test data public key hash
result = bip143.preimage_hash(self.tx, self.inp1, unhexlify('79091972186c449eb1ded22b78e40d009bdf0089'))
result = bip143.preimage_hash(self.tx, self.inp1, unhexlify('79091972186c449eb1ded22b78e40d009bdf0089'), 0x01)
self.assertEqual(hexlify(result), b'64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6')