Update ethereum plugin-sdk

This commit is contained in:
Charles-Edouard de la Vergne
2024-05-07 16:01:12 +02:00
parent 817e7a846a
commit c0d19fdf6d
8 changed files with 23 additions and 42 deletions

View File

@@ -58,20 +58,3 @@ void reverseString(char *const str, uint32_t length) {
str[j] = c; 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;
}

View File

@@ -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); uint64_t readUint64BE(const uint8_t *const buffer);
void reverseString(char *const str, uint32_t length); 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_ #endif //_UINT_COMMON_H_

View File

@@ -5,7 +5,7 @@
#include "uint_common.h" #include "uint_common.h"
void prepare_eth2_public_key() { void prepare_eth2_public_key() {
bytes_to_string(strings.tmp.tmp, array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W, tmpCtx.publicKeyContext.publicKey.W,
48); 48);

View File

@@ -4,14 +4,14 @@
#include "uint_common.h" #include "uint_common.h"
void prepare_domain_hash_v0() { void prepare_domain_hash_v0() {
bytes_to_string(strings.tmp.tmp, array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.domainHash, tmpCtx.messageSigningContext712.domainHash,
KECCAK256_HASH_BYTESIZE); KECCAK256_HASH_BYTESIZE);
} }
void prepare_message_hash_v0() { void prepare_message_hash_v0() {
bytes_to_string(strings.tmp.tmp, array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash, tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE); KECCAK256_HASH_BYTESIZE);

View File

@@ -166,7 +166,7 @@ void ui_712_message_hash(void) {
const char *const title = "Message hash"; const char *const title = "Message hash";
ui_712_set_title(title, strlen(title)); ui_712_set_title(title, strlen(title));
bytes_to_string(strings.tmp.tmp, array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
tmpCtx.messageSigningContext712.messageHash, tmpCtx.messageSigningContext712.messageHash,
KECCAK256_HASH_BYTESIZE); KECCAK256_HASH_BYTESIZE);
@@ -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) { static void ui_712_format_bytes(const uint8_t *const data, uint8_t length) {
if (ui_712_field_shown()) { 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" // +2 for the "0x"
// x2 for each byte value is represented by 2 ASCII characters // x2 for each byte value is represented by 2 ASCII characters
if ((2 + (length * 2)) > (sizeof(strings.tmp.tmp) - 1)) { if ((2 + (length * 2)) > (sizeof(strings.tmp.tmp) - 1)) {

View File

@@ -21,7 +21,7 @@ static void reviewChoice(bool confirm) {
} }
void ui_display_public_eth2(void) { void ui_display_public_eth2(void) {
bytes_to_string(strings.tmp.tmp, array_bytes_string(strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
tmpCtx.publicKeyContext.publicKey.W, tmpCtx.publicKeyContext.publicKey.W,
48); 48);

View File

@@ -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) { 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; return buffer + offset;
} }