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

Flex support #164

Merged
merged 6 commits into from
Jul 23, 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
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,38 @@ jobs:
tag_name: ${{ steps.stax.outputs.tag_name }}
draft: false
prerelease: false

build_package_flex:
needs: [configure, build_ledger, test_zemu, rust_tests]
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
container:
image: zondax/ledger-app-builder:latest
options: --user ${{ needs.configure.outputs.uid_gid }}
env:
BOLOS_SDK: /opt/flex-secure-sdk
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install deps
run: pip install ledgerblue

- name: Build Flex
shell: bash -l {0}
run: |
PRODUCTION_BUILD=0 make
- name: Set tag
id: flex
run: echo "tag_name=$(./app/pkg/installer_flex.sh version)" >> $GITHUB_OUTPUT
- name: Update Release
id: update_release_2
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
files: ./app/pkg/installer_flex.sh
tag_name: ${{ steps.flex.outputs.tag_name }}
draft: false
prerelease: false
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install node
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=0
APPVERSION_N=24
APPVERSION_P=1
APPVERSION_P=2
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.
129 changes: 78 additions & 51 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*******************************************************************************
* (c) 2019 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* (c) 2019 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#include "tx.h"
#include "apdu_codes.h"
Expand All @@ -21,7 +21,7 @@
#include <string.h>
#include "zxmacros.h"

#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 8192
#define FLASH_BUFFER_SIZE 16384
#elif defined(TARGET_NANOS)
Expand All @@ -33,70 +33,81 @@
uint8_t ram_buffer[RAM_BUFFER_SIZE];

// Flash
typedef struct {
typedef struct
{
uint8_t buffer[FLASH_BUFFER_SIZE];
} storage_t;

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)
storage_t NV_CONST N_appdata_impl __attribute__ ((aligned(64)));
#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

static parser_context_t ctx_parsed_tx;

void tx_initialize() {
void tx_initialize()
{
buffering_init(
ram_buffer,
sizeof(ram_buffer),
(uint8_t *) N_appdata.buffer,
sizeof(N_appdata.buffer)
);
ram_buffer,
sizeof(ram_buffer),
(uint8_t *)N_appdata.buffer,
sizeof(N_appdata.buffer));
Dismissed Show dismissed Hide dismissed
}

void tx_reset() {
void tx_reset()
{
buffering_reset();
}

void tx_reset_state() {
void tx_reset_state()
{
parser_resetState();
}

uint32_t tx_append(unsigned char *buffer, uint32_t length) {
uint32_t tx_append(unsigned char *buffer, uint32_t length)
{
return buffering_append(buffer, length);
}

uint32_t tx_get_buffer_length() {
uint32_t tx_get_buffer_length()
{
return buffering_get_buffer()->pos;
}

uint8_t *tx_get_buffer() {
uint8_t *tx_get_buffer()
{
return buffering_get_buffer()->data;
}

const char *tx_parse() {
const char *tx_parse()
{
uint8_t err = parser_parse(
&ctx_parsed_tx,
tx_get_buffer(),
tx_get_buffer_length());

if (err != parser_ok) {
if (err != parser_ok)
{
return parser_getErrorDescription(err);
}

err = parser_validate(&ctx_parsed_tx);
CHECK_APP_CANARY()

if (err != parser_ok) {
if (err != parser_ok)
{
return parser_getErrorDescription(err);
}

return NULL;
}

zxerr_t tx_getNumItems(uint8_t *num_items) {
zxerr_t tx_getNumItems(uint8_t *num_items)
{
parser_error_t err = parser_getNumItems(&ctx_parsed_tx, num_items);

if (err != parser_ok) {
if (err != parser_ok)
{
return zxerr_no_data;
}

Expand All @@ -106,12 +117,14 @@
zxerr_t tx_getItem(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
uint8_t pageIdx, uint8_t *pageCount)
{
uint8_t numItems = 0;

CHECK_ZXERR(tx_getNumItems(&numItems))

if (displayIdx < 0 || displayIdx > numItems) {
if (displayIdx < 0 || displayIdx > numItems)
{
return zxerr_no_data;
}

Expand All @@ -133,33 +146,40 @@
return zxerr_ok;
}

zxerr_t tx_auth_flag(uint8_t *flag) {
zxerr_t tx_auth_flag(uint8_t *flag)
{
if (parser_tx_auth_flag(flag) != parser_ok)
return zxerr_unknown;
return zxerr_ok;
}

uint8_t tx_fee(uint8_t *fee, uint16_t fee_len){
uint8_t tx_fee(uint8_t *fee, uint16_t fee_len)
{
return parser_tx_fee(fee, fee_len);
}

uint8_t tx_nonce(uint8_t *nonce, uint16_t nonce_len) {
uint8_t tx_nonce(uint8_t *nonce, uint16_t nonce_len)
{
return parser_tx_nonce(nonce, nonce_len);
}

uint16_t tx_presig_hash_data(uint8_t *buf, uint16_t bufLen) {
uint16_t tx_presig_hash_data(uint8_t *buf, uint16_t bufLen)
{
return parser_presig_hash_data(buf, bufLen);
}

uint16_t tx_last_tx_block(uint8_t ** last_tx_block) {
uint16_t tx_last_tx_block(uint8_t **last_tx_block)
{
return parser_last_transaction_block(last_tx_block);
}

int8_t tx_is_multisig() {
int8_t tx_is_multisig()
{
return parser_is_transaction_multisig();
}

zxerr_t tx_hash_mode(uint8_t *hash_mode) {
zxerr_t tx_hash_mode(uint8_t *hash_mode)
{
parser_error_t err = parser_hash_mode(hash_mode);

// Convert error codes
Expand All @@ -172,15 +192,18 @@
return zxerr_ok;
}

uint16_t tx_previous_signer_data(uint8_t **data) {
uint16_t tx_previous_signer_data(uint8_t **data)
{
return parser_previous_signer_data(data);
}

uint32_t tx_num_multisig_fields() {
uint32_t tx_num_multisig_fields()
{
return parser_num_multisig_fields();
}

zxerr_t tx_get_multisig_field(uint32_t index, uint8_t *id, uint8_t **data) {
zxerr_t tx_get_multisig_field(uint32_t index, uint8_t *id, uint8_t **data)
{
parser_error_t err = parser_get_multisig_field(index, id, data);

// Convert error codes
Expand All @@ -193,23 +216,27 @@
return zxerr_ok;
}

transaction_type_t tx_get_transaction_type(){
transaction_type_t tx_get_transaction_type()
{
return parser_get_transaction_type();
}

zxerr_t tx_structured_msg_hash(uint8_t *out, uint16_t out_len){
zxerr_t tx_structured_msg_hash(uint8_t *out, uint16_t out_len)
{
return parser_structured_msg_hash(out, out_len);
}

uint16_t get_error_message(char *out, uint16_t outLen, parser_error_t error_code) {
uint16_t get_error_message(char *out, uint16_t outLen, parser_error_t error_code)
{
const char *error_message = parser_getErrorDescription(error_code);
if (error_message == NULL || outLen == 0) {
if (error_message == NULL || outLen == 0)
{
return 0;
}

uint16_t len = strlen(error_message);

if (outLen < len )
if (outLen < len)
return 0;

memcpy(out, error_message, len);
Expand Down
1 change: 1 addition & 0 deletions deps/ledger-secure-sdk
Submodule ledger-secure-sdk added at b46b4b
1 change: 0 additions & 1 deletion deps/nanos-secure-sdk
Submodule nanos-secure-sdk deleted from 7583ae
1 change: 0 additions & 1 deletion deps/nanosplus-secure-sdk
Submodule nanosplus-secure-sdk deleted from 7583ae
1 change: 0 additions & 1 deletion deps/nanox-secure-sdk
Submodule nanox-secure-sdk deleted from 7583ae
1 change: 0 additions & 1 deletion deps/stax-secure-sdk
Submodule stax-secure-sdk deleted from 7583ae
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./app/"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]

[tests]
unit_directory = "./tests/"
38 changes: 19 additions & 19 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
],
"dependencies": {
"@zondax/ledger-stacks": "link:../js",
"@zondax/zemu": "=0.49.0"
"@zondax/zemu": "0.50.2"
},
"devDependencies": {
"@ledgerhq/hw-transport-node-hid": "^6.29.0",
"@ledgerhq/hw-transport-node-hid": "^6.29.2",
"@matteoh2o1999/github-actions-jest-reporter": "^2.0.0",
"@stacks/network": "^2.0.1",
"@stacks/transactions": "^2.0.1",
"@types/jest": "^29.4.0",
"@types/ledgerhq__hw-transport": "^4.21.8",
"@types/secp256k1": "^4.0.3",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"@types/secp256k1": "^4.0.6",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"bn.js": "^5.2.0",
"crypto-js": "4.1.1",
"elliptic": "^6.5.4",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"crypto-js": "4.2.0",
"elliptic": "^6.5.6",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.5.0",
"jest-serial-runner": "^1.2.0",
"js-sha256": "0.9.0",
"js-sha512": "^0.8.0",
"js-sha256": "0.11.0",
"js-sha512": "^0.9.0",
"noble-secp256k1": "^1.2.9",
"prettier": "^2.3.2",
"secp256k1": "^4.0.2",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"prettier": "^3.3.3",
"secp256k1": "^5.0.0",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"varuint-bitcoin": "^1.1.2"
}
}
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.
Binary file added tests_zemu/snapshots/fl-multisigTest/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-multisigTest/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-multisigTest/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-multisigTest/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-multisigTest/00004.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.
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-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-sign/00000.png
Binary file added tests_zemu/snapshots/fl-sign/00001.png
Binary file added tests_zemu/snapshots/fl-sign/00002.png
Binary file added tests_zemu/snapshots/fl-sign/00003.png
Binary file added tests_zemu/snapshots/fl-sign/00004.png
Binary file added tests_zemu/snapshots/fl-sign_jwt/00000.png
Binary file added tests_zemu/snapshots/fl-sign_jwt/00001.png
Binary file added tests_zemu/snapshots/fl-sign_jwt/00002.png
Binary file added tests_zemu/snapshots/fl-sign_jwt/00003.png
Binary file added tests_zemu/snapshots/fl-sign_message/00000.png
Binary file added tests_zemu/snapshots/fl-sign_message/00001.png
Binary file added tests_zemu/snapshots/fl-sign_message/00002.png
Binary file added tests_zemu/snapshots/fl-sign_message/00003.png
Binary file added tests_zemu/snapshots/fl-sign_message/00004.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-call_with_string_args/00000.png
Binary file modified tests_zemu/snapshots/st-call_with_string_args/00001.png
Binary file modified tests_zemu/snapshots/st-call_with_string_args/00002.png
Binary file modified tests_zemu/snapshots/st-call_with_string_args/00003.png
Binary file modified tests_zemu/snapshots/st-call_with_string_args/00004.png
Binary file modified tests_zemu/snapshots/st-call_with_string_args/00005.png
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-multisigTest/00000.png
Binary file modified tests_zemu/snapshots/st-multisigTest/00001.png
Binary file modified tests_zemu/snapshots/st-multisigTest/00002.png
Binary file modified tests_zemu/snapshots/st-multisigTest/00003.png
Binary file modified tests_zemu/snapshots/st-multisigTest/00004.png
Binary file modified tests_zemu/snapshots/st-order_independent_multisigTest/00000.png
Binary file modified tests_zemu/snapshots/st-order_independent_multisigTest/00001.png
Binary file modified tests_zemu/snapshots/st-order_independent_multisigTest/00003.png
Binary file modified tests_zemu/snapshots/st-order_independent_multisigTest/00004.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-sign-structured_data_big_tuple/00000.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_big_tuple/00001.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_big_tuple/00003.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_empty_list/00000.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_some_tuple/00000.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_string/00000.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_string/00001.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_string/00002.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_string/00003.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_tuple/00000.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_tuple/00001.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_tuple/00002.png
Binary file modified tests_zemu/snapshots/st-sign-structured_data_tuple/00003.png
Binary file modified tests_zemu/snapshots/st-sign/00000.png
Binary file modified tests_zemu/snapshots/st-sign/00001.png
Binary file modified tests_zemu/snapshots/st-sign/00002.png
Binary file modified tests_zemu/snapshots/st-sign/00003.png
Binary file modified tests_zemu/snapshots/st-sign/00004.png
Binary file modified tests_zemu/snapshots/st-sign_jwt/00000.png
Binary file modified tests_zemu/snapshots/st-sign_jwt/00001.png
Binary file modified tests_zemu/snapshots/st-sign_jwt/00002.png
Binary file modified tests_zemu/snapshots/st-sign_jwt/00003.png
Binary file modified tests_zemu/snapshots/st-sign_message/00000.png
Binary file modified tests_zemu/snapshots/st-sign_message/00001.png
Binary file modified tests_zemu/snapshots/st-sign_message/00002.png
Binary file modified tests_zemu/snapshots/st-sign_message/00003.png
Binary file modified tests_zemu/snapshots/st-sign_message/00004.png
Binary file modified tests_zemu/snapshots/st-sign_standard_contract_call_tx/00000.png
Binary file modified tests_zemu/snapshots/st-sign_standard_contract_call_tx/00001.png
Binary file modified tests_zemu/snapshots/st-sign_standard_contract_call_tx/00002.png
Binary file modified tests_zemu/snapshots/st-sign_standard_contract_call_tx/00003.png
Binary file modified tests_zemu/snapshots/st-sign_standard_contract_call_tx/00005.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Loading