From c01ebeb552b2b81490b6e8edb3d505e1eb19c6fc Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Sun, 25 Feb 2018 19:12:20 +0100 Subject: [PATCH] signing/multisig: reuse some code --- src/apps/wallet/sign_tx/multisig.py | 3 ++- src/apps/wallet/sign_tx/signing.py | 14 +------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/apps/wallet/sign_tx/multisig.py b/src/apps/wallet/sign_tx/multisig.py index 70c2bf2f24..09acb09cfa 100644 --- a/src/apps/wallet/sign_tx/multisig.py +++ b/src/apps/wallet/sign_tx/multisig.py @@ -66,7 +66,8 @@ def multisig_pubkey_index(multisig: MultisigRedeemScriptType, pubkey: bytes) -> for i, hd in enumerate(multisig.pubkeys): if multisig_get_pubkey(hd) == pubkey: return i - return None + raise SigningError(FailureType.DataError, + 'Pubkey not found in multisig script') def multisig_get_pubkey(hd: HDNodePathType) -> bytes: diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index f18cb4bb8c..16069ee1fd 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -185,10 +185,7 @@ async def sign_tx(tx: SignTx, root): # if multisig, check if singing with a key that is included in multisig if txi_sign.multisig: - pubkey_idx = multisig_pubkey_index(txi_sign.multisig, key_sign_pub) - if pubkey_idx is None: - raise SigningError(FailureType.DataError, - 'Pubkey not found in multisig script') + multisig_pubkey_index(txi_sign.multisig, key_sign_pub) signature = ecdsa_sign(key_sign, bip143_hash) tx_ser.signature_index = i_sign @@ -285,9 +282,6 @@ async def sign_tx(tx: SignTx, root): # if multisig, check if singing with a key that is included in multisig if txi_sign.multisig: pubkey_idx = multisig_pubkey_index(txi_sign.multisig, key_sign_pub) - if pubkey_idx is None: - raise SigningError(FailureType.DataError, - 'Pubkey not found in multisig script') # compute the signature from the tx digest signature = ecdsa_sign(key_sign, get_tx_hash(h_sign, True)) @@ -349,9 +343,6 @@ async def sign_tx(tx: SignTx, root): if txi.multisig: # find out place of our signature based on the pubkey signature_index = multisig_pubkey_index(txi.multisig, key_sign_pub) - if signature_index is None: - raise SigningError(FailureType.DataError, - 'Pubkey not found in multisig script') witness = witness_p2wsh(txi.multisig, signature, signature_index, get_hash_type(coin)) else: witness = witness_p2wpkh(signature, key_sign_pub, get_hash_type(coin)) @@ -525,9 +516,6 @@ def input_derive_script(coin: CoinType, i: TxInputType, pubkey: bytes, signature # multisig elif i.script_type == InputScriptType.SPENDMULTISIG: signature_index = multisig_pubkey_index(i.multisig, pubkey) - if signature_index is None: - raise SigningError(FailureType.DataError, - 'Pubkey not found in multisig script') return input_script_multisig( i.multisig, signature, signature_index, get_hash_type(coin)) else: