diff --git a/src_features/signMessageEIP712/context.c b/src_features/signMessageEIP712/context.c index 6db0e0d..b76a3eb 100644 --- a/src_features/signMessageEIP712/context.c +++ b/src_features/signMessageEIP712/context.c @@ -4,6 +4,7 @@ #include "eip712.h" #include "mem.h" #include "sol_typenames.h" +#include "path.h" uint8_t *typenames_array; uint8_t *structs_array; @@ -21,9 +22,16 @@ bool init_eip712_context(void) if (init_sol_typenames() == false) return false; + if (init_path() == false) + { + return false; + } + // set types pointer if ((structs_array = mem_alloc(sizeof(uint8_t))) == NULL) + { return false; + } // create len(types) *structs_array = 0; diff --git a/src_features/signMessageEIP712/encode_field.c b/src_features/signMessageEIP712/encode_field.c index e075f4d..0f670d2 100644 --- a/src_features/signMessageEIP712/encode_field.c +++ b/src_features/signMessageEIP712/encode_field.c @@ -60,6 +60,10 @@ void *encode_integer(const uint8_t *const value, uint16_t length) { uint8_t *padded_value; + if (length > 32) // sanity check + { + return NULL; + } // 0-pad the value to 32 bytes if ((padded_value = mem_alloc(EIP_712_ENCODED_FIELD_LENGTH)) != NULL) { @@ -93,7 +97,7 @@ void *encode_string(const char *const value, uint16_t length) */ void *encode_bool(const bool *const value, uint16_t length) { - if (length != 1) + if (length != 1) // sanity check { return NULL; } @@ -109,7 +113,7 @@ void *encode_bool(const bool *const value, uint16_t length) */ void *encode_address(const uint8_t *const value, uint16_t length) { - if (length != ADDRESS_LENGTH) + if (length != ADDRESS_LENGTH) // sanity check { return NULL; } diff --git a/src_features/signMessageEIP712/entrypoint.c b/src_features/signMessageEIP712/entrypoint.c index f265ad7..08751cc 100644 --- a/src_features/signMessageEIP712/entrypoint.c +++ b/src_features/signMessageEIP712/entrypoint.c @@ -258,6 +258,7 @@ bool set_struct_name(const uint8_t *const data) return true; } +// TODO: Split this function bool set_struct_field(const uint8_t *const data) { uint8_t data_idx = OFFSET_DATA; diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index db7b38f..f4aee73 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -9,6 +9,8 @@ const uint8_t *field_hash(const void *const structs_array, (void)structs_array; (void)data; (void)data_length; + // get field by path encode_integer(data, data_length); + // path += 1 return NULL; } diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c new file mode 100644 index 0000000..dc7368d --- /dev/null +++ b/src_features/signMessageEIP712/path.c @@ -0,0 +1,22 @@ +#include +#include +#include "path.h" +#include "mem.h" +#include "context.h" + +uint8_t *path_indexes; + +/** + * Allocates the the path indexes in memory and sets them all to 0 with a count of 1. + */ +bool init_path(void) +{ + // + 1 for the used index count + if ((path_indexes = mem_alloc(sizeof(uint8_t) * (MAX_PATH_DEPTH + 1))) != NULL) + { + // set all to 0 + explicit_bzero(path_indexes + 1, sizeof(uint8_t) * MAX_PATH_DEPTH); + *path_indexes = 1; // init count at 1, so the default path will be 0 + } + return path_indexes != NULL; +} diff --git a/src_features/signMessageEIP712/path.h b/src_features/signMessageEIP712/path.h new file mode 100644 index 0000000..8eda5ba --- /dev/null +++ b/src_features/signMessageEIP712/path.h @@ -0,0 +1,12 @@ +#ifndef PATH_H_ +#define PATH_H_ + +#include + +#define MAX_PATH_DEPTH 16 + +extern uint8_t *path_indexes; + +bool init_path(void); + +#endif // PATH_H_