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

Support for Flex device #227

Merged
merged 7 commits into from
Jul 19, 2024
Merged
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
9 changes: 7 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

DEFAULT_ICON = nanos_$(ICON_NAME).gif
DEFAULT_NANOS_ICON = nanos_$(ICON_NAME).gif
DEFAULT_NBGL_ICON_32 = stax_$(ICON_NAME).gif
DEFAULT_NBGL_ICON_64 = stax_$(ICON_NAME)_64.gif

copy_icon:
cp $(DEFAULT_ICON) glyphs/icon_app.gif
cp $(DEFAULT_NANOS_ICON) glyphs/icon_app.gif
cp $(DEFAULT_NBGL_ICON_32) glyphs/icon_stax_32.gif
cp $(DEFAULT_NBGL_ICON_64) glyphs/icon_stax_64.gif

all: copy_icon

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=100
# This is the `spec_version` field of `Runtime`
APPVERSION_N=0
# This is the patch version of this release
APPVERSION_P=5
APPVERSION_P=6
Binary file added app/flex_icon.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 app/flex_migration.gif
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 app/src/common/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void migrationOk() {

void migrationStartMessage() {
#ifdef MIGRATION_APP
#ifdef TARGET_STAX
#if defined(TARGET_STAX) || defined(TARGET_FLEX)
const review_type_e reviewType = REVIEW_UI;
#else
const review_type_e reviewType = REVIEW_MSG;
Expand Down
4 changes: 2 additions & 2 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern uint16_t blobLen;

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
#define RAM_BUFFER_SIZE 16384 // 16 KiB
#define FLASH_BUFFER_SIZE 16384 // 16 KiB
#elif defined(TARGET_NANOS)
Expand All @@ -44,7 +44,7 @@ typedef struct {
uint8_t buffer[FLASH_BUFFER_SIZE];
} storage_t;

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
storage_t NV_CONST N_appdata_impl __attribute__((aligned(64)));
#define N_appdata (*(NV_VOLATILE storage_t *)PIC(&N_appdata_impl))
#endif
Expand Down
2 changes: 1 addition & 1 deletion app/src/crypto_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
const unsigned char SS58_BLAKE_PREFIX[] = "SS58PRE";
#define SS58_BLAKE_PREFIX_LEN 7

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
#include "cx.h"

cx_err_t ss58hash(const unsigned char *in, unsigned int inLen, unsigned char *out, unsigned int outLen) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/metadata_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "substrate_types.h"
#include "zxmacros.h"

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
#define STACK_SHIFT 20
#define MINIMUM_STACK 400
#else
Expand All @@ -42,7 +42,7 @@ static uint16_t recursionDepthCounter = 0;
* @return parser_error_t Returns parser_running_out_of_stack if stack space is insufficient, otherwise parser_ok.
*/
parser_error_t checkStack() {
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
// NOLINTNEXTLINE(readability-identifier-length): here `p` is fine
void *p = NULL;
const uint32_t availableStack = (uint32_t)((void *)&p) + STACK_SHIFT - (uint32_t)&app_stack_canary;
Expand All @@ -65,7 +65,8 @@ parser_error_t checkStack() {
* @return parser_error_t Always returns parser_ok.
*/
parser_error_t freeStack() {
#if !defined(TARGET_NANOS) && !defined(TARGET_NANOX) && !defined(TARGET_NANOS2) && !defined(TARGET_STAX)
#if !defined(TARGET_NANOS) && !defined(TARGET_NANOX) && !defined(TARGET_NANOS2) && !defined(TARGET_STAX) && \
!defined(TARGET_FLEX)
if (recursionDepthCounter > 0) {
recursionDepthCounter--;
}
Expand Down
Binary file added app/stax_icon_64.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 modified app/stax_migration.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 app/stax_migration_64.gif
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 deps/nanos-secure-sdk
Submodule nanos-secure-sdk updated 1 files
+4 −0 README.md
2 changes: 1 addition & 1 deletion deps/nanosplus-secure-sdk
2 changes: 1 addition & 1 deletion deps/nanox-secure-sdk
Submodule nanox-secure-sdk updated 136 files
2 changes: 1 addition & 1 deletion deps/stax-secure-sdk
Submodule stax-secure-sdk updated 136 files
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@zondax/ledger-js": "^0.10.0",
"@zondax/ledger-substrate": "^0.44.3",
"@zondax/zemu": "^0.49.0"
"@zondax/zemu": "^0.50.1"
},
"devDependencies": {
"@ledgerhq/hw-transport-node-hid": "^6.29.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 tests_zemu/snapshots/fl-mainmenu/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 added tests_zemu/snapshots/fl-mainmenu/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 added tests_zemu/snapshots/fl-mainmenu/00002.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 added tests_zemu/snapshots/fl-mainmenu/00003.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 added tests_zemu/snapshots/fl-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 added tests_zemu/snapshots/fl-mainmenu/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 added tests_zemu/snapshots/fl-mainmenu/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 tests_zemu/snapshots/fl-raw_sign/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 added tests_zemu/snapshots/fl-raw_sign/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 added tests_zemu/snapshots/fl-raw_sign/00002.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 added tests_zemu/snapshots/fl-raw_sign/00003.png
Binary file added tests_zemu/snapshots/fl-raw_sign_hex/00000.png
Binary file added tests_zemu/snapshots/fl-raw_sign_hex/00001.png
Binary file added tests_zemu/snapshots/fl-raw_sign_hex/00002.png
Binary file added tests_zemu/snapshots/fl-raw_sign_hex/00003.png
Binary file added tests_zemu/snapshots/fl-show_address/00000.png
Binary file added tests_zemu/snapshots/fl-show_address/00001.png
Binary file added tests_zemu/snapshots/fl-show_address/00002.png
Binary file added tests_zemu/snapshots/fl-show_address/00003.png
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Binary file modified tests_zemu/snapshots/st-balances_force_transfer_rococo/00000.png
Binary file modified tests_zemu/snapshots/st-balances_force_transfer_rococo/00001.png
Binary file modified tests_zemu/snapshots/st-balances_force_transfer_rococo/00002.png
Diff not rendered.
Binary file modified tests_zemu/snapshots/st-mainmenu/00000.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00001.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00002.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00003.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00005.png
Binary file added tests_zemu/snapshots/st-mainmenu/00006.png
Binary file modified tests_zemu/snapshots/st-migration-mainmenu/00000.png
Binary file modified tests_zemu/snapshots/st-migration-mainmenu/00001.png
Binary file modified tests_zemu/snapshots/st-migration-mainmenu/00002.png
Binary file modified tests_zemu/snapshots/st-raw_sign/00000.png
Binary file modified tests_zemu/snapshots/st-raw_sign/00001.png
Binary file modified tests_zemu/snapshots/st-raw_sign/00002.png
Binary file modified tests_zemu/snapshots/st-raw_sign/00003.png
Binary file modified tests_zemu/snapshots/st-raw_sign_hex/00000.png
Binary file modified tests_zemu/snapshots/st-raw_sign_hex/00001.png
Binary file modified tests_zemu/snapshots/st-raw_sign_hex/00002.png
Binary file modified tests_zemu/snapshots/st-raw_sign_hex/00003.png
Binary file modified tests_zemu/snapshots/st-show_address/00000.png
Binary file modified tests_zemu/snapshots/st-show_address/00001.png
Binary file modified tests_zemu/snapshots/st-show_address/00002.png
Binary file modified tests_zemu/snapshots/st-show_address/00003.png
Binary file modified tests_zemu/snapshots/st-show_address_reject/00000.png
Binary file modified tests_zemu/snapshots/st-show_address_reject/00001.png
Binary file modified tests_zemu/snapshots/st-show_address_reject/00002.png
Binary file modified tests_zemu/snapshots/st-show_address_reject/00003.png
Binary file modified tests_zemu/snapshots/st-show_address_reject/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
6 changes: 5 additions & 1 deletion tests_zemu/tests/common.ts

Large diffs are not rendered by default.

32 changes: 12 additions & 20 deletions tests_zemu/tests/migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
******************************************************************************/

import Zemu, { ButtonKind, ClickNavigation, TouchNavigation } from '@zondax/zemu'
import Zemu, { ButtonKind, ClickNavigation, TouchNavigation, isTouchDevice } from '@zondax/zemu'

import { ASTAR_PATH, defaultOptions, DOT_SS58_PREFIX, migrationModels, PATH } from './common'
import { PolkadotGenericApp } from '@zondax/ledger-substrate'
import { IButton } from '@zondax/zemu/dist/types'
import { IButton, SwipeDirection } from '@zondax/zemu/dist/types'

const polkadot_pk = 'e1b4d72d27b3e91b9b6116555b4ea17138ddc12ca7cdbab30e2e0509bd848419'
const astar_pk = 'cf557b2d2bebf3e14f932fec31d2b3ea776b63eede6658e282c9ab3f27d1287b'
Expand All @@ -29,20 +29,9 @@ describe('Migration', function () {
test.concurrent.each(migrationModels)('main menu + get version', async function (m) {
const sim = new Zemu(m.path)
try {
let migrationStartText = ''
switch (m.name) {
case 'nanos':
migrationStartText = 'Migration'
break;

case 'nanosp':
case 'nanox':
migrationStartText = 'Please'
break;

case 'stax':
migrationStartText = 'Review'
break;
let migrationStartText = 'review'
if (m.name === 'nanos') {
migrationStartText = 'Migration'
}

await sim.start({
Expand All @@ -52,21 +41,24 @@ describe('Migration', function () {
})

let nav = undefined;
if (m.name === 'stax') {
if (isTouchDevice(m.name)) {
const okButton: IButton = {
x: 200,
y: 550,
delay: 0.25,
direction: SwipeDirection.NoSwipe,
};
nav = new TouchNavigation([
ButtonKind.TapContinueButton,
nav = new TouchNavigation(m.name, [
ButtonKind.SwipeContinueButton,
ButtonKind.ConfirmYesButton,
]);
nav.schedule[1].button = okButton;
} else {
nav = new ClickNavigation([4, 0]);
}
await sim.navigate('.', `${m.prefix.toLowerCase()}-migration-mainmenu`, nav.schedule);
const lastIndex = await sim.navigate('.', `${m.prefix.toLowerCase()}-migration-mainmenu`, nav.schedule);
await sim.compareSnapshots('.', `${m.prefix.toLowerCase()}-migration-mainmenu`, lastIndex)

const app = new PolkadotGenericApp(sim.getTransport(), 'dot')

// Verify app version
Expand Down
12 changes: 6 additions & 6 deletions tests_zemu/tests/raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { defaultOptions, DOT_SS58_PREFIX, PATH, models } from './common'
import ed25519 from 'ed25519-supercop'
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'
import { PolkadotGenericApp } from '@zondax/ledger-substrate'
import {ResponseError} from "@zondax/ledger-js";
import { ResponseError } from "@zondax/ledger-js";

jest.setTimeout(180000)

Expand Down Expand Up @@ -72,31 +72,31 @@ describe.each(TESTS)('Raw signing', function (data) {
})
})

test.concurrent.each(models)('raw signing - incorrect', async function (m) {
test.concurrent.each(models)('Raw signing - incorrect', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new PolkadotGenericApp(sim.getTransport(), 'dot')

const txBlob = Buffer.from('<Bytes>Incorrect blob/Bytes>')

let errorFound:any = undefined
let errorFound: any = undefined
try {
await app.signRaw(PATH, txBlob)
} catch (error) {
errorFound = error
}

console.log(errorFound)

expect(errorFound).toBeDefined()
expect('returnCode' in errorFound).toBeTruthy()
expect('errorMessage' in errorFound).toBeTruthy()

if('returnCode' in errorFound){
if ('returnCode' in errorFound) {
expect(errorFound.returnCode).toBe(27012)
}
if('errorMessage' in errorFound){
if ('errorMessage' in errorFound) {
expect(errorFound.errorMessage).toBe("Data is invalid : Unexpected value")
}

Expand Down
6 changes: 3 additions & 3 deletions tests_zemu/tests/standard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
******************************************************************************* */

import Zemu, { ButtonKind, zondaxMainmenuNavigation } from '@zondax/zemu'
import Zemu, { ButtonKind, zondaxMainmenuNavigation, isTouchDevice } from '@zondax/zemu'
import { defaultOptions, DOT_SS58_PREFIX, PATH, models } from './common'
import { PolkadotGenericApp } from '@zondax/ledger-substrate'

Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Standard', function () {
await sim.start({
...defaultOptions,
model: m.name,
approveKeyword: m.name === 'stax' ? 'Public key' : '',
approveKeyword: isTouchDevice(m.name) ? 'Public key' : '',
approveAction: ButtonKind.ApproveTapButton,
})
const app = new PolkadotGenericApp(sim.getTransport(), 'dot', '')
Expand All @@ -112,7 +112,7 @@ describe('Standard', function () {
await sim.start({
...defaultOptions,
model: m.name,
rejectKeyword: m.name === 'stax' ? 'Public key' : '',
rejectKeyword: isTouchDevice(m.name) ? 'Public key' : '',
})
const app = new PolkadotGenericApp(sim.getTransport(), 'dot')

Expand Down
8 changes: 4 additions & 4 deletions tests_zemu/tests/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'
jest.setTimeout(180000)

describe.each(TEST_TRANSACTIONS)('Transactions - OK', function (data) {
test.each(models)(`Test: ${data.name}`, async function (m) {
test.concurrent.each(models)(`Test: ${data.name}`, async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
Expand Down Expand Up @@ -63,13 +63,13 @@ describe.each(TEST_TRANSACTIONS)('Transactions - OK', function (data) {
})

describe.each(TEST_TRANSACTIONS)('Transactions - API - OK', function (data) {
test.each(models)(`Test: ${data.name}`, async function (m) {
test.concurrent.each(models)(`Test: ${data.name}`, async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new PolkadotGenericApp(sim.getTransport(), 'roc', 'https://api.zondax.ch/polkadot/transaction/metadata')

const resp = await axios.post("https://api.zondax.ch/polkadot/node/metadata/hash", {id: 'roc'})
const resp = await axios.post("https://api.zondax.ch/polkadot/node/metadata/hash", { id: 'roc' })
const blob = Buffer.from(data.blob.replace("<rootHash>", resp.data.metadataHash), 'hex')

const { pubKey } = await app.getAddress(PATH, DOT_SS58_PREFIX)
Expand Down Expand Up @@ -100,7 +100,7 @@ describe.each(TEST_TRANSACTIONS)('Transactions - API - OK', function (data) {
})

describe.each(TEST_TRANSACTIONS_FAIL)('Transactions - FAIL', function (data) {
test.each(models)(`Test: ${data.name} - ${data.description}`, async function (m) {
test.concurrent.each(models)(`Test: ${data.name} - ${data.description}`, async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
Expand Down
Loading