Skip to content

Commit

Permalink
support for Stax
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Nov 22, 2023
1 parent a295e45 commit 4ce1033
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "deps/nanos-secure-sdk"]
path = deps/nanos-secure-sdk
url = https://github.com/LedgerHQ/nanos-secure-sdk
[submodule "deps/ledger-secure-sdk"]
path = deps/ledger-secure-sdk
url = https://github.com/LedgerHQ/ledger-secure-sdk
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ TESTS_JS_DIR = $(CURDIR)/js
ifeq ($(BOLOS_SDK),)
# In this case, there is not predefined SDK and we run dockerized
# When not using the SDK, we override and build the XL complete app

SUBSTRATE_PARSER_FULL ?= 1
ZXLIB_COMPILE_STAX ?= 1
include $(CURDIR)/deps/ledger-zxlib/dockerized_build.mk

else
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 @@ -21,7 +21,7 @@
#include <string.h>
#include "zxmacros.h"

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

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
storage_t NV_CONST N_appdata_impl __attribute__((aligned(64)));
#define N_appdata (*(NV_VOLATILE storage_t *)PIC(&N_appdata_impl))
#endif
Expand Down
12 changes: 6 additions & 6 deletions app/src/crypto_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "bolos_target.h"
#endif

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
#include "cx.h"
#include "cx_sha256.h"
#else
Expand All @@ -47,7 +47,7 @@ static zxerr_t crypto_publicKeyHash_ed25519(uint8_t *publicKeyHash, const uint8_

// Step 2. Hash the serialized public key with sha256.
uint8_t pkh[CX_SHA256_SIZE] = {0};
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
cx_hash_sha256((const uint8_t*) borshEncodedPubKey, PK_LEN_25519 + 1, pkh, CX_SHA256_SIZE);
#else
picohash_ctx_t ctx;
Expand Down Expand Up @@ -111,7 +111,7 @@ zxerr_t crypto_sha256(const uint8_t *input, uint16_t inputLen, uint8_t *output,

MEMZERO(output, outputLen);

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
cx_hash_sha256(input, inputLen, output, CX_SHA256_SIZE);
#else
picohash_ctx_t ctx;
Expand All @@ -127,7 +127,7 @@ zxerr_t crypto_hashExtraDataSection(const section_t *extraData, uint8_t *output,
return zxerr_invalid_crypto_settings;
}

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
cx_sha256_t sha256 = {0};
cx_sha256_init(&sha256);
cx_sha256_update(&sha256, &extraData->discriminant, 1);
Expand Down Expand Up @@ -159,7 +159,7 @@ zxerr_t crypto_hashDataSection(const section_t *data, uint8_t *output, uint32_t
return zxerr_no_data;
}

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
cx_sha256_t sha256 = {0};
cx_sha256_init(&sha256);
cx_sha256_update(&sha256, &data->discriminant, 1);
Expand All @@ -185,7 +185,7 @@ zxerr_t crypto_hashCodeSection(const section_t *code, uint8_t *output, uint32_t
return zxerr_invalid_crypto_settings;
}

#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX)
#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) || defined(TARGET_STAX)
cx_sha256_t sha256 = {0};
cx_sha256_init(&sha256);
cx_sha256_update(&sha256, &code->discriminant, 1);
Expand Down
1 change: 1 addition & 0 deletions deps/ledger-secure-sdk
Submodule ledger-secure-sdk added at e050ce
8 changes: 5 additions & 3 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export const APP_SEED = 'equip will roof matter pink blind book anxiety banner e
const APP_PATH_S = Resolve('../app/output/app_s.elf')
const APP_PATH_X = Resolve('../app/output/app_x.elf')
const APP_PATH_SP = Resolve('../app/output/app_s2.elf')
const APP_PATH_ST = Resolve('../app/output/app_stax.elf')

export const models: IDeviceModel[] = [
{ name: 'nanos', prefix: 'S', path: APP_PATH_S },
{ name: 'nanox', prefix: 'X', path: APP_PATH_X },
{ name: 'nanosp', prefix: 'SP', path: APP_PATH_SP },
// { name: 'nanos', prefix: 'S', path: APP_PATH_S },
// { name: 'nanox', prefix: 'X', path: APP_PATH_X },
// { name: 'nanosp', prefix: 'SP', path: APP_PATH_SP },
{ name: 'stax', prefix: 'ST', path: APP_PATH_ST },
]

export const hdpath = `m/44'/877'/0'/0'/0'`
Expand Down
20 changes: 15 additions & 5 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 from '@zondax/zemu'
import Zemu, { ButtonKind, zondaxMainmenuNavigation } from '@zondax/zemu'
import { NamadaApp } from '@zondax/ledger-namada'
import { models, hdpath, defaultOptions } from './common'

Expand All @@ -36,8 +36,9 @@ describe('Standard', function () {
test.concurrent.each(models)('main menu', async function (m) {
const sim = new Zemu(m.path)
try {
const mainmenuNavigation = zondaxMainmenuNavigation(m.name)
await sim.start({ ...defaultOptions, model: m.name })
await sim.navigateAndCompareSnapshots('.', `${m.prefix.toLowerCase()}-mainmenu`, [1, 0, 0, 4, -5])
await sim.navigateAndCompareSnapshots('.', `${m.prefix.toLowerCase()}-mainmenu`, mainmenuNavigation.schedule)
} finally {
await sim.close()
}
Expand Down Expand Up @@ -91,7 +92,12 @@ describe('Standard', function () {
test.concurrent.each(models)('show address', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
await sim.start({
...defaultOptions,
model: m.name,
approveKeyword: m.name === 'stax' ? 'QR' : '',
approveAction: ButtonKind.ApproveTapButton,
})
const app = new NamadaApp(sim.getTransport())

const respRequest = app.showAddressAndPubKey(hdpath)
Expand Down Expand Up @@ -120,13 +126,17 @@ describe('Standard', function () {
test.concurrent.each(models)('show address - reject', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
await sim.start({
...defaultOptions,
model: m.name,
rejectKeyword: m.name === 'stax' ? 'QR' : '',
})
const app = new NamadaApp(sim.getTransport())

const respRequest = app.showAddressAndPubKey(hdpath)

await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.navigateAndCompareUntilText('.', `${m.prefix.toLowerCase()}-show_address_reject`, 'REJECT')
await sim.compareSnapshotsAndReject('.', `${m.prefix.toLowerCase()}-show_address_reject`)

const resp = await respRequest
console.log(resp)
Expand Down
Loading

0 comments on commit 4ce1033

Please sign in to comment.