WIP integration in app

This commit is contained in:
Alexandre Paillier
2022-05-12 17:28:40 +02:00
parent e070c379da
commit 9f8b2da74c
3 changed files with 56 additions and 39 deletions

View File

@@ -21,6 +21,8 @@
#define INS_PROVIDE_NFT_INFORMATION 0x14
#define INS_SET_PLUGIN 0x16
#define INS_PERFORM_PRIVACY_OPERATION 0x18
#define INS_EIP712_STRUCT_DEF 0x1A
#define INS_EIP712_STRUCT_IMPL 0x1C
#define P1_CONFIRM 0x01
#define P1_NON_CONFIRM 0x00
#define P2_NO_CHAINCODE 0x00
@@ -168,4 +170,7 @@ void handleStarkwareUnsafeSign(uint8_t p1,
#endif
bool handle_eip712_struct_def(const uint8_t *const apdu_buf);
bool handle_eip712_struct_impl(const uint8_t *const apdu_buf);
#endif // _APDU_CONSTANTS_H_

View File

@@ -29,6 +29,7 @@
#include "handle_swap_sign_transaction.h"
#include "handle_get_printable_amount.h"
#include "handle_check_address.h"
#include "mem.h"
#ifdef HAVE_STARKWARE
#include "stark_crypto.h"
@@ -694,6 +695,14 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
#endif
case INS_EIP712_STRUCT_DEF:
handle_eip712_struct_def(G_io_apdu_buffer);
break;
case INS_EIP712_STRUCT_IMPL:
handle_eip712_struct_impl(G_io_apdu_buffer);
break;
#if 0
case 0xFF: // return to dashboard
goto return_to_dashboard;
@@ -884,6 +893,7 @@ void coin_main(chain_config_t *coin_config) {
}
reset_app_context();
tmpCtx.transactionContext.currentItemIndex = 0;
mem_init();
for (;;) {
UX_INIT();

View File

@@ -360,49 +360,51 @@ bool set_struct_field(const uint8_t *const data)
}
bool handle_apdu(const uint8_t *const data)
bool handle_eip712_struct_def(const uint8_t *const apdu_buf)
{
switch (data[OFFSET_INS])
bool ret = true;
switch (apdu_buf[OFFSET_P2])
{
case INS_STRUCT_DEF:
switch (data[OFFSET_P2])
{
case P2_NAME:
set_struct_name(data);
break;
case P2_FIELD:
set_struct_field(data);
break;
default:
PRINTF("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]);
return false;
}
case P2_NAME:
ret = set_struct_name(apdu_buf);
break;
case INS_STRUCT_IMPL:
switch (data[OFFSET_P2])
{
case P2_NAME:
// set root type
path_set_root((char*)&data[OFFSET_DATA], data[OFFSET_LC]);
break;
case P2_FIELD:
if ((data[OFFSET_P1] != P1_COMPLETE) && (data[OFFSET_P1] != P1_PARTIAL))
{
return false;
}
field_hash(&data[OFFSET_DATA], data[OFFSET_LC], data[OFFSET_P1] == P1_PARTIAL);
break;
case P2_ARRAY:
path_new_array_depth(data[OFFSET_DATA]);
break;
default:
PRINTF("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]);
return false;
}
case P2_FIELD:
ret = set_struct_field(apdu_buf);
break;
default:
PRINTF("Unrecognized APDU (0x%.02x)\n", data[OFFSET_INS]);
return false;
PRINTF("Unknown P2 0x%x for APDU 0x%x\n",
apdu_buf[OFFSET_P2],
apdu_buf[OFFSET_INS]);
ret = false;
}
return true;
return ret;
}
bool handle_eip712_struct_impl(const uint8_t *const apdu_buf)
{
bool ret;
switch (apdu_buf[OFFSET_P2])
{
case P2_NAME:
// set root type
ret = path_set_root((char*)&apdu_buf[OFFSET_DATA],
apdu_buf[OFFSET_LC]);
break;
case P2_FIELD:
ret = field_hash(&apdu_buf[OFFSET_DATA],
apdu_buf[OFFSET_LC],
apdu_buf[OFFSET_P1] != P1_COMPLETE);
break;
case P2_ARRAY:
ret = path_new_array_depth(apdu_buf[OFFSET_DATA]);
break;
default:
PRINTF("Unknown P2 0x%x for APDU 0x%x\n",
apdu_buf[OFFSET_P2],
apdu_buf[OFFSET_INS]);
ret = false;
}
return ret;
}