mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-03 04:18:17 +00:00
refactor(core): Add sanitize_input_script_type().
This commit is contained in:
parent
d800c41e61
commit
4287d2b377
@ -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:
|
def tagged_hashwriter(tag: bytes) -> HashWriter:
|
||||||
from trezor.crypto.hashlib import sha256
|
from trezor.crypto.hashlib import sha256
|
||||||
from trezor.utils import HashWriter
|
from trezor.utils import HashWriter
|
||||||
|
@ -13,7 +13,6 @@ if TYPE_CHECKING:
|
|||||||
async def get_ownership_id(
|
async def get_ownership_id(
|
||||||
msg: GetOwnershipId, keychain: Keychain, coin: CoinInfo
|
msg: GetOwnershipId, keychain: Keychain, coin: CoinInfo
|
||||||
) -> OwnershipId:
|
) -> OwnershipId:
|
||||||
from trezor.enums import InputScriptType
|
|
||||||
from trezor.messages import OwnershipId
|
from trezor.messages import OwnershipId
|
||||||
from trezor.wire import DataError
|
from trezor.wire import DataError
|
||||||
|
|
||||||
@ -34,11 +33,7 @@ async def get_ownership_id(
|
|||||||
if script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES:
|
if script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES:
|
||||||
raise DataError("Invalid script type")
|
raise DataError("Invalid script type")
|
||||||
|
|
||||||
if script_type in common.SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit:
|
common.sanitize_input_script_type(coin, script_type)
|
||||||
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")
|
|
||||||
|
|
||||||
node = keychain.derive(msg.address_n)
|
node = keychain.derive(msg.address_n)
|
||||||
address = addresses.get_address(script_type, coin, node, msg.multisig)
|
address = addresses.get_address(script_type, coin, node, msg.multisig)
|
||||||
|
@ -19,7 +19,6 @@ async def get_ownership_proof(
|
|||||||
authorization: CoinJoinAuthorization | None = None,
|
authorization: CoinJoinAuthorization | None = None,
|
||||||
) -> OwnershipProof:
|
) -> OwnershipProof:
|
||||||
from trezor import TR
|
from trezor import TR
|
||||||
from trezor.enums import InputScriptType
|
|
||||||
from trezor.messages import OwnershipProof
|
from trezor.messages import OwnershipProof
|
||||||
from trezor.ui.layouts import confirm_action, confirm_blob
|
from trezor.ui.layouts import confirm_action, confirm_blob
|
||||||
from trezor.wire import DataError, ProcessError
|
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:
|
if script_type not in common.INTERNAL_INPUT_SCRIPT_TYPES:
|
||||||
raise DataError("Invalid script type")
|
raise DataError("Invalid script type")
|
||||||
|
|
||||||
if script_type in common.SEGWIT_INPUT_SCRIPT_TYPES and not coin.segwit:
|
common.sanitize_input_script_type(coin, script_type)
|
||||||
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")
|
|
||||||
|
|
||||||
node = keychain.derive(msg.address_n)
|
node = keychain.derive(msg.address_n)
|
||||||
address = addresses.get_address(script_type, coin, node, msg.multisig)
|
address = addresses.get_address(script_type, coin, node, msg.multisig)
|
||||||
|
Loading…
Reference in New Issue
Block a user