|
|
|
@ -2,7 +2,7 @@ from common import *
|
|
|
|
|
|
|
|
|
|
from apps.bitcoin.common import SIGHASH_ALL
|
|
|
|
|
from apps.bitcoin.scripts import output_derive_script
|
|
|
|
|
from apps.bitcoin.sign_tx.bitcoin import Bip143Hash
|
|
|
|
|
from apps.bitcoin.sign_tx.bitcoin import BitcoinSigHasher
|
|
|
|
|
from apps.bitcoin.writers import get_tx_hash
|
|
|
|
|
from apps.common import coins
|
|
|
|
|
from apps.common.keychain import Keychain
|
|
|
|
@ -49,53 +49,53 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_prevouts(self):
|
|
|
|
|
coin = coins.by_name(self.tx.coin_name)
|
|
|
|
|
bip143 = Bip143Hash()
|
|
|
|
|
bip143.add_input(self.inp1, b"")
|
|
|
|
|
bip143.add_input(self.inp2, b"")
|
|
|
|
|
prevouts_hash = get_tx_hash(bip143.h_prevouts, double=coin.sign_hash_double)
|
|
|
|
|
sig_hasher = BitcoinSigHasher()
|
|
|
|
|
sig_hasher.add_input(self.inp1, b"")
|
|
|
|
|
sig_hasher.add_input(self.inp2, b"")
|
|
|
|
|
prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double)
|
|
|
|
|
self.assertEqual(hexlify(prevouts_hash), b'96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37')
|
|
|
|
|
|
|
|
|
|
def test_sequence(self):
|
|
|
|
|
coin = coins.by_name(self.tx.coin_name)
|
|
|
|
|
bip143 = Bip143Hash()
|
|
|
|
|
bip143.add_input(self.inp1, b"")
|
|
|
|
|
bip143.add_input(self.inp2, b"")
|
|
|
|
|
sequence_hash = get_tx_hash(bip143.h_sequences, double=coin.sign_hash_double)
|
|
|
|
|
sig_hasher = BitcoinSigHasher()
|
|
|
|
|
sig_hasher.add_input(self.inp1, b"")
|
|
|
|
|
sig_hasher.add_input(self.inp2, b"")
|
|
|
|
|
sequence_hash = get_tx_hash(sig_hasher.h_sequences, double=coin.sign_hash_double)
|
|
|
|
|
self.assertEqual(hexlify(sequence_hash), b'52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b')
|
|
|
|
|
|
|
|
|
|
def test_outputs(self):
|
|
|
|
|
|
|
|
|
|
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
|
|
|
|
|
coin = coins.by_name(self.tx.coin_name)
|
|
|
|
|
bip143 = Bip143Hash()
|
|
|
|
|
sig_hasher = BitcoinSigHasher()
|
|
|
|
|
|
|
|
|
|
for txo in [self.out1, self.out2]:
|
|
|
|
|
script_pubkey = output_derive_script(txo.address, coin)
|
|
|
|
|
txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey)
|
|
|
|
|
bip143.add_output(txo_bin, script_pubkey)
|
|
|
|
|
sig_hasher.add_output(txo_bin, script_pubkey)
|
|
|
|
|
|
|
|
|
|
outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double)
|
|
|
|
|
outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double)
|
|
|
|
|
self.assertEqual(hexlify(outputs_hash), b'863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5')
|
|
|
|
|
|
|
|
|
|
def test_preimage_testdata(self):
|
|
|
|
|
|
|
|
|
|
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
|
|
|
|
|
coin = coins.by_name(self.tx.coin_name)
|
|
|
|
|
bip143 = Bip143Hash()
|
|
|
|
|
bip143.add_input(self.inp1, b"")
|
|
|
|
|
bip143.add_input(self.inp2, b"")
|
|
|
|
|
sig_hasher = BitcoinSigHasher()
|
|
|
|
|
sig_hasher.add_input(self.inp1, b"")
|
|
|
|
|
sig_hasher.add_input(self.inp2, b"")
|
|
|
|
|
|
|
|
|
|
for txo in [self.out1, self.out2]:
|
|
|
|
|
script_pubkey = output_derive_script(txo.address, coin)
|
|
|
|
|
txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey)
|
|
|
|
|
bip143.add_output(txo_bin, script_pubkey)
|
|
|
|
|
sig_hasher.add_output(txo_bin, script_pubkey)
|
|
|
|
|
|
|
|
|
|
keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema])
|
|
|
|
|
node = keychain.derive(self.inp2.address_n)
|
|
|
|
|
|
|
|
|
|
# test data public key hash
|
|
|
|
|
# only for input 2 - input 1 is not segwit
|
|
|
|
|
result = bip143.preimage_hash(1, self.inp2, [node.public_key()], 1, self.tx, coin, SIGHASH_ALL)
|
|
|
|
|
result = sig_hasher.hash143(self.inp2, [node.public_key()], 1, self.tx, coin, SIGHASH_ALL)
|
|
|
|
|
self.assertEqual(hexlify(result), b'2fa3f1351618b2532228d7182d3221d95c21fd3d496e7e22e9ded873cf022a8b')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|