From 437f8a5679c641f85648211c2ac65fe5bd9bb6bc Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Fri, 27 Oct 2023 17:16:15 +0200 Subject: [PATCH 1/2] Fix python-client github job trigger --- .github/workflows/python-client.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index 9f5eeef9a..cb3139673 100644 --- a/.github/workflows/python-client.yml +++ b/.github/workflows/python-client.yml @@ -7,11 +7,11 @@ on: - develop - master paths: - - ./client/** + - client/** - .github/workflows/python-client.yml pull_request: paths: - - ./client/** + - client/** - .github/workflows/python-client.yml jobs: From a82b61ff8e5258cf44e898de9e6b61aa6b195bc1 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Fri, 27 Oct 2023 17:28:29 +0200 Subject: [PATCH 2/2] Fix mypy and flake8 --- .../src/ledger_app_clients/ethereum/client.py | 18 +++++++++++------- .../ethereum/command_builder.py | 4 ++-- .../ethereum/response_parser.py | 1 + .../src/ledger_app_clients/ethereum/utils.py | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/src/ledger_app_clients/ethereum/client.py b/client/src/ledger_app_clients/ethereum/client.py index d2015a1aa..bd7544788 100644 --- a/client/src/ledger_app_clients/ethereum/client.py +++ b/client/src/ledger_app_clients/ethereum/client.py @@ -2,7 +2,7 @@ from enum import IntEnum from ragger.backend import BackendInterface from ragger.utils import RAPDU -from typing import List, Optional +from typing import List, Optional, Union from .command_builder import CommandBuilder from .eip712 import EIP712FieldType @@ -13,13 +13,16 @@ WEI_IN_ETH = 1e+18 GWEI_IN_ETH = 1e+9 + class TxData: selector: bytes parameters: list[bytes] + def __init__(self, selector: bytes, params: list[bytes]): self.selector = selector self.parameters = params + class StatusWord(IntEnum): OK = 0x9000 ERROR_NO_INFO = 0x6a00 @@ -30,6 +33,7 @@ class StatusWord(IntEnum): CONDITION_NOT_SATISFIED = 0x6985 REF_DATA_NOT_FOUND = 0x6a88 + class DomainNameTag(IntEnum): STRUCTURE_TYPE = 0x01 STRUCTURE_VERSION = 0x02 @@ -121,7 +125,7 @@ def _sign_common(self, gas_limit: int, destination: bytes, amount: float, - data: TxData): + data: Optional[TxData]): tx.append(int(gas_price * GWEI_IN_ETH)) tx.append(gas_limit) tx.append(destination) @@ -143,8 +147,8 @@ def sign_legacy(self, destination: bytes, amount: float, chain_id: int, - data: TxData = None): - tx = list() + data: Optional[TxData] = None): + tx: List[Union[int, bytes]] = list() tx.append(nonce) tx = self._sign_common(tx, gas_price, gas_limit, destination, amount, data) tx.append(chain_id) @@ -161,9 +165,9 @@ def sign_1559(self, gas_limit: int, destination: bytes, amount: float, - data: TxData = None, - access_list = list()): - tx = list() + data: Optional[TxData] = None, + access_list=list()): + tx: List[Union[int, bytes]] = list() tx.append(chain_id) tx.append(nonce) tx.append(int(max_prio_gas_price * GWEI_IN_ETH)) diff --git a/client/src/ledger_app_clients/ethereum/command_builder.py b/client/src/ledger_app_clients/ethereum/command_builder.py index 4170a3086..63ab0ae7b 100644 --- a/client/src/ledger_app_clients/ethereum/command_builder.py +++ b/client/src/ledger_app_clients/ethereum/command_builder.py @@ -182,12 +182,12 @@ def eip712_filtering_show_field(self, name: str, sig: bytes) -> bytes: P2Type.FILTERING_FIELD_NAME, self._eip712_filtering_send_name(name, sig)) - def set_external_plugin(self, plugin_name: str, contract_address: bytes, method_selelector: bytes, sig: bytes) -> bytes: + def set_external_plugin(self, plugin_name: str, contract_address: bytes, selector: bytes, sig: bytes) -> bytes: data = bytearray() data.append(len(plugin_name)) data += self._string_to_bytes(plugin_name) data += contract_address - data += method_selelector + data += selector data += sig return self._serialize(InsType.EXTERNAL_PLUGIN_SETUP, diff --git a/client/src/ledger_app_clients/ethereum/response_parser.py b/client/src/ledger_app_clients/ethereum/response_parser.py index a00205cbe..641e1bbc9 100644 --- a/client/src/ledger_app_clients/ethereum/response_parser.py +++ b/client/src/ledger_app_clients/ethereum/response_parser.py @@ -14,6 +14,7 @@ def challenge(data: bytes) -> int: assert len(data) == 4 return int.from_bytes(data, "big") + def pk_addr(data: bytes, has_chaincode: bool = False): idx = 0 diff --git a/client/src/ledger_app_clients/ethereum/utils.py b/client/src/ledger_app_clients/ethereum/utils.py index aa3c710d5..e6177455e 100644 --- a/client/src/ledger_app_clients/ethereum/utils.py +++ b/client/src/ledger_app_clients/ethereum/utils.py @@ -1,4 +1,5 @@ import sha3 + def get_selector_from_function(fn: str) -> bytes: return sha3.keccak_256(fn.encode()).digest()[0:4]