Skip to content

Commit

Permalink
Merge pull request #95 from Zondax/update_zxlib
Browse files Browse the repository at this point in the history
Update zxlib
  • Loading branch information
jleni authored Mar 6, 2022
2 parents 1d8ea32 + f0fcec8 commit 25578dd
Show file tree
Hide file tree
Showing 43 changed files with 1,562 additions and 955 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ endif

APPVERSION_M=0
APPVERSION_N=20
APPVERSION_P=1
APPVERSION_P=2

$(info COIN = [$(COIN)])
ifeq ($(COIN),FIL)
Expand Down
3 changes: 1 addition & 2 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void extractHDPath(uint32_t rx, uint32_t offset) {
}
}

bool process_chunk(volatile uint32_t *tx, uint32_t rx) {
UNUSED(tx);
bool process_chunk(volatile uint32_t *tx, __Z_UNUSED uint32_t rx) {

const uint8_t payloadType = G_io_apdu_buffer[OFFSET_PAYLOAD_TYPE];

Expand Down
6 changes: 2 additions & 4 deletions app/src/common/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ static bool tx_initialized = false;

unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

unsigned char io_event(unsigned char channel) {
UNUSED(channel);
unsigned char io_event(__Z_UNUSED unsigned char channel) {

switch (G_io_seproxyhal_spi_buffer[0]) {
case SEPROXYHAL_TAG_FINGER_EVENT: //
Expand Down Expand Up @@ -96,8 +95,7 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
return 0;
}

void handle_generic_apdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
UNUSED(flags);
void handle_generic_apdu(__Z_UNUSED volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {

if (rx > 4 && MEMCMP(G_io_apdu_buffer, "\xE0\x01\x00\x00", 4) == 0) {
// Respond to get device info command
Expand Down
8 changes: 3 additions & 5 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,15 @@ parser_error_t _read(const parser_context_t *c, parser_tx_t *v) {
return parser_ok;
}

parser_error_t _validateTx(const parser_context_t *c, const parser_tx_t *v) {
(void) c;
(void) v;
parser_error_t _validateTx(__Z_UNUSED const parser_context_t *c, __Z_UNUSED const parser_tx_t *v) {
// Note: This is place holder for transaction level checks that the project may require before accepting
// the parsed values. the parser already validates input
// This function is called by parser_validate, where additional checks are made (formatting, UI/UX, etc.(
return parser_ok;
}

uint8_t _getNumItems(const parser_context_t *c, const parser_tx_t *v) {
UNUSED(c);
uint8_t _getNumItems(__Z_UNUSED const parser_context_t *c, const parser_tx_t *v) {

uint8_t itemCount = 8;

return itemCount + v->numparams;
Expand Down
19 changes: 0 additions & 19 deletions deps/ledger-zxlib/.circleci/config.yml

This file was deleted.

29 changes: 29 additions & 0 deletions deps/ledger-zxlib/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Test/Build"
on:
workflow_dispatch:
push:
pull_request:
branches: [ main ]

jobs:
configure:
runs-on: ubuntu-latest
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"

build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Install deps
run: |
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
brew install conan
conan config install https://github.com/conan-io/conanclientcert.git
- run: cmake -DCMAKE_BUILD_TYPE=Debug . && make
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ledger-zxlib

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![CircleCI](https://circleci.com/gh/Zondax/ledger-zxlib/tree/master.svg?style=shield)](https://circleci.com/gh/Zondax/ledger-zxlib/tree/master)
[![GithubActions](https://github.com/zondax/ledger-zxlib/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-zxlib/blob/main/.github/workflows/main.yaml)
[![CodeFactor](https://www.codefactor.io/repository/github/zondax/ledger-zxlib/badge)](https://www.codefactor.io/repository/github/zondax/ledger-zxlib)
16 changes: 15 additions & 1 deletion deps/ledger-zxlib/app/common/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void h_error_accept(__Z_UNUSED unsigned int _) {
app_reply_error();
}

void h_initialize(__Z_UNUSED unsigned int _) {
view_idle_show(0, NULL);
UX_WAIT();
}

///////////////////////////////////
// Paging related

Expand Down Expand Up @@ -178,13 +183,22 @@ void h_review_action() {
return;
}
#endif
};
}

zxerr_t h_review_update_data() {
if (viewdata.viewfuncGetNumItems == NULL) {
zemu_log_stack("h_review_update_data - GetNumItems==NULL");
return zxerr_no_data;
}
if (viewdata.viewfuncGetItem == NULL) {
zemu_log_stack("h_review_update_data - GetItem==NULL");
return zxerr_no_data;
}

if (viewdata.viewfuncGetItem == NULL) {
zemu_log_stack("h_review_update_data - GetItem==NULL");
return zxerr_no_data;
}

if (viewdata.viewfuncGetItem == NULL) {
zemu_log_stack("h_review_update_data - GetItem==NULL");
Expand Down
3 changes: 3 additions & 0 deletions deps/ledger-zxlib/app/common/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ zxerr_t secret_enabled();
/// view_init (initializes UI)
void view_init();

/// view_initialize_show (idle view - main menu + status)
void view_initialize_show(uint8_t item_idx, char *statusString);

/// view_idle_show (idle view - main menu + status)
void view_idle_show(uint8_t item_idx, char *statusString);

Expand Down
8 changes: 6 additions & 2 deletions deps/ledger-zxlib/app/common/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@

#define CUR_FLOW G_ux.flow_stack[G_ux.stack_count-1]

#if defined(TARGET_NANOX)
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#define MAX_CHARS_PER_KEY_LINE 64
#define MAX_CHARS_PER_VALUE1_LINE 4096
#define MAX_CHARS_HEXMESSAGE 160
#else
#define MAX_CHARS_PER_KEY_LINE (17+1)
#ifndef MAX_CHARS_PER_VALUE_LINE
#define MAX_CHARS_PER_VALUE_LINE (17)
#endif
#define MAX_CHARS_PER_KEY_LINE (MAX_CHARS_PER_VALUE_LINE+1)
#define MAX_CHARS_PER_VALUE1_LINE (2*MAX_CHARS_PER_VALUE_LINE+1)
#define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE+1)
#define MAX_CHARS_HEXMESSAGE 40
Expand Down Expand Up @@ -100,6 +102,8 @@ max_char_display get_max_char_per_line();
///////////////////////////////////////////////
///////////////////////////////////////////////

void view_initialize_show_impl(uint8_t item_idx, char *statusString);

void view_idle_show_impl(uint8_t item_idx, char *statusString);

void view_message_impl(char *title, char *message);
Expand Down
43 changes: 34 additions & 9 deletions deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
#include "bagl.h"
#include "zxmacros.h"
#include "view_templates.h"
#include "zxutils_ledger.h"

#include <string.h>
#include <stdio.h>

#if defined(TARGET_NANOS)

void h_initialize();

#define BAGL_WIDTH 128
#define BAGL_HEIGHT 32
#define BAGL_WIDTH_MARGIN 10

void h_expert_toggle();
void h_expert_update();
void h_review_button_left();
Expand Down Expand Up @@ -66,6 +73,17 @@ const ux_menu_entry_t menu_main[] = {
UX_MENU_END
};

const ux_menu_entry_t menu_initialize[] = {
{NULL, NULL, 0, &C_icon_app, MENU_MAIN_APP_LINE1, viewdata.key, 33, 12},
{NULL, h_initialize, 0, &C_icon_app, "Click to", "Initialize", 33, 12},
{NULL, h_expert_toggle, 0, &C_icon_app, "Expert mode:", viewdata.value, 33, 12},
{NULL, NULL, 0, &C_icon_app, APPVERSION_LINE1, APPVERSION_LINE2, 33, 12},
{NULL, NULL, 0, &C_icon_app, "Developed by:", "Zondax.ch", 33, 12},
{NULL, NULL, 0, &C_icon_app, "License: ", "Apache 2.0", 33, 12},
{NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29},
UX_MENU_END
};

static const bagl_element_t view_message[] = {
UI_BACKGROUND,
UI_LabelLine(UIID_LABEL + 0, 0, 8, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, viewdata.key),
Expand Down Expand Up @@ -200,13 +218,13 @@ void splitValueField() {
void splitValueAddress() {
uint8_t len = MAX_CHARS_PER_VALUE_LINE;
bool exceeding_max = exceed_pixel_in_display(len);
while(exceeding_max) {
len--;
while(exceeding_max && len--) {
exceeding_max = exceed_pixel_in_display(len);
}
print_value2("");
const uint16_t vlen = strlen(viewdata.value);
if (vlen > len) {
//if viewdata.value == NULL --> len = 0
if (vlen > len && len > 0) {
snprintf(viewdata.value2, MAX_CHARS_PER_VALUE2_LINE, "%s", viewdata.value + len);
viewdata.value[len] = 0;
}
Expand All @@ -215,18 +233,15 @@ void splitValueAddress() {
max_char_display get_max_char_per_line() {
uint8_t len = MAX_CHARS_PER_VALUE_LINE;
bool exceeding_max = exceed_pixel_in_display(len);
while(exceeding_max) {
len--;
while(exceeding_max && len--) {
exceeding_max = exceed_pixel_in_display(len);
}
//MAX_CHARS_PER_VALUE1_LINE is defined this way
return 2 * len + 1;
return (len > 0) ? (2 * len + 1) : len;
}

bool exceed_pixel_in_display(const uint8_t length) {
unsigned short strWidth = bagl_compute_line_width((BAGL_FONT_OPEN_SANS_EXTRABOLD_11px
| BAGL_FONT_ALIGNMENT_CENTER |BAGL_FONT_ALIGNMENT_MIDDLE),
200, viewdata.value, length, BAGL_ENCODING_LATIN1);
const unsigned short strWidth = zx_compute_line_width_light(viewdata.value, length);
return (strWidth >= (BAGL_WIDTH - BAGL_WIDTH_MARGIN));
}

Expand All @@ -236,6 +251,16 @@ bool exceed_pixel_in_display(const uint8_t length) {
//////////////////////////
//////////////////////////

void view_initialize_show_impl(uint8_t item_idx, char *statusString) {
if (statusString == NULL ) {
snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", MENU_MAIN_APP_LINE2);
} else {
snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", statusString);
}
h_expert_update();
UX_MENU_DISPLAY(item_idx, menu_initialize, NULL);
}

void view_idle_show_impl(uint8_t item_idx, char *statusString) {
if (statusString == NULL ) {
snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", MENU_MAIN_APP_LINE2);
Expand Down
23 changes: 21 additions & 2 deletions deps/ledger-zxlib/app/common/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <string.h>
#include <stdio.h>

#if defined(TARGET_NANOX)
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)

void h_expert_toggle();
void h_expert_update();
Expand Down Expand Up @@ -76,6 +76,15 @@ const ux_flow_step_t *const ux_idle_flow [] = {

///////////

UX_STEP_NOCB(ux_message_flow_1_step, pbb, { &C_icon_app, viewdata.key, viewdata.value,});

UX_FLOW(
ux_message_flow,
&ux_message_flow_1_step
);

///////////

UX_STEP_NOCB(ux_error_flow_1_step, bnnn_paging, { .title = viewdata.key, .text = viewdata.value, });
UX_STEP_VALID(ux_error_flow_2_step, pb, h_error_accept(0), { &C_icon_validate_14, "Ok"});

Expand Down Expand Up @@ -235,7 +244,7 @@ void h_secret_click() {
//////////////////////////
//////////////////////////

void view_idle_show_impl(uint8_t item_idx, char *statusString) {
void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, char *statusString) {
if (statusString == NULL ) {
if (app_mode_secret()) {
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", MENU_MAIN_APP_LINE2_SECRET);
Expand Down Expand Up @@ -263,6 +272,16 @@ void view_review_show_impl(){
ux_flow_init(0, ux_review_flow, NULL);
}

void view_message_impl(char *title, char *message) {
snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", title);
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", message);
ux_layout_bnnn_paging_reset();
if(G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_message_flow, NULL);
}

void view_error_show_impl() {
ux_layout_bnnn_paging_reset();
if(G_ux.stack_count == 0) {
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/cmake/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ add_subdirectory(
${CMAKE_BINARY_DIR}/googletest-build
)

if (CMAKE_VERSION VERSION_LESS 2.8.11)
if (CMAKE_VERSION VERSION_LESS 3.0.0)
include_directories("${gtest_SOURCE_DIR}/include")
endif ()
4 changes: 2 additions & 2 deletions deps/ledger-zxlib/cmake/gtest/CMakeLists.txt.gtest.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Based on https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
cmake_minimum_required(VERSION 2.8.2)
cmake_minimum_required(VERSION 3.0.0)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
GIT_TAG release-1.11.0
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
Expand Down
4 changes: 2 additions & 2 deletions deps/ledger-zxlib/dockerized_build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ delete:

.PHONY: loadX
loadX:
${LEDGER_SRC}/pkg/installer_x.sh load
${LEDGER_SRC}/pkg/installer_XL.sh load

.PHONY: deleteX
deleteX:
${LEDGER_SRC}/pkg/installer_x.sh delete
${LEDGER_SRC}/pkg/installer_XL.sh delete

.PHONY: show_info_recovery_mode
show_info_recovery_mode:
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/include/segwit_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int bech32_encode(
* data_len: Pointer to a size_t that will be updated to be the number
* of entries in data.
* In: input: Pointer to a null-terminated Bech32 string.
* Returns 1 if succesful.
* Returns 1 if successful.
*/
int bech32_decode(
char *hrp,
Expand Down
Loading

0 comments on commit 25578dd

Please sign in to comment.