diff --git a/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.c b/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.c index 40003da50..8128e353b 100644 --- a/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.c +++ b/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.c @@ -29,21 +29,60 @@ // #if MICROPY_PY_TREZORMINTLAYER -#include "modtrezormintlayer-utils.h" +#include "modtrezormintlayer.h" -STATIC const mp_rom_map_elem_t mp_module_trezormintlayer_globals_table[] = { +STATIC const mp_rom_map_elem_t mod_trezormintlayer_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezormintlayer)}, - {MP_ROM_QSTR(MP_QSTR_utils), MP_ROM_PTR(&mod_trezormintlayer_utils_module)}, + {MP_ROM_QSTR(MP_QSTR_encode_utxo_input), + MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_utxo_input_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_account_spending_input), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_account_spending_input_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_account_command_input), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_account_command_input_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_transfer_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_transfer_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_lock_then_transfer_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_lock_then_transfer_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_burn_output), + MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_burn_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_create_stake_pool_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_create_stake_pool_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_produce_from_stake_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_produce_from_stake_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_create_delegation_id_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_create_delegation_id_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_delegate_staking_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_delegate_staking_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_issue_fungible_token_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_issue_fungible_token_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_issue_nft_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_issue_nft_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_data_deposit_output), + MP_ROM_PTR( + &mod_trezormintlayer_utils_mintlayer_encode_data_deposit_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_htlc_output), + MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_htlc_output_obj)}, + {MP_ROM_QSTR(MP_QSTR_encode_compact_length), + MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_comact_length_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_trezormintlayer_globals, - mp_module_trezormintlayer_globals_table); +STATIC MP_DEFINE_CONST_DICT(mod_trezormintlayer_globals, + mod_trezormintlayer_globals_table); -const mp_obj_module_t mp_module_trezormintlayer = { +STATIC const mp_obj_module_t mp_module_trezormintlayer = { .base = {&mp_type_module}, - .globals = (mp_obj_dict_t *)&mp_module_trezormintlayer_globals, + .globals = (mp_obj_dict_t *)&mod_trezormintlayer_globals, }; MP_REGISTER_MODULE(MP_QSTR_trezormintlayer, mp_module_trezormintlayer); // #endif // MICROPY_PY_TREZORMINTLAYER - diff --git a/core/embed/extmod/modtrezormintlayer/modtrezormintlayer-utils.h b/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.h similarity index 88% rename from core/embed/extmod/modtrezormintlayer/modtrezormintlayer-utils.h rename to core/embed/extmod/modtrezormintlayer/modtrezormintlayer.h index a92f603ad..042d6b19b 100644 --- a/core/embed/extmod/modtrezormintlayer/modtrezormintlayer-utils.h +++ b/core/embed/extmod/modtrezormintlayer/modtrezormintlayer.h @@ -578,55 +578,3 @@ mod_trezormintlayer_utils_mintlayer_encode_comact_length(mp_obj_t length) { STATIC MP_DEFINE_CONST_FUN_OBJ_1( mod_trezormintlayer_utils_mintlayer_encode_comact_length_obj, mod_trezormintlayer_utils_mintlayer_encode_comact_length); - -STATIC const mp_rom_map_elem_t mod_trezormintlayer_utils_globals_table[] = { - {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip32)}, - {MP_ROM_QSTR(MP_QSTR_encode_utxo_input), - MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_utxo_input_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_account_spending_input), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_account_spending_input_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_account_command_input), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_account_command_input_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_transfer_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_transfer_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_lock_then_transfer_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_lock_then_transfer_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_burn_output), - MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_burn_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_create_stake_pool_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_create_stake_pool_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_produce_from_stake_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_produce_from_stake_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_create_delegation_id_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_create_delegation_id_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_delegate_staking_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_delegate_staking_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_issue_fungible_token_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_issue_fungible_token_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_issue_nft_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_issue_nft_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_data_deposit_output), - MP_ROM_PTR( - &mod_trezormintlayer_utils_mintlayer_encode_data_deposit_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_htlc_output), - MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_htlc_output_obj)}, - {MP_ROM_QSTR(MP_QSTR_encode_compact_length), - MP_ROM_PTR(&mod_trezormintlayer_utils_mintlayer_encode_comact_length_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(mod_trezormintlayer_utils_globals, - mod_trezormintlayer_utils_globals_table); - -STATIC const mp_obj_module_t mod_trezormintlayer_utils_module = { - .base = {&mp_type_module}, - .globals = (mp_obj_dict_t *)&mod_trezormintlayer_utils_globals, -}; diff --git a/core/mocks/generated/trezormintlayer.pyi b/core/mocks/generated/trezormintlayer.pyi index c97a6249d..0606325cd 100644 --- a/core/mocks/generated/trezormintlayer.pyi +++ b/core/mocks/generated/trezormintlayer.pyi @@ -1,14 +1,14 @@ from typing import * -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_utxo_input(tx_hash: bytes, index: int, utxo_type: int) -> bytes: """ encodes an utxo input from tx_hash and index """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_account_spending_input(nonce: int, delegation_id: str, amount: bytes) -> bytes: """ @@ -16,7 +16,7 @@ bytes) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_account_command_input(nonce: int, command: int token_id: str, data: bytes) -> bytes: """ @@ -24,7 +24,7 @@ data: bytes) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_transfer_output(amount: str, token_id: str, address: str) -> bytes: """ @@ -32,7 +32,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_lock_then_transfer_output(amount: str, token_id: str, lock_type: int, lock_amount:int, address: str) -> bytes: """ @@ -40,7 +40,7 @@ int, lock_amount:int, address: str) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_burn_output(amount: str, token_id: str) -> bytes: """ @@ -48,7 +48,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_create_stake_pool_output(pool_id: str, pledge_amount: str, staker: str, vrf_public_key: str, decommission_key: str, margin_ratio_per_thousand: int, cost_per_block: str) -> bytes: @@ -57,7 +57,7 @@ margin_ratio_per_thousand: int, cost_per_block: str) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_produce_from_stake_output(destination: str, pool_id: str) -> bytes: """ @@ -65,7 +65,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_create_delegation_id_output(destination: str, pool_id: str) -> bytes: """ @@ -73,7 +73,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_delegate_staking_output(amount: str, delegation_id: str) -> bytes: """ @@ -81,7 +81,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_issue_fungible_token_output(token_ticker: str, number_of_decimals: int, metadata_uri: str, total_supply_type: int, fixed_amount: str, authority: str, is_freezable: int) -> bytes: @@ -90,7 +90,7 @@ fixed_amount: str, authority: str, is_freezable: int) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_issue_nft_output(token_id: str, creator: str, name: str, destination: str, ticker: str, icon_uri: str, additional_metadata_uri: str, media_uri: str, @@ -100,7 +100,7 @@ media_hash: str, destination: str) -> bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_data_deposit_output(deposit: str) -> bytes: """ @@ -108,7 +108,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_htlc_output(amount: str, token_id: str, lock_type: int, lock_amount:int, refund_key: str, spend_key: str, secret_has: bytes) -> bytes: @@ -117,7 +117,7 @@ bytes: """ -# extmod/modtrezormintlayer/modtrezormintlayer-utils.h +# extmod/modtrezormintlayer/modtrezormintlayer.h def encode_compact_length(length: int) -> bytes: """ encodes a comapct length to bytes diff --git a/core/src/all_modules.py b/core/src/all_modules.py index 781d76ddf..68d64b78c 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -561,8 +561,6 @@ import apps.mintlayer.sign_tx.progress apps.mintlayer.sign_tx.signer import apps.mintlayer.sign_tx.signer - apps.mintlayer.writers - import apps.mintlayer.writers apps.monero import apps.monero apps.monero.diag diff --git a/core/src/apps/mintlayer/sign_tx/helpers.py b/core/src/apps/mintlayer/sign_tx/helpers.py index 215545c9e..43611cfdd 100644 --- a/core/src/apps/mintlayer/sign_tx/helpers.py +++ b/core/src/apps/mintlayer/sign_tx/helpers.py @@ -1,9 +1,9 @@ +from micropython import const from typing import TYPE_CHECKING, Tuple from trezor import utils from trezor.enums import MintlayerRequestType from trezor.wire import DataError -from ..writers import TX_HASH_SIZE from . import layout if TYPE_CHECKING: @@ -26,6 +26,8 @@ from apps.common.coininfo import CoinInfo from apps.common.paths import Bip32Path +TX_HASH_SIZE = const(32) + # Machine instructions # === @@ -59,93 +61,6 @@ def confirm_dialog(self) -> Awaitable[Any]: ) -class UiConfirmDecredSSTXSubmission(UiConfirm): - def __init__(self, output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit): - self.output = output - self.coin = coin - self.amount_unit = amount_unit - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_decred_sstx_submission( - self.output, self.coin, self.amount_unit - ) - - -class UiConfirmPaymentRequest(UiConfirm): - def __init__( - self, - payment_req: TxAckPaymentRequest, - coin: CoinInfo, - amount_unit: AmountUnit, - ): - self.payment_req = payment_req - self.amount_unit = amount_unit - self.coin = coin - - def confirm_dialog(self) -> Awaitable[bool]: - return layout.should_show_payment_request_details( - self.payment_req, self.coin, self.amount_unit - ) - - __eq__ = utils.obj_eq - - -class UiConfirmReplacement(UiConfirm): - def __init__(self, title: str, txid: bytes): - self.title = title - self.txid = txid - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_replacement(self.title, self.txid) - - -class UiConfirmModifyOutput(UiConfirm): - def __init__( - self, - txo: TxOutput, - orig_txo: TxOutput, - coin: CoinInfo, - amount_unit: AmountUnit, - ): - self.txo = txo - self.orig_txo = orig_txo - self.coin = coin - self.amount_unit = amount_unit - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_modify_output( - self.txo, self.orig_txo, self.coin, self.amount_unit - ) - - -class UiConfirmModifyFee(UiConfirm): - def __init__( - self, - title: str, - user_fee_change: int, - total_fee_new: int, - fee_rate: float, - coin: CoinInfo, - amount_unit: AmountUnit, - ): - self.title = title - self.user_fee_change = user_fee_change - self.total_fee_new = total_fee_new - self.fee_rate = fee_rate - self.coin = coin - self.amount_unit = amount_unit - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_modify_fee( - self.title, - self.user_fee_change, - self.total_fee_new, - self.fee_rate, - self.coin, - self.amount_unit, - ) - - class UiConfirmTotal(UiConfirm): def __init__( self, @@ -153,14 +68,12 @@ def __init__( fee: int, fee_rate: float, coin: CoinInfo, - amount_unit: AmountUnit, address_n: Bip32Path | None, ): self.spending = spending self.fee = fee self.fee_rate = fee_rate self.coin = coin - self.amount_unit = amount_unit self.address_n = address_n def confirm_dialog(self) -> Awaitable[Any]: @@ -169,36 +82,10 @@ def confirm_dialog(self) -> Awaitable[Any]: self.fee, self.fee_rate, self.coin, - self.amount_unit, self.address_n, ) -class UiConfirmJointTotal(UiConfirm): - def __init__( - self, spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit - ): - self.spending = spending - self.total = total - self.coin = coin - self.amount_unit = amount_unit - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_joint_total( - self.spending, self.total, self.coin, self.amount_unit - ) - - -class UiConfirmFeeOverThreshold(UiConfirm): - def __init__(self, fee: int, coin: CoinInfo, amount_unit: AmountUnit): - self.fee = fee - self.coin = coin - self.amount_unit = amount_unit - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_feeoverthreshold(self.fee, self.coin, self.amount_unit) - - class UiConfirmChangeCountOverThreshold(UiConfirm): def __init__(self, change_count: int): self.change_count = change_count @@ -222,17 +109,6 @@ def confirm_dialog(self) -> Awaitable[Any]: return paths.show_path_warning(self.address_n) -class UiConfirmNonDefaultLocktime(UiConfirm): - def __init__(self, lock_time: int, lock_time_disabled: bool): - self.lock_time = lock_time - self.lock_time_disabled = lock_time_disabled - - def confirm_dialog(self) -> Awaitable[Any]: - return layout.confirm_nondefault_locktime( - self.lock_time, self.lock_time_disabled - ) - - class UiConfirmMultipleAccounts(UiConfirm): def confirm_dialog(self) -> Awaitable[Any]: return layout.confirm_multiple_accounts() @@ -242,40 +118,8 @@ def confirm_output(output: TxOutput, coin: CoinInfo, output_index: int, chunkify return (yield UiConfirmOutput(output, coin, output_index, chunkify)) -def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[None]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit)) - - -def should_show_payment_request_details(payment_req: TxAckPaymentRequest, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[bool]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmPaymentRequest(payment_req, coin, amount_unit)) - - -def confirm_replacement(description: str, txid: bytes) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmReplacement(description, txid)) - - -def confirm_modify_output(txo: TxOutput, orig_txo: TxOutput, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmModifyOutput(txo, orig_txo, coin, amount_unit)) - - -def confirm_modify_fee(title: str, user_fee_change: int, total_fee_new: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return ( - yield UiConfirmModifyFee( - title, user_fee_change, total_fee_new, fee_rate, coin, amount_unit - ) - ) - - -def confirm_total(spending: int, fee: int, fee_rate: float, coin: CoinInfo, amount_unit: AmountUnit, address_n: Bip32Path | None) -> Awaitable[None]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmTotal(spending, fee, fee_rate, coin, amount_unit, address_n)) - - -def confirm_joint_total(spending: int, total: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmJointTotal(spending, total, coin, amount_unit)) - - -def confirm_feeoverthreshold(fee: int, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmFeeOverThreshold(fee, coin, amount_unit)) +def confirm_total(spending: int, fee: int, fee_rate: float, coin: CoinInfo, address_n: Bip32Path | None) -> Awaitable[None]: # type: ignore [awaitable-is-generator] + return (yield UiConfirmTotal(spending, fee, fee_rate, coin, address_n)) def confirm_change_count_over_threshold(change_count: int) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] @@ -290,10 +134,6 @@ def confirm_foreign_address(address_n: list) -> Awaitable[Any]: # type: ignore return (yield UiConfirmForeignAddress(address_n)) -def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> Awaitable[Any]: # type: ignore [awaitable-is-generator] - return (yield UiConfirmNonDefaultLocktime(lock_time, lock_time_disabled)) - - def confirm_multiple_accounts() -> Awaitable[Any]: # type: ignore [awaitable-is-generator] return (yield UiConfirmMultipleAccounts()) @@ -320,18 +160,6 @@ def request_tx_input(tx_req: MintlayerTxRequest, i: int) -> Awaitable[MintlayerT return _sanitize_tx_input(ack.tx.input) -def request_tx_prev_input(tx_req: MintlayerTxRequest, i: int, tx_hash: bytes | None = None) -> Awaitable[PrevInput]: # type: ignore [awaitable-is-generator] - from trezor.messages import TxAckPrevInput - - assert tx_req.details is not None - tx_req.request_type = MintlayerRequestType.TXINPUT - tx_req.details.request_index = i - tx_req.details.tx_hash = tx_hash - ack = yield TxAckPrevInput, tx_req - _clear_tx_request(tx_req) - return _sanitize_tx_prev_input(ack.tx.input, coin) - - def request_tx_output(tx_req: TxRequest, i: int, tx_hash: bytes | None = None) -> Awaitable[MintlayerTxOutput]: # type: ignore [awaitable-is-generator] from trezor.messages import MintlayerTxAckOutput @@ -347,19 +175,6 @@ def request_tx_output(tx_req: TxRequest, i: int, tx_hash: bytes | None = None) - return _sanitize_tx_output(ack.tx.output) -def request_tx_prev_output(tx_req: TxRequest, i: int, coin: CoinInfo, tx_hash: bytes | None = None) -> Awaitable[PrevOutput]: # type: ignore [awaitable-is-generator] - from trezor.messages import TxAckPrevOutput - - assert tx_req.details is not None - tx_req.request_type = MintlayerRequestType.TXOUTPUT - tx_req.details.request_index = i - tx_req.details.tx_hash = tx_hash - ack = yield TxAckPrevOutput, tx_req - _clear_tx_request(tx_req) - # return sanitize_tx_prev_output(ack.tx, coin) # no sanitize is required - return ack.tx.output - - def request_tx_finish(tx_req: TxRequest) -> Awaitable[None]: # type: ignore [awaitable-is-generator] tx_req.request_type = MintlayerRequestType.TXFINISHED yield None, tx_req @@ -470,16 +285,6 @@ def _sanitize_tx_input(txi: MintlayerTxInput) -> MintlayerTxInput: return txi -def _sanitize_tx_prev_input(txi: PrevInput, coin: CoinInfo) -> PrevInput: - if len(txi.prev_hash) != TX_HASH_SIZE: - raise DataError("Provided prev_hash is invalid.") - - if not coin.decred and txi.decred_tree is not None: - raise DataError("Decred details provided but Decred coin not specified.") - - return txi - - def _sanitize_tx_output(txo: MintlayerTxOutput) -> MintlayerTxOutput: from trezor.wire import DataError # local_cache_global @@ -518,5 +323,5 @@ def get_lock(x: MintlayerOutputTimeLock) -> Tuple[int, int]: lock_type = 3 lock_amount = x.for_seconds else: - raise Exception("unhandled mintlayer lock type") + raise DataError("unhandled mintlayer lock type") return (lock_type, lock_amount) diff --git a/core/src/apps/mintlayer/sign_tx/layout.py b/core/src/apps/mintlayer/sign_tx/layout.py index 031a55540..8a133cbe4 100644 --- a/core/src/apps/mintlayer/sign_tx/layout.py +++ b/core/src/apps/mintlayer/sign_tx/layout.py @@ -1,4 +1,3 @@ -from micropython import const from typing import TYPE_CHECKING from trezor import TR @@ -10,7 +9,6 @@ from trezor.crypto.bech32 import bech32_encode, convertbits, Encoding -from ...bitcoin import addresses from ...bitcoin.common import ( BIP32_WALLET_DEPTH, format_fee_rate, @@ -18,8 +16,7 @@ from ...bitcoin.keychain import address_n_to_name if TYPE_CHECKING: - from trezor.enums import AmountUnit - from trezor.messages import TxAckPaymentRequest, TxOutput, MintlayerTokenOutputValue, MintlayerOutputTimeLock + from trezor.messages import MintlayerTokenOutputValue, MintlayerOutputTimeLock from apps.common.coininfo import CoinInfo from apps.common.paths import Bip32Path @@ -28,8 +25,6 @@ MintlayerTxOutput, ) -_LOCKTIME_TIMESTAMP_MIN_VALUE = const(500_000_000) - ML_COIN = "ML" POOL_HRP = "mpool" DELEGATION_HRP = "mdeleg" @@ -110,6 +105,7 @@ async def confirm_output( x = output.create_delegation_id assert x.destination is not None amount = "" + # FIXME: extract those 2 into 1 helper function data = convertbits(x.pool_id, 8, 5) pool_id_address = bech32_encode(POOL_HRP, data, Encoding.BECH32M) address_short = f"Address: {x.destination}\nPoolId: {pool_id_address}" @@ -201,65 +197,11 @@ async def confirm_output( await layout -async def confirm_decred_sstx_submission( - output: TxOutput, coin: CoinInfo, amount_unit: AmountUnit -) -> None: - assert output.address is not None - address_short = addresses.address_short(coin, output.address) - amount = format_coin_amount(output.amount, coin, amount_unit) - - await layouts.confirm_value( - TR.bitcoin__title_purchase_ticket, - amount, - TR.bitcoin__ticket_amount, - "confirm_decred_sstx_submission", - ButtonRequestType.ConfirmOutput, - verb=TR.buttons__confirm, - ) - - await layouts.confirm_value( - TR.bitcoin__title_purchase_ticket, - address_short, - TR.bitcoin__voting_rights, - "confirm_decred_sstx_submission", - ButtonRequestType.ConfirmOutput, - verb=TR.buttons__purchase, - ) - - -async def should_show_payment_request_details( - msg: TxAckPaymentRequest, - coin: CoinInfo, - amount_unit: AmountUnit, -) -> bool: - from trezor import wire - - memo_texts: list[str] = [] - for m in msg.memos: - if m.text_memo is not None: - memo_texts.append(m.text_memo.text) - elif m.refund_memo is not None: - pass - elif m.coin_purchase_memo is not None: - memo_texts.append(f"{TR.words__buying} {m.coin_purchase_memo.amount}.") - else: - raise wire.DataError("Unrecognized memo type in payment request memo.") - - assert msg.amount is not None - - return await layouts.should_show_payment_request_details( - msg.recipient_name, - format_coin_amount(msg.amount, coin, amount_unit), - memo_texts, - ) - - async def confirm_total( spending: int, fee: int, fee_rate: float, coin: CoinInfo, - amount_unit: AmountUnit, address_n: Bip32Path | None, ) -> None: @@ -298,32 +240,3 @@ async def confirm_multiple_accounts() -> None: button=TR.buttons__continue, br_code=ButtonRequestType.SignTx, ) - - -async def confirm_nondefault_locktime(lock_time: int, lock_time_disabled: bool) -> None: - from trezor.strings import format_timestamp - - if lock_time_disabled: - await layouts.show_warning( - "nondefault_locktime", - TR.bitcoin__locktime_no_effect, - TR.words__continue_anyway, - button=TR.buttons__continue, - br_code=ButtonRequestType.SignTx, - ) - else: - if lock_time < _LOCKTIME_TIMESTAMP_MIN_VALUE: - text = TR.bitcoin__locktime_set_to_blockheight - value = str(lock_time) - else: - text = TR.bitcoin__locktime_set_to - value = format_timestamp(lock_time) - await layouts.confirm_value( - TR.bitcoin__confirm_locktime, - value, - text, - "nondefault_locktime", - br_code=ButtonRequestType.SignTx, - verb=TR.buttons__confirm, - ) - diff --git a/core/src/apps/mintlayer/sign_tx/signer.py b/core/src/apps/mintlayer/sign_tx/signer.py index 041bb2e47..55157c8d0 100644 --- a/core/src/apps/mintlayer/sign_tx/signer.py +++ b/core/src/apps/mintlayer/sign_tx/signer.py @@ -70,13 +70,11 @@ async def signer(self) -> None: fee = input_totals[ML_COIN] - output_totals[ML_COIN] fee_rate = 0 coin = by_name('Bitcoin') - amount_unit = AmountUnit.BITCOIN await helpers.confirm_total( output_totals[ML_COIN], fee, fee_rate, coin, - amount_unit, None, ) diff --git a/core/src/apps/mintlayer/writers.py b/core/src/apps/mintlayer/writers.py deleted file mode 100644 index 13f89e63c..000000000 --- a/core/src/apps/mintlayer/writers.py +++ /dev/null @@ -1,110 +0,0 @@ -from micropython import const -from typing import TYPE_CHECKING - -from trezor.utils import ensure - -from apps.common.writers import ( # noqa: F401 - write_bytes_fixed, - write_bytes_reversed, - write_bytes_unchecked, - write_compact_size, - write_uint8, - write_uint16_le, - write_uint32_le, - write_uint64_le, -) - -if TYPE_CHECKING: - from trezor.messages import PrevInput, PrevOutput, TxInput, TxOutput - from trezor.utils import HashWriter - - from apps.common.writers import Writer - -write_uint16 = write_uint16_le -write_uint32 = write_uint32_le -write_uint64 = write_uint64_le - -TX_HASH_SIZE = const(32) - - -def write_bytes_prefixed(w: Writer, b: bytes) -> None: - write_compact_size(w, len(b)) - write_bytes_unchecked(w, b) - - -def write_tx_input(w: Writer, i: TxInput | PrevInput, script: bytes) -> None: - write_bytes_reversed(w, i.prev_hash, TX_HASH_SIZE) - write_uint32(w, i.prev_index) - write_bytes_prefixed(w, script) - write_uint32(w, i.sequence) - - -def write_tx_input_check(w: Writer, i: TxInput) -> None: - from .multisig import multisig_fingerprint - - write_uint32(w, len(i.address_n)) - for n in i.address_n: - write_uint32(w, n) - write_bytes_fixed(w, i.prev_hash, TX_HASH_SIZE) - write_uint32(w, i.prev_index) - write_bytes_prefixed(w, i.script_sig or b"") - write_uint32(w, i.sequence) - write_uint32(w, i.script_type) - multisig_fp = multisig_fingerprint(i.multisig) if i.multisig else b"" - write_bytes_prefixed(w, multisig_fp) - write_uint64(w, i.amount or 0) - write_bytes_prefixed(w, i.witness or b"") - write_bytes_prefixed(w, i.ownership_proof or b"") - write_bytes_prefixed(w, i.orig_hash or b"") - write_uint32(w, i.orig_index or 0) - write_bytes_prefixed(w, i.script_pubkey or b"") - - -def write_tx_output(w: Writer, o: TxOutput | PrevOutput, script_pubkey: bytes) -> None: - write_uint64(w, o.amount) - write_bytes_prefixed(w, script_pubkey) - - -def write_op_push(w: Writer, n: int) -> None: - append = w.append # local_cache_attribute - - ensure(0 <= n <= 0xFFFF_FFFF) - if n < 0x4C: - append(n & 0xFF) - elif n < 0x100: - append(0x4C) - append(n & 0xFF) - elif n < 0x1_0000: - append(0x4D) - append(n & 0xFF) - append((n >> 8) & 0xFF) - else: - append(0x4E) - append(n & 0xFF) - append((n >> 8) & 0xFF) - append((n >> 16) & 0xFF) - append((n >> 24) & 0xFF) - - -def op_push_length(n: int) -> int: - ensure(0 <= n <= 0xFFFF_FFFF) - if n < 0x4C: - return 1 - elif n < 0x100: - return 2 - elif n < 0x1_0000: - return 3 - else: - return 4 - - -def get_tx_hash(w: HashWriter, double: bool = False, reverse: bool = False) -> bytes: - from trezor.crypto.hashlib import sha256 - - d = w.get_digest() - if double: - d = sha256(d).digest() - if reverse: - d = bytes(reversed(d)) - return d - diff --git a/core/src/trezor/crypto/__init__.py b/core/src/trezor/crypto/__init__.py index 7f7756fbd..4ae21b762 100644 --- a/core/src/trezor/crypto/__init__.py +++ b/core/src/trezor/crypto/__init__.py @@ -18,7 +18,7 @@ if not utils.BITCOIN_ONLY: from trezorcrypto import cardano, monero, nem # noqa: F401 - from trezormintlayer import utils as mintlayer_utils + import trezormintlayer as mintlayer_utils if utils.USE_OPTIGA: from trezorcrypto import optiga # noqa: F401 diff --git a/rust/trezor-client/src/error.rs b/rust/trezor-client/src/error.rs index 18c273ab5..e38c90d9e 100644 --- a/rust/trezor-client/src/error.rs +++ b/rust/trezor-client/src/error.rs @@ -103,11 +103,3 @@ pub enum Error { #[error("malformed MintlayerTxRequest: {0:?}")] MalformedMintlayerTxRequest(protos::MintlayerTxRequest), } - -impl PartialEq for Error { - fn eq(&self, _other: &Self) -> bool { - false - } -} - -impl Eq for Error {}