From 53a6b4535d3b89a0baf553314b35496b20ca109b Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 20 May 2024 18:19:22 +0200 Subject: [PATCH] Add date/time support in client --- client/src/ledger_app_clients/ethereum/client.py | 3 +++ .../ethereum/command_builder.py | 7 +++++++ .../ethereum/eip712/InputData.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/client/src/ledger_app_clients/ethereum/client.py b/client/src/ledger_app_clients/ethereum/client.py index 2061ef56f4..a09bd41cea 100644 --- a/client/src/ledger_app_clients/ethereum/client.py +++ b/client/src/ledger_app_clients/ethereum/client.py @@ -115,6 +115,9 @@ def eip712_filtering_amount_join_value(self, token_idx: int, name: str, sig: byt name, sig)) + def eip712_filtering_datetime(self, name: str, sig: bytes): + return self._exchange_async(self._cmd_builder.eip712_filtering_datetime(name, sig)) + def eip712_filtering_raw(self, name: str, sig: bytes): return self._exchange_async(self._cmd_builder.eip712_filtering_raw(name, sig)) diff --git a/client/src/ledger_app_clients/ethereum/command_builder.py b/client/src/ledger_app_clients/ethereum/command_builder.py index 1e9466bb6e..bcd505cbe4 100644 --- a/client/src/ledger_app_clients/ethereum/command_builder.py +++ b/client/src/ledger_app_clients/ethereum/command_builder.py @@ -42,6 +42,7 @@ class P2Type(IntEnum): NEW_IMPLEM = 0x01 FILTERING_ACTIVATE = 0x00 FILTERING_MESSAGE_INFO = 0x0f + FILTERING_DATETIME = 0xfc FILTERING_TOKEN_ADDR_CHECK = 0xfd FILTERING_AMOUNT_FIELD = 0xfe FILTERING_RAW = 0xff @@ -197,6 +198,12 @@ def eip712_filtering_amount_join_value(self, token_idx: int, name: str, sig: byt P2Type.FILTERING_AMOUNT_FIELD, data) + def eip712_filtering_datetime(self, name: str, sig: bytes) -> bytes: + return self._serialize(InsType.EIP712_SEND_FILTERING, + P1Type.COMPLETE_SEND, + P2Type.FILTERING_DATETIME, + self._eip712_filtering_send_name(name, sig)) + def eip712_filtering_raw(self, name: str, sig: bytes) -> bytes: return self._serialize(InsType.EIP712_SEND_FILTERING, P1Type.COMPLETE_SEND, diff --git a/client/src/ledger_app_clients/ethereum/eip712/InputData.py b/client/src/ledger_app_clients/ethereum/eip712/InputData.py index f507748845..e5ffbbd1d0 100644 --- a/client/src/ledger_app_clients/ethereum/eip712/InputData.py +++ b/client/src/ledger_app_clients/ethereum/eip712/InputData.py @@ -205,6 +205,8 @@ def send_struct_impl_field(value, field): elif filtering_paths[path]["type"] == "amount_join_value": send_filtering_amount_join_value(filtering_paths[path]["token"], filtering_paths[path]["name"]) + elif filtering_paths[path]["type"] == "datetime": + send_filtering_datetime(filtering_paths[path]["name"]) elif filtering_paths[path]["type"] == "raw": send_filtering_raw(filtering_paths[path]["name"]) else: @@ -311,6 +313,19 @@ def send_filtering_amount_join_value(token_idx: int, display_name: str): pass +def send_filtering_datetime(display_name: str): + global sig_ctx + + path_str = ".".join(current_path) + + to_sign = start_signature_payload(sig_ctx, 33) + to_sign += path_str.encode() + to_sign += display_name.encode() + sig = keychain.sign_data(keychain.Key.CAL, to_sign) + with app_client.eip712_filtering_datetime(display_name, sig): + pass + + # ledgerjs doesn't actually sign anything, and instead uses already pre-computed signatures def send_filtering_raw(display_name): global sig_ctx