2022-05-16 10:59:20 +02:00
|
|
|
#ifdef HAVE_EIP712_FULL_SUPPORT
|
|
|
|
|
|
2022-05-02 15:28:50 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdint.h>
|
2022-08-25 10:54:34 +02:00
|
|
|
#include "context_712.h"
|
2022-05-02 15:28:50 +02:00
|
|
|
#include "mem.h"
|
2022-06-09 12:00:42 +02:00
|
|
|
#include "mem_utils.h"
|
2022-05-02 15:28:50 +02:00
|
|
|
#include "sol_typenames.h"
|
2022-05-02 15:30:26 +02:00
|
|
|
#include "path.h"
|
2022-04-28 16:47:48 +02:00
|
|
|
#include "field_hash.h"
|
2022-05-12 17:29:35 +02:00
|
|
|
#include "ui_logic.h"
|
2022-07-06 17:51:57 +02:00
|
|
|
#include "typed_data.h"
|
2022-07-19 11:49:18 +02:00
|
|
|
#include "apdu_constants.h" // APDU response codes
|
|
|
|
|
#include "shared_context.h" // reset_app_context
|
2022-10-17 11:44:28 +02:00
|
|
|
#include "common_ui.h" // ui_idle
|
2022-05-02 15:28:50 +02:00
|
|
|
|
2022-08-08 13:53:41 +02:00
|
|
|
e_struct_init struct_state = NOT_INITIALIZED;
|
2022-06-09 12:00:42 +02:00
|
|
|
s_eip712_context *eip712_context = NULL;
|
2022-05-02 15:28:50 +02:00
|
|
|
|
|
|
|
|
/**
|
2022-07-11 17:12:58 +02:00
|
|
|
* Initialize the EIP712 context
|
2022-05-02 15:28:50 +02:00
|
|
|
*
|
|
|
|
|
* @return a boolean indicating if the initialization was successful or not
|
|
|
|
|
*/
|
2022-07-19 11:49:18 +02:00
|
|
|
bool eip712_context_init(void) {
|
2022-05-02 15:28:50 +02:00
|
|
|
// init global variables
|
|
|
|
|
mem_init();
|
|
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if ((eip712_context = MEM_ALLOC_AND_ALIGN_TYPE(*eip712_context)) == NULL) {
|
2022-07-19 11:04:16 +02:00
|
|
|
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY;
|
2022-06-09 12:00:42 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if (sol_typenames_init() == false) {
|
2022-05-02 15:28:50 +02:00
|
|
|
return false;
|
2022-04-08 18:55:56 +02:00
|
|
|
}
|
2022-05-02 15:28:50 +02:00
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if (path_init() == false) {
|
2022-05-02 15:30:26 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if (field_hash_init() == false) {
|
2022-04-28 16:47:48 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if (ui_712_init() == false) {
|
2022-05-12 17:29:35 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 11:49:18 +02:00
|
|
|
if (typed_data_init() == false) // this needs to be initialized last !
|
2022-05-02 15:30:26 +02:00
|
|
|
{
|
2022-05-02 15:28:50 +02:00
|
|
|
return false;
|
2022-05-02 15:30:26 +02:00
|
|
|
}
|
2022-05-02 15:28:50 +02:00
|
|
|
|
2022-08-16 18:44:28 +02:00
|
|
|
// Since they are optional, they might not be provided by the JSON data
|
|
|
|
|
explicit_bzero(eip712_context->contract_addr, sizeof(eip712_context->contract_addr));
|
|
|
|
|
eip712_context->chain_id = 0;
|
|
|
|
|
|
2022-08-08 13:53:41 +02:00
|
|
|
struct_state = NOT_INITIALIZED;
|
|
|
|
|
|
2022-05-02 15:28:50 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2022-05-12 17:29:35 +02:00
|
|
|
|
2022-07-11 17:12:58 +02:00
|
|
|
/**
|
|
|
|
|
* De-initialize the EIP712 context
|
|
|
|
|
*/
|
2022-07-19 11:49:18 +02:00
|
|
|
void eip712_context_deinit(void) {
|
2022-07-06 17:51:57 +02:00
|
|
|
typed_data_deinit();
|
2022-05-12 17:30:26 +02:00
|
|
|
path_deinit();
|
|
|
|
|
field_hash_deinit();
|
|
|
|
|
ui_712_deinit();
|
|
|
|
|
mem_reset();
|
2022-06-09 12:00:42 +02:00
|
|
|
eip712_context = NULL;
|
2022-07-19 11:04:16 +02:00
|
|
|
reset_app_context();
|
2022-05-12 17:30:26 +02:00
|
|
|
}
|
2022-05-16 10:59:20 +02:00
|
|
|
|
|
|
|
|
#endif
|