Skip to content

Commit

Permalink
EIP-712 trusted name filtering support in python client
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Sep 20, 2024
1 parent 8afb956 commit 5a0e294
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client/src/ledger_app_clients/ethereum/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ def eip712_filtering_amount_join_value(self, token_idx: int, name: str, sig: byt
def eip712_filtering_datetime(self, name: str, sig: bytes, discarded: bool):
return self._exchange_async(self._cmd_builder.eip712_filtering_datetime(name, sig, discarded))

def eip712_filtering_trusted_name(self,
name: str,
name_type: list[int],
name_source: list[int],
sig: bytes,
discarded: bool):
return self._exchange_async(self._cmd_builder.eip712_filtering_trusted_name(name,
name_type,
name_source,
sig,
discarded))

def eip712_filtering_raw(self, name: str, sig: bytes, discarded: bool):
return self._exchange_async(self._cmd_builder.eip712_filtering_raw(name, sig, discarded))

Expand Down
23 changes: 23 additions & 0 deletions client/src/ledger_app_clients/ethereum/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class P2Type(IntEnum):
FILTERING_ACTIVATE = 0x00
FILTERING_DISCARDED_PATH = 0x01
FILTERING_MESSAGE_INFO = 0x0f
FILTERING_TRUSTED_NAME = 0xfb
FILTERING_DATETIME = 0xfc
FILTERING_TOKEN_ADDR_CHECK = 0xfd
FILTERING_AMOUNT_FIELD = 0xfe
Expand Down Expand Up @@ -214,6 +215,28 @@ def eip712_filtering_datetime(self, name: str, sig: bytes, discarded: bool) -> b
P2Type.FILTERING_DATETIME,
self._eip712_filtering_send_name(name, sig))

def eip712_filtering_trusted_name(self,
name: str,
name_type: int,
name_source: int,
sig: bytes,
discarded: bool) -> bytes:
data = bytearray()
data.append(len(name))
data += name.encode()
data.append(len(name_type))
for t in name_type:
data.append(t)
data.append(len(name_source))
for s in name_source:
data.append(s)
data.append(len(sig))
data += sig
return self._serialize(InsType.EIP712_SEND_FILTERING,
int(discarded),
P2Type.FILTERING_TRUSTED_NAME,
data)

def eip712_filtering_raw(self, name: str, sig: bytes, discarded: bool) -> bytes:
return self._serialize(InsType.EIP712_SEND_FILTERING,
int(discarded),
Expand Down
21 changes: 21 additions & 0 deletions client/src/ledger_app_clients/ethereum/eip712/InputData.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def send_filter(path: str, discarded: bool):
discarded)
elif filtering_paths[path]["type"] == "datetime":
send_filtering_datetime(path, filtering_paths[path]["name"], discarded)
elif filtering_paths[path]["type"] == "trusted_name":
send_filtering_trusted_name(path,
filtering_paths[path]["name"],
filtering_paths[path]["tn_type"],
filtering_paths[path]["tn_source"],
discarded)
elif filtering_paths[path]["type"] == "raw":
send_filtering_raw(path, filtering_paths[path]["name"], discarded)
else:
Expand Down Expand Up @@ -358,6 +364,21 @@ def send_filtering_datetime(path: str, display_name: str, discarded: bool):
pass


def send_filtering_trusted_name(path: str, display_name: 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()
for t in name_type:
to_sign.append(t)
for s in name_source:
to_sign.append(s)
sig = keychain.sign_data(keychain.Key.CAL, to_sign)
with app_client.eip712_filtering_trusted_name(display_name, name_type, name_source, sig, discarded):
pass


# 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
Expand Down

0 comments on commit 5a0e294

Please sign in to comment.