Skip to content

Commit

Permalink
Merge pull request #66 from Zondax/main
Browse files Browse the repository at this point in the history
Sync with latest from Zondax repo
  • Loading branch information
gmalouf authored Sep 16, 2022
2 parents 2ccad75 + 99ef765 commit 6ffe0d3
Show file tree
Hide file tree
Showing 34 changed files with 95 additions and 62 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DEFINES += ZEMU_LOGGING
$(info ************ LOGGING ENABLED ************)
endif

DEFINES += REVIEW_SCREEN_ENABLED APP_BLIND_MODE_ENABLED
DEFINES += REVIEW_SCREEN_ENABLED SHORTCUT_MODE_ENABLED

ifndef COIN
COIN=ALGO
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=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=0
# This is the patch version of this release
APPVERSION_P=4
APPVERSION_P=7
15 changes: 9 additions & 6 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ __Z_INLINE void handle_sign_msgpack(volatile uint32_t *flags, volatile uint32_t
__Z_INLINE void handle_get_public_key(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)
{
const uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1];
const bool u2f_compatibility = G_io_apdu_buffer[OFFSET_INS] == INS_GET_PUBLIC_KEY;
extractHDPath();

zxerr_t err = app_fill_address();
Expand All @@ -160,6 +161,11 @@ __Z_INLINE void handle_get_public_key(volatile uint32_t *flags, volatile uint32_
return;
}

//U2F compatibility: return only pubkey
if (u2f_compatibility) {
action_addrResponseLen = PK_LEN_25519;
}

*tx = action_addrResponseLen;
THROW(APDU_CODE_OK);
}
Expand Down Expand Up @@ -210,16 +216,13 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
const uint8_t ins = G_io_apdu_buffer[OFFSET_INS];
switch (ins) {
case INS_SIGN_MSGPACK:
if (os_global_pin_is_validated() != BOLOS_UX_OK) {
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
}
CHECK_PIN_VALIDATED()
handle_sign_msgpack(flags, tx, rx);
break;

case INS_GET_ADDRESS:
case INS_GET_PUBLIC_KEY: {
if( os_global_pin_is_validated() != BOLOS_UX_OK ) {
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
}
CHECK_PIN_VALIDATED()
handle_get_public_key(flags, tx, rx);
break;
}
Expand Down
10 changes: 2 additions & 8 deletions app/src/common/app_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@
#define P2_LAST 0x00
#define P2_MORE 0x80

#define INS_GET_VERSION 0x00
#define INS_SIGN_SECP256K1 0x02
#define INS_GET_ADDR_SECP256K1 0x04

#define INS_GET_VERSION 0x00
#define INS_GET_PUBLIC_KEY 0x03
#define INS_SIGN_PAYMENT_V2 0x04
#define INS_SIGN_KEYREG_V2 0x05
#define INS_SIGN_PAYMENT_V3 0x06
#define INS_SIGN_KEYREG_V3 0x07
#define INS_GET_ADDRESS 0x04
#define INS_SIGN_MSGPACK 0x08

void app_init();
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static parser_error_t parser_printTxAssetConfig(const txn_asset_config *asset_co
uint8_t pageIdx, uint8_t *pageCount)
{
*pageCount = 1;
char buff[45] = {0};
char buff[100] = {0};
switch (displayIdx) {
case IDX_CONFIG_ASSET_ID:
snprintf(outKey, outKeyLen, "Asset ID");
Expand Down
18 changes: 9 additions & 9 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ static uint8_t getMsgPackType(uint8_t byte)
return byte;
}

parser_error_t _readMapSize(parser_context_t *c, uint8_t *mapItems)
parser_error_t _readMapSize(parser_context_t *c, uint16_t *mapItems)
{
uint8_t byte = 0;
CHECK_ERROR(_readUInt8(c, &byte))

switch (getMsgPackType(byte)) {
case FIXMAP_0:
*mapItems = byte - FIXMAP_0;
*mapItems = (uint16_t) byte - FIXMAP_0;
break;

case MAP16:
CHECK_ERROR(_readUInt16(c, (uint16_t*)mapItems))
CHECK_ERROR(_readUInt16(c, mapItems))
break;

case MAP32:
Expand Down Expand Up @@ -198,7 +198,7 @@ parser_error_t _readString(parser_context_t *c, uint8_t *buff, uint16_t buffLen)
break;
}

if (strLen > buffLen) {
if (strLen >= buffLen) {
return parser_msgpack_str_too_big;
}
CHECK_ERROR(_readBytes(c, buff, strLen))
Expand Down Expand Up @@ -404,15 +404,15 @@ static parser_error_t _readAssetParams(parser_context_t *c, txn_asset_config *as
uint8_t available_params[MAX_PARAM_SIZE];
memset(available_params, 0xFF, MAX_PARAM_SIZE);

uint8_t paramsSize = 0;
uint16_t paramsSize = 0;
CHECK_ERROR(_readMapSize(c, &paramsSize))

if(paramsSize > MAX_PARAM_SIZE) {
return parser_unexpected_number_items;
}

uint8_t key[10] = {0};
for(uint8_t i = 0; i < paramsSize; i++) {
for(uint16_t i = 0; i < paramsSize; i++) {
CHECK_ERROR(_readString(c, key, sizeof(key)))

if (strncmp((char*)key, KEY_APARAMS_TOTAL, strlen(KEY_APARAMS_TOTAL)) == 0) {
Expand Down Expand Up @@ -615,10 +615,10 @@ parser_error_t _verifyAccounts(parser_context_t *c, uint8_t* num_accounts, uint8

parser_error_t _readStateSchema(parser_context_t *c, state_schema *schema)
{
uint8_t mapSize = 0;
uint16_t mapSize = 0;
CHECK_ERROR(_readMapSize(c, &mapSize))
uint8_t key[32];
for (size_t i = 0; i < mapSize; i++) {
for (uint16_t i = 0; i < mapSize; i++) {
CHECK_ERROR(_readString(c, key, sizeof(key)))
if (strncmp((char*)key, KEY_SCHEMA_NUI, sizeof(KEY_SCHEMA_NUI)) == 0) {
CHECK_ERROR(_readInteger(c, &schema->num_uint))
Expand Down Expand Up @@ -985,7 +985,7 @@ parser_error_t _readArray_args(parser_context_t *c, uint8_t args[][MAX_ARGLEN],

parser_error_t _read(parser_context_t *c, parser_tx_t *v)
{
uint8_t keyLen = 0;
uint16_t keyLen = 0;
CHECK_ERROR(initializeItemArray())

CHECK_ERROR(_readMapSize(c, &keyLen))
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ uint8_t _getTxNumItems();

parser_error_t _read(parser_context_t *c, parser_tx_t *v);

parser_error_t _readMapSize(parser_context_t *c, uint8_t *mapItems);
parser_error_t _readMapSize(parser_context_t *c, uint16_t *mapItems);
parser_error_t _readArraySize(parser_context_t *c, uint8_t *mapItems);
parser_error_t _readString(parser_context_t *c, uint8_t *buff, uint16_t buffLen);
parser_error_t _readInteger(parser_context_t *c, uint64_t* value);
Expand Down
6 changes: 3 additions & 3 deletions app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ typedef struct {
uint64_t total;
uint64_t decimals;
uint8_t default_frozen;
char unitname[8];
char assetname[32];
char url[32];
char unitname[9];
char assetname[33];
char url[97];
uint8_t metadata_hash[32];
uint8_t manager[32];
uint8_t reserve[32];
Expand Down
24 changes: 12 additions & 12 deletions app/src/blind.c → app/src/shortcut.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
#include "view_internal.h"
#include "zxformat.h"

void blind_toggle() {
#ifdef APP_BLIND_MODE_ENABLED
app_mode_set_blind(!app_mode_blind());
void shortcut_toggle() {
#ifdef SHORTCUT_MODE_ENABLED
app_mode_set_shortcut(!app_mode_shortcut());
view_idle_show(0, NULL);
#endif
}

static const char *blindMessage =
"You are about to enable blind signing mode. If you are not sure why you "
static const char *shortcutMessage =
"You are about to enable shortcut mode. If you are not sure why you "
"are here, reject or unplug your device immediately. Activating this mode "
"will allow you to sign transactions without reviewing each transaction "
"field.";

zxerr_t blind_getNumItems(uint8_t *num_items) {
zemu_log_stack("blind_getNumItems");
zxerr_t shortcut_getNumItems(uint8_t *num_items) {
zemu_log_stack("shortcut_getNumItems\n");
*num_items = 1;
return zxerr_ok;
}

zxerr_t blind_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
zxerr_t shortcut_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen, uint8_t pageIdx,
uint8_t *pageCount) {
if (displayIdx != 0) {
Expand All @@ -52,13 +52,13 @@ zxerr_t blind_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,

snprintf(outKey, outKeyLen, "Warning!");

pageString(outVal, outValLen, (char*)PIC(blindMessage), pageIdx, pageCount);
pageString(outVal, outValLen, (const char*)PIC(shortcutMessage), pageIdx, pageCount);
return zxerr_ok;
}

zxerr_t blind_enabled() {
#ifdef APP_BLIND_MODE_ENABLED
view_review_init(blind_getItem, blind_getNumItems, blind_toggle);
zxerr_t shortcut_enabled() {
#ifdef SHORTCUT_MODE_ENABLED
view_review_init(shortcut_getItem, shortcut_getNumItems, shortcut_toggle);
view_review_show(REVIEW_UI);
#endif
return zxerr_ok;
Expand Down
2 changes: 1 addition & 1 deletion deps/nanos-secure-sdk
2 changes: 1 addition & 1 deletion deps/nanosplus-secure-sdk
2 changes: 1 addition & 1 deletion deps/nanox-secure-sdk
2 changes: 1 addition & 1 deletion deps/picohash
Submodule picohash updated 1 files
+9 −6 picohash.h
Binary file modified docs/zondax_dark.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 docs/zondax_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions js/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const CLA = 0x80;
export const INS = {
GET_VERSION: 0x00,
GET_PUBLIC_KEY: 0x03,
GET_ADDRESS: 0x04,
SIGN_MSGPACK: 0x08,
};
export const PKLEN = 32;
14 changes: 13 additions & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class AlgorandApp {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getAddressAndPubKey(accountId = 0, requireConfirmation = false): Promise<ResponseAddress> {
async getPubkey(accountId = 0, requireConfirmation = false): Promise<ResponseAddress> {
const data = Buffer.alloc(4);
data.writeUInt32BE(accountId)

Expand All @@ -213,6 +213,18 @@ export default class AlgorandApp {
.then(processGetAddrResponse, processErrorResponse);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getAddressAndPubKey(accountId = 0, requireConfirmation = false): Promise<ResponseAddress> {
const data = Buffer.alloc(4);
data.writeUInt32BE(accountId)

const p1_value = requireConfirmation ? P1_VALUES.SHOW_ADDRESS_IN_DEVICE : P1_VALUES.ONLY_RETRIEVE

return this.transport
.send(CLA, INS.GET_ADDRESS, p1_value, P2_VALUES.DEFAULT, data, [0x9000])
.then(processGetAddrResponse, processErrorResponse);
}

async signSendChunk(chunkIdx: number, chunkNum: number, accountId: number, chunk: Buffer): Promise<ResponseSign> {
let p1 = P1_VALUES.MSGPACK_ADD
let p2 = P2_VALUES.MSGPACK_ADD
Expand Down
12 changes: 6 additions & 6 deletions tests/parser_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST(SCALE, EncodingUint8) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down Expand Up @@ -127,7 +127,7 @@ TEST(SCALE, EncodingUint16) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down Expand Up @@ -167,7 +167,7 @@ TEST(SCALE, EncodingUint32) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down Expand Up @@ -207,7 +207,7 @@ TEST(SCALE, EncodingUint64) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down Expand Up @@ -247,7 +247,7 @@ TEST(SCALE, EncodingString) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down Expand Up @@ -286,7 +286,7 @@ TEST(SCALE, EncodingBoolean) {

parser_init(&ctx, buffer, bufferLen);

uint8_t mapItems {0};
uint16_t mapItems {0};
err = _readMapSize(&ctx, &mapItems);
EXPECT_EQ(err, parser_ok) << parser_getErrorDescription(err);
EXPECT_EQ(mapItems, 2);
Expand Down
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@zondax/ledger-algorand": "../js",
"@zondax/zemu": "^0.32.0"
"@zondax/zemu": "^0.33.1"
},
"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/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/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-mainmenu/00012.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/sp-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/sp-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 modified tests_zemu/snapshots/sp-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/sp-mainmenu/00012.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/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/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/x-mainmenu/00012.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/big_transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_application_big`, 50000)
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_application_big`)

const signatureResponse = await signatureRequest
console.log(signatureResponse)
Expand Down
Loading

0 comments on commit 6ffe0d3

Please sign in to comment.