Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #116 from Zondax/dev
Browse files Browse the repository at this point in the history
update zxlib
  • Loading branch information
jleni authored Nov 11, 2021
2 parents 912053d + fd4d5a5 commit ef4acd0
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 50 deletions.
2 changes: 2 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else
# Assume Nano S
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=32
DEFINES += BAGL_WIDTH_MARGIN=10
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
endif

Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=7
# This is the `spec_version` field of `Runtime`
APPVERSION_N=9122
# This is the patch version of this release
APPVERSION_P=0
APPVERSION_P=1
16 changes: 12 additions & 4 deletions deps/ledger-zxlib/app/common/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,31 @@ zxerr_t h_review_update_data() {
#endif

do {
viewdata.pageCount = 1;
CHECK_ZXERR(viewdata.viewfuncGetNumItems(&viewdata.itemCount))

// be sure we are not out of bounds
//Verify how many chars fit in display (nanos)
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, MAX_CHARS_PER_VALUE1_LINE,
0, &viewdata.pageCount))
viewdata.pageCount = 1;
const max_char_display dyn_max_char_per_line1 = get_max_char_per_line();

// be sure we are not out of bounds
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, dyn_max_char_per_line1,
0, &viewdata.pageCount))
if (viewdata.pageCount != 0 && viewdata.pageIdx > viewdata.pageCount) {
// try again and get last page
viewdata.pageIdx = viewdata.pageCount - 1;
}
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, MAX_CHARS_PER_VALUE1_LINE,
viewdata.value, dyn_max_char_per_line1,
viewdata.pageIdx, &viewdata.pageCount))

viewdata.itemCount++;
Expand All @@ -249,7 +257,7 @@ zxerr_t h_review_update_data() {
}
} while (viewdata.pageCount == 0);

splitValueField();
splitValueAddress();
return zxerr_ok;
}

Expand Down
4 changes: 4 additions & 0 deletions deps/ledger-zxlib/app/common/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
#if defined(TARGET_NANOS)
#define INCLUDE_ACTIONS_AS_ITEMS 2
#define INCLUDE_ACTIONS_COUNT (INCLUDE_ACTIONS_AS_ITEMS-1)
typedef uint8_t max_char_display;
#else
#define INCLUDE_ACTIONS_COUNT 0
typedef int max_char_display;
#endif

typedef struct {
Expand Down Expand Up @@ -86,6 +88,8 @@ extern view_t viewdata;
#endif

void splitValueField();
void splitValueAddress();
max_char_display get_max_char_per_line();

///////////////////////////////////////////////
///////////////////////////////////////////////
Expand Down
34 changes: 33 additions & 1 deletion deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "bagl.h"
#include "zxmacros.h"
#include "view_templates.h"
#include "zxutils_ledger.h"

#include <string.h>
#include <stdio.h>
Expand All @@ -35,6 +36,8 @@ void h_review_button_left();
void h_review_button_right();
void h_review_button_both();

bool exceed_pixel_in_display(const uint8_t length);

#ifdef APP_SECRET_MODE_ENABLED
void h_secret_click();
#endif
Expand Down Expand Up @@ -189,12 +192,41 @@ void h_review_button_both() {

void splitValueField() {
print_value2("");
uint16_t vlen = strlen(viewdata.value);
const uint16_t vlen = strlen(viewdata.value);
if (vlen > MAX_CHARS_PER_VALUE2_LINE - 1) {
snprintf(viewdata.value2, MAX_CHARS_PER_VALUE2_LINE, "%s", viewdata.value + MAX_CHARS_PER_VALUE_LINE);
viewdata.value[MAX_CHARS_PER_VALUE_LINE] = 0;
}
}
void splitValueAddress() {
uint8_t len = MAX_CHARS_PER_VALUE_LINE;
bool exceeding_max = exceed_pixel_in_display(len);
while(exceeding_max && len--) {
exceeding_max = exceed_pixel_in_display(len);
}
print_value2("");
const uint16_t vlen = strlen(viewdata.value);
//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;
}
}

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--) {
exceeding_max = exceed_pixel_in_display(len);
}
//MAX_CHARS_PER_VALUE1_LINE is defined this way
return (len > 0) ? (2 * len + 1) : len;
}

bool exceed_pixel_in_display(const uint8_t length) {
const unsigned short strWidth = zx_compute_line_width_light(viewdata.value, length);
return (strWidth >= (BAGL_WIDTH - BAGL_WIDTH_MARGIN));
}

//////////////////////////
//////////////////////////
Expand Down
9 changes: 8 additions & 1 deletion deps/ledger-zxlib/app/common/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "zxmacros.h"
#include "view_templates.h"
#include "tx.h"
#include "view_internal.h"

#ifdef APP_SECRET_MODE_ENABLED
#include "secret.h"
Expand Down Expand Up @@ -187,6 +186,14 @@ void splitValueField() {
}
}

void splitValueAddress() {
splitValueField();
}

max_char_display get_max_char_per_line() {
return MAX_CHARS_PER_VALUE1_LINE;
}

void h_expert_toggle() {
app_mode_set_expert(!app_mode_expert());
ux_flow_init(0, ux_idle_flow, &ux_idle_flow_2_step);
Expand Down
44 changes: 3 additions & 41 deletions deps/ledger-zxlib/include/zxformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ __Z_INLINE int64_t str_to_int64(const char *start, const char *end, char *error)
}

int64_t value = 0;
int64_t multiplier = 1;
uint64_t multiplier = 1;
for (const char *s = end - 1; s >= start; s--) {
int64_t delta = (*s - '0');
int delta = (*s - '0');
if (delta >= 0 && delta <= 9) {
value += delta * multiplier;
value += (delta * multiplier);
multiplier *= 10;
} else {
if (error != NULL) {
Expand Down Expand Up @@ -320,44 +320,6 @@ __Z_INLINE void pageString(char *outValue, uint16_t outValueLen,
pageStringExt(outValue, outValueLen, inValue, (uint16_t) strlen(inValue), pageIdx, pageCount);
}

__Z_INLINE zxerr_t formatBufferData(
const uint8_t *ptr,
uint64_t len,
char *outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount) {
char bufferUI[500 + 1];
MEMZERO(bufferUI, sizeof(bufferUI));
MEMZERO(outValue, 0);
CHECK_APP_CANARY();

if (len >= sizeof(bufferUI)) {
return zxerr_buffer_too_small;
}
memcpy(bufferUI, ptr, len);

// Check we have all ascii
uint8_t allAscii = 1;
for (size_t i = 0; i < len && allAscii; i++) {
if (bufferUI[i] < 32 || bufferUI[i] > 127) {
allAscii = 0;
}
}

if (!allAscii) {
bufferUI[0] = '0';
bufferUI[1] = 'x';
if (array_to_hexstr(bufferUI + 2, sizeof(bufferUI) - 2, ptr, len) == 0) {
return zxerr_buffer_too_small;
}
}

pageString(outValue, outValueLen, bufferUI, pageIdx, pageCount);

return zxerr_ok;
}

size_t asciify(char *utf8_in);

size_t asciify_ext(const char *utf8_in, char *ascii_only_out);
Expand Down
12 changes: 12 additions & 0 deletions deps/ledger-zxlib/include/zxutils_ledger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

unsigned short zx_compute_line_width_light(const char* text, unsigned char text_length);


#ifdef __cplusplus
}
#endif
138 changes: 138 additions & 0 deletions deps/ledger-zxlib/src/zxutils_ledger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "zxutils_ledger.h"

#ifndef NULL
#define NULL ((void *)0)
#endif

// We implement a light mecanism in order to be able to retrieve the width of
// nano S characters, in the two possible fonts:
// - BAGL_FONT_OPEN_SANS_EXTRABOLD_11px,
// - BAGL_FONT_OPEN_SANS_REGULAR_11px.
#define NANOS_FIRST_CHAR 0x20
#define NANOS_LAST_CHAR 0x7F

// OPEN_SANS_REGULAR_11PX << 4 | OPEN_SANS_EXTRABOLD_11PX
const char nanos_characters_width[96] = {
3 << 4 | 3, /* code 0020 */
3 << 4 | 3, /* code 0021 */
4 << 4 | 6, /* code 0022 */
7 << 4 | 7, /* code 0023 */
6 << 4 | 6, /* code 0024 */
9 << 4 | 10, /* code 0025 */
8 << 4 | 9, /* code 0026 */
2 << 4 | 3, /* code 0027 */
3 << 4 | 4, /* code 0028 */
3 << 4 | 4, /* code 0029 */
6 << 4 | 6, /* code 002A */
6 << 4 | 6, /* code 002B */
3 << 4 | 3, /* code 002C */
4 << 4 | 4, /* code 002D */
3 << 4 | 3, /* code 002E */
4 << 4 | 5, /* code 002F */
6 << 4 | 8, /* code 0030 */
6 << 4 | 6, /* code 0031 */
6 << 4 | 7, /* code 0032 */
6 << 4 | 7, /* code 0033 */
8 << 4 | 8, /* code 0034 */
6 << 4 | 6, /* code 0035 */
6 << 4 | 8, /* code 0036 */
6 << 4 | 7, /* code 0037 */
6 << 4 | 8, /* code 0038 */
6 << 4 | 8, /* code 0039 */
3 << 4 | 3, /* code 003A */
3 << 4 | 3, /* code 003B */
6 << 4 | 5, /* code 003C */
6 << 4 | 6, /* code 003D */
6 << 4 | 5, /* code 003E */
5 << 4 | 6, /* code 003F */
10 << 4 | 10, /* code 0040 */
7 << 4 | 8, /* code 0041 */
7 << 4 | 7, /* code 0042 */
7 << 4 | 7, /* code 0043 */
8 << 4 | 8, /* code 0044 */
6 << 4 | 6, /* code 0045 */
6 << 4 | 6, /* code 0046 */
8 << 4 | 8, /* code 0047 */
8 << 4 | 8, /* code 0048 */
3 << 4 | 4, /* code 0049 */
4 << 4 | 5, /* code 004A */
7 << 4 | 8, /* code 004B */
6 << 4 | 6, /* code 004C */
10 << 4 | 11, /* code 004D */
8 << 4 | 9, /* code 004E */
9 << 4 | 9, /* code 004F */
7 << 4 | 7, /* code 0050 */
9 << 4 | 9, /* code 0051 */
7 << 4 | 8, /* code 0052 */
6 << 4 | 6, /* code 0053 */
7 << 4 | 6, /* code 0054 */
8 << 4 | 8, /* code 0055 */
7 << 4 | 6, /* code 0056 */
10 << 4 | 11, /* code 0057 */
6 << 4 | 8, /* code 0058 */
6 << 4 | 7, /* code 0059 */
6 << 4 | 7, /* code 005A */
4 << 4 | 5, /* code 005B */
4 << 4 | 5, /* code 005C */
4 << 4 | 5, /* code 005D */
6 << 4 | 7, /* code 005E */
5 << 4 | 6, /* code 005F */
6 << 4 | 7, /* code 0060 */
6 << 4 | 7, /* code 0061 */
7 << 4 | 7, /* code 0062 */
5 << 4 | 6, /* code 0063 */
7 << 4 | 7, /* code 0064 */
6 << 4 | 7, /* code 0065 */
5 << 4 | 6, /* code 0066 */
6 << 4 | 7, /* code 0067 */
7 << 4 | 7, /* code 0068 */
3 << 4 | 4, /* code 0069 */
4 << 4 | 5, /* code 006A */
6 << 4 | 7, /* code 006B */
3 << 4 | 4, /* code 006C */
10 << 4 | 10, /* code 006D */
7 << 4 | 7, /* code 006E */
7 << 4 | 7, /* code 006F */
7 << 4 | 7, /* code 0070 */
7 << 4 | 7, /* code 0071 */
4 << 4 | 5, /* code 0072 */
5 << 4 | 6, /* code 0073 */
4 << 4 | 5, /* code 0074 */
7 << 4 | 7, /* code 0075 */
6 << 4 | 7, /* code 0076 */
9 << 4 | 10, /* code 0077 */
6 << 4 | 7, /* code 0078 */
6 << 4 | 7, /* code 0079 */
5 << 4 | 6, /* code 007A */
4 << 4 | 5, /* code 007B */
6 << 4 | 6, /* code 007C */
4 << 4 | 5, /* code 007D */
6 << 4 | 6, /* code 007E */
7 << 4 | 6, /* code 007F */
};

unsigned short zx_compute_line_width_light(const char* text, unsigned char text_length) {
char current_char;
unsigned short line_width = 0;

if(text == NULL) {
return 0xFFFF;
}

// We parse the characters of the input text on all the input length.
while (text_length--) {
current_char = *text;

if (current_char < NANOS_FIRST_CHAR || current_char > NANOS_LAST_CHAR) {
if (current_char == '\n' || current_char == '\r') {
break;
}
}
else {
// Regular.
line_width += (nanos_characters_width[current_char - NANOS_FIRST_CHAR] >> 0x04) & 0x0F;
}
text++;
}
return line_width;
}
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@zondax/ledger-substrate": "^0.18.0",
"@zondax/zemu": "^0.17.2"
"@zondax/zemu": "^0.18.0"
},
"devDependencies": {
"@types/jest": "^27.0.2",
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-show_address/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-show_address/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-show_address_reject/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-show_address_reject/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-show_address_reject/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests_zemu/tests/sr25519.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const defaultOptions = {
X11: false,
}

jest.setTimeout(60000)
jest.setTimeout(180000)

beforeAll(async () => {
await Zemu.checkAndPullImage()
Expand Down

0 comments on commit ef4acd0

Please sign in to comment.