mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 20:11:00 +00:00
signing/multisig: reuse some code
This commit is contained in:
parent
b9c111f6ae
commit
c01ebeb552
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user