From e888b6b967d0d5bda715336d38696a947c3d28bb Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Fri, 9 Feb 2018 14:16:33 +0100 Subject: [PATCH] apps/wallet/sign_tx: fix sighash --- src/apps/wallet/sign_tx/signing.py | 6 +++--- tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py | 2 +- tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index 06c340b30..b51c0113c 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -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 diff --git a/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py b/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py index a44de48fb..163124e3e 100644 --- a/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py +++ b/tests/test_apps.wallet.segwit.bip143.native_p2wpkh.py @@ -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') diff --git a/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py b/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py index 1a5861296..738f987f5 100644 --- a/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py +++ b/tests/test_apps.wallet.segwit.bip143.p2wpkh_in_p2sh.py @@ -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')