Skip to content

Commit 4d8e044

Browse files
author
ldg-github-ci
committed
[update] Branch develop | Commit 0241d094bd76635f6b246a03a1c12f11b9c43ce2
1 parent 1fe4085 commit 4d8e044

File tree

2 files changed

+158
-45
lines changed

2 files changed

+158
-45
lines changed

include/eth_plugin_interface.h

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
/* This file is auto-generated, don't edit it */
2+
// clang-format off
3+
24
#ifndef _ETH_PLUGIN_INTERFACE_H_
35
#define _ETH_PLUGIN_INTERFACE_H_
46

57
#include "os.h"
68
#include "cx.h"
79
#include "eth_internals.h"
810

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 {
1120
ETH_PLUGIN_INTERFACE_VERSION_1 = 1,
1221
ETH_PLUGIN_INTERFACE_VERSION_2 = 2,
1322
ETH_PLUGIN_INTERFACE_VERSION_3 = 3,
1423
ETH_PLUGIN_INTERFACE_VERSION_4 = 4,
1524
ETH_PLUGIN_INTERFACE_VERSION_5 = 5,
16-
ETH_PLUGIN_INTERFACE_VERSION_LATEST = 6
25+
ETH_PLUGIN_INTERFACE_VERSION_LATEST = 6,
1726
} eth_plugin_interface_version_t;
1827

19-
typedef enum {
2028

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
2133
ETH_PLUGIN_INIT_CONTRACT = 0x0101,
2234
ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102,
2335
ETH_PLUGIN_FINALIZE = 0x0103,
2436
ETH_PLUGIN_PROVIDE_INFO = 0x0104,
2537
ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105,
2638
ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106,
27-
ETH_PLUGIN_CHECK_PRESENCE = 0x01FF
2839

40+
// Special request: the Ethereum app is checking if we are installed on the device
41+
ETH_PLUGIN_CHECK_PRESENCE = 0x01FF,
2942
} eth_plugin_msg_t;
3043

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
3348
ETH_PLUGIN_RESULT_ERROR = 0x00,
3449
ETH_PLUGIN_RESULT_UNAVAILABLE = 0x01,
3550
ETH_PLUGIN_RESULT_UNSUCCESSFUL = 0x02, // Used for comparison
@@ -38,38 +53,58 @@ typedef enum {
3853
ETH_PLUGIN_RESULT_SUCCESSFUL = 0x03, // Used for comparison
3954
ETH_PLUGIN_RESULT_OK = 0x04,
4055
ETH_PLUGIN_RESULT_OK_ALIAS = 0x05,
41-
ETH_PLUGIN_RESULT_FALLBACK = 0x06
42-
56+
ETH_PLUGIN_RESULT_FALLBACK = 0x06,
4357
} eth_plugin_result_t;
4458

45-
typedef enum {
4659

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
4765
ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01,
48-
ETH_UI_TYPE_GENERIC = 0x02
4966

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,
5072
} eth_ui_type_t;
5173

52-
typedef void (*PluginCall)(int, void *);
53-
54-
// Shared objects, read-write
5574

56-
typedef struct ethPluginSharedRW_t {
75+
// Scratch objects and utilities available to the plugin READ-WRITE
76+
typedef struct ethPluginSharedRW_s {
5777
cx_sha3_t *sha3;
58-
5978
} ethPluginSharedRW_t;
6079

61-
// Shared objects, read-only
6280

63-
typedef struct ethPluginSharedRO_t {
81+
// Transaction data available to the plugin READ-ONLY
82+
typedef struct ethPluginSharedRO_s {
6483
txContent_t *txContent;
65-
6684
} ethPluginSharedRO_t;
6785

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+
68103
// Init Contract
69104

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;
73108

74109
// in
75110
ethPluginSharedRW_t *pluginSharedRW;
@@ -82,26 +117,30 @@ typedef struct ethPluginInitContract_t {
82117
char *alias; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set
83118

84119
} ethPluginInitContract_t;
120+
// void handle_init_contract(ethPluginInitContract_t *parameters);
121+
85122

86123
// Provide parameter
87124

88-
typedef struct ethPluginProvideParameter_t {
125+
typedef struct ethPluginProvideParameter_s {
89126
ethPluginSharedRW_t *pluginSharedRW;
90127
ethPluginSharedRO_t *pluginSharedRO;
91-
uint8_t *pluginContext;
128+
uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE
92129
const uint8_t *parameter; // 32 bytes parameter
93130
uint32_t parameterOffset;
94131

95-
uint8_t result;
132+
eth_plugin_result_t result;
96133

97134
} ethPluginProvideParameter_t;
135+
// void handle_provide_parameter(ethPluginProvideParameter_t *parameters);
136+
98137

99138
// Finalize
100139

101-
typedef struct ethPluginFinalize_t {
140+
typedef struct ethPluginFinalize_s {
102141
ethPluginSharedRW_t *pluginSharedRW;
103142
ethPluginSharedRO_t *pluginSharedRO;
104-
uint8_t *pluginContext;
143+
uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE
105144

106145
uint8_t *tokenLookup1; // set by the plugin if a token should be looked up
107146
uint8_t *tokenLookup2;
@@ -110,73 +149,74 @@ typedef struct ethPluginFinalize_t {
110149
const uint8_t *address; // set to the destination address if uiType is UI_AMOUNT_ADDRESS. Set
111150
// to the user's address if uiType is UI_TYPE_GENERIC
112151

113-
uint8_t uiType;
152+
eth_ui_type_t uiType;
114153
uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS
115-
uint8_t result;
154+
eth_plugin_result_t result;
116155

117156
} ethPluginFinalize_t;
157+
// void handle_finalize(ethPluginFinalize_t *parameters);
118158

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
126159

127160
// Provide token
128161

129-
typedef struct ethPluginProvideInfo_t {
162+
typedef struct ethPluginProvideInfo_s {
130163
ethPluginSharedRW_t *pluginSharedRW;
131164
ethPluginSharedRO_t *pluginSharedRO;
132-
uint8_t *pluginContext;
165+
uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE
133166

134167
union extraInfo_t *item1; // set by the ETH application, to be saved by the plugin
135168
union extraInfo_t *item2;
136169

137170
uint8_t additionalScreens; // Used by the plugin if it needs to display additional screens
138171
// based on the information received from the token definitions.
139172

140-
uint8_t result;
173+
eth_plugin_result_t result;
141174

142175
} ethPluginProvideInfo_t;
176+
// void handle_provide_token(ethPluginProvideInfo_t *parameters);
177+
143178

144179
// Query Contract name and version
145180

146181
// This is always called on the non aliased contract
147182

148-
typedef struct ethQueryContractID_t {
183+
typedef struct ethQueryContractID_s {
149184
ethPluginSharedRW_t *pluginSharedRW;
150185
ethPluginSharedRO_t *pluginSharedRO;
151-
uint8_t *pluginContext;
186+
uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE
152187

153188
char *name;
154189
size_t nameLength;
155190
char *version;
156191
size_t versionLength;
157192

158-
uint8_t result;
193+
eth_plugin_result_t result;
159194

160195
} ethQueryContractID_t;
196+
// void handle_query_contract_id(ethQueryContractID_t *parameters);
197+
161198

162199
// Query Contract UI
163200

164-
typedef struct ethQueryContractUI_t {
201+
typedef struct ethQueryContractUI_s {
165202
ethPluginSharedRW_t *pluginSharedRW;
166203
ethPluginSharedRO_t *pluginSharedRO;
167204
union extraInfo_t *item1;
168205
union extraInfo_t *item2;
169206
char network_ticker[MAX_TICKER_LEN];
170-
uint8_t *pluginContext;
207+
uint8_t *pluginContext; // PLUGIN_CONTEXT_SIZE
171208
uint8_t screenIndex;
172209

173210
char *title;
174211
size_t titleLength;
175212
char *msg;
176213
size_t msgLength;
177214

178-
uint8_t result;
215+
eth_plugin_result_t result;
179216

180217
} ethQueryContractUI_t;
218+
// void handle_query_contract_ui(ethQueryContractUI_t *parameters);
181219

182220
#endif // _ETH_PLUGIN_INTERFACE_H_
221+
222+
// clang-format on

standard_plugin.mk

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ****************************************************************************
2+
# Ledger Ethereum Plugin SDK
3+
# (c) 2023 Ledger SAS.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# ****************************************************************************
17+
18+
ifeq ($(BOLOS_SDK),)
19+
$(error Environment variable BOLOS_SDK is not set)
20+
endif
21+
22+
# Prevent compilation of BAGL/NBGL
23+
# Has to be before any SDK include
24+
DISABLE_UI = 1
25+
26+
include $(BOLOS_SDK)/Makefile.defines
27+
28+
APPVERSION ?= "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"
29+
30+
# Application source files
31+
APP_SOURCE_PATH += src ethereum-plugin-sdk
32+
33+
# Application icons following guidelines:
34+
# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon
35+
NORMAL_NAME ?= $(shell echo -n "$(APPNAME)" | tr " ." "_" | tr "[:upper:]" "[:lower:]")
36+
ICON_NANOS = icons/nanos_app_$(NORMAL_NAME).gif
37+
ICON_NANOX = icons/nanox_app_$(NORMAL_NAME).gif
38+
ICON_NANOSP = $(ICON_NANOX)
39+
ICON_STAX = icons/stax_app_$(NORMAL_NAME).gif
40+
41+
ifeq ($(TARGET_NAME),TARGET_STAX)
42+
DEFINES += ICONGLYPH=C_stax_$(NORMAL_NAME)_64px
43+
DEFINES += ICONBITMAP=C_stax_$(NORMAL_NAME)_64px_bitmap
44+
endif
45+
46+
CURVE_APP_LOAD_PARAMS = secp256k1
47+
48+
PATH_APP_LOAD_PARAMS ?= "44'/60'"
49+
50+
VARIANT_PARAM = COIN
51+
VARIANTS_VALUES ?= $(NORMAL_NAME)
52+
53+
HAVE_APPLICATION_FLAG_LIBRARY = 1
54+
55+
DISABLE_STANDARD_APP_FILES = 1
56+
DISABLE_STANDARD_SNPRINTF = 1
57+
DISABLE_STANDARD_USB = 1
58+
DISABLE_STANDARD_WEBUSB = 1
59+
DISABLE_STANDARD_BAGL_UX_FLOW = 1
60+
61+
# Required for PRINTFs to compile
62+
ifeq ($(DEBUG),0)
63+
DISABLE_STANDARD_SEPROXYHAL = 1
64+
endif
65+
66+
# So the plugin can still access the necessary NBGL types and pass its icon to
67+
# the Ethereum app
68+
ifeq ($(TARGET_NAME),TARGET_STAX)
69+
DEFINES += HAVE_NBGL
70+
INCLUDES_PATH += $(BOLOS_SDK)/lib_nbgl/include $(BOLOS_SDK)/lib_ux_stax
71+
endif
72+
73+
include $(BOLOS_SDK)/Makefile.standard_app

0 commit comments

Comments
 (0)