diff --git a/tests/ragger/app/client.py b/tests/ragger/app/client.py index 7e25093..6904c87 100644 --- a/tests/ragger/app/client.py +++ b/tests/ragger/app/client.py @@ -91,8 +91,8 @@ class EthereumClient: self._disable_click_until_response() assert self._recv().status == 0x9000 - def eip712_sign_new(self, bip32): - with self._send(self._cmd_builder.eip712_sign_new(bip32)): + def eip712_sign_new(self, bip32_path: str): + with self._send(self._cmd_builder.eip712_sign_new(bip32_path)): time.sleep(0.5) # tight on timing, needed by the CI otherwise might fail sometimes if not self._settings[SettingType.VERBOSE_EIP712].value and \ not self._eip712_filtering: # need to skip the message hash @@ -104,10 +104,10 @@ class EthereumClient: return self._resp_parser.sign(resp.data) def eip712_sign_legacy(self, - bip32, + bip32_path: str, domain_hash: bytes, message_hash: bytes): - with self._send(self._cmd_builder.eip712_sign_legacy(bip32, + with self._send(self._cmd_builder.eip712_sign_legacy(bip32_path, domain_hash, message_hash)): self._client.right_click() # sign typed message screen diff --git a/tests/ragger/app/command_builder.py b/tests/ragger/app/command_builder.py index 04fdc20..9dea245 100644 --- a/tests/ragger/app/command_builder.py +++ b/tests/ragger/app/command_builder.py @@ -1,6 +1,7 @@ from enum import IntEnum, auto from typing import Iterator, Optional from .eip712 import EIP712FieldType +from ragger.bip import pack_derivation_path import struct class InsType(IntEnum): @@ -110,28 +111,18 @@ class EthereumCmdBuilder: data_w_length[:0xff]) data_w_length = data_w_length[0xff:] - def _format_bip32(self, path: list[Optional[int]], data: bytearray) -> bytearray: - data.append(len(path)) - for p in path: - if p == None: - val = 0 - else: - val = (0x8 << 28) | p - data += struct.pack(">I", val) - return data - - def eip712_sign_new(self, bip32_path: list[Optional[int]]) -> bytes: - data = self._format_bip32(bip32_path, bytearray()) + def eip712_sign_new(self, bip32_path: str) -> bytes: + data = pack_derivation_path(bip32_path) return self._serialize(InsType.EIP712_SIGN, P1Type.COMPLETE_SEND, P2Type.NEW_IMPLEM, data) def eip712_sign_legacy(self, - bip32_path: list[Optional[int]], + bip32_path: str, domain_hash: bytes, message_hash: bytes) -> bytes: - data = self._format_bip32(bip32_path, bytearray()) + data = pack_derivation_path(bip32_path) data += domain_hash data += message_hash return self._serialize(InsType.EIP712_SIGN, diff --git a/tests/ragger/test_eip712.py b/tests/ragger/test_eip712.py index 51cc773..29cb843 100644 --- a/tests/ragger/test_eip712.py +++ b/tests/ragger/test_eip712.py @@ -7,13 +7,7 @@ from eip712 import InputData from pathlib import Path from configparser import ConfigParser -bip32_path = [ - 44, - 60, - 0, - None, - None -] +BIP32_PATH = "m/44'/60'/0'/0/0" def input_files() -> List[str]: @@ -38,7 +32,7 @@ def filtering(request) -> bool: def test_eip712_legacy(app_client: EthereumClient): v, r, s = app_client.eip712_sign_legacy( - bip32_path, + BIP32_PATH, bytes.fromhex('6137beb405d9ff777172aa879e33edb34a1460e701802746c5ef96e741710e59'), bytes.fromhex('eb4221181ff3f1a83ea7313993ca9218496e424604ba9492bb4052c03d5c3df8') ) @@ -74,7 +68,7 @@ def test_eip712_new(app_client: EthereumClient, input_file: Path, verbose: bool, }) assert InputData.process_file(app_client, input_file, filter_file) == True - v, r, s = app_client.eip712_sign_new(bip32_path) + v, r, s = app_client.eip712_sign_new(BIP32_PATH) #print("[signature]") #print("v = %s" % (v.hex())) #print("r = %s" % (r.hex()))