2022-03-07 14:21:32 +01:00
|
|
|
#ifndef _ETH_PLUGIN_INTERFACE_H_
|
|
|
|
|
#define _ETH_PLUGIN_INTERFACE_H_
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
|
#include "cx.h"
|
|
|
|
|
#include "ethUstream.h"
|
|
|
|
|
#include "tokens.h"
|
2021-11-22 14:39:36 +01:00
|
|
|
#include "shared_context.h"
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-06-11 14:45:45 +02:00
|
|
|
// Interface version. To be updated everytime we introduce breaking changes to the plugin interface.
|
2021-05-17 16:56:59 +02:00
|
|
|
typedef enum {
|
2021-11-22 14:39:36 +01:00
|
|
|
ETH_PLUGIN_INTERFACE_VERSION_1 = 1,
|
2021-10-28 18:10:21 +02:00
|
|
|
ETH_PLUGIN_INTERFACE_VERSION_2 = 2,
|
2021-11-22 14:39:36 +01:00
|
|
|
ETH_PLUGIN_INTERFACE_VERSION_3 = 3,
|
|
|
|
|
ETH_PLUGIN_INTERFACE_VERSION_LATEST = 4,
|
2021-05-17 16:56:59 +02:00
|
|
|
} eth_plugin_interface_version_t;
|
|
|
|
|
|
2020-09-22 09:22:49 +02:00
|
|
|
typedef enum {
|
|
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
ETH_PLUGIN_INIT_CONTRACT = 0x0101,
|
|
|
|
|
ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102,
|
|
|
|
|
ETH_PLUGIN_FINALIZE = 0x0103,
|
2021-11-22 14:39:36 +01:00
|
|
|
ETH_PLUGIN_PROVIDE_INFO = 0x0104,
|
2020-12-01 16:20:13 +01:00
|
|
|
ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105,
|
2020-12-03 16:32:40 +01:00
|
|
|
ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106,
|
|
|
|
|
ETH_PLUGIN_CHECK_PRESENCE = 0x01FF
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} eth_plugin_msg_t;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
2021-04-24 12:14:36 +02:00
|
|
|
// Unsuccesful return values
|
2020-12-01 16:20:13 +01:00
|
|
|
ETH_PLUGIN_RESULT_ERROR = 0x00,
|
2021-04-24 12:14:36 +02:00
|
|
|
ETH_PLUGIN_RESULT_UNAVAILABLE = 0x01,
|
2021-04-27 10:37:22 +02:00
|
|
|
ETH_PLUGIN_RESULT_UNSUCCESSFUL = 0x02, // Used for comparison
|
2021-04-24 12:14:36 +02:00
|
|
|
|
|
|
|
|
// Successful return values
|
2021-04-27 10:37:22 +02:00
|
|
|
ETH_PLUGIN_RESULT_SUCCESSFUL = 0x03, // Used for comparison
|
2021-04-24 12:14:36 +02:00
|
|
|
ETH_PLUGIN_RESULT_OK = 0x04,
|
|
|
|
|
ETH_PLUGIN_RESULT_OK_ALIAS = 0x05,
|
|
|
|
|
ETH_PLUGIN_RESULT_FALLBACK = 0x06
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} eth_plugin_result_t;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01,
|
|
|
|
|
ETH_UI_TYPE_GENERIC = 0x02
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} eth_ui_type_t;
|
|
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
typedef void (*PluginCall)(int, void *);
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
// Shared objects, read-write
|
|
|
|
|
|
|
|
|
|
typedef struct ethPluginSharedRW_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
cx_sha3_t *sha3;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethPluginSharedRW_t;
|
|
|
|
|
|
|
|
|
|
// Shared objects, read-only
|
|
|
|
|
|
|
|
|
|
typedef struct ethPluginSharedRO_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
txContent_t *txContent;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethPluginSharedRO_t;
|
|
|
|
|
|
|
|
|
|
// Init Contract
|
|
|
|
|
|
|
|
|
|
typedef struct ethPluginInitContract_t {
|
2021-05-17 16:56:59 +02:00
|
|
|
uint8_t interfaceVersion;
|
|
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-05-17 16:56:59 +02:00
|
|
|
// in
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
|
|
|
|
uint8_t *pluginContext;
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t pluginContextLength;
|
2022-02-03 14:19:53 +01:00
|
|
|
const uint8_t *selector; // 4 bytes selector
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t dataSize;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
char *alias; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethPluginInitContract_t;
|
|
|
|
|
|
|
|
|
|
// Provide parameter
|
|
|
|
|
|
|
|
|
|
typedef struct ethPluginProvideParameter_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
|
|
|
|
uint8_t *pluginContext;
|
2022-02-03 14:19:53 +01:00
|
|
|
const uint8_t *parameter; // 32 bytes parameter
|
2020-12-01 16:20:13 +01:00
|
|
|
uint32_t parameterOffset;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethPluginProvideParameter_t;
|
|
|
|
|
|
|
|
|
|
// Finalize
|
|
|
|
|
|
|
|
|
|
typedef struct ethPluginFinalize_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
|
|
|
|
uint8_t *pluginContext;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t *tokenLookup1; // set by the plugin if a token should be looked up
|
|
|
|
|
uint8_t *tokenLookup2;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2022-02-03 14:19:53 +01:00
|
|
|
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
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t uiType;
|
|
|
|
|
uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS
|
|
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethPluginFinalize_t;
|
|
|
|
|
|
|
|
|
|
// If uiType is UI_AMOUNT_ADDRESS, the amount and address provided by the plugin will be used
|
|
|
|
|
// If tokenLookup1 is set, the amount is provided for this token
|
|
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
// if uiType is UI_TYPE_GENERIC, the ETH application provides tokens if requested then prompts
|
2020-09-22 09:22:49 +02:00
|
|
|
// for each UI field
|
2020-12-01 16:20:13 +01:00
|
|
|
// The first field is forced by the ETH app to be the name + version of the plugin handling the
|
|
|
|
|
// request The last field is the fee amount
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
// Provide token
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-11-22 14:39:36 +01:00
|
|
|
typedef struct ethPluginProvideInfo_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
|
|
|
|
uint8_t *pluginContext;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-11-22 14:39:36 +01:00
|
|
|
union extraInfo_t *item1; // set by the ETH application, to be saved by the plugin
|
|
|
|
|
union extraInfo_t *item2;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-05-20 14:34:45 +02:00
|
|
|
uint8_t additionalScreens; // Used by the plugin if it needs to display additional screens
|
|
|
|
|
// based on the information received from the token definitions.
|
2021-05-20 14:34:32 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2021-11-22 14:39:36 +01:00
|
|
|
} ethPluginProvideInfo_t;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
// Query Contract name and version
|
|
|
|
|
|
|
|
|
|
// This is always called on the non aliased contract
|
|
|
|
|
|
|
|
|
|
typedef struct ethQueryContractID_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
|
|
|
|
uint8_t *pluginContext;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
char *name;
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t nameLength;
|
2020-12-01 16:20:13 +01:00
|
|
|
char *version;
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t versionLength;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethQueryContractID_t;
|
|
|
|
|
|
|
|
|
|
// Query Contract UI
|
|
|
|
|
|
|
|
|
|
typedef struct ethQueryContractUI_t {
|
2020-12-01 16:20:13 +01:00
|
|
|
ethPluginSharedRW_t *pluginSharedRW;
|
|
|
|
|
ethPluginSharedRO_t *pluginSharedRO;
|
2021-11-22 14:39:36 +01:00
|
|
|
union extraInfo_t *item1;
|
|
|
|
|
union extraInfo_t *item2;
|
|
|
|
|
char network_ticker[MAX_TICKER_LEN];
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t *pluginContext;
|
|
|
|
|
uint8_t screenIndex;
|
2021-10-28 18:10:21 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
char *title;
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t titleLength;
|
2020-12-01 16:20:13 +01:00
|
|
|
char *msg;
|
2021-05-17 17:09:29 +02:00
|
|
|
size_t msgLength;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
2020-12-01 16:20:13 +01:00
|
|
|
uint8_t result;
|
2020-09-22 09:22:49 +02:00
|
|
|
|
|
|
|
|
} ethQueryContractUI_t;
|
|
|
|
|
|
2022-03-07 14:21:32 +01:00
|
|
|
#endif // _ETH_PLUGIN_INTERFACE_H_
|