Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ 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));
getEthAddressStringFromBinary(hashAddress + 12, out, chainId);
}

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 {
Expand Down
7 changes: 3 additions & 4 deletions src/common_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down
95 changes: 48 additions & 47 deletions src/eth_plugin_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -106,30 +94,35 @@ 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);


// 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down