Skip to content

Commit

Permalink
Added provide_token_metadata to client
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Jan 31, 2024
1 parent 0d7b89f commit d587204
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client/src/ledger_app_clients/ethereum/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,25 @@ def personal_sign(self, path: str, msg: bytes):
with self._send(chunk):
pass
return self._send(chunks[-1])

def provide_token_metadata(self,
ticker: str,
addr: bytes,
decimals: int,
chain_id: int,
sig: Optional[bytes] = None):
if sig is None:
# Temporarily get a command with an empty signature to extract the payload and
# compute the signature on it
tmp = self._cmd_builder.provide_erc20_token_information(ticker,
addr,
decimals,
chain_id,
bytes())
# skip APDU header & empty sig
sig = sign_data(Key.CAL, tmp[6:])
return self._send(self._cmd_builder.provide_erc20_token_information(ticker,
addr,
decimals,
chain_id,
sig))
19 changes: 19 additions & 0 deletions client/src/ledger_app_clients/ethereum/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InsType(IntEnum):
GET_PUBLIC_ADDR = 0x02
SIGN = 0x04
PERSONAL_SIGN = 0x08
PROVIDE_ERC20_TOKEN_INFORMATION = 0x0a
PROVIDE_NFT_INFORMATION = 0x14
SET_PLUGIN = 0x16
EIP712_SEND_STRUCT_DEF = 0x1a
Expand Down Expand Up @@ -310,3 +311,21 @@ def personal_sign(self, path: str, msg: bytes):
payload = payload[chunk_size:]
p1 = P1Type.SIGN_SUBSQT_CHUNK
return chunks

def provide_erc20_token_information(self,
ticker: str,
addr: bytes,
decimals: int,
chain_id: int,
sig: bytes) -> bytes:
payload = bytearray()
payload.append(len(ticker))
payload += ticker.encode()
payload += addr
payload += struct.pack(">I", decimals)
payload += struct.pack(">I", chain_id)
payload += sig
return self._serialize(InsType.PROVIDE_ERC20_TOKEN_INFORMATION,
0x00,
0x00,
payload)

0 comments on commit d587204

Please sign in to comment.