diff --git a/src/signMsg.c b/src/signMsg.c index f4d942e..f2921bd 100644 --- a/src/signMsg.c +++ b/src/signMsg.c @@ -68,14 +68,11 @@ bool sign_message(void) { } void handleSignMsg(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, volatile unsigned int *flags, volatile unsigned int *tx) { - uint8_t hashMessage[32]; if (p1 == P1_FIRST) { char tmp[11]; uint32_t index; uint32_t base = 10; uint8_t pos = 0; - uint32_t i; - cx_sha3_t sha; // first 4 bytes from dataBuffer should be the message length (big endian uint32) if (dataLength < 4) THROW(ERR_INVALID_MESSAGE); diff --git a/src/signTx.c b/src/signTx.c index c9c0b72..54460c7 100644 --- a/src/signTx.c +++ b/src/signTx.c @@ -1,7 +1,4 @@ #include "signTx.h" -#include "os.h" -#include "ux.h" -#include "utils.h" #include "../deps/jsmn/jsmn.h" #include #include "base64.h" @@ -27,25 +24,6 @@ VERSION_FIELD \ ) -// additional space for "0." and " eGLD" -#define PRETTY_SIZE (2 + MAX_TICKER_LEN) - -typedef struct { - char buffer[MAX_BUFFER_LEN]; // buffer to hold large transactions that are composed from multiple APDUs - uint16_t bufLen; - - char receiver[FULL_ADDRESS_LENGTH]; - char amount[MAX_AMOUNT_LEN + PRETTY_SIZE]; - uint64_t gas_limit; - uint64_t gas_price; - char fee[MAX_AMOUNT_LEN + PRETTY_SIZE]; - char data[MAX_DISPLAY_DATA_SIZE + DATA_SIZE_LEN]; - uint16_t data_size; - char signature[64]; -} tx_context_t; - -static tx_context_t tx_context; - static uint8_t setResultSignature(); void makeFeePretty(network_t network); static int jsoneq(const char *json, jsmntok_t *tok, const char *s); @@ -132,7 +110,7 @@ static bool gas_to_fee(uint64_t gas_limit, uint64_t gas_price, char *fee, size_t return true; } -static bool isdigit(char c) { +static bool is_digit(char c) { return c >= '0' && c <= '9'; } @@ -140,7 +118,7 @@ static bool parse_int(char *str, size_t size, uint64_t *result) { uint64_t min = 0, n = 0; for (size_t i = 0; i < size; i++) { - if (!isdigit(str[i])) { + if (!is_digit(str[i])) { return false; } n = n * 10 + str[i] - '0'; @@ -158,7 +136,7 @@ static bool parse_int(char *str, size_t size, uint64_t *result) { static bool valid_amount(char *amount, size_t size) { for (size_t i = 0; i < size; i++) { - if (!isdigit(amount[i])) { + if (!is_digit(amount[i])) { return false; } } @@ -236,6 +214,7 @@ static void computeDataSize(char *base64, int b64len) { if (base64[b64len - 2] == '=') tx_context.data_size--; } + tx_context.data[tx_context.data_size] = '\0'; int len = sizeof(tx_context.data); // prepare the first display page, which contains the data field size char str_size[DATA_SIZE_LEN] = "[ Size: 000 ] "; diff --git a/src/signTx.h b/src/signTx.h index 56da7ab..a8f25de 100644 --- a/src/signTx.h +++ b/src/signTx.h @@ -5,11 +5,9 @@ #ifndef _SIGN_TX_H_ #define _SIGN_TX_H_ -void handleSignTx(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, volatile unsigned int *flags, volatile unsigned int *tx); - #define MAX_AMOUNT_LEN 32 -#define MAX_BUFFER_LEN 1024 -#define MAX_DATA_SIZE 800 // 800 in base64 = 600 in ASCII +#define MAX_BUFFER_LEN 700 +#define MAX_DATA_SIZE 600 // 600 in base64 = 450 in ASCII #define MAX_DISPLAY_DATA_SIZE 64 // must be multiple of 4 #define DATA_SIZE_LEN 17 #define MAX_CHAINID_LEN 32 @@ -17,5 +15,24 @@ void handleSignTx(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLeng #define MAX_UINT32_LEN 10 // len(f"{0xffffffff:d}") #define MAX_UINT64_LEN 20 // len(f"{0xffffffffffffffff:d}") #define MAX_UINT128_LEN 39 // len(f"{0xffffffffffffffffffffffffffffffff:d}") +#define PRETTY_SIZE (2 + MAX_TICKER_LEN) // additional space for "0." and " eGLD" + +typedef struct { + uint8_t buffer[MAX_BUFFER_LEN]; // buffer to hold large transactions that are composed from multiple APDUs + uint16_t bufLen; + + char receiver[FULL_ADDRESS_LENGTH]; + char amount[MAX_AMOUNT_LEN + PRETTY_SIZE]; + uint64_t gas_limit; + uint64_t gas_price; + char fee[MAX_AMOUNT_LEN + PRETTY_SIZE]; + char data[MAX_DISPLAY_DATA_SIZE + DATA_SIZE_LEN]; + uint16_t data_size; + uint8_t signature[64]; +} tx_context_t; + +static tx_context_t tx_context; + +void handleSignTx(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, volatile unsigned int *flags, volatile unsigned int *tx); #endif diff --git a/src/utils.c b/src/utils.c index 7c3dc62..7db964e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -79,15 +79,15 @@ bool getPublicKey(uint32_t accountNumber, uint32_t index, uint8_t *publicKeyArra return true; } -bool getPrivateKey(uint32_t accountNumber, uint32_t index, cx_ecfp_private_key_t *privateKey) { +bool getPrivateKey(uint32_t account, uint32_t addressIndex, cx_ecfp_private_key_t *privateKey) { uint8_t privateKeyData[32]; uint32_t bip32Path[BIP32_PATH]; bool success = true; os_memmove(bip32Path, derivePath, sizeof(derivePath)); - bip32Path[2] = accountNumber | HARDENED_OFFSET; - bip32Path[4] = index | HARDENED_OFFSET; + bip32Path[2] = account | HARDENED_OFFSET; + bip32Path[4] = addressIndex | HARDENED_OFFSET; BEGIN_TRY { TRY {