Moved EIP712 filtering argument switch from P1 to P2, more in line with other EIP712 APDUs
This commit is contained in:
@@ -837,12 +837,12 @@ _Command_
|
||||
[width="80%"]
|
||||
|=========================================================================
|
||||
| *CLA* | *INS* | *P1* | *P2* | *LC* | *Le*
|
||||
| E0 | 1E | 00 : activate
|
||||
| E0 | 1E | 00
|
||||
| 00 : activate
|
||||
|
||||
0F : contract name
|
||||
0F : contract name
|
||||
|
||||
FF : field name
|
||||
| 00
|
||||
FF : field name
|
||||
| variable | variable
|
||||
|=========================================================================
|
||||
|
||||
|
||||
@@ -50,10 +50,10 @@ bool handle_eip712_struct_def(const uint8_t *const apdu_buf) {
|
||||
}
|
||||
if (ret) {
|
||||
switch (apdu_buf[OFFSET_P2]) {
|
||||
case P2_NAME:
|
||||
case P2_DEF_NAME:
|
||||
ret = set_struct_name(apdu_buf[OFFSET_LC], &apdu_buf[OFFSET_CDATA]);
|
||||
break;
|
||||
case P2_FIELD:
|
||||
case P2_DEF_FIELD:
|
||||
ret = set_struct_field(apdu_buf[OFFSET_LC], &apdu_buf[OFFSET_CDATA]);
|
||||
break;
|
||||
default:
|
||||
@@ -82,7 +82,7 @@ bool handle_eip712_struct_impl(const uint8_t *const apdu_buf) {
|
||||
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
|
||||
} else {
|
||||
switch (apdu_buf[OFFSET_P2]) {
|
||||
case P2_NAME:
|
||||
case P2_IMPL_NAME:
|
||||
// set root type
|
||||
if ((ret = path_set_root((char *) &apdu_buf[OFFSET_CDATA], apdu_buf[OFFSET_LC]))) {
|
||||
if (N_storage.verbose_eip712) {
|
||||
@@ -92,14 +92,14 @@ bool handle_eip712_struct_impl(const uint8_t *const apdu_buf) {
|
||||
ui_712_field_flags_reset();
|
||||
}
|
||||
break;
|
||||
case P2_FIELD:
|
||||
case P2_IMPL_FIELD:
|
||||
if ((ret = field_hash(&apdu_buf[OFFSET_CDATA],
|
||||
apdu_buf[OFFSET_LC],
|
||||
apdu_buf[OFFSET_P1] != P1_COMPLETE))) {
|
||||
reply_apdu = false;
|
||||
}
|
||||
break;
|
||||
case P2_ARRAY:
|
||||
case P2_IMPL_ARRAY:
|
||||
ret = path_new_array_depth(&apdu_buf[OFFSET_CDATA], apdu_buf[OFFSET_LC]);
|
||||
break;
|
||||
default:
|
||||
@@ -130,28 +130,28 @@ bool handle_eip712_filtering(const uint8_t *const apdu_buf) {
|
||||
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
|
||||
ret = false;
|
||||
} else {
|
||||
switch (apdu_buf[OFFSET_P1]) {
|
||||
case P1_ACTIVATE:
|
||||
switch (apdu_buf[OFFSET_P2]) {
|
||||
case P2_FILT_ACTIVATE:
|
||||
if (!N_storage.verbose_eip712) {
|
||||
ui_712_set_filtering_mode(EIP712_FILTERING_FULL);
|
||||
ret = compute_schema_hash();
|
||||
}
|
||||
break;
|
||||
case P1_CONTRACT_NAME:
|
||||
case P1_FIELD_NAME:
|
||||
type = (apdu_buf[OFFSET_P1] == P1_CONTRACT_NAME) ? FILTERING_CONTRACT_NAME
|
||||
: FILTERING_STRUCT_FIELD;
|
||||
case P2_FILT_CONTRACT_NAME:
|
||||
case P2_FILT_FIELD_NAME:
|
||||
type = (apdu_buf[OFFSET_P2] == P2_FILT_CONTRACT_NAME) ? FILTERING_CONTRACT_NAME
|
||||
: FILTERING_STRUCT_FIELD;
|
||||
if (ui_712_get_filtering_mode() == EIP712_FILTERING_FULL) {
|
||||
ret =
|
||||
provide_filtering_info(&apdu_buf[OFFSET_CDATA], apdu_buf[OFFSET_LC], type);
|
||||
if ((apdu_buf[OFFSET_P1] == P1_CONTRACT_NAME) && ret) {
|
||||
if ((apdu_buf[OFFSET_P2] == P2_FILT_CONTRACT_NAME) && ret) {
|
||||
reply_apdu = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PRINTF("Unknown P1 0x%x for APDU 0x%x\n",
|
||||
apdu_buf[OFFSET_P1],
|
||||
PRINTF("Unknown P2 0x%x for APDU 0x%x\n",
|
||||
apdu_buf[OFFSET_P2],
|
||||
apdu_buf[OFFSET_INS]);
|
||||
apdu_response_code = APDU_RESPONSE_INVALID_P1_P2;
|
||||
ret = false;
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// APDUs P1
|
||||
#define P1_COMPLETE 0x00
|
||||
#define P1_PARTIAL 0xFF
|
||||
#define P1_ACTIVATE 0x00
|
||||
#define P1_CONTRACT_NAME 0x0F
|
||||
#define P1_FIELD_NAME 0xFF
|
||||
#define P1_COMPLETE 0x00
|
||||
#define P1_PARTIAL 0xFF
|
||||
|
||||
// APDUs P2
|
||||
#define P2_NAME 0x00
|
||||
#define P2_ARRAY 0x0F
|
||||
#define P2_FIELD 0xFF
|
||||
#define P2_KEY 0x00
|
||||
#define P2_VALUE 0xFF
|
||||
#define P2_DEF_NAME 0x00
|
||||
#define P2_DEF_FIELD 0xFF
|
||||
#define P2_IMPL_NAME P2_DEF_NAME
|
||||
#define P2_IMPL_ARRAY 0x0F
|
||||
#define P2_IMPL_FIELD P2_DEF_FIELD
|
||||
#define P2_FILT_ACTIVATE 0x00
|
||||
#define P2_FILT_CONTRACT_NAME 0x0F
|
||||
#define P2_FILT_FIELD_NAME 0xFF
|
||||
|
||||
#define DOMAIN_STRUCT_NAME "EIP712Domain"
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class EthereumClient:
|
||||
def _recv(self) -> RAPDU:
|
||||
return self._client._last_async_response
|
||||
|
||||
def _click_signal_timeout(self, signum: int, frame):
|
||||
def _click_signal_timeout(self, _signum: int, _frame):
|
||||
self._client.right_click()
|
||||
|
||||
def _enable_click_until_response(self):
|
||||
|
||||
@@ -3,24 +3,24 @@ from typing import Iterator
|
||||
from ethereum_client.eip712 import EIP712FieldType
|
||||
|
||||
class InsType(IntEnum):
|
||||
EIP712_SEND_STRUCT_DEF = 0x1a,
|
||||
EIP712_SEND_STRUCT_IMPL = 0x1c,
|
||||
EIP712_SEND_FILTERING = 0x1e,
|
||||
EIP712_SEND_STRUCT_DEF = 0x1a
|
||||
EIP712_SEND_STRUCT_IMPL = 0x1c
|
||||
EIP712_SEND_FILTERING = 0x1e
|
||||
EIP712_SIGN = 0x0c
|
||||
|
||||
class P1Type(IntEnum):
|
||||
COMPLETE_SEND = 0x00,
|
||||
PARTIAL_SEND = 0x01,
|
||||
FILTERING_ACTIVATE = 0x00,
|
||||
FILTERING_CONTRACT_NAME = 0x0f,
|
||||
FILTERING_FIELD_NAME = 0xff
|
||||
COMPLETE_SEND = 0x00
|
||||
PARTIAL_SEND = 0x01
|
||||
|
||||
class P2Type(IntEnum):
|
||||
STRUCT_NAME = 0x00,
|
||||
STRUCT_FIELD = 0xff,
|
||||
ARRAY = 0x0f,
|
||||
STRUCT_NAME = 0x00
|
||||
STRUCT_FIELD = 0xff
|
||||
ARRAY = 0x0f
|
||||
LEGACY_IMPLEM = 0x00
|
||||
NEW_IMPLEM = 0x01
|
||||
FILTERING_ACTIVATE = 0x00
|
||||
FILTERING_CONTRACT_NAME = 0x0f
|
||||
FILTERING_FIELD_NAME = 0xff
|
||||
|
||||
class EthereumCmdBuilder:
|
||||
_CLA: int = 0xE0
|
||||
@@ -139,8 +139,8 @@ class EthereumCmdBuilder:
|
||||
|
||||
def eip712_filtering_activate(self):
|
||||
return self._serialize(InsType.EIP712_SEND_FILTERING,
|
||||
P1Type.FILTERING_ACTIVATE,
|
||||
0x00,
|
||||
P1Type.COMPLETE_SEND,
|
||||
P2Type.FILTERING_ACTIVATE,
|
||||
bytearray())
|
||||
|
||||
def _eip712_filtering_send_name(self, name: str, sig: bytes) -> bytes:
|
||||
@@ -153,12 +153,12 @@ class EthereumCmdBuilder:
|
||||
|
||||
def eip712_filtering_send_contract_name(self, name: str, sig: bytes) -> bytes:
|
||||
return self._serialize(InsType.EIP712_SEND_FILTERING,
|
||||
P1Type.FILTERING_CONTRACT_NAME,
|
||||
0x00,
|
||||
P1Type.COMPLETE_SEND,
|
||||
P2Type.FILTERING_CONTRACT_NAME,
|
||||
self._eip712_filtering_send_name(name, sig))
|
||||
|
||||
def eip712_filtering_send_field_name(self, name: str, sig: bytes) -> bytes:
|
||||
return self._serialize(InsType.EIP712_SEND_FILTERING,
|
||||
P1Type.FILTERING_FIELD_NAME,
|
||||
0x00,
|
||||
P1Type.COMPLETE_SEND,
|
||||
P2Type.FILTERING_FIELD_NAME,
|
||||
self._eip712_filtering_send_name(name, sig))
|
||||
|
||||
Reference in New Issue
Block a user