diff --git a/.github/workflows/build_and_functional_tests.yml b/.github/workflows/build_and_functional_tests.yml index f72e6cc65..895de2e2d 100644 --- a/.github/workflows/build_and_functional_tests.yml +++ b/.github/workflows/build_and_functional_tests.yml @@ -15,7 +15,7 @@ on: type: choice required: true default: 'Raise an error (default)' - description: CI behavior if the test snaphots are different than expected. + description: CI behavior if the test snapshots are different than expected. options: - 'Raise an error (default)' - 'Open a PR' diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index c591393b9..27c980531 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -23,4 +23,4 @@ jobs: with: builtin: clear,rare check_filenames: true - path: src, src_bagl, src_features, src_nbgl, src_plugin_sdk, src_plugins, doc, client + path: src, src_bagl, src_features, src_nbgl, src_plugins, doc, client diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06afa812d..764c27066 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -14,7 +14,7 @@ repos: - id: check-case-conflict - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell args: ['--ignore-words-list', 'ontop,shft,hte', '--skip', 'makefile_conf/chain/*,tests/ragger/eip712_input_files/*'] @@ -26,7 +26,7 @@ repos: types_or: [c] - repo: https://github.com/Mateusz-Grzelinski/actionlint-py - rev: v1.6.27.13 + rev: v1.7.6.22 hooks: - id: actionlint types_or: [yaml] @@ -39,9 +39,10 @@ repos: types_or: [markdown] - repo: https://github.com/PyCQA/pylint - rev: v2.16.2 + rev: v3.3.3 hooks: - id: pylint + language: system types: [python] args: ['--jobs=0', '--rcfile=tests/ragger/setup.cfg'] files: '^tests/ragger/.*$' diff --git a/client/src/ledger_app_clients/ethereum/client.py b/client/src/ledger_app_clients/ethereum/client.py index 13d253f28..8e55969ec 100644 --- a/client/src/ledger_app_clients/ethereum/client.py +++ b/client/src/ledger_app_clients/ethereum/client.py @@ -1,20 +1,20 @@ -import rlp import struct from enum import IntEnum +from typing import Optional, Tuple +from hashlib import sha256 +import rlp +from web3 import Web3 + from ragger.backend import BackendInterface from ragger.firmware import Firmware from ragger.error import ExceptionRAPDU from ragger.utils import RAPDU -from typing import Optional from .command_builder import CommandBuilder from .eip712 import EIP712FieldType from .keychain import sign_data, Key from .tlv import format_tlv -from hashlib import sha256 -from web3 import Web3 - class StatusWord(IntEnum): OK = 0x9000 @@ -92,7 +92,7 @@ class PKIClient: def __init__(self, client: BackendInterface) -> None: self._client = client - def send_certificate(self, p1: PKIPubKeyUsage, payload: bytes) -> RAPDU: + def send_certificate(self, p1: PKIPubKeyUsage, payload: bytes) -> None: try: response = self.send_raw(p1, payload) assert response.status == StatusWord.OK @@ -275,6 +275,7 @@ def perform_privacy_operation(self, def _provide_trusted_name_common(self, payload: bytes, name_source: TrustedNameSource) -> RAPDU: payload += format_tlv(FieldTag.STRUCT_TYPE, 3) # TrustedName + cert_apdu = "" if name_source == TrustedNameSource.CAL: if self._pki_client is not None: # pylint: disable=line-too-long @@ -286,6 +287,8 @@ def _provide_trusted_name_common(self, payload: bytes, name_source: TrustedNameS cert_apdu = "010101020102110400000002120100130200021401011604000000002010547275737465645F4E616D655F43414C300200093101043201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C64056188734010135010415473045022100ABA9D58446EE81EB073DA91941989DD7E133556D58DE2BCBA59E46253DB448B102201DF8AE930A9E318B50576D8922503A5D3EC84C00C332A7C8FF7CD48708751840" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "010101020102110400000002120100130200021401011604000000002010547275737465645F4E616D655F43414C300200093101043201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C6405618873401013501051546304402206DC9F82C53F3B13400D3E343E3C8C81868E8C73B1EF2655D07891064B7AC3166022069A36E4059D75C93E488A5D58C02BCA9C80C081F77B31C5EDCF07F1A500C565A" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") # pylint: enable=line-too-long key_id = 9 key = Key.CAL @@ -300,11 +303,13 @@ def _provide_trusted_name_common(self, payload: bytes, name_source: TrustedNameS cert_apdu = "01010102010211040000000212010013020002140101160400000000200C547275737465645F4E616D6530020007310104320121332102B91FBEC173E3BA4A714E014EBC827B6F899A9FA7F4AC769CDE284317A00F4F6534010135010415473045022100A57DC7AB3F0E38A8D10783C7449024D929C60843BB75E5FF7B8088CB71CB130C022045A03E6F501F3702871466473BA08CE1F111357ED9EF395959733477165924C4" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "01010102010211040000000212010013020002140101160400000000200C547275737465645F4E616D6530020007310104320121332102B91FBEC173E3BA4A714E014EBC827B6F899A9FA7F4AC769CDE284317A00F4F6534010135010515473045022100D5BB77756C3D7C1B4254EA8D5351B94A89B13BA69C3631A523F293A10B7144B302201519B29A882BB22DCDDF6BE79A9CBA76566717FA877B7CA4B9CC40361A2D579E" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") # pylint: enable=line-too-long key_id = 7 key = Key.TRUSTED_NAME - if self._pki_client is not None: + if self._pki_client is not None and cert_apdu: self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_TRUSTED_NAME, bytes.fromhex(cert_apdu)) payload += format_tlv(FieldTag.SIGNER_KEY_ID, key_id) # test key @@ -332,7 +337,7 @@ def provide_trusted_name_v2(self, chain_id: int, nft_id: Optional[int] = None, challenge: Optional[int] = None, - not_valid_after: Optional[tuple[int]] = None) -> RAPDU: + not_valid_after: Optional[Tuple[int]] = None) -> RAPDU: payload = format_tlv(FieldTag.STRUCT_VERSION, 2) payload += format_tlv(FieldTag.TRUSTED_NAME, name) payload += format_tlv(FieldTag.ADDRESS, addr) @@ -371,9 +376,12 @@ def set_plugin(self, cert_apdu = "01010102010211040000000212010013020002140101160400000000200A53657420506C7567696E30020003310107320121332103C055BC4ECF055E2D85085D35127A3DE6705C7F885055CD7071E87671BF191FE334010135010415473045022100B8AF9667C190B60BF350D8F8CA66A4BCEA22BF47D757CB7F88F8D16C7794BCDC02205F7D6C8E9294F73744A82E1062B10FFEB809252682112E71A419EFC78227211B" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "01010102010211040000000212010013020002140101160400000000200A53657420506C7567696E30020003310107320121332103C055BC4ECF055E2D85085D35127A3DE6705C7F885055CD7071E87671BF191FE334010135010515473045022100F5069D8BCEDCF7CC55273266E3871B09FFCACD084B5753347A809DDDA67E6235022003CE65364BFA96B6FE7A9D8C13EC87B8E727E8B7BF4A63176F5D61AB8F97807E" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long - - self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_PLUGIN_METADATA, bytes.fromhex(cert_apdu)) + if cert_apdu: + self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_PLUGIN_METADATA, bytes.fromhex(cert_apdu)) if sig is None: # Temporarily get a command with an empty signature to extract the payload and @@ -421,9 +429,12 @@ def provide_nft_metadata(self, cert_apdu = "0101010201021104000000021201001302000214010116040000000020084E46545F496E666F300200043101033201213321023CFB5FB31905F4BD39D9D535A40C26AAB51C5D7D3219B28AC942B980FB206CFB3401013501041546304402201DEE04EC830FFDE5C98A708EC6865605FC14FF6105A54BE5230F2B954C673B940220581A0A5E42A7779140963703E43B3BEABE4C69284EDEF00E76BB5875E0810C9B" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "0101010201021104000000021201001302000214010116040000000020084E46545F496E666F300200043101033201213321023CFB5FB31905F4BD39D9D535A40C26AAB51C5D7D3219B28AC942B980FB206CFB340101350105154730450221009ABCC7056D54C1B5DBB353178B13850C20521EE6884AA415AA61B329DB1D87F602204E308F273B8D18080184695438577F770524F717E5D08EE20ECBF1BC599F3538" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long - - self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_NFT_METADATA, bytes.fromhex(cert_apdu)) + if cert_apdu: + self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_NFT_METADATA, bytes.fromhex(cert_apdu)) if sig is None: # Temporarily get a command with an empty signature to extract the payload and @@ -489,9 +500,12 @@ def provide_token_metadata(self, cert_apdu = "01010102010211040000000212010013020002140101160400000000200B45524332305F546F6B656E300200063101083201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C6405618873401013501041546304402206731FCD3E2432C5CA162381392FD17AD3A41EEF852E1D706F21A656AB165263602204B89FAE8DBAF191E2D79FB00EBA80D613CB7EDF0BE960CB6F6B29D96E1437F5F" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "01010102010211040000000212010013020002140101160400000000200B45524332305F546F6B656E300200063101083201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C64056188734010135010515473045022100B59EA8B958AA40578A6FBE9BBFB761020ACD5DBD8AA863C11DA17F42B2AFDE790220186316059EFA58811337D47C7F815F772EA42BBBCEA4AE123D1118C80588F5CB" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long - - self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_COIN_META, bytes.fromhex(cert_apdu)) + if cert_apdu: + self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_COIN_META, bytes.fromhex(cert_apdu)) if sig is None: # Temporarily get a command with an empty signature to extract the payload and @@ -525,15 +539,14 @@ def _prepare_network_info(self, # Network Icon payload += format_tlv(FieldTag.NETWORK_ICON_HASH, sha256(icon).digest()) # Append the data Signature - payload += format_tlv(FieldTag.DER_SIGNATURE, - sign_data(Key.NETWORK, payload)) + payload += format_tlv(FieldTag.DER_SIGNATURE, sign_data(Key.NETWORK, payload)) return payload def provide_network_information(self, name: str, ticker: str, chain_id: int, - icon: Optional[bytes] = None) -> RAPDU: + icon: Optional[bytes] = None) -> None: if self._pki_client is None: print(f"Ledger-PKI Not supported on '{self._firmware.name}'") @@ -547,9 +560,12 @@ def provide_network_information(self, cert_apdu = "0101010201021104000000021201001302000214010116040000000020076E6574776F726B3002000A31010C32012133210304AF5CF32094F855E93235E9EB43F48E9B436C2E1DFAEA58ECAFA68AAFB1D27C34010135010415463044022044C595C3E98100D4ECA75A73BF294090FF94948E80EE1430624C886B15BE862302200994E1D98CA72B78D57808B5FD236F439376AFC7C651B55D4AFBFB5AF4C15E00" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "0101010201021104000000021201001302000214010116040000000020076E6574776F726B3002000A31010C32012133210304AF5CF32094F855E93235E9EB43F48E9B436C2E1DFAEA58ECAFA68AAFB1D27C34010135010515463044022008D276684F1A1CC3A89DB0B15120860414FF6A60E227FCAA29ED8F2096C982460220343FE956D443CEA33A2F8BD9DD1EAD783ACFF86088CF01BCE63C224DC815D7F0" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long - - self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_NETWORK, bytes.fromhex(cert_apdu)) + if cert_apdu: + self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_NETWORK, bytes.fromhex(cert_apdu)) # Add the network info payload = self._prepare_network_info(name, ticker, chain_id, icon) @@ -579,9 +595,13 @@ def provide_transaction_info(self, payload: bytes) -> RAPDU: cert_apdu = "01010102010211040000000212010013020002140101160400000000200863616C6C646174613002000831010B32012133210381C0821E2A14AC2546FB0B9852F37CA2789D7D76483D79217FB36F51DCE1E7B434010135010415473045022100A88646AD72CA012D5FDAF8F6AE0B7EBEF079212768D57323CB5B57CADD9EB20D022005872F8EA06092C9783F01AF02C5510588FB60CBF4BA51FB382B39C1E060BB6B" # noqa: E501 elif self._firmware == Firmware.FLEX: cert_apdu = "01010102010211040000000212010013020002140101160400000000200863616C6C646174613002000831010B32012133210381C0821E2A14AC2546FB0B9852F37CA2789D7D76483D79217FB36F51DCE1E7B43401013501051546304402205305BDDDAD0284A2EAC2A9BE4CEF6604AE9415C5F46883448F5F6325026234A3022001ED743BCF33CCEB070FDD73C3D3FCC2CEE5AB30A5C3EB7D2A8D21C6F58D493F" # noqa: E501 + else: + print(f"Invalid device '{self._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long + if cert_apdu: + self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_CALLDATA, bytes.fromhex(cert_apdu)) - self._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_CALLDATA, bytes.fromhex(cert_apdu)) chunks = self._cmd_builder.provide_transaction_info(payload) for chunk in chunks[:-1]: self._exchange(chunk) diff --git a/client/src/ledger_app_clients/ethereum/command_builder.py b/client/src/ledger_app_clients/ethereum/command_builder.py index 090833dd8..3ed849e4a 100644 --- a/client/src/ledger_app_clients/ethereum/command_builder.py +++ b/client/src/ledger_app_clients/ethereum/command_builder.py @@ -125,7 +125,7 @@ def eip712_send_struct_impl_array(self, size: int) -> bytes: data) def eip712_send_struct_impl_struct_field(self, data: bytearray) -> list[bytes]: - chunks = list() + chunks = [] # Add a 16-bit integer with the data's byte length (network byte order) data_w_length = bytearray() data_w_length.append((len(data) & 0xff00) >> 8) @@ -264,7 +264,7 @@ def set_external_plugin(self, plugin_name: str, contract_address: bytes, selecto data) def sign(self, bip32_path: str, rlp_data: bytes, p2: int) -> list[bytes]: - apdus = list() + apdus = [] payload = pack_derivation_path(bip32_path) payload += rlp_data p1 = P1Type.SIGN_FIRST_CHUNK @@ -281,7 +281,7 @@ def get_challenge(self) -> bytes: return self._serialize(InsType.GET_CHALLENGE, 0x00, 0x00) def provide_trusted_name(self, tlv_payload: bytes) -> list[bytes]: - chunks = list() + chunks = [] payload = struct.pack(">H", len(tlv_payload)) payload += tlv_payload p1 = 1 @@ -376,7 +376,7 @@ def personal_sign(self, path: str, msg: bytes): payload = pack_derivation_path(path) payload += struct.pack(">I", len(msg)) payload += msg - chunks = list() + chunks = [] p1 = P1Type.SIGN_FIRST_CHUNK while len(payload) > 0: chunk_size = 0xff @@ -431,7 +431,7 @@ def provide_network_information(self, return chunks def common_tlv_serialize(self, tlv_payload: bytes, ins: InsType) -> list[bytes]: - chunks = list() + chunks = [] payload = struct.pack(">H", len(tlv_payload)) payload += tlv_payload p1 = 1 diff --git a/client/src/ledger_app_clients/ethereum/eip712/InputData.py b/client/src/ledger_app_clients/ethereum/eip712/InputData.py index c83e37ef9..bd65d7abd 100644 --- a/client/src/ledger_app_clients/ethereum/eip712/InputData.py +++ b/client/src/ledger_app_clients/ethereum/eip712/InputData.py @@ -7,13 +7,13 @@ from typing import Any, Callable, Optional, Union import struct -from client import keychain -from client.client import EthAppClient, EIP712FieldType - from ragger.firmware import Firmware +from client import keychain +from client.client import EthAppClient, EIP712FieldType from client.client import PKIPubKeyUsage + # global variables app_client: EthAppClient = None filtering_paths: dict = {} @@ -34,7 +34,7 @@ def default_handler(): # Input = "uint8[2][][4]" | "bool" # Output = ('uint8', [2, None, 4]) | ('bool', []) def get_array_levels(typename): - array_lvls = list() + array_lvls = [] regex = re.compile(r"(.*)\[([0-9]*)\]$") while True: @@ -109,7 +109,7 @@ def send_struct_def_field(typename, keyname): (typename, array_lvls) = get_array_levels(typename) (typename, typesize) = get_typesize(typename) - if typename in parsing_type_functions.keys(): + if typename in parsing_type_functions: (type_enum, typesize) = parsing_type_functions[typename](typesize) else: type_enum = EIP712FieldType.CUSTOM @@ -278,8 +278,7 @@ def evaluate_field(structs, data, field, lvls_left, new_level=True): idx += 1 if array_lvls[lvls_left - 1] is not None: if array_lvls[lvls_left - 1] != idx: - print("Mismatch in array size! Got %d, expected %d\n" % - (idx, array_lvls[lvls_left - 1]), + print(f"Mismatch in array size! Got {idx}, expected {array_lvls[lvls_left - 1]}\n", file=sys.stderr) return False else: @@ -298,8 +297,7 @@ def send_struct_impl(structs, data, structname): if structname not in structs.keys(): return False - struct = structs[structname] - for f in struct: + for f in structs[structname]: if not evaluate_field(structs, data[f["name"]], f, len(f["array_lvls"])): return False return True @@ -318,8 +316,6 @@ def start_signature_payload(ctx: dict, magic: int) -> bytearray: # ledgerjs doesn't actually sign anything, and instead uses already pre-computed signatures def send_filtering_message_info(display_name: str, filters_count: int): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 183) to_sign.append(filters_count) to_sign += display_name.encode() @@ -331,8 +327,6 @@ def send_filtering_message_info(display_name: str, filters_count: int): def send_filtering_amount_join_token(path: str, token_idx: int, discarded: bool): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 11) to_sign += path.encode() to_sign.append(token_idx) @@ -342,8 +336,6 @@ def send_filtering_amount_join_token(path: str, token_idx: int, discarded: bool) def send_filtering_amount_join_value(path: str, token_idx: int, display_name: str, discarded: bool): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 22) to_sign += path.encode() to_sign += display_name.encode() @@ -354,8 +346,6 @@ def send_filtering_amount_join_value(path: str, token_idx: int, display_name: st def send_filtering_datetime(path: str, display_name: str, discarded: bool): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 33) to_sign += path.encode() to_sign += display_name.encode() @@ -369,8 +359,6 @@ def send_filtering_trusted_name(path: str, name_type: list[int], name_source: list[int], discarded: bool): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 44) to_sign += path.encode() to_sign += display_name.encode() @@ -385,8 +373,6 @@ def send_filtering_trusted_name(path: str, # ledgerjs doesn't actually sign anything, and instead uses already pre-computed signatures def send_filtering_raw(path: str, display_name: str, discarded: bool): - global sig_ctx - to_sign = start_signature_payload(sig_ctx, 72) to_sign += path.encode() to_sign += display_name.encode() @@ -395,7 +381,7 @@ def send_filtering_raw(path: str, display_name: str, discarded: bool): pass -def prepare_filtering(filtr_data, message): +def prepare_filtering(filtr_data): global filtering_paths global filtering_tokens @@ -421,8 +407,6 @@ def handle_optional_domain_values(domain): def init_signature_context(types, domain): - global sig_ctx - handle_optional_domain_values(domain) caddr = domain["verifyingContract"] if caddr.startswith("0x"): @@ -465,7 +449,6 @@ def process_data(aclient: EthAppClient, filters: Optional[dict] = None, autonext: Optional[Callable] = None, golden_run: bool = False) -> bool: - global sig_ctx global app_client global autonext_handler global is_golden_run @@ -499,7 +482,7 @@ def process_data(aclient: EthAppClient, if filters: with app_client.eip712_filtering_activate(): pass - prepare_filtering(filters, message) + prepare_filtering(filters) if aclient._pki_client is None: print(f"Ledger-PKI Not supported on '{aclient._firmware.name}'") @@ -513,9 +496,12 @@ def process_data(aclient: EthAppClient, cert_apdu = "0101010201021104000000021201001302000214010116040000000020104549503731325F46696C746572696E67300200053101083201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C6405618873401013501041546304402204EA7B30F0EEFEF25FAB3ADDA6609E25296C41DD1C5969A92FAE6B600AAC2902E02206212054E123F5F965F787AE7EE565E243F21B11725626D3FF058522D6BDCD995" # noqa: E501 elif aclient._firmware == Firmware.FLEX: cert_apdu = "0101010201021104000000021201001302000214010116040000000020104549503731325F46696C746572696E67300200053101083201213321024CCA8FAD496AA5040A00A7EB2F5CC3B85376D88BA147A7D7054A99C6405618873401013501051546304402205FB5E970065A95C57F00FFA3964946251815527613724ED6745C37E303934BE702203CC9F4124B42806F0A7CA765CFAB5AADEB280C35AB8F809FC49ADC97D9B9CE15" # noqa: E501 + else: + print(f"Invalid device '{aclient._firmware.name}'") + cert_apdu = "" # pylint: enable=line-too-long - - aclient._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_COIN_META, bytes.fromhex(cert_apdu)) + if cert_apdu: + aclient._pki_client.send_certificate(PKIPubKeyUsage.PUBKEY_USAGE_COIN_META, bytes.fromhex(cert_apdu)) # send domain implementation with app_client.eip712_send_struct_impl_root_struct(domain_typename): diff --git a/client/src/ledger_app_clients/ethereum/keychain.py b/client/src/ledger_app_clients/ethereum/keychain.py index b913c867a..f769be404 100644 --- a/client/src/ledger_app_clients/ethereum/keychain.py +++ b/client/src/ledger_app_clients/ethereum/keychain.py @@ -1,8 +1,8 @@ import os import hashlib +from enum import Enum, auto from ecdsa import SigningKey from ecdsa.util import sigencode_der -from enum import Enum, auto # Private key PEM files have to be named the same (lowercase) as their corresponding enum entries @@ -16,20 +16,18 @@ class Key(Enum): NETWORK = auto() -_keys: dict[Key, SigningKey] = dict() +_keys: dict[Key, SigningKey] = {} # Open the corresponding PEM file and load its key in the global dict def _init_key(key: Key): - global _keys - with open("%s/keychain/%s.pem" % (os.path.dirname(__file__), key.name.lower())) as pem_file: + with open(f"{os.path.dirname(__file__)}/keychain/{key.name.lower()}.pem", encoding="utf-8") as pem_file: _keys[key] = SigningKey.from_pem(pem_file.read(), hashlib.sha256) assert (key in _keys) and (_keys[key] is not None) # Generate a SECP256K1 signature of the given data with the given key def sign_data(key: Key, data: bytes) -> bytes: - global _keys if key not in _keys: _init_key(key) return _keys[key].sign_deterministic(data, sigencode=sigencode_der) diff --git a/client/src/ledger_app_clients/ethereum/settings.py b/client/src/ledger_app_clients/ethereum/settings.py index 25718b6dc..10a745ce0 100644 --- a/client/src/ledger_app_clients/ethereum/settings.py +++ b/client/src/ledger_app_clients/ethereum/settings.py @@ -1,7 +1,7 @@ from enum import Enum, auto +from typing import Union from ragger.firmware import Firmware from ragger.navigator import Navigator, NavInsID, NavIns -from typing import Union class SettingID(Enum): diff --git a/client/src/ledger_app_clients/ethereum/utils.py b/client/src/ledger_app_clients/ethereum/utils.py index 0fa350840..3b61e657b 100644 --- a/client/src/ledger_app_clients/ethereum/utils.py +++ b/client/src/ledger_app_clients/ethereum/utils.py @@ -5,7 +5,7 @@ # eth_account requires it for some reason def normalize_vrs(vrs: tuple) -> tuple: - vrs_l = list() + vrs_l = [] for elem in vrs: vrs_l.append(elem.lstrip(b'\x00')) return tuple(vrs_l) diff --git a/src/chainConfig.h b/src/chainConfig.h index cc0f5b8d5..b73dd6e90 100644 --- a/src/chainConfig.h +++ b/src/chainConfig.h @@ -18,9 +18,6 @@ #ifndef _CHAIN_CONFIG_H_ #define _CHAIN_CONFIG_H_ -#include - -#include "os.h" #include "asset_info.h" typedef struct chain_config_s { diff --git a/src/common_ui.h b/src/common_ui.h index 06ffc5d10..18cd49a34 100644 --- a/src/common_ui.h +++ b/src/common_ui.h @@ -1,9 +1,8 @@ #ifndef _COMMON_UI_H_ #define _COMMON_UI_H_ -#include #include -#include "ui_logic.h" +#include void ui_idle(void); void ui_warning_blind_signing(void); @@ -32,7 +31,4 @@ void ui_712_switch_to_sign(void); // Generic clear-signing bool ui_gcs(void); -#include "ui_callbacks.h" -#include - #endif // _COMMON_UI_H_ diff --git a/src/handle_check_address.c b/src/handle_check_address.c index cf9e4f9c6..0fc790524 100644 --- a/src/handle_check_address.c +++ b/src/handle_check_address.c @@ -1,8 +1,5 @@ #include "handle_check_address.h" #include "apdu_constants.h" -#include "os.h" -#include "shared_context.h" -#include "string.h" #include "crypto_helpers.h" #define ZERO(x) explicit_bzero(&x, sizeof(x)) diff --git a/src/handle_get_printable_amount.c b/src/handle_get_printable_amount.c index 5b8d1f6c0..ca299869c 100644 --- a/src/handle_get_printable_amount.c +++ b/src/handle_get_printable_amount.c @@ -1,12 +1,5 @@ -#include -#include - +#include "os.h" #include "eth_swap_utils.h" -#include "handle_get_printable_amount.h" -#include "shared_context.h" -#include "common_utils.h" -#include "uint256.h" -#include "string.h" #include "network.h" #include "apdu_constants.h" diff --git a/src/handle_swap_sign_transaction.c b/src/handle_swap_sign_transaction.c index 7fda283c1..e3dff7f7a 100644 --- a/src/handle_swap_sign_transaction.c +++ b/src/handle_swap_sign_transaction.c @@ -1,10 +1,5 @@ -#include "os_io_seproxyhal.h" -#include "os.h" -#include "ux.h" #include "eth_swap_utils.h" -#include "handle_swap_sign_transaction.h" #include "shared_context.h" -#include "common_utils.h" #include "network.h" #include "cmd_setPlugin.h" #ifdef HAVE_NBGL @@ -162,7 +157,7 @@ void __attribute__((noreturn)) handle_swap_sign_transaction(const chain_config_t storage_init(); -#ifdef HAVE_NBGL +#ifdef SCREEN_SIZE_WALLET nbgl_useCaseSpinner("Signing"); #endif // HAVE_NBGL diff --git a/src/manage_asset_info.c b/src/manage_asset_info.c index 5965b5f64..4599d07ae 100644 --- a/src/manage_asset_info.c +++ b/src/manage_asset_info.c @@ -1,5 +1,4 @@ #include "manage_asset_info.h" -#include "shared_context.h" void forget_known_assets(void) { memset(tmpCtx.transactionContext.assetSet, false, MAX_ASSETS); diff --git a/src/manage_asset_info.h b/src/manage_asset_info.h index 3b8a30613..4a3465317 100644 --- a/src/manage_asset_info.h +++ b/src/manage_asset_info.h @@ -2,8 +2,6 @@ #define MANAGE_ASSET_INFO_H_ #include "shared_context.h" -#include "common_utils.h" -#include "asset_info.h" void forget_known_assets(void); int get_asset_index_by_addr(const uint8_t *addr); diff --git a/src/mem_utils.h b/src/mem_utils.h index 114b21fcd..55d1ae2c3 100644 --- a/src/mem_utils.h +++ b/src/mem_utils.h @@ -4,7 +4,6 @@ #ifdef HAVE_DYN_MEM_ALLOC #include -#include #define MEM_ALLOC_AND_ALIGN_TYPE(type) mem_alloc_and_align(sizeof(type), __alignof__(type)) diff --git a/src/network.c b/src/network.c index 70ffef78f..a2952a5f5 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,3 @@ -#include #include "os_utils.h" #include "os_pic.h" #include "network.h" diff --git a/src/shared_context.h b/src/shared_context.h index d1700dd4f..94825c7e5 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -1,23 +1,11 @@ #ifndef _SHARED_CONTEXT_H_ #define _SHARED_CONTEXT_H_ -#include -#include - -#include "os.h" -#include "cx.h" -#include "bip32.h" #include "bip32_utils.h" #include "ethUstream.h" -#include "tx_content.h" #include "chainConfig.h" -#include "asset_info.h" #include "swap_utils.h" -#ifdef HAVE_NBGL -#include "nbgl_types.h" -#endif - extern void app_exit(void); extern void common_app_init(void); diff --git a/src/ui_callbacks.h b/src/ui_callbacks.h index 52296356f..d46c3790a 100644 --- a/src/ui_callbacks.h +++ b/src/ui_callbacks.h @@ -3,10 +3,6 @@ #include "shared_context.h" #include "ux.h" -#ifdef HAVE_NBGL -typedef int bagl_element_t; -#endif - unsigned int io_seproxyhal_touch_tx_ok(void); unsigned int io_seproxyhal_touch_tx_cancel(void); unsigned int io_seproxyhal_touch_address_ok(void); diff --git a/src_bagl/common_ui.c b/src_bagl/common_ui.c index 96826f8e6..3aef4442e 100644 --- a/src_bagl/common_ui.c +++ b/src_bagl/common_ui.c @@ -3,6 +3,7 @@ #include "common_ui.h" #include "ux.h" #include "ui_flow.h" +#include "ui_callbacks.h" void ui_idle(void) { // reserve a display stack slot if none yet diff --git a/src_features/generic_tx_parser/gtp_tx_info.c b/src_features/generic_tx_parser/gtp_tx_info.c index 39ed016ca..d73407849 100644 --- a/src_features/generic_tx_parser/gtp_tx_info.c +++ b/src_features/generic_tx_parser/gtp_tx_info.c @@ -287,8 +287,7 @@ bool verify_tx_info_struct(const s_tx_info_ctx *context) { NULL, 0, #ifdef HAVE_LEDGER_PKI - // TODO: change once SDK has the enum value for this - 0x0b, + CERTIFICATE_PUBLIC_KEY_USAGE_CALLDATA, #endif (uint8_t *) context->tx_info->signature, context->tx_info->signature_len) != CX_OK) { diff --git a/src_features/getChallenge/cmd_get_challenge.c b/src_features/getChallenge/cmd_get_challenge.c index 84898aa2f..83a5942d1 100644 --- a/src_features/getChallenge/cmd_get_challenge.c +++ b/src_features/getChallenge/cmd_get_challenge.c @@ -1,8 +1,7 @@ #ifdef HAVE_TRUSTED_NAME -#include -#include -#include +#include "os_io.h" +#include "cx.h" #include "apdu_constants.h" #include "challenge.h" diff --git a/src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c b/src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c index 81dbea90d..a3e668b88 100644 --- a/src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c +++ b/src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c @@ -1,9 +1,8 @@ #ifdef HAVE_ETH2 -#include "shared_context.h" #include "apdu_constants.h" #include "feature_getEth2PublicKey.h" -#include "common_ui.h" +#include "ui_callbacks.h" unsigned int io_seproxyhal_touch_eth2_address_ok(void) { uint32_t tx = set_result_get_eth2_publicKey(); diff --git a/src_features/getPublicKey/ui_common_getPublicKey.c b/src_features/getPublicKey/ui_common_getPublicKey.c index fe1a0bae0..abee55425 100644 --- a/src_features/getPublicKey/ui_common_getPublicKey.c +++ b/src_features/getPublicKey/ui_common_getPublicKey.c @@ -1,7 +1,6 @@ -#include "shared_context.h" #include "apdu_constants.h" #include "feature_getPublicKey.h" -#include "common_ui.h" +#include "ui_callbacks.h" unsigned int io_seproxyhal_touch_address_ok(void) { uint32_t tx = set_result_get_publicKey(); diff --git a/src_features/performPrivacyOperation/ui_common_performPrivacyOperation.c b/src_features/performPrivacyOperation/ui_common_performPrivacyOperation.c index 652e6be11..70413b053 100644 --- a/src_features/performPrivacyOperation/ui_common_performPrivacyOperation.c +++ b/src_features/performPrivacyOperation/ui_common_performPrivacyOperation.c @@ -1,7 +1,5 @@ -#include "shared_context.h" #include "apdu_constants.h" -#include "feature_getPublicKey.h" -#include "common_ui.h" +#include "ui_callbacks.h" #include "feature_performPrivacyOperation.h" unsigned int io_seproxyhal_touch_privacy_ok(void) { diff --git a/src_features/provideDynamicNetwork/network_dynamic.c b/src_features/provideDynamicNetwork/network_dynamic.c index c496d88c2..48de9a8a4 100644 --- a/src_features/provideDynamicNetwork/network_dynamic.c +++ b/src_features/provideDynamicNetwork/network_dynamic.c @@ -450,8 +450,7 @@ static bool verify_signature(s_sig_ctx *sig_ctx) { NULL, 0, #ifdef HAVE_LEDGER_PKI - // TODO: change once SDK has the enum value for this - 0x0c, + CERTIFICATE_PUBLIC_KEY_USAGE_NETWORK, #endif (uint8_t *) (sig_ctx->sig), sig_ctx->sig_size) != CX_OK) { diff --git a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c index 492c5244f..b264a2ac2 100644 --- a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c +++ b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c @@ -1,8 +1,5 @@ -#include "shared_context.h" #include "apdu_constants.h" #include "public_keys.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" #include "network.h" #include "manage_asset_info.h" #ifdef HAVE_LEDGER_PKI diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index dc29dbddf..3584e3b41 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -1,11 +1,7 @@ #ifdef HAVE_NFT_SUPPORT -#include "shared_context.h" #include "apdu_constants.h" #include "asset_info.h" -#include "common_utils.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" #include "network.h" #include "public_keys.h" #include "manage_asset_info.h" diff --git a/src_features/provideTrustedName/cmd_provide_trusted_name.c b/src_features/provideTrustedName/cmd_provide_trusted_name.c index 1fe121dc4..a71ce17bf 100644 --- a/src_features/provideTrustedName/cmd_provide_trusted_name.c +++ b/src_features/provideTrustedName/cmd_provide_trusted_name.c @@ -1,6 +1,5 @@ #ifdef HAVE_TRUSTED_NAME -#include #include #include #include diff --git a/src_features/provide_enum_value/cmd_enum_value.c b/src_features/provide_enum_value/cmd_enum_value.c index 33bc68bd8..45cb17d71 100644 --- a/src_features/provide_enum_value/cmd_enum_value.c +++ b/src_features/provide_enum_value/cmd_enum_value.c @@ -1,9 +1,7 @@ #ifdef HAVE_ENUM_VALUE -#include #include "cmd_enum_value.h" #include "apdu_constants.h" -#include "read.h" #include "mem.h" #include "enum_value.h" #include "tlv_apdu.h" diff --git a/src_features/provide_enum_value/enum_value.c b/src_features/provide_enum_value/enum_value.c index 84c34d40e..50e967d2d 100644 --- a/src_features/provide_enum_value/enum_value.c +++ b/src_features/provide_enum_value/enum_value.c @@ -1,6 +1,5 @@ #ifdef HAVE_ENUM_VALUE -#include #include "enum_value.h" #include "read.h" #include "public_keys.h" @@ -156,8 +155,7 @@ bool verify_enum_value_struct(const s_enum_value_ctx *context) { NULL, 0, #ifdef HAVE_LEDGER_PKI - // TODO: change once SDK has the enum value for this - 0x0b, + CERTIFICATE_PUBLIC_KEY_USAGE_CALLDATA, #endif (uint8_t *) context->enum_value.signature, context->enum_value.signature_length) != CX_OK) { diff --git a/src_features/setExternalPlugin/cmd_setExternalPlugin.c b/src_features/setExternalPlugin/cmd_setExternalPlugin.c index 6ab3b3915..8d5141f92 100644 --- a/src_features/setExternalPlugin/cmd_setExternalPlugin.c +++ b/src_features/setExternalPlugin/cmd_setExternalPlugin.c @@ -1,11 +1,8 @@ -#include "shared_context.h" #include "apdu_constants.h" #include "public_keys.h" #include "eth_plugin_interface.h" #include "eth_plugin_internal.h" #include "plugin_utils.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" #ifdef HAVE_LEDGER_PKI #include "os_pki.h" #endif diff --git a/src_features/setPlugin/cmd_setPlugin.c b/src_features/setPlugin/cmd_setPlugin.c index 91455b4ce..a6e6f10a0 100644 --- a/src_features/setPlugin/cmd_setPlugin.c +++ b/src_features/setPlugin/cmd_setPlugin.c @@ -1,12 +1,7 @@ -#include "shared_context.h" #include "apdu_constants.h" -#include "asset_info.h" #include "eth_plugin_interface.h" #include "eth_plugin_internal.h" #include "plugin_utils.h" -#include "common_utils.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" #include "network.h" #include "public_keys.h" #ifdef HAVE_LEDGER_PKI diff --git a/src_features/signMessage/cmd_signMessage.c b/src_features/signMessage/cmd_signMessage.c index e9549c4f9..f50287270 100644 --- a/src_features/signMessage/cmd_signMessage.c +++ b/src_features/signMessage/cmd_signMessage.c @@ -1,9 +1,8 @@ -#include #include -#include #include "apdu_constants.h" #include "sign_message.h" #include "common_ui.h" +#include "ui_callbacks.h" static uint8_t processed_size; static struct { diff --git a/src_features/signMessage/ui_common_signMessage.c b/src_features/signMessage/ui_common_signMessage.c index 047b21a37..feb6c606c 100644 --- a/src_features/signMessage/ui_common_signMessage.c +++ b/src_features/signMessage/ui_common_signMessage.c @@ -1,7 +1,7 @@ #include "os_io_seproxyhal.h" #include "apdu_constants.h" #include "crypto_helpers.h" -#include "common_ui.h" +#include "ui_callbacks.h" unsigned int io_seproxyhal_touch_signMessage_ok(void) { unsigned int info = 0; diff --git a/src_features/signMessageEIP712/commands_712.c b/src_features/signMessageEIP712/commands_712.c index dd3485a7e..c8f44ba18 100644 --- a/src_features/signMessageEIP712/commands_712.c +++ b/src_features/signMessageEIP712/commands_712.c @@ -1,9 +1,5 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include -#include -#include "commands_712.h" #include "apdu_constants.h" // APDU response codes #include "context_712.h" #include "field_hash.h" @@ -12,9 +8,9 @@ #include "typed_data.h" #include "schema_hash.h" #include "filtering.h" -#include "common_712.h" #include "common_ui.h" // ui_idle #include "manage_asset_info.h" +#include "ui_callbacks.h" // APDUs P1 #define P1_COMPLETE 0x00 diff --git a/src_features/signMessageEIP712/context_712.c b/src_features/signMessageEIP712/context_712.c index 89a2a98b0..79d3bed64 100644 --- a/src_features/signMessageEIP712/context_712.c +++ b/src_features/signMessageEIP712/context_712.c @@ -1,7 +1,5 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include #include "context_712.h" #include "mem.h" #include "mem_utils.h" diff --git a/src_features/signMessageEIP712/encode_field.c b/src_features/signMessageEIP712/encode_field.c index 2c3339d4b..bffade56d 100644 --- a/src_features/signMessageEIP712/encode_field.c +++ b/src_features/signMessageEIP712/encode_field.c @@ -1,10 +1,7 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include #include "encode_field.h" #include "mem.h" -#include "shared_context.h" #include "apdu_constants.h" // APDU response codes typedef enum { MSB, LSB } e_padding_type; diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index 0818be856..73d9e06a4 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -6,7 +6,6 @@ #include "path.h" #include "mem.h" #include "mem_utils.h" -#include "shared_context.h" #include "ui_logic.h" #include "context_712.h" // contract_addr #include "common_utils.h" // u64_from_BE diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index c163a4bb4..e186279e5 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -1,13 +1,11 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include #include #include "path.h" #include "mem.h" #include "context_712.h" #include "commands_712.h" #include "type_hash.h" -#include "shared_context.h" #include "mem_utils.h" #include "apdu_constants.h" // APDU response codes #include "typed_data.h" diff --git a/src_features/signMessageEIP712/sol_typenames.c b/src_features/signMessageEIP712/sol_typenames.c index 6163e7fa9..0d09e56bd 100644 --- a/src_features/signMessageEIP712/sol_typenames.c +++ b/src_features/signMessageEIP712/sol_typenames.c @@ -1,7 +1,5 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include #include "sol_typenames.h" #include "mem.h" #include "os_pic.h" diff --git a/src_features/signMessageEIP712/type_hash.c b/src_features/signMessageEIP712/type_hash.c index 8318abcfd..a005718d7 100644 --- a/src_features/signMessageEIP712/type_hash.c +++ b/src_features/signMessageEIP712/type_hash.c @@ -1,12 +1,8 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include -#include #include "mem.h" #include "mem_utils.h" #include "type_hash.h" -#include "shared_context.h" #include "format_hash_field_type.h" #include "hash_bytes.h" #include "apdu_constants.h" // APDU response codes diff --git a/src_features/signMessageEIP712/typed_data.c b/src_features/signMessageEIP712/typed_data.c index e5f75b700..703223758 100644 --- a/src_features/signMessageEIP712/typed_data.c +++ b/src_features/signMessageEIP712/typed_data.c @@ -1,7 +1,5 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include #include "typed_data.h" #include "sol_typenames.h" #include "apdu_constants.h" // APDU response codes diff --git a/src_features/signMessageEIP712/ui_logic.c b/src_features/signMessageEIP712/ui_logic.c index d022fcb13..309a02321 100644 --- a/src_features/signMessageEIP712/ui_logic.c +++ b/src_features/signMessageEIP712/ui_logic.c @@ -1,25 +1,18 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include -#include -#include #include "ui_logic.h" #include "mem.h" #include "mem_utils.h" #include "os_io.h" -#include "shared_context.h" #include "common_utils.h" // uint256_to_decimal #include "common_712.h" #include "context_712.h" // eip712_context_deinit -#include "uint256.h" // tostring256 && tostring256_signed #include "path.h" // path_get_root_type #include "apdu_constants.h" // APDU response codes #include "typed_data.h" #include "commands_712.h" #include "common_ui.h" -#include "uint_common.h" #include "filtering.h" -#include "trusted_name.h" #include "network.h" #include "time_format.h" diff --git a/src_features/signMessageEIP712_common/common_712.c b/src_features/signMessageEIP712_common/common_712.c index bdf64cbd1..50daac84f 100644 --- a/src_features/signMessageEIP712_common/common_712.c +++ b/src_features/signMessageEIP712_common/common_712.c @@ -1,11 +1,8 @@ -#include "shared_context.h" #include "apdu_constants.h" #include "os_io_seproxyhal.h" #include "crypto_helpers.h" #include "ui_callbacks.h" #include "common_712.h" -#include "ui_callbacks.h" -#include "common_ui.h" static const uint8_t EIP_712_MAGIC[] = {0x19, 0x01}; diff --git a/src_features/signMessageEIP712_v0/cmd_signMessage712.c b/src_features/signMessageEIP712_v0/cmd_signMessage712.c index 844a3c8fc..e829f47e3 100644 --- a/src_features/signMessageEIP712_v0/cmd_signMessage712.c +++ b/src_features/signMessageEIP712_v0/cmd_signMessage712.c @@ -1,4 +1,3 @@ -#include "shared_context.h" #include "apdu_constants.h" #include "common_utils.h" #include "common_ui.h" diff --git a/src_features/signTx/cmd_signTx.c b/src_features/signTx/cmd_signTx.c index 07a778e77..cea6cc4a6 100644 --- a/src_features/signTx/cmd_signTx.c +++ b/src_features/signTx/cmd_signTx.c @@ -8,6 +8,7 @@ #include "gtp_tx_info.h" #endif #include "common_ui.h" +#include "ui_callbacks.h" typedef enum { SIGN_MODE_BASIC = 0, diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index 03bc1888b..ffc629440 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -640,7 +640,6 @@ uint16_t finalize_parsing(const txContext_t *context) { // If called from swap, the user has already validated a standard transaction // And we have already checked the fields of this transaction above if (G_called_from_swap && g_use_standard_ui) { - ui_idle(); io_seproxyhal_touch_tx_ok(); } else { #ifdef HAVE_BAGL diff --git a/src_features/signTx/ui_common_signTx.c b/src_features/signTx/ui_common_signTx.c index 40c6d109c..30a9bdd31 100644 --- a/src_features/signTx/ui_common_signTx.c +++ b/src_features/signTx/ui_common_signTx.c @@ -1,12 +1,9 @@ #include "swap_entrypoints.h" #include "crypto_helpers.h" -#include "os_io_seproxyhal.h" -#include "shared_context.h" -#include "common_utils.h" -#include "common_ui.h" #include "handle_swap_sign_transaction.h" #include "feature_signTx.h" #include "apdu_constants.h" +#include "ui_callbacks.h" uint32_t io_seproxyhal_touch_tx_ok(void) { uint32_t info = 0; diff --git a/src_nbgl/network_icons.h b/src_nbgl/network_icons.h index 0a85afebf..7eec96ddf 100644 --- a/src_nbgl/network_icons.h +++ b/src_nbgl/network_icons.h @@ -1,9 +1,6 @@ #ifndef NETWORK_ICONS_H_ #define NETWORK_ICONS_H_ -#include -#include "nbgl_types.h" - const nbgl_icon_details_t *get_network_icon_from_chain_id(const uint64_t *chain_id); #endif // NETWORK_ICONS_H_ diff --git a/src_nbgl/ui_approve_tx.c b/src_nbgl/ui_approve_tx.c index 300b4fa7c..ff5d5aca0 100644 --- a/src_nbgl/ui_approve_tx.c +++ b/src_nbgl/ui_approve_tx.c @@ -1,15 +1,13 @@ #include -#include "nbgl_page.h" #include "shared_context.h" #include "ui_callbacks.h" +#include "ui_message_signing.h" #include "ui_nbgl.h" -#include "ui_signing.h" #include "plugins.h" #include "trusted_name.h" #include "caller_api.h" #include "network_icons.h" #include "network.h" -#include "ledger_assert.h" // 1 more than actually displayed on screen, because of calculations in StaticReview #define MAX_PLUGIN_ITEMS 8 @@ -219,11 +217,10 @@ void ux_approve_tx(bool fromPlugin) { (pluginType == EXTERNAL ? "on " : ""), strings.common.toAddress); } else { - snprintf(g_stax_shared_buffer, buf_size, REVIEW("transaction")); - snprintf( - g_stax_shared_buffer + buf_size, - buf_size, - tmpContent.txContent.dataPresent ? BLIND_SIGN("transaction") : SIGN("transaction")); + snprintf(g_stax_shared_buffer, buf_size, TEXT_REVIEW_TRANSACTION); + snprintf(g_stax_shared_buffer + buf_size, + buf_size, + tmpContent.txContent.dataPresent ? TEXT_BLIND_TRANSACTION : TEXT_SIGN_TRANSACTION); } if (tmpContent.txContent.dataPresent) { diff --git a/src_nbgl/ui_blind_signing.c b/src_nbgl/ui_blind_signing.c index d5ad753c8..173a12e64 100644 --- a/src_nbgl/ui_blind_signing.c +++ b/src_nbgl/ui_blind_signing.c @@ -1,9 +1,4 @@ -#include -#include "shared_context.h" -#include "ui_callbacks.h" #include "ui_nbgl.h" -#include "apdu_constants.h" -#include "context_712.h" static void ui_error_blind_signing_choice(bool confirm) { if (confirm) { @@ -14,7 +9,7 @@ static void ui_error_blind_signing_choice(bool confirm) { } void ui_error_blind_signing(void) { - nbgl_useCaseChoice(&C_Warning_64px, + nbgl_useCaseChoice(&ICON_APP_WARNING, "This transaction cannot be clear-signed", "Enable blind signing in the settings to sign this transaction.", "Go to settings", diff --git a/src_nbgl/ui_confirm_parameter_selector.c b/src_nbgl/ui_confirm_parameter_selector.c index 2292e6226..520a8daa0 100644 --- a/src_nbgl/ui_confirm_parameter_selector.c +++ b/src_nbgl/ui_confirm_parameter_selector.c @@ -1,7 +1,5 @@ -#include "common_ui.h" -#include "ui_signing.h" #include "ui_nbgl.h" -#include "network.h" +#include "ui_callbacks.h" typedef enum { PARAMETER_CONFIRMATION, SELECTOR_CONFIRMATION } e_confirmation_type; static nbgl_contentTagValue_t pair; diff --git a/src_nbgl/ui_display_privacy.c b/src_nbgl/ui_display_privacy.c index 209e0d99b..edcd8a304 100644 --- a/src_nbgl/ui_display_privacy.c +++ b/src_nbgl/ui_display_privacy.c @@ -1,8 +1,5 @@ -#include "common_ui.h" -#include "ui_signing.h" #include "ui_nbgl.h" -#include "nbgl_use_case.h" -#include "nbgl_content.h" +#include "ui_callbacks.h" static void reviewChoice(bool confirm) { if (confirm) { diff --git a/src_nbgl/ui_gcs.c b/src_nbgl/ui_gcs.c index 8f842837d..99414e57a 100644 --- a/src_nbgl/ui_gcs.c +++ b/src_nbgl/ui_gcs.c @@ -163,7 +163,7 @@ bool ui_gcs(void) { return cleanup_on_error(mem_before); } explicit_bzero(&tip_box, sizeof(tip_box)); - tip_box.icon = &C_review_info_button; + tip_box.icon = &ICON_APP_REVIEW_INFO; tip_box.text = NULL; tip_box.modalTitle = "Contract information"; tip_box.type = INFOS_LIST; @@ -223,6 +223,7 @@ bool ui_gcs(void) { NULL, sign_title, &tip_box, + NULL, review_choice); g_alloc_size = mem_alloc(0) - mem_before; return true; diff --git a/src_nbgl/ui_get_eth2_public_key.c b/src_nbgl/ui_get_eth2_public_key.c index e9b2ded0f..2058d9806 100644 --- a/src_nbgl/ui_get_eth2_public_key.c +++ b/src_nbgl/ui_get_eth2_public_key.c @@ -1,8 +1,5 @@ -#include -#include "shared_context.h" #include "ui_callbacks.h" #include "ui_nbgl.h" -#include "uint_common.h" static void reviewChoice(bool confirm) { if (confirm) { diff --git a/src_nbgl/ui_get_public_key.c b/src_nbgl/ui_get_public_key.c index bcaccfb78..f1f6a06d2 100644 --- a/src_nbgl/ui_get_public_key.c +++ b/src_nbgl/ui_get_public_key.c @@ -1,4 +1,3 @@ -#include "nbgl_use_case.h" #include "shared_context.h" #include "ui_callbacks.h" #include "ui_nbgl.h" diff --git a/src_nbgl/ui_home.c b/src_nbgl/ui_home.c index 9eaf38fb9..069d96365 100644 --- a/src_nbgl/ui_home.c +++ b/src_nbgl/ui_home.c @@ -1,6 +1,4 @@ -#include "common_ui.h" #include "ui_nbgl.h" -#include "nbgl_use_case.h" #include "caller_api.h" #include "network.h" diff --git a/src_nbgl/ui_message_signing.h b/src_nbgl/ui_message_signing.h index 8c8c193b7..9a6f223f7 100644 --- a/src_nbgl/ui_message_signing.h +++ b/src_nbgl/ui_message_signing.h @@ -2,13 +2,22 @@ #define UI_MESSAGE_SIGNING_H_ #include -#include "ui_signing.h" -#define TEXT_MESSAGE "message" -#define TEXT_TYPED_MESSAGE "typed " TEXT_MESSAGE -#define TEXT_REVIEW_EIP712 REVIEW(TEXT_TYPED_MESSAGE) -#define TEXT_SIGN_EIP712 SIGN(TEXT_TYPED_MESSAGE) -#define TEXT_BLIND_SIGN_EIP712 BLIND_SIGN(TEXT_TYPED_MESSAGE) +#define SIGN(msg) "Sign " msg "?" +#define BLIND_SIGN(msg) "Accept risk and sign " msg "?" +#define REVIEW(msg) "Review " msg +#define TEXT_TRANSACTION "transaction" +#define TEXT_MESSAGE "message" +#define TEXT_TYPED_MESSAGE "typed " TEXT_MESSAGE + +#define TEXT_REVIEW_TRANSACTION REVIEW(TEXT_TRANSACTION) +#define TEXT_SIGN_TRANSACTION SIGN(TEXT_TRANSACTION) +#define TEXT_BLIND_TRANSACTION BLIND_SIGN(TEXT_TRANSACTION) +#define TEXT_REVIEW_EIP191 REVIEW(TEXT_MESSAGE) +#define TEXT_SIGN_EIP191 SIGN(TEXT_MESSAGE) +#define TEXT_REVIEW_EIP712 REVIEW(TEXT_TYPED_MESSAGE) +#define TEXT_SIGN_EIP712 SIGN(TEXT_TYPED_MESSAGE) +#define TEXT_BLIND_SIGN_EIP712 BLIND_SIGN(TEXT_TYPED_MESSAGE) void ui_typed_message_review_choice_v0(bool confirm); #ifdef HAVE_EIP712_FULL_SUPPORT diff --git a/src_nbgl/ui_nbgl.h b/src_nbgl/ui_nbgl.h index ad07dc31c..949383e65 100644 --- a/src_nbgl/ui_nbgl.h +++ b/src_nbgl/ui_nbgl.h @@ -1,15 +1,23 @@ #ifndef _UI_NBGL_H_ #define _UI_NBGL_H_ -#include -#include -#include +#include "nbgl_use_case.h" +#include "shared_context.h" +#include "glyphs.h" + +#ifdef SCREEN_SIZE_WALLET +#define ICON_APP_WARNING C_Warning_64px +#define ICON_APP_REVIEW C_Review_64px +#define ICON_APP_REVIEW_INFO C_Warning_64px +#else +#define ICON_APP_WARNING C_icon_warning +#define ICON_APP_REVIEW C_icon_certificate +#define ICON_APP_REVIEW_INFO C_icon_eye +#endif #define SHARED_BUFFER_SIZE SHARED_CTX_FIELD_1_SIZE extern char g_stax_shared_buffer[SHARED_BUFFER_SIZE]; -extern nbgl_page_t* pageContext; - const nbgl_icon_details_t* get_app_icon(bool caller_icon); const nbgl_icon_details_t* get_tx_icon(void); diff --git a/src_nbgl/ui_sign_712.c b/src_nbgl/ui_sign_712.c index cd4afcf90..55ea6d9c6 100644 --- a/src_nbgl/ui_sign_712.c +++ b/src_nbgl/ui_sign_712.c @@ -1,14 +1,9 @@ #ifdef HAVE_EIP712_FULL_SUPPORT -#include // explicit_bzero #include "common_ui.h" #include "ui_nbgl.h" #include "ui_logic.h" -#include "common_712.h" -#include "nbgl_use_case.h" #include "ui_message_signing.h" -#include "ledger_assert.h" -#include "apdu_constants.h" static nbgl_contentTagValue_t pairs[7]; static nbgl_contentTagValueList_t pairs_list; @@ -92,7 +87,7 @@ static void ui_712_start_common(bool has_filtering) { void ui_712_start_unfiltered(void) { ui_712_start_common(false); nbgl_useCaseReviewStreamingBlindSigningStart(TYPE_MESSAGE | SKIPPABLE_OPERATION, - &C_Review_64px, + &ICON_APP_REVIEW, TEXT_REVIEW_EIP712, NULL, message_update); @@ -101,7 +96,7 @@ void ui_712_start_unfiltered(void) { void ui_712_start(void) { ui_712_start_common(true); nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE, - &C_Review_64px, + &ICON_APP_REVIEW, TEXT_REVIEW_EIP712, NULL, message_update); diff --git a/src_nbgl/ui_sign_712_v0.c b/src_nbgl/ui_sign_712_v0.c index 64bc640f5..ea394b51b 100644 --- a/src_nbgl/ui_sign_712_v0.c +++ b/src_nbgl/ui_sign_712_v0.c @@ -1,6 +1,3 @@ -#include // explicit_bzero -#include "os_utils.h" // ARRAYLEN -#include "common_ui.h" #include "ui_nbgl.h" #include "common_712.h" #include "ui_message_signing.h" @@ -34,7 +31,7 @@ void ui_sign_712_v0(void) { nbgl_useCaseReviewBlindSigning(TYPE_TRANSACTION, &pairs_list, - &C_Review_64px, + &ICON_APP_REVIEW, TEXT_REVIEW_EIP712, NULL, TEXT_BLIND_SIGN_EIP712, diff --git a/src_nbgl/ui_sign_message.c b/src_nbgl/ui_sign_message.c index efabd82d2..298d5c504 100644 --- a/src_nbgl/ui_sign_message.c +++ b/src_nbgl/ui_sign_message.c @@ -1,16 +1,7 @@ -#include "nbgl_page.h" -#include "shared_context.h" #include "ui_callbacks.h" #include "ui_nbgl.h" #include "sign_message.h" -#include "glyphs.h" -#include "nbgl_use_case.h" -#include "common_ui.h" #include "ui_message_signing.h" -#include "ui_signing.h" - -#define TEXT_REVIEW_EIP191 REVIEW(TEXT_MESSAGE) -#define TEXT_SIGN_EIP191 SIGN(TEXT_MESSAGE) typedef enum { UI_191_ACTION_IDLE = 0, @@ -50,11 +41,11 @@ static bool ui_191_update_display_buffer(void) { g_stax_shared_buffer[g_display_buffer_idx] = '\0'; strlcat(g_stax_shared_buffer + g_display_buffer_idx, - strings.tmp.tmp + g_rcv_buffer_idx, + UI_191_BUFFER + g_rcv_buffer_idx, sizeof(g_stax_shared_buffer) - g_display_buffer_idx); reached = nbgl_getTextMaxLenInNbLines(LARGE_MEDIUM_FONT, (char *) g_stax_shared_buffer, - SCREEN_WIDTH - (2 * BORDER_MARGIN), + AVAILABLE_WIDTH, NB_MAX_LINES_IN_REVIEW, &len, false); @@ -114,7 +105,7 @@ void ui_191_start(void) { g_skipped = false; nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE | SKIPPABLE_OPERATION, - &C_Review_64px, + &ICON_APP_REVIEW, TEXT_REVIEW_EIP191, NULL, ui_191_data_cb); diff --git a/src_nbgl/ui_signing.c b/src_nbgl/ui_signing.c deleted file mode 100644 index 2becdf07d..000000000 --- a/src_nbgl/ui_signing.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "ui_signing.h" - -e_ui_signing_position g_position; diff --git a/src_nbgl/ui_signing.h b/src_nbgl/ui_signing.h deleted file mode 100644 index 6595f1066..000000000 --- a/src_nbgl/ui_signing.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef UI_SIGNING_H_ -#define UI_SIGNING_H_ - -#define SIGN_BUTTON "Hold to sign" -#define REJECT_BUTTON "Reject" -#define SIGN(msg) "Sign " msg "?" -#define BLIND_SIGN(msg) "Accept risk and sign " msg "?" -#define REVIEW(msg) "Review " msg -#define REJECT(msg) "Reject " msg -#define REJECT_QUESTION(msg) REJECT(msg) "?" -#define REJECT_CONFIRM_BUTTON "Yes, reject" -#define RESUME(msg) "Go back to " msg - -typedef enum { - UI_SIGNING_POSITION_START = 0, - UI_SIGNING_POSITION_REVIEW, - UI_SIGNING_POSITION_SIGN -} e_ui_signing_position; - -extern e_ui_signing_position g_position; - -#endif // UI_SIGNING_H_ diff --git a/tests/ragger/conftest.py b/tests/ragger/conftest.py index f3ddde95e..7f2d57ecb 100644 --- a/tests/ragger/conftest.py +++ b/tests/ragger/conftest.py @@ -1,8 +1,5 @@ -import sys from pathlib import Path -from os import path import warnings -import glob import re import pytest @@ -30,8 +27,8 @@ def pytest_configure(config): @pytest.fixture(name="app_version") def app_version_fixture(request) -> tuple[int, int, int]: - with open(Path(__file__).parent.parent.parent / "Makefile") as f: - parsed = dict() + with open(Path(__file__).parent.parent.parent / "Makefile", encoding="utf-8") as f: + parsed = {} for m in re.findall(r"^APPVERSION_(\w)\s*=\s*(\d*)$", f.read(), re.MULTILINE): parsed[m[0]] = int(m[1]) return (parsed["M"], parsed["N"], parsed["P"]) diff --git a/tests/ragger/setup.cfg b/tests/ragger/setup.cfg index 4a673e2c3..a2fd6373f 100644 --- a/tests/ragger/setup.cfg +++ b/tests/ragger/setup.cfg @@ -7,6 +7,7 @@ disable = C0114, # missing-module-docstring C0116, # missing-function-docstring C0103, # invalid-name R0801, # duplicate-code + R0902, # too-many-instance-attributes R0903, # too-few-public-methods R0904, # too-many-public-methods R0911, # too-many-statements @@ -14,6 +15,7 @@ disable = C0114, # missing-module-docstring R0913, # too-many-arguments R0914, # too-many-locals R0915, # too-many-statements + R0917, # too-many-positional-arguments W0603, # global-statement E0401 # import-error extension-pkg-whitelist=hid diff --git a/tests/ragger/snapshots/flex/test_1inch/00000.png b/tests/ragger/snapshots/flex/test_1inch/00000.png index bb8112a26..812971ef2 100644 Binary files a/tests/ragger/snapshots/flex/test_1inch/00000.png and b/tests/ragger/snapshots/flex/test_1inch/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign/00000.png b/tests/ragger/snapshots/flex/test_blind_sign/00000.png index 039eff047..d17942d01 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign/00000.png and b/tests/ragger/snapshots/flex/test_blind_sign/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign/00001.png b/tests/ragger/snapshots/flex/test_blind_sign/00001.png index a36989ec6..30c604f3d 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign/00001.png and b/tests/ragger/snapshots/flex/test_blind_sign/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00000.png b/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00000.png index 039eff047..d17942d01 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00000.png and b/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00001.png b/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00001.png index a36989ec6..30c604f3d 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00001.png and b/tests/ragger/snapshots/flex/test_blind_sign_nonzero/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign_rejected/00000.png b/tests/ragger/snapshots/flex/test_blind_sign_rejected/00000.png index 039eff047..d17942d01 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign_rejected/00000.png and b/tests/ragger/snapshots/flex/test_blind_sign_rejected/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_blind_sign_rejected/00001.png b/tests/ragger/snapshots/flex/test_blind_sign_rejected/00001.png index a36989ec6..30c604f3d 100644 Binary files a/tests/ragger/snapshots/flex/test_blind_sign_rejected/00001.png and b/tests/ragger/snapshots/flex/test_blind_sign_rejected/00001.png differ diff --git a/tests/ragger/snapshots/flex/test_nft/00000.png b/tests/ragger/snapshots/flex/test_nft/00000.png index dcae9dcaf..37447b418 100644 Binary files a/tests/ragger/snapshots/flex/test_nft/00000.png and b/tests/ragger/snapshots/flex/test_nft/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_poap/00000.png b/tests/ragger/snapshots/flex/test_poap/00000.png index 763cb990e..423be2e9a 100644 Binary files a/tests/ragger/snapshots/flex/test_poap/00000.png and b/tests/ragger/snapshots/flex/test_poap/00000.png differ diff --git a/tests/ragger/snapshots/flex/test_sign_parameter_selector/00006.png b/tests/ragger/snapshots/flex/test_sign_parameter_selector/00006.png index 039eff047..d17942d01 100644 Binary files a/tests/ragger/snapshots/flex/test_sign_parameter_selector/00006.png and b/tests/ragger/snapshots/flex/test_sign_parameter_selector/00006.png differ diff --git a/tests/ragger/snapshots/flex/test_sign_parameter_selector/00007.png b/tests/ragger/snapshots/flex/test_sign_parameter_selector/00007.png index a36989ec6..30c604f3d 100644 Binary files a/tests/ragger/snapshots/flex/test_sign_parameter_selector/00007.png and b/tests/ragger/snapshots/flex/test_sign_parameter_selector/00007.png differ diff --git a/tests/ragger/snapshots/stax/test_1inch/00000.png b/tests/ragger/snapshots/stax/test_1inch/00000.png index 7034dc469..20a65be2a 100644 Binary files a/tests/ragger/snapshots/stax/test_1inch/00000.png and b/tests/ragger/snapshots/stax/test_1inch/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign/00000.png b/tests/ragger/snapshots/stax/test_blind_sign/00000.png index 0463721b1..e7a78b5be 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign/00000.png and b/tests/ragger/snapshots/stax/test_blind_sign/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign/00001.png b/tests/ragger/snapshots/stax/test_blind_sign/00001.png index e993bf998..a9cb3a2f0 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign/00001.png and b/tests/ragger/snapshots/stax/test_blind_sign/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00000.png b/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00000.png index 0463721b1..e7a78b5be 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00000.png and b/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00001.png b/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00001.png index e993bf998..a9cb3a2f0 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00001.png and b/tests/ragger/snapshots/stax/test_blind_sign_nonzero/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign_rejected/00000.png b/tests/ragger/snapshots/stax/test_blind_sign_rejected/00000.png index 0463721b1..e7a78b5be 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign_rejected/00000.png and b/tests/ragger/snapshots/stax/test_blind_sign_rejected/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_blind_sign_rejected/00001.png b/tests/ragger/snapshots/stax/test_blind_sign_rejected/00001.png index e993bf998..a9cb3a2f0 100644 Binary files a/tests/ragger/snapshots/stax/test_blind_sign_rejected/00001.png and b/tests/ragger/snapshots/stax/test_blind_sign_rejected/00001.png differ diff --git a/tests/ragger/snapshots/stax/test_nft/00000.png b/tests/ragger/snapshots/stax/test_nft/00000.png index b0958508a..266fc2a24 100644 Binary files a/tests/ragger/snapshots/stax/test_nft/00000.png and b/tests/ragger/snapshots/stax/test_nft/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_poap/00000.png b/tests/ragger/snapshots/stax/test_poap/00000.png index 751240cb5..2a07a860a 100644 Binary files a/tests/ragger/snapshots/stax/test_poap/00000.png and b/tests/ragger/snapshots/stax/test_poap/00000.png differ diff --git a/tests/ragger/snapshots/stax/test_sign_parameter_selector/00006.png b/tests/ragger/snapshots/stax/test_sign_parameter_selector/00006.png index 0463721b1..e7a78b5be 100644 Binary files a/tests/ragger/snapshots/stax/test_sign_parameter_selector/00006.png and b/tests/ragger/snapshots/stax/test_sign_parameter_selector/00006.png differ diff --git a/tests/ragger/snapshots/stax/test_sign_parameter_selector/00007.png b/tests/ragger/snapshots/stax/test_sign_parameter_selector/00007.png index e993bf998..a9cb3a2f0 100644 Binary files a/tests/ragger/snapshots/stax/test_sign_parameter_selector/00007.png and b/tests/ragger/snapshots/stax/test_sign_parameter_selector/00007.png differ diff --git a/tests/ragger/test_eip712.py b/tests/ragger/test_eip712.py index a2b09f261..146b17da7 100644 --- a/tests/ragger/test_eip712.py +++ b/tests/ragger/test_eip712.py @@ -613,7 +613,7 @@ def test_eip712_advanced_missing_token(firmware: Firmware, golden_run: bool): global snapshots_dirname - test_name += "-%s-%s" % (len(tokens[0]) == 0, len(tokens[1]) == 0) + test_name += f"-{len(tokens[0]) == 0}-{len(tokens[1]) == 0}" snapshots_dirname = test_name app_client = EthAppClient(backend) @@ -721,9 +721,9 @@ def test_eip712_advanced_trusted_name(firmware: Firmware, golden_run: bool): global snapshots_dirname - test_name += "_%s_with" % (trusted_name[0].name.lower()) + test_name += f"_{trusted_name[0].name.lower()}_with" for t in filt_tn_types: - test_name += "_%s" % (t.name.lower()) + test_name += f"_{t.name.lower()}" snapshots_dirname = test_name app_client = EthAppClient(backend) @@ -822,7 +822,6 @@ def test_eip712_skip(firmware: Firmware, backend: BackendInterface, navigator: Navigator, default_screenshot_path: Path, - test_name: str, golden_run: bool): global unfiltered_flow global skip_flow diff --git a/tests/ragger/test_gcs.py b/tests/ragger/test_gcs.py index a05c0c066..918556155 100644 --- a/tests/ragger/test_gcs.py +++ b/tests/ragger/test_gcs.py @@ -1,21 +1,21 @@ import struct import json import hashlib +import pytest +from web3 import Web3 from ragger.backend import BackendInterface from ragger.firmware import Firmware -from ragger.navigator import Navigator from ragger.navigator.navigation_scenario import NavigateWithScenario -import pytest -from web3 import Web3 + +from constants import ABIS_FOLDER import client.response_parser as ResponseParser from client.client import EthAppClient, SignMode, TrustedNameType, TrustedNameSource from client.utils import get_selector_from_data from client.gcs import * -from constants import ABIS_FOLDER def test_nft(firmware: Firmware, @@ -227,6 +227,7 @@ def test_poap(firmware: Firmware, abi=json.load(file), address=None ) + # pylint: disable=line-too-long data = contract.encode_abi("mintToken", [ 175676, 7163978, @@ -244,6 +245,7 @@ def test_poap(firmware: Firmware, "data": data, "chainId": 1 } + # pylint: enable=line-too-long with app_client.sign("m/44'/60'/0'/0/0", tx_params, SignMode.STORE): pass diff --git a/tests/ragger/test_get_address.py b/tests/ragger/test_get_address.py index e670295a2..d4ee4dff2 100644 --- a/tests/ragger/test_get_address.py +++ b/tests/ragger/test_get_address.py @@ -46,7 +46,8 @@ def test_get_pk_rejected(backend: BackendInterface, assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED -def test_get_pk(backend: BackendInterface, +def test_get_pk(firmware: Firmware, + backend: BackendInterface, scenario_navigator: NavigateWithScenario, with_chaincode: bool, chain: Optional[int]): @@ -66,8 +67,10 @@ def test_get_pk(backend: BackendInterface, # pylint: enable=line-too-long else: name = "" + ticker = "" + icon = "" - if (app_client._firmware != Firmware.NANOS) and name: + if (firmware != Firmware.NANOS) and name: app_client.provide_network_information(name, ticker, chain, bytes.fromhex(icon)) with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain): diff --git a/tests/ragger/test_nft.py b/tests/ragger/test_nft.py index d80f8a03a..7c2bd0491 100644 --- a/tests/ragger/test_nft.py +++ b/tests/ragger/test_nft.py @@ -74,6 +74,8 @@ def common_test_nft(firmware: Firmware, # pylint: enable=line-too-long else: name = "" + ticker = "" + icon = "" if name: app_client.provide_network_information(name, ticker, collec.chain_id, bytes.fromhex(icon)) diff --git a/tests/ragger/test_sign.py b/tests/ragger/test_sign.py index 3ac93064d..9d8cdb4a7 100644 --- a/tests/ragger/test_sign.py +++ b/tests/ragger/test_sign.py @@ -55,6 +55,8 @@ def common(firmware: Firmware, # pylint: enable=line-too-long else: name = "" + ticker = "" + icon = "" if (app_client._firmware != Firmware.NANOS) and name: app_client.provide_network_information(name, ticker, tx_params["chainId"], bytes.fromhex(icon))