Skip to content

Commit

Permalink
Merge pull request #12 from LedgerHQ/ui-improvements
Browse files Browse the repository at this point in the history
Ui improvements
  • Loading branch information
TamtamHero authored Sep 10, 2020
2 parents d85816a + d1d1557 commit 10b5ba1
Show file tree
Hide file tree
Showing 37 changed files with 1,284 additions and 732 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/dep
/obj
*.swp
/src/glyphs.*
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include $(BOLOS_SDK)/Makefile.glyphs
# Main app configuration

APPNAME = "Algorand"
APPVERSION = 1.0.8
APPVERSION = 1.2.8
APP_LOAD_PARAMS = --appFlags 0x250 $(COMMON_LOAD_PARAMS)
APP_LOAD_PARAMS += --path "44'/283'"

Expand All @@ -22,16 +22,16 @@ endif
# Build configuration

APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f lib_ux

DEFINES += APPVERSION=\"$(APPVERSION)\"

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += HAVE_UX_FLOW

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_UX_LEGACY
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else ifeq ($(TARGET_NAME),TARGET_NANOX)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
Expand All @@ -45,10 +45,7 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW

SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux
else
$(error unknown device TARGET_NAME)
endif
Expand Down Expand Up @@ -94,13 +91,13 @@ $(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
endif

CC := $(CLANGPATH)clang
CFLAGS += -O3 -Oz
CFLAGS += -O3 -Os

AS := $(GCCPATH)arm-none-eabi-gcc
AFLAGS +=

LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -O3 -Oz
LDFLAGS += -O3 -Os
LDLIBS += -lm -lgcc -lc

# Main rules
Expand Down
2 changes: 1 addition & 1 deletion cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*.pyc
/*.pyc
Binary file added glyphs/icon_back.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_back_x.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_certificate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_eye.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_toggle_reset.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_toggle_set.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glyphs/icon_warning.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/algo_asa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "os.h"
#include "algo_asa.h"


#define ARRAY_SIZE(__arr) (sizeof(__arr) / sizeof(__arr[0]))

#define ALGO_ASA(__id, __name, __unit, __decimals) { \
.assetId = __id, \
.decimals = __decimals, \
.unit = __unit, \
.name = __name, \
}


static const algo_asset_info_t algo_assets[] = {
ALGO_ASA(438840, "Micro-Tesla", "M-TSLA", 0),
ALGO_ASA(438839, "Micro-Apple", "M-AAPL", 0),
ALGO_ASA(438838, "Micro-Google", "M-GOOGL", 0),
ALGO_ASA(438837, "Micro-Netflix", "M-NFLX", 0),
ALGO_ASA(438836, "Micro-Twitter", "M-TWTR", 0),
ALGO_ASA(438833, "Micro-Amazon", "M-AMZN", 0),
ALGO_ASA(438832, "Micro-Microsoft", "M-MSFT", 0),
ALGO_ASA(438831, "MESE Index Fund", "MESX", 6),
ALGO_ASA(438828, "MESE USD Exchange Token", "USD-MESE", 6),
ALGO_ASA(312769, "Tether USDt", "USDt", 6),
ALGO_ASA(163650, "Asia Reserve Currency Coin", "ARCC", 6),
};


const algo_asset_info_t *
algo_asa_get(uint64_t id)
{
const algo_asset_info_t *p;
const algo_asset_info_t *endp = algo_assets + ARRAY_SIZE(algo_assets);

for (p = algo_assets; p && p < endp; p++) {
if (p->assetId == id) {
return p;
}
}
return NULL;
}

17 changes: 17 additions & 0 deletions src/algo_asa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __ALGO_ASA_H__
#define __ALGO_ASA_H__

#define __packed __attribute__((packed))


typedef struct {
uint64_t assetId;
uint8_t decimals;
const char unit[15];
const char name[32];
} __packed algo_asset_info_t;


const algo_asset_info_t *algo_asa_get(uint64_t id);

#endif
18 changes: 16 additions & 2 deletions src/algo_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
void
algorand_key_derive(uint32_t accountId, cx_ecfp_private_key_t *privateKey)
{
static uint8_t privateKeyData[64];
static uint32_t bip32Path[5];
uint8_t privateKeyData[64];
uint32_t bip32Path[5];

bip32Path[0] = 44 | 0x80000000;
bip32Path[1] = 283 | 0x80000000;
Expand Down Expand Up @@ -51,3 +51,17 @@ algorand_public_key(const cx_ecfp_private_key_t *privateKey, uint8_t *buf)
}
return 32;
}

size_t fetch_public_key(uint32_t accountId, uint8_t* pubkey){
if(!current_pubkey.initialized ||
current_pubkey.accountID != accountId){
cx_ecfp_private_key_t privateKey;
algorand_key_derive(accountId, &privateKey);
algorand_public_key(&privateKey, current_pubkey.pubkey);
memset(&privateKey, 0, sizeof(privateKey));
current_pubkey.accountID = accountId;
current_pubkey.initialized = true;
}
memcpy(pubkey, current_pubkey.pubkey, sizeof(current_pubkey.pubkey));
return sizeof(current_pubkey.pubkey);
}
11 changes: 10 additions & 1 deletion src/algo_keys.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#include "cx.h"
#include "stdbool.h"

typedef struct{
bool initialized;
uint32_t accountID;
uint8_t pubkey[32];
} already_computed_key_t;

extern already_computed_key_t current_pubkey;

void algorand_key_derive(uint32_t accountId, cx_ecfp_private_key_t *privateKey);
size_t algorand_public_key(const cx_ecfp_private_key_t *privateKey, uint8_t *buf);
size_t fetch_public_key(uint32_t accountId, uint8_t* pubkey);
2 changes: 1 addition & 1 deletion src/algo_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ map_kv_params(uint8_t **p, uint8_t *e, char *key, struct asset_params *params)
}

unsigned int
tx_encode(struct txn *t, uint8_t *buf, int buflen)
tx_encode(txn_t *t, uint8_t *buf, int buflen)
{
char *typestr;
switch (t->type) {
Expand Down
15 changes: 8 additions & 7 deletions src/algo_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct txn_asset_config {
struct asset_params params;
};

struct txn {
typedef struct{
enum TXTYPE type;
// Account Id asscociated with this transaction.
uint32_t accountId;
Expand Down Expand Up @@ -88,23 +88,24 @@ struct txn {
struct txn_asset_freeze asset_freeze;
struct txn_asset_config asset_config;
};
};
} txn_t;

// tx_encode produces a canonical msgpack encoding of a transaction.
// buflen is the size of the buffer. The return value is the length
// of the resulting encoding.
unsigned int tx_encode(struct txn *t, uint8_t *buf, int buflen);
unsigned int tx_encode(txn_t *t, uint8_t *buf, int buflen);

// tx_decode takes a canonical msgpack encoding of a transaction, and
// unpacks it into a struct txn. The return value is NULL for success,
// unpacks it into a txn_t. The return value is NULL for success,
// or a string describing the error on failure. Decoding may or may
// not succeed for a non-canonical encoding.
char* tx_decode(uint8_t *buf, int buflen, struct txn *t);
char* tx_decode(uint8_t *buf, int buflen, txn_t *t);

// We have a global transaction that is the subject of the current
// operation, if any.
extern struct txn current_txn;
extern txn_t current_txn;

// Two callbacks into the main code: approve and deny signing.
void txn_approve();
void txn_deny();
void address_approve();
void user_approval_denied();
2 changes: 1 addition & 1 deletion src/algo_tx_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ decode_asset_params(uint8_t **bufp, uint8_t *buf_end, struct asset_params *res)
}

char*
tx_decode(uint8_t *buf, int buflen, struct txn *t)
tx_decode(uint8_t *buf, int buflen, txn_t *t)
{
char* ret = NULL;
uint8_t* buf_end = buf + buflen;
Expand Down
56 changes: 5 additions & 51 deletions src/algo_ui.h
Original file line number Diff line number Diff line change
@@ -1,62 +1,16 @@
#if defined(TARGET_NANOX)
#include "ux.h"
#endif // TARGET_NANOX

extern char lineBuffer[];
extern char caption[20];
extern char text[128];

void ui_loading();
void ui_idle();
void ui_address();
void ui_address_approval();
void ui_txn();
void ux_approve_txn();

void ui_text_put(const char *msg);
void ui_text_putn(const char *msg, size_t maxlen);
int ui_text_more();

void step_address();

// Override some of the Ledger X UI macros to enable step skipping
#if defined(TARGET_NANOX)

// If going backwards, skip backwards. Otherwise, skip forwards.
#define SKIPEMPTY(stepnum) \
if (stepnum < ux_last_step) { \
ux_flow_prev(); \
} else { \
ux_flow_next(); \
} \
return

#define ALGO_UX_STEP_NOCB_INIT(txtype, stepnum, layoutkind, preinit, ...) \
void txn_flow_ ## stepnum ##_init (unsigned int stack_slot) { \
if (txtype != ALL_TYPES && txtype != current_txn.type) { SKIPEMPTY(stepnum); }; \
if (preinit == 0) { SKIPEMPTY(stepnum); }; \
ux_last_step = stepnum; \
ux_layout_ ## layoutkind ## _init(stack_slot); \
} \
const ux_layout_ ## layoutkind ## _params_t txn_flow_ ## stepnum ##_val = __VA_ARGS__; \
const ux_flow_step_t txn_flow_ ## stepnum = { \
txn_flow_ ## stepnum ## _init, \
& txn_flow_ ## stepnum ## _val, \
NULL, \
NULL, \
}

#define ALGO_UX_STEP(stepnum, layoutkind, preinit, timeout_ms, validate_cb, error_flow, ...) \
UX_FLOW_CALL(txn_flow_ ## stepnum ## _validate, { validate_cb; }) \
void txn_flow_ ## stepnum ##_init (unsigned int stack_slot) { \
preinit; \
ux_last_step = stepnum; \
ux_layout_ ## layoutkind ## _init(stack_slot); \
ux_layout_set_timeout(stack_slot, timeout_ms);\
} \
const ux_layout_ ## layoutkind ## _params_t txn_flow_ ## stepnum ##_val = __VA_ARGS__; \
const ux_flow_step_t txn_flow_ ## stepnum = { \
txn_flow_ ## stepnum ## _init, \
& txn_flow_ ## stepnum ## _val, \
txn_flow_ ## stepnum ## _validate, \
error_flow, \
}

#endif // TARGET_NANOX
#define ALGORAND_PUBLIC_KEY_SIZE 32
#define ALGORAND_DECIMALS 6
Loading

0 comments on commit 10b5ba1

Please sign in to comment.