diff --git a/src/common_utils.c b/src/common_utils.c index f9ceed2..a080361 100644 --- a/src/common_utils.c +++ b/src/common_utils.c @@ -235,7 +235,7 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65], } void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65], - char out[static (ADDRESS_LENGTH * 2) + 1], + char out[static(ADDRESS_LENGTH * 2) + 1], uint64_t chainId) { uint8_t hashAddress[CX_KECCAK_256_SIZE]; CX_ASSERT(cx_keccak_256_hash(raw_pubkey + 1, 64, hashAddress)); @@ -243,7 +243,7 @@ void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65], } bool getEthAddressStringFromBinary(uint8_t *address, - char out[static (ADDRESS_LENGTH * 2) + 1], + char out[static(ADDRESS_LENGTH * 2) + 1], uint64_t chainId) { // save some precious stack space union locals_union { diff --git a/src/common_utils.h b/src/common_utils.h index 55d29e7..57a279b 100644 --- a/src/common_utils.h +++ b/src/common_utils.h @@ -40,8 +40,7 @@ static const char HEXDIGITS[] = "0123456789abcdef"; * @deprecated * See format_hex in SDK */ -DEPRECATED static inline void array_hexstr(char *strbuf, const void *bin, unsigned int len) -{ +DEPRECATED static inline void array_hexstr(char *strbuf, const void *bin, unsigned int len) { // Consider the output buffer is sufficiently large! format_hex(bin, len, strbuf, (2 * len + 1)); } @@ -71,11 +70,11 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65], uint8_t out[static ADDRESS_LENGTH]); void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65], - char out[static (ADDRESS_LENGTH * 2) + 1], + char out[static(ADDRESS_LENGTH * 2) + 1], uint64_t chainId); bool getEthAddressStringFromBinary(uint8_t *address, - char out[static (ADDRESS_LENGTH * 2) + 1], + char out[static(ADDRESS_LENGTH * 2) + 1], uint64_t chainId); bool getEthDisplayableAddress(uint8_t *in, char *out, size_t out_len, uint64_t chainId); diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h index faa2be5..a84d00a 100644 --- a/src/eth_plugin_interface.h +++ b/src/eth_plugin_interface.h @@ -75,18 +75,6 @@ typedef enum eth_ui_type_e { } eth_ui_type_t; -// Scratch objects and utilities available to the plugin READ-WRITE -typedef struct ethPluginSharedRW_s { - cx_sha3_t *sha3; -} ethPluginSharedRW_t; - - -// Transaction data available to the plugin READ-ONLY -typedef struct ethPluginSharedRO_s { - txContent_t *txContent; -} ethPluginSharedRO_t; - - // Plugin-only memory allocated by the Ethereum application and used by the plugin. #define PLUGIN_CONTEXT_SIZE (5 * INT256_LENGTH) // It is recommended to cast the raw uin8_t array to a structure meaningful for your plugin @@ -106,17 +94,19 @@ typedef struct ethPluginSharedRO_s { // Init Contract typedef struct ethPluginInitContract_s { + // READ ONLY // eth_plugin_interface_version_t interfaceVersion; - eth_plugin_result_t result; - - // in - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; + const txContent_t *txContent; size_t pluginContextLength; const uint8_t *selector; // 4 bytes selector size_t dataSize; + // READ WRITE // + uint8_t *pluginContext; + + // WRITE ONLY // + eth_plugin_result_t result; + } ethPluginInitContract_t; // void handle_init_contract(ethPluginInitContract_t *parameters); @@ -124,12 +114,15 @@ typedef struct ethPluginInitContract_s { // Provide parameter typedef struct ethPluginProvideParameter_s { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + // READ ONLY // + const txContent_t *txContent; const uint8_t *parameter; // 32 bytes parameter uint32_t parameterOffset; + // READ WRITE // + uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + + // WRITE ONLY // eth_plugin_result_t result; } ethPluginProvideParameter_t; @@ -139,19 +132,22 @@ typedef struct ethPluginProvideParameter_s { // Finalize typedef struct ethPluginFinalize_s { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + // READ ONLY // + const txContent_t *txContent; - uint8_t *tokenLookup1; // set by the plugin if a token should be looked up - uint8_t *tokenLookup2; - - const uint8_t *amount; // set an uint256 pointer if uiType is UI_AMOUNT_ADDRESS - const uint8_t *address; // set to the destination address if uiType is UI_AMOUNT_ADDRESS. Set - // to the user's address if uiType is UI_TYPE_GENERIC + // READ WRITE // + uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + // WRITE ONLY // + const uint8_t *tokenLookup1; // set by the plugin if a token should be looked up + const uint8_t *tokenLookup2; eth_ui_type_t uiType; - uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS + union { + const uint8_t *amount; // set a pointer to the amount (in pluginContext) if uiType is UI_AMOUNT_ADDRESS + uint8_t numScreens; // set the number of screens to query if uiType is UI_TYPE_GENERIC + }; + const uint8_t *address; // set a pointer to the destination address (in pluginContext) if uiType is UI_AMOUNT_ADDRESS. Set + // to the user's address if uiType is UI_TYPE_GENERIC eth_plugin_result_t result; } ethPluginFinalize_t; @@ -161,16 +157,17 @@ typedef struct ethPluginFinalize_s { // Provide token typedef struct ethPluginProvideInfo_s { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE - + // READ ONLY // + const txContent_t *txContent; union extraInfo_t *item1; // set by the ETH application, to be saved by the plugin union extraInfo_t *item2; + // READ WRITE // + uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + + // WRITE ONLY // uint8_t additionalScreens; // Used by the plugin if it needs to display additional screens // based on the information received from the token definitions. - eth_plugin_result_t result; } ethPluginProvideInfo_t; @@ -182,15 +179,17 @@ typedef struct ethPluginProvideInfo_s { // This is always called on the non aliased contract typedef struct ethQueryContractID_s { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; + // READ ONLY // + const txContent_t *txContent; + size_t nameLength; + size_t versionLength; + + // READ WRITE // uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + // WRITE ONLY // char *name; - size_t nameLength; char *version; - size_t versionLength; - eth_plugin_result_t result; } ethQueryContractID_t; @@ -200,19 +199,21 @@ typedef struct ethQueryContractID_s { // Query Contract UI typedef struct ethQueryContractUI_s { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; + // READ ONLY // + const txContent_t *txContent; union extraInfo_t *item1; union extraInfo_t *item2; char network_ticker[MAX_TICKER_LEN]; - uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE uint8_t screenIndex; - - char *title; size_t titleLength; - char *msg; size_t msgLength; + // READ WRITE // + uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE + + // WRITE ONLY // + char *title; + char *msg; eth_plugin_result_t result; } ethQueryContractUI_t;