1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

refactor(core): Add sanitize_input_script_type().

This commit is contained in:
Andrew Kozlik 2024-11-03 10:59:08 +01:00
parent d800c41e61
commit 4287d2b377
3 changed files with 10 additions and 12 deletions

View File

@ -190,6 +190,14 @@ def input_is_external_unverified(txi: TxInput) -> bool:
)
def sanitize_input_script_type(coin: CoinInfo, script_type: InputScriptType) -> None:
if script_type in SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit:
raise wire.DataError("Segwit not enabled on this coin.")
if script_type == InputScriptType.SPENDTAPROOT and not coin.taproot:
raise wire.DataError("Taproot not enabled on this coin")
def tagged_hashwriter(tag: bytes) -> HashWriter:
from trezor.crypto.hashlib import sha256
from trezor.utils import HashWriter

View File

@ -13,7 +13,6 @@ if TYPE_CHECKING:
async def get_ownership_id(
msg: GetOwnershipId, keychain: Keychain, coin: CoinInfo
) -> OwnershipId:
from trezor.enums import InputScriptType
from trezor.messages import OwnershipId
from trezor.wire import DataError
@ -34,11 +33,7 @@ async def get_ownership_id(
if script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES:
raise DataError("Invalid script type")
if script_type in common.SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit:
raise DataError("Segwit not enabled on this coin")
if script_type == InputScriptType.SPENDTAPROOT and not coin.taproot:
raise DataError("Taproot not enabled on this coin")
common.sanitize_input_script_type(coin, script_type)
node = keychain.derive(msg.address_n)
address = addresses.get_address(script_type, coin, node, msg.multisig)

View File

@ -19,7 +19,6 @@ async def get_ownership_proof(
authorization: CoinJoinAuthorization | None = None,
) -> OwnershipProof:
from trezor import TR
from trezor.enums import InputScriptType
from trezor.messages import OwnershipProof
from trezor.ui.layouts import confirm_action, confirm_blob
from trezor.wire import DataError, ProcessError
@ -46,11 +45,7 @@ async def get_ownership_proof(
if script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES:
raise DataError("Invalid script type")
if script_type in common.SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit:
raise DataError("Segwit not enabled on this coin")
if script_type == InputScriptType.SPENDTAPROOT and not coin.taproot:
raise DataError("Taproot not enabled on this coin")
common.sanitize_input_script_type(coin, script_type)
node = keychain.derive(msg.address_n)
address = addresses.get_address(script_type, coin, node, msg.multisig)