Skip to content

Commit

Permalink
Now buffers the EIP-712 pairs to show more than one per screen
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Jun 12, 2024
1 parent 14474fc commit 6617cd5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
4 changes: 0 additions & 4 deletions src_features/signMessageEIP712/field_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ static const uint8_t *field_hash_finalize_static(const void *const field_ptr,
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
PRINTF("Unknown solidity type!\n");
}

if (value == NULL) {
return NULL;
}
return value;
}

Expand Down
19 changes: 18 additions & 1 deletion src_features/signMessageEIP712/ui_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ typedef struct {
uint8_t field_flags;
uint8_t structs_to_review;
s_amount_context amount;
#ifdef SCREEN_SIZE_WALLET
char ui_pairs_buffer[(SHARED_CTX_FIELD_1_SIZE + SHARED_CTX_FIELD_2_SIZE) * 2];
#endif
} t_ui_context;

static t_ui_context *ui_ctx = NULL;
Expand Down Expand Up @@ -210,6 +213,7 @@ void ui_712_message_hash(void) {
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
ui_ctx->end_reached = true;
ui_712_redraw_generic_step();
}

Expand Down Expand Up @@ -587,9 +591,9 @@ void ui_712_end_sign(void) {
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return;
}
ui_ctx->end_reached = true;

if (N_storage.verbose_eip712 || (ui_ctx->filtering_mode == EIP712_FILTERING_FULL)) {
ui_ctx->end_reached = true;
ui_712_switch_to_sign();
}
}
Expand Down Expand Up @@ -771,4 +775,17 @@ bool ui_712_show_raw_key(const void *field_ptr) {
return true;
}

#ifdef SCREEN_SIZE_WALLET
/*
* Get UI pairs buffer
*
* @param[out] size buffer size
* @return pointer to the buffer
*/
char *get_ui_pairs_buffer(size_t *size) {
*size = sizeof(ui_ctx->ui_pairs_buffer);
return ui_ctx->ui_pairs_buffer;
}
#endif

#endif // HAVE_EIP712_FULL_SUPPORT
3 changes: 3 additions & 0 deletions src_features/signMessageEIP712/ui_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void ui_712_notify_filter_change(void);
void ui_712_token_join_prepare_addr_check(uint8_t index);
void ui_712_token_join_prepare_amount(uint8_t index, const char *name, uint8_t name_length);
bool ui_712_show_raw_key(const void *field_ptr);
#ifdef SCREEN_SIZE_WALLET
char *get_ui_pairs_buffer(size_t *size);
#endif

#endif // HAVE_EIP712_FULL_SUPPORT

Expand Down
63 changes: 52 additions & 11 deletions src_nbgl/ui_sign_712.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
#include "common_712.h"
#include "nbgl_use_case.h"
#include "ui_message_signing.h"
#include "ledger_assert.h"

static nbgl_contentTagValue_t pair;
static nbgl_contentTagValue_t pairs[6];
static nbgl_contentTagValueList_t pairs_list;
static uint8_t pair_idx;
static size_t buf_idx;

static void message_progress(bool confirm) {
char *buf;
size_t buf_size;
size_t shift_off;

if (pairs_list.nbPairs < pair_idx) {
buf = get_ui_pairs_buffer(&buf_size);
memmove(&pairs[0], &pairs[pairs_list.nbPairs], sizeof(pairs[0]));
memmove(buf, pairs[0].item, (buf + buf_idx) - pairs[0].item);
shift_off = pairs[0].item - buf;
buf_idx -= shift_off;
pairs[0].value -= shift_off;
pairs[0].item = buf;
pair_idx = 1;
}
if (confirm) {
if (ui_712_next_field() == EIP712_NO_MORE_FIELD) {
ui_712_switch_to_sign();
Expand All @@ -22,22 +39,40 @@ static void message_progress(bool confirm) {
}

static void message_update(bool confirm) {
char *buf;
size_t buf_size;
size_t buf_off;
bool flag;

buf = get_ui_pairs_buffer(&buf_size);
if (confirm) {
explicit_bzero(&pair, sizeof(pair));
explicit_bzero(&pairs_list, sizeof(pairs_list));

pair.item = strings.tmp.tmp2;
pair.value = strings.tmp.tmp;
pairs_list.nbPairs = 1;
pairs_list.pairs = &pair;
pairs_list.wrapping = false;
nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress);
buf_off = strlen(strings.tmp.tmp2) + 1;
LEDGER_ASSERT((buf_idx + buf_off) < buf_size, "UI pairs buffer overflow");
pairs[pair_idx].item = memmove(buf + buf_idx, strings.tmp.tmp2, buf_off);
buf_idx += buf_off;
buf_off = strlen(strings.tmp.tmp) + 1;
LEDGER_ASSERT((buf_idx + buf_off) < buf_size, "UI pairs buffer overflow");
pairs[pair_idx].value = memmove(buf + buf_idx, strings.tmp.tmp, buf_off);
buf_idx += buf_off;
pair_idx += 1;
pairs_list.nbPairs = nbgl_useCaseGetNbTagValuesInPage(pair_idx, &pairs_list, 0, &flag);
if (pairs_list.nbPairs < pair_idx) {
nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress);
} else {
message_progress(true);
}
} else {
ui_typed_message_review_choice(false);
}
}

void ui_712_start(void) {
explicit_bzero(&pairs, sizeof(pairs));
explicit_bzero(&pairs_list, sizeof(pairs_list));
pairs_list.pairs = pairs;
pair_idx = 0;
buf_idx = 0;

nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE,
&C_Review_64px,
TEXT_REVIEW_EIP712,
Expand All @@ -50,7 +85,13 @@ void ui_712_switch_to_message(void) {
}

void ui_712_switch_to_sign(void) {
nbgl_useCaseReviewStreamingFinish(TEXT_SIGN_EIP712, ui_typed_message_review_choice);
if (pair_idx > 0) {
pairs_list.nbPairs = pair_idx;
pair_idx = 0;
nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress);
} else {
nbgl_useCaseReviewStreamingFinish(TEXT_SIGN_EIP712, ui_typed_message_review_choice);
}
}

#endif // HAVE_EIP712_FULL_SUPPORT

0 comments on commit 6617cd5

Please sign in to comment.