1
1
/* This file is auto-generated, don't edit it */
2
+ // clang-format off
3
+
2
4
#ifndef _ETH_PLUGIN_INTERFACE_H_
3
5
#define _ETH_PLUGIN_INTERFACE_H_
4
6
5
7
#include "os.h"
6
8
#include "cx.h"
7
9
#include "eth_internals.h"
8
10
9
- // Interface version. To be updated everytime we introduce breaking changes to the plugin interface.
10
- typedef enum {
11
+ /*************************************************************************************************
12
+ * Comments provided in this file are quick reminders on the usage of the plugin interface *
13
+ * Reading the real plugin documentation is GREATLY recommended. *
14
+ * You can find the latest version here: *
15
+ * https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp_plugins.adoc *
16
+ *************************************************************************************************/
17
+
18
+ // Interface version. Will be updated every time a breaking change in the interface is introduced.
19
+ typedef enum eth_plugin_interface_version_e {
11
20
ETH_PLUGIN_INTERFACE_VERSION_1 = 1 ,
12
21
ETH_PLUGIN_INTERFACE_VERSION_2 = 2 ,
13
22
ETH_PLUGIN_INTERFACE_VERSION_3 = 3 ,
14
23
ETH_PLUGIN_INTERFACE_VERSION_4 = 4 ,
15
24
ETH_PLUGIN_INTERFACE_VERSION_5 = 5 ,
16
- ETH_PLUGIN_INTERFACE_VERSION_LATEST = 6
25
+ ETH_PLUGIN_INTERFACE_VERSION_LATEST = 6 ,
17
26
} eth_plugin_interface_version_t ;
18
27
19
- typedef enum {
20
28
29
+ // Codes for the different requests Ethereum can send to the plugin
30
+ // The dispatch is handled by the SDK itself, the plugin code does not have to handle it
31
+ typedef enum eth_plugin_msg_e {
32
+ // Codes for actions the Ethereum app can ask the plugin to perform
21
33
ETH_PLUGIN_INIT_CONTRACT = 0x0101 ,
22
34
ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102 ,
23
35
ETH_PLUGIN_FINALIZE = 0x0103 ,
24
36
ETH_PLUGIN_PROVIDE_INFO = 0x0104 ,
25
37
ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105 ,
26
38
ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106 ,
27
- ETH_PLUGIN_CHECK_PRESENCE = 0x01FF
28
39
40
+ // Special request: the Ethereum app is checking if we are installed on the device
41
+ ETH_PLUGIN_CHECK_PRESENCE = 0x01FF ,
29
42
} eth_plugin_msg_t ;
30
43
31
- typedef enum {
32
- // Unsuccesful return values
44
+
45
+ // Reply codes when responding to the Ethereum application
46
+ typedef enum eth_plugin_result_e {
47
+ // Unsuccessful return values
33
48
ETH_PLUGIN_RESULT_ERROR = 0x00 ,
34
49
ETH_PLUGIN_RESULT_UNAVAILABLE = 0x01 ,
35
50
ETH_PLUGIN_RESULT_UNSUCCESSFUL = 0x02 , // Used for comparison
@@ -38,38 +53,58 @@ typedef enum {
38
53
ETH_PLUGIN_RESULT_SUCCESSFUL = 0x03 , // Used for comparison
39
54
ETH_PLUGIN_RESULT_OK = 0x04 ,
40
55
ETH_PLUGIN_RESULT_OK_ALIAS = 0x05 ,
41
- ETH_PLUGIN_RESULT_FALLBACK = 0x06
42
-
56
+ ETH_PLUGIN_RESULT_FALLBACK = 0x06 ,
43
57
} eth_plugin_result_t ;
44
58
45
- typedef enum {
46
59
60
+ // Format of UI the Ethereum application has to use for this plugin
61
+ typedef enum eth_ui_type_e {
62
+ // If uiType is UI_AMOUNT_ADDRESS, Ethereum will use the amount/address UI
63
+ // the amount and address provided by the plugin will be used
64
+ // If tokenLookup1 is set, the amount is provided for this token
47
65
ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01 ,
48
- ETH_UI_TYPE_GENERIC = 0x02
49
66
67
+ // If uiType is UI_TYPE_GENERIC, Ethereum will use the dedicated ETH plugin UI
68
+ // the ETH application provides tokens if requested then prompts for each UI field
69
+ // The first field is forced by the ETH app to be the name + version of the plugin handling the
70
+ // request. The last field is the fee amount
71
+ ETH_UI_TYPE_GENERIC = 0x02 ,
50
72
} eth_ui_type_t ;
51
73
52
- typedef void (* PluginCall )(int , void * );
53
-
54
- // Shared objects, read-write
55
74
56
- typedef struct ethPluginSharedRW_t {
75
+ // Scratch objects and utilities available to the plugin READ-WRITE
76
+ typedef struct ethPluginSharedRW_s {
57
77
cx_sha3_t * sha3 ;
58
-
59
78
} ethPluginSharedRW_t ;
60
79
61
- // Shared objects, read-only
62
80
63
- typedef struct ethPluginSharedRO_t {
81
+ // Transaction data available to the plugin READ-ONLY
82
+ typedef struct ethPluginSharedRO_s {
64
83
txContent_t * txContent ;
65
-
66
84
} ethPluginSharedRO_t ;
67
85
86
+
87
+ // Plugin-only memory allocated by the Ethereum application and used by the plugin.
88
+ #define PLUGIN_CONTEXT_SIZE (5 * INT256_LENGTH)
89
+ // It is recommended to cast the raw uin8_t array to a structure meaningfull for your plugin
90
+ // Helper to check that the actual plugin context structure is not bigger than the allocated memory
91
+ #define ASSERT_SIZEOF_PLUGIN_CONTEXT (s ) \
92
+ _Static_assert(sizeof(s) <= PLUGIN_CONTEXT_SIZE, "Plugin context structure is too big.")
93
+
94
+
95
+ /*
96
+ * HANDLERS AND PARAMETERS
97
+ * Parameters associated with the requests the Ethereum application can ask the plugin to perform
98
+ * The plugin SDK will automatically call the relevant handler for the received code, so the plugin
99
+ * has to define each of the handler functions declared below.
100
+ */
101
+
102
+
68
103
// Init Contract
69
104
70
- typedef struct ethPluginInitContract_t {
71
- uint8_t interfaceVersion ;
72
- uint8_t result ;
105
+ typedef struct ethPluginInitContract_s {
106
+ eth_plugin_interface_version_t interfaceVersion ;
107
+ eth_plugin_result_t result ;
73
108
74
109
// in
75
110
ethPluginSharedRW_t * pluginSharedRW ;
@@ -82,26 +117,30 @@ typedef struct ethPluginInitContract_t {
82
117
char * alias ; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set
83
118
84
119
} ethPluginInitContract_t ;
120
+ // void handle_init_contract(ethPluginInitContract_t *parameters);
121
+
85
122
86
123
// Provide parameter
87
124
88
- typedef struct ethPluginProvideParameter_t {
125
+ typedef struct ethPluginProvideParameter_s {
89
126
ethPluginSharedRW_t * pluginSharedRW ;
90
127
ethPluginSharedRO_t * pluginSharedRO ;
91
- uint8_t * pluginContext ;
128
+ uint8_t * pluginContext ; // PLUGIN_CONTEXT_SIZE
92
129
const uint8_t * parameter ; // 32 bytes parameter
93
130
uint32_t parameterOffset ;
94
131
95
- uint8_t result ;
132
+ eth_plugin_result_t result ;
96
133
97
134
} ethPluginProvideParameter_t ;
135
+ // void handle_provide_parameter(ethPluginProvideParameter_t *parameters);
136
+
98
137
99
138
// Finalize
100
139
101
- typedef struct ethPluginFinalize_t {
140
+ typedef struct ethPluginFinalize_s {
102
141
ethPluginSharedRW_t * pluginSharedRW ;
103
142
ethPluginSharedRO_t * pluginSharedRO ;
104
- uint8_t * pluginContext ;
143
+ uint8_t * pluginContext ; // PLUGIN_CONTEXT_SIZE
105
144
106
145
uint8_t * tokenLookup1 ; // set by the plugin if a token should be looked up
107
146
uint8_t * tokenLookup2 ;
@@ -110,73 +149,74 @@ typedef struct ethPluginFinalize_t {
110
149
const uint8_t * address ; // set to the destination address if uiType is UI_AMOUNT_ADDRESS. Set
111
150
// to the user's address if uiType is UI_TYPE_GENERIC
112
151
113
- uint8_t uiType ;
152
+ eth_ui_type_t uiType ;
114
153
uint8_t numScreens ; // ignored if uiType is UI_AMOUNT_ADDRESS
115
- uint8_t result ;
154
+ eth_plugin_result_t result ;
116
155
117
156
} ethPluginFinalize_t ;
157
+ // void handle_finalize(ethPluginFinalize_t *parameters);
118
158
119
- // If uiType is UI_AMOUNT_ADDRESS, the amount and address provided by the plugin will be used
120
- // If tokenLookup1 is set, the amount is provided for this token
121
-
122
- // if uiType is UI_TYPE_GENERIC, the ETH application provides tokens if requested then prompts
123
- // for each UI field
124
- // The first field is forced by the ETH app to be the name + version of the plugin handling the
125
- // request The last field is the fee amount
126
159
127
160
// Provide token
128
161
129
- typedef struct ethPluginProvideInfo_t {
162
+ typedef struct ethPluginProvideInfo_s {
130
163
ethPluginSharedRW_t * pluginSharedRW ;
131
164
ethPluginSharedRO_t * pluginSharedRO ;
132
- uint8_t * pluginContext ;
165
+ uint8_t * pluginContext ; // PLUGIN_CONTEXT_SIZE
133
166
134
167
union extraInfo_t * item1 ; // set by the ETH application, to be saved by the plugin
135
168
union extraInfo_t * item2 ;
136
169
137
170
uint8_t additionalScreens ; // Used by the plugin if it needs to display additional screens
138
171
// based on the information received from the token definitions.
139
172
140
- uint8_t result ;
173
+ eth_plugin_result_t result ;
141
174
142
175
} ethPluginProvideInfo_t ;
176
+ // void handle_provide_token(ethPluginProvideInfo_t *parameters);
177
+
143
178
144
179
// Query Contract name and version
145
180
146
181
// This is always called on the non aliased contract
147
182
148
- typedef struct ethQueryContractID_t {
183
+ typedef struct ethQueryContractID_s {
149
184
ethPluginSharedRW_t * pluginSharedRW ;
150
185
ethPluginSharedRO_t * pluginSharedRO ;
151
- uint8_t * pluginContext ;
186
+ uint8_t * pluginContext ; // PLUGIN_CONTEXT_SIZE
152
187
153
188
char * name ;
154
189
size_t nameLength ;
155
190
char * version ;
156
191
size_t versionLength ;
157
192
158
- uint8_t result ;
193
+ eth_plugin_result_t result ;
159
194
160
195
} ethQueryContractID_t ;
196
+ // void handle_query_contract_id(ethQueryContractID_t *parameters);
197
+
161
198
162
199
// Query Contract UI
163
200
164
- typedef struct ethQueryContractUI_t {
201
+ typedef struct ethQueryContractUI_s {
165
202
ethPluginSharedRW_t * pluginSharedRW ;
166
203
ethPluginSharedRO_t * pluginSharedRO ;
167
204
union extraInfo_t * item1 ;
168
205
union extraInfo_t * item2 ;
169
206
char network_ticker [MAX_TICKER_LEN ];
170
- uint8_t * pluginContext ;
207
+ uint8_t * pluginContext ; // PLUGIN_CONTEXT_SIZE
171
208
uint8_t screenIndex ;
172
209
173
210
char * title ;
174
211
size_t titleLength ;
175
212
char * msg ;
176
213
size_t msgLength ;
177
214
178
- uint8_t result ;
215
+ eth_plugin_result_t result ;
179
216
180
217
} ethQueryContractUI_t ;
218
+ // void handle_query_contract_ui(ethQueryContractUI_t *parameters);
181
219
182
220
#endif // _ETH_PLUGIN_INTERFACE_H_
221
+
222
+ // clang-format on
0 commit comments