Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stax porting #59

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: compiled_app_binaries
run_for_devices: '["nanos", "nanox", "nanosp"]'
run_for_devices: '["nanos", "nanox", "nanosp", "stax"]'

ragger_tests:
name: Run ragger tests using the reusable workflow
Expand All @@ -23,7 +23,7 @@ jobs:
with:
download_app_binaries_artifact: compiled_app_binaries
test_dir: tests/python
run_for_devices: '["nanos", "nanox", "nanosp"]'
run_for_devices: '["nanos", "nanox", "nanosp", "stax"]'

job_C_test:
name: C tests
Expand Down
42 changes: 28 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@ endif
include $(BOLOS_SDK)/Makefile.defines

APP_LOAD_PARAMS = --curve ed25519
ifeq ($(TARGET_NAME), TARGET_NANOS)
APP_LOAD_PARAMS += --appFlags 0x800 # APPLICATION_FLAG_LIBRARY
else
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
APP_LOAD_PARAMS += --appFlags 0xa00 # APPLICATION_FLAG_LIBRARY + APPLICATION_FLAG_BOLOS_SETTINGS
fbeutin-ledger marked this conversation as resolved.
Show resolved Hide resolved
else
APP_LOAD_PARAMS += --appFlags 0x800 # APPLICATION_FLAG_LIBRARY
endif
APP_LOAD_PARAMS += --path "44'/501'"
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPNAME = "Solana"
APPVERSION_M = 1
APPVERSION_N = 3
APPVERSION_N = 4
APPVERSION_P = 0
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME=icons/nanos_app_solana.gif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ICONNAME=icons/stax_app_solana.gif
else
ICONNAME=icons/nanox_app_solana.gif
endif
Expand All @@ -59,27 +61,35 @@ DEFINES += APPNAME=\"$(APPNAME)\"
DEFINES += APPVERSION=\"$(APPVERSION)\"
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P)
DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_UX_FLOW HAVE_SPRINTF
DEFINES += HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += BLE_SEGMENT_SIZE=32
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
DEFINES += UNUSED\(x\)=\(void\)x

ifeq ($(TARGET_NAME),TARGET_NANOX)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU
endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_GLO096
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
endif

ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += NBGL_QRCODE
else
DEFINES += HAVE_BAGL HAVE_UX_FLOW
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_GLO096
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
endif
endif

DEBUG = 0
Expand Down Expand Up @@ -118,9 +128,13 @@ LDLIBS += -lm -lgcc -lc
include $(BOLOS_SDK)/Makefile.glyphs

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

ifneq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_ux
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
endif

Expand Down
File renamed without changes
Binary file added glyphs/icon_solana_64x64.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 icons/stax_app_solana.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 6 additions & 33 deletions src/getPubkey.c → src/handle_get_pubkey.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
#include "apdu.h"
#include "getPubkey.h"
#include "os.h"
#include "ux.h"
#include "utils.h"
#include "globals.h"
#include "handle_get_pubkey.h"
#include "sol/printer.h"
#include "ui_api.h"

static uint8_t G_publicKey[PUBKEY_LENGTH];
static char G_publicKeyStr[BASE58_PUBKEY_LENGTH];
char G_publicKeyStr[BASE58_PUBKEY_LENGTH];

void reset_getpubkey_globals(void) {
MEMCLEAR(G_publicKey);
MEMCLEAR(G_publicKeyStr);
}

static uint8_t set_result_get_pubkey() {
uint8_t set_result_get_pubkey(void) {
memcpy(G_io_apdu_buffer, G_publicKey, PUBKEY_LENGTH);
return PUBKEY_LENGTH;
}

//////////////////////////////////////////////////////////////////////

UX_STEP_NOCB(ux_display_public_flow_5_step,
bnnn_paging,
{
.title = "Pubkey",
.text = G_publicKeyStr,
});
UX_STEP_CB(ux_display_public_flow_6_step,
pb,
sendResponse(set_result_get_pubkey(), true, true),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(ux_display_public_flow_7_step,
pb,
sendResponse(0, false, true),
{
&C_icon_crossmark,
"Reject",
});

UX_FLOW(ux_display_public_flow,
&ux_display_public_flow_5_step,
&ux_display_public_flow_6_step,
&ux_display_public_flow_7_step);

void handle_get_pubkey(volatile unsigned int *flags, volatile unsigned int *tx) {
if (!flags || !tx ||
(G_command.instruction != InsDeprecatedGetPubkey &&
Expand All @@ -61,7 +34,7 @@ void handle_get_pubkey(volatile unsigned int *flags, volatile unsigned int *tx)
*tx = set_result_get_pubkey();
THROW(ApduReplySuccess);
} else {
ux_flow_init(0, ux_display_public_flow, NULL);
ui_get_public_key();
*flags |= IO_ASYNCH_REPLY;
}
}
8 changes: 5 additions & 3 deletions src/getPubkey.h → src/handle_get_pubkey.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include "os.h"
#include "cx.h"
#include "globals.h"
#include "sol/printer.h"

#ifndef _GET_PUBKEY_H_
#define _GET_PUBKEY_H_
extern char G_publicKeyStr[BASE58_PUBKEY_LENGTH];

void reset_getpubkey_globals(void);

void handle_get_pubkey(volatile unsigned int *flags, volatile unsigned int *tx);

#endif
uint8_t set_result_get_pubkey(void);
97 changes: 6 additions & 91 deletions src/signMessage.c → src/handle_sign_message.c
Original file line number Diff line number Diff line change
@@ -1,89 +1,15 @@
#include "getPubkey.h"
#include "os.h"
#include "ux.h"
#include "cx.h"
#include "menu.h"
#include "io.h"
#include "utils.h"
#include "handle_swap_sign_transaction.h"

#include "sol/parser.h"
#include "sol/printer.h"
#include "sol/print_config.h"
#include "sol/message.h"
#include "sol/transaction_summary.h"
#include "globals.h"
#include "apdu.h"

#include "handle_swap_sign_transaction.h"

static uint8_t set_result_sign_message() {
uint8_t signature[SIGNATURE_LENGTH];
cx_ecfp_private_key_t privateKey;
BEGIN_TRY {
TRY {
get_private_key_with_seed(&privateKey,
G_command.derivation_path,
G_command.derivation_path_length);
cx_eddsa_sign(&privateKey,
CX_LAST,
CX_SHA512,
G_command.message,
G_command.message_length,
NULL,
0,
signature,
SIGNATURE_LENGTH,
NULL);
memcpy(G_io_apdu_buffer, signature, SIGNATURE_LENGTH);
}
CATCH_OTHER(e) {
THROW(e);
}
FINALLY {
MEMCLEAR(privateKey);
}
}
END_TRY;
return SIGNATURE_LENGTH;
}

//////////////////////////////////////////////////////////////////////

UX_STEP_CB(ux_approve_step,
pb,
sendResponse(set_result_sign_message(), true, true),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(ux_reject_step,
pb,
sendResponse(0, false, true),
{
&C_icon_crossmark,
"Reject",
});
UX_STEP_NOCB_INIT(ux_summary_step,
bnnn_paging,
{
size_t step_index = G_ux.flow_stack[stack_slot].index;
enum DisplayFlags flags = DisplayFlagNone;
if (N_storage.settings.pubkey_display == PubkeyDisplayLong) {
flags |= DisplayFlagLongPubkeys;
}
if (transaction_summary_display_item(step_index, flags)) {
THROW(ApduReplySolanaSummaryUpdateFailed);
}
},
{
.title = G_transaction_summary_title,
.text = G_transaction_summary_text,
});

#define MAX_FLOW_STEPS \
(MAX_TRANSACTION_SUMMARY_ITEMS + 1 /* approve */ \
+ 1 /* reject */ \
+ 1 /* FLOW_END_STEP */ \
)
ux_flow_step_t const *flow_steps[MAX_FLOW_STEPS];
#include "handle_sign_message.h"
#include "ui_api.h"

static int scan_header_for_signer(const uint32_t *derivation_path,
uint32_t derivation_path_length,
Expand Down Expand Up @@ -219,18 +145,7 @@ void handle_sign_message_ui(volatile unsigned int *flags) {
THROW(ApduReplySolanaSummaryFinalizeFailed);
}
} else {
MEMCLEAR(flow_steps);
size_t num_flow_steps = 0;

for (size_t i = 0; i < num_summary_steps; i++) {
flow_steps[num_flow_steps++] = &ux_summary_step;
}

flow_steps[num_flow_steps++] = &ux_approve_step;
flow_steps[num_flow_steps++] = &ux_reject_step;
flow_steps[num_flow_steps++] = FLOW_END_STEP;

ux_flow_init(0, flow_steps, NULL);
start_sign_tx_ui(num_summary_steps);
}
} else {
THROW(ApduReplySolanaSummaryFinalizeFailed);
Expand Down
9 changes: 1 addition & 8 deletions src/signMessage.h → src/handle_sign_message.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#include "os.h"
#include "cx.h"
#include "globals.h"

#ifndef _SIGN_MESSAGE_H_
#define _SIGN_MESSAGE_H_
#pragma once

void handle_sign_message_parse_message(volatile unsigned int *tx);

void handle_sign_message_ui(volatile unsigned int *flags);

#endif
Loading