Skip to content

Commit 6d4cb4f

Browse files
Merge pull request #12 from LedgerHQ/cev/B2CA-1558_Port-Flex
B2CA-1558: Port flex
2 parents 2bf928b + 7899ca3 commit 6d4cb4f

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,3 @@
22

33
This repository is meant to be linked as submodule and used in external plugins working with [app-ethereum](https://github.com/LedgerHQ/app-ethereum).
44
It is composed of a few headers containing definitions about app-ethereum's internal transaction parsing state and some structures to communicate via shared memory.
5-
6-
## Updating this SDK
7-
8-
This SDK is updated at (app-ethereum) build time every time one of app-ethereum internals structures of interest are modified.
9-
If this SDK gets updated, it is possible that all plugins must be recompiled (and eventually updated to work again with the update) with this new SDK.
10-
Be careful, and weight your choices.
11-
12-
## Manual build
13-
14-
If for some reasons you want to rebuild this SDK manually from [app-ethereum](https://github.com/LedgerHQ/app-ethereum) (reminder: it is rebuild automatically when building app-ethereum itself):
15-
16-
```shell
17-
$> ./tools/build_sdk.sh
18-
```

src/common_utils.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@
2323
#include "lcx_ecfp.h"
2424
#include "lcx_sha3.h"
2525

26-
void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
27-
while (len--) {
28-
*strbuf++ = HEXDIGITS[((*((char *) bin)) >> 4) & 0xF];
29-
*strbuf++ = HEXDIGITS[(*((char *) bin)) & 0xF];
30-
bin = (const void *) ((unsigned int) bin + 1);
26+
int array_bytes_string(char *out, size_t outl, const void *value, size_t len) {
27+
if (outl <= 2) {
28+
// Need at least '0x' and 1 digit
29+
return -1;
3130
}
32-
*strbuf = 0; // EOS
31+
if (strlcpy(out, "0x", outl) != 2) {
32+
goto err;
33+
}
34+
if (format_hex(value, len, out + 2, outl - 2) < 0) {
35+
goto err;
36+
}
37+
return 0;
38+
err:
39+
*out = '\0';
40+
return -1;
3341
}
3442

3543
uint64_t u64_from_BE(const uint8_t *in, uint8_t size) {
@@ -227,15 +235,15 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65],
227235
}
228236

229237
void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65],
230-
char out[static ADDRESS_LENGTH * 2],
238+
char out[static (ADDRESS_LENGTH * 2) + 1],
231239
uint64_t chainId) {
232240
uint8_t hashAddress[CX_KECCAK_256_SIZE];
233241
CX_ASSERT(cx_keccak_256_hash(raw_pubkey + 1, 64, hashAddress));
234242
getEthAddressStringFromBinary(hashAddress + 12, out, chainId);
235243
}
236244

237245
bool getEthAddressStringFromBinary(uint8_t *address,
238-
char out[static ADDRESS_LENGTH * 2],
246+
char out[static (ADDRESS_LENGTH * 2) + 1],
239247
uint64_t chainId) {
240248
// save some precious stack space
241249
union locals_union {
@@ -287,7 +295,7 @@ bool getEthAddressStringFromBinary(uint8_t *address,
287295
}
288296
}
289297
}
290-
out[40] = '\0';
298+
out[ADDRESS_LENGTH * 2] = '\0';
291299

292300
return true;
293301
}

src/common_utils.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "os.h"
2424
#include "cx.h"
25+
#include "format.h"
2526

2627
#define WEI_TO_ETHER 18
2728

@@ -35,7 +36,17 @@ static const char HEXDIGITS[] = "0123456789abcdef";
3536

3637
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
3738

38-
void array_hexstr(char *strbuf, const void *bin, unsigned int len);
39+
/**
40+
* @deprecated
41+
* See format_hex in SDK
42+
*/
43+
DEPRECATED static inline void array_hexstr(char *strbuf, const void *bin, unsigned int len)
44+
{
45+
// Consider the output buffer is sufficiently large!
46+
format_hex(bin, len, strbuf, (2 * len + 1));
47+
}
48+
49+
int array_bytes_string(char *out, size_t outl, const void *value, size_t len);
3950

4051
uint64_t u64_from_BE(const uint8_t *in, uint8_t size);
4152

@@ -60,11 +71,11 @@ void getEthAddressFromRawKey(const uint8_t raw_pubkey[static 65],
6071
uint8_t out[static ADDRESS_LENGTH]);
6172

6273
void getEthAddressStringFromRawKey(const uint8_t raw_pubkey[static 65],
63-
char out[static ADDRESS_LENGTH * 2],
74+
char out[static (ADDRESS_LENGTH * 2) + 1],
6475
uint64_t chainId);
6576

6677
bool getEthAddressStringFromBinary(uint8_t *address,
67-
char out[static ADDRESS_LENGTH * 2],
78+
char out[static (ADDRESS_LENGTH * 2) + 1],
6879
uint64_t chainId);
6980

7081
bool getEthDisplayableAddress(uint8_t *in, char *out, size_t out_len, uint64_t chainId);

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*****************************************************************************/
1717

1818
#include "eth_plugin_interface.h"
19-
#include "lib_standard_app/swap_lib_calls.h" // RUN_APPLICATION
19+
#include "swap_lib_calls.h" // RUN_APPLICATION
2020

2121
// Functions implemented by the plugin
2222
void handle_init_contract(ethPluginInitContract_t *parameters);

standard_plugin.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ APPVERSION ?= "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"
2525

2626
# Application source files
2727
APP_SOURCE_PATH += src ethereum-plugin-sdk
28+
INCLUDES_PATH += ${BOLOS_SDK}/lib_standard_app
2829

2930
# Application icons following guidelines:
3031
# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon
@@ -33,8 +34,9 @@ ICON_NANOS = icons/nanos_app_$(NORMAL_NAME).gif
3334
ICON_NANOX = icons/nanox_app_$(NORMAL_NAME).gif
3435
ICON_NANOSP = $(ICON_NANOX)
3536
ICON_STAX = icons/stax_app_$(NORMAL_NAME).gif
37+
ICON_FLEX = icons/flex_app_$(NORMAL_NAME).gif
3638

37-
ifeq ($(TARGET_NAME),TARGET_STAX)
39+
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
3840
DEFINES += ICONGLYPH=C_stax_$(NORMAL_NAME)_64px
3941
DEFINES += ICONBITMAP=C_stax_$(NORMAL_NAME)_64px_bitmap
4042
endif

0 commit comments

Comments
 (0)