1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

core/sign_tx: Clarify sign_nonsegwit_input().

This commit is contained in:
Andrew Kozlik 2020-05-05 09:41:55 +02:00 committed by Andrew Kozlik
parent 9005093435
commit d5faeb3f51

View File

@ -310,27 +310,29 @@ class Bitcoin:
txi = await helpers.request_tx_input(self.tx_req, i, self.coin) txi = await helpers.request_tx_input(self.tx_req, i, self.coin)
writers.write_tx_input_check(h_check, txi) writers.write_tx_input_check(h_check, txi)
if i == i_sign: if i == i_sign:
txi_sign = txi self.wallet_path.check_input(txi)
self.wallet_path.check_input(txi_sign) self.multisig_fingerprint.check_input(txi)
self.multisig_fingerprint.check_input(txi_sign)
# NOTE: wallet_path is checked in write_tx_input_check() # NOTE: wallet_path is checked in write_tx_input_check()
node = self.keychain.derive(txi.address_n, self.coin.curve_name) node = self.keychain.derive(txi.address_n, self.coin.curve_name)
key_sign_pub = node.public_key() key_sign_pub = node.public_key()
# if multisig, do a sanity check to ensure we are signing with a key that is included in the multisig
if txi.multisig:
multisig.multisig_pubkey_index(txi.multisig, key_sign_pub)
# for the signing process the script_sig is equal # for the signing process the script_sig is equal
# to the previous tx's scriptPubKey (P2PKH) or a redeem script (P2SH) # to the previous tx's scriptPubKey (P2PKH) or a redeem script (P2SH)
if txi_sign.script_type == InputScriptType.SPENDMULTISIG: if txi.script_type == InputScriptType.SPENDMULTISIG:
txi_sign.script_sig = scripts.output_script_multisig( txi.script_sig = scripts.output_script_multisig(
multisig.multisig_get_pubkeys(txi_sign.multisig), multisig.multisig_get_pubkeys(txi.multisig), txi.multisig.m,
txi_sign.multisig.m,
) )
elif txi_sign.script_type == InputScriptType.SPENDADDRESS: elif txi.script_type == InputScriptType.SPENDADDRESS:
txi_sign.script_sig = scripts.output_script_p2pkh( txi.script_sig = scripts.output_script_p2pkh(
addresses.ecdsa_hash_pubkey(key_sign_pub, self.coin) addresses.ecdsa_hash_pubkey(key_sign_pub, self.coin)
) )
else: else:
raise SigningError( raise SigningError(
FailureType.ProcessError, "Unknown transaction type" FailureType.ProcessError, "Unknown transaction type"
) )
txi_sign = txi
else: else:
txi.script_sig = bytes() txi.script_sig = bytes()
self.write_tx_input(h_sign, txi) self.write_tx_input(h_sign, txi)
@ -355,10 +357,6 @@ class Bitcoin:
FailureType.ProcessError, "Transaction has changed during signing" FailureType.ProcessError, "Transaction has changed during signing"
) )
# if multisig, do a sanity check to ensure we are signing with a key that is included in the multisig
if txi_sign.multisig:
multisig.multisig_pubkey_index(txi_sign.multisig, key_sign_pub)
# compute the signature from the tx digest # compute the signature from the tx digest
signature = ecdsa_sign( signature = ecdsa_sign(
node, writers.get_tx_hash(h_sign, double=self.coin.sign_hash_double) node, writers.get_tx_hash(h_sign, double=self.coin.sign_hash_double)