From 0478854de7050cea65d8f23dce43bd208e976f45 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 17 Nov 2023 14:01:26 +0100 Subject: [PATCH] Added EIP-191 to the client --- .../src/ledger_app_clients/ethereum/client.py | 7 +++++++ .../ethereum/command_builder.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/client/src/ledger_app_clients/ethereum/client.py b/client/src/ledger_app_clients/ethereum/client.py index 5cce4f37d..f9d0640b9 100644 --- a/client/src/ledger_app_clients/ethereum/client.py +++ b/client/src/ledger_app_clients/ethereum/client.py @@ -224,3 +224,10 @@ def set_external_plugin(self, # skip APDU header & empty sig sig = sign_data(Key.SET_PLUGIN, tmp[5:-1]) return self._send(self._cmd_builder.set_external_plugin(plugin_name, contract_address, method_selelector, sig)) + + def personal_sign(self, path: str, msg: bytes): + chunks = self._cmd_builder.personal_sign(path, msg) + for chunk in chunks[:-1]: + with self._send(chunk): + pass + return self._send(chunks[-1]) diff --git a/client/src/ledger_app_clients/ethereum/command_builder.py b/client/src/ledger_app_clients/ethereum/command_builder.py index 61ebec928..e460461a2 100644 --- a/client/src/ledger_app_clients/ethereum/command_builder.py +++ b/client/src/ledger_app_clients/ethereum/command_builder.py @@ -13,6 +13,7 @@ class InsType(IntEnum): GET_PUBLIC_ADDR = 0x02 SIGN = 0x04 + PERSONAL_SIGN = 0x08 PROVIDE_NFT_INFORMATION = 0x14 SET_PLUGIN = 0x16 EIP712_SEND_STRUCT_DEF = 0x1a @@ -294,3 +295,19 @@ def provide_nft_information(self, payload.append(len(sig)) payload += sig return self._serialize(InsType.PROVIDE_NFT_INFORMATION, 0x00, 0x00, payload) + + def personal_sign(self, path: str, msg: bytes): + payload = pack_derivation_path(path) + payload += struct.pack(">I", len(msg)) + payload += msg + chunks = list() + p1 = P1Type.SIGN_FIRST_CHUNK + while len(payload) > 0: + chunk_size = 0xff + chunks.append(self._serialize(InsType.PERSONAL_SIGN, + p1, + 0x00, + payload[:chunk_size])) + payload = payload[chunk_size:] + p1 = P1Type.SIGN_SUBSQT_CHUNK + return chunks