Skip to content

Commit

Permalink
Update ethereum plugin-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed May 7, 2024
1 parent 6af4a9a commit 2b9fd72
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
17 changes: 0 additions & 17 deletions src/uint_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,3 @@ void reverseString(char *const str, uint32_t length) {
str[j] = c;
}
}

int bytes_to_string(char *out, size_t outl, const void *value, size_t len) {
if (outl <= 2) {
// Need at least '0x' and 1 digit
return -1;
}
if (strlcpy(out, "0x", outl) != 2) {
goto err;
}
if (format_hex(value, len, out + 2, outl - 2) < 0) {
goto err;
}
return 0;
err:
*out = '\0';
return -1;
}
2 changes: 0 additions & 2 deletions src/uint_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ void read_u64_be(const uint8_t *const in, uint64_t *const out);
uint64_t readUint64BE(const uint8_t *const buffer);
void reverseString(char *const str, uint32_t length);

int bytes_to_string(char *out, size_t outl, const void *value, size_t len);

#endif //_UINT_COMMON_H_
8 changes: 4 additions & 4 deletions src_bagl/ui_flow_getEth2PublicKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "uint_common.h"

void prepare_eth2_public_key() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
}

// clang-format off
Expand Down
16 changes: 8 additions & 8 deletions src_bagl/ui_flow_signMessage712_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#include "uint_common.h"

void prepare_domain_hash_v0() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.domainHash,
KECCAK256_HASH_BYTESIZE);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.domainHash,
KECCAK256_HASH_BYTESIZE);
}

void prepare_message_hash_v0() {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
}

// clang-format off
Expand Down
10 changes: 5 additions & 5 deletions src_features/signMessageEIP712/ui_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ void ui_712_message_hash(void) {
const char *const title = "Message hash";

ui_712_set_title(title, strlen(title));
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE);
ui_712_redraw_generic_step();
}

Expand Down Expand Up @@ -286,7 +286,7 @@ static bool ui_712_format_bool(const uint8_t *const data, uint8_t length) {
*/
static void ui_712_format_bytes(const uint8_t *const data, uint8_t length) {
if (ui_712_field_shown()) {
bytes_to_string(strings.tmp.tmp, sizeof(strings.tmp.tmp), data, length);
array_bytes_string(strings.tmp.tmp, sizeof(strings.tmp.tmp), data, length);
// +2 for the "0x"
// x2 for each byte value is represented by 2 ASCII characters
if ((2 + (length * 2)) > (sizeof(strings.tmp.tmp) - 1)) {
Expand Down
8 changes: 4 additions & 4 deletions src_nbgl/ui_get_eth2_public_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ static void reviewChoice(bool confirm) {
}

void ui_display_public_eth2(void) {
bytes_to_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W,
48);
strlcpy(g_stax_shared_buffer, "Verify ETH2\naddress", sizeof(g_stax_shared_buffer));
nbgl_useCaseAddressReview(strings.tmp.tmp,
NULL,
Expand Down
2 changes: 1 addition & 1 deletion src_nbgl/ui_sign_712_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void messageReviewChoice_cb(bool confirm) {
}

static char *format_hash(const uint8_t *hash, char *buffer, size_t buffer_size, size_t offset) {
bytes_to_string(buffer + offset, buffer_size - offset, hash, KECCAK256_HASH_BYTESIZE);
array_bytes_string(buffer + offset, buffer_size - offset, hash, KECCAK256_HASH_BYTESIZE);
return buffer + offset;
}

Expand Down

0 comments on commit 2b9fd72

Please sign in to comment.