From 9c589b86cee4cd85c33f073d98a8490b7e7acee5 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Mon, 4 Mar 2024 10:38:06 -0300 Subject: [PATCH] minor cleanup --- app/Makefile | 6 +- app/src/apdu_handler.c | 18 +++-- app/src/crypto.c | 56 ++++++-------- app/src/crypto.h | 2 - app/src/parser_impl.c | 43 ++--------- app/src/parser_txdef.h | 8 -- tests/ui_tests.cpp | 14 ---- tests_zemu/tests/standard.test.ts | 121 +----------------------------- 8 files changed, 41 insertions(+), 227 deletions(-) diff --git a/app/Makefile b/app/Makefile index 49445df7..46056702 100755 --- a/app/Makefile +++ b/app/Makefile @@ -56,8 +56,7 @@ endif APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH) -NANOS_STACK_SIZE := 2050 - +APP_STACK_MIN_SIZE := 3100 include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices $(info TARGET_NAME = [$(TARGET_NAME)]) @@ -72,9 +71,6 @@ CFLAGS += -Wvla -Wno-implicit-fallthrough CFLAGS += -I$(MY_DIR)/../deps/tinycbor/src APP_SOURCE_PATH += $(MY_DIR)/../deps/tinycbor-ledger -CFLAGS += -I$(MY_DIR)/../deps/nanopb/ -APP_SOURCE_PATH += $(MY_DIR)/../deps/nanopb_tiny/ - .PHONY: rust rust: @echo "No rust code" diff --git a/app/src/apdu_handler.c b/app/src/apdu_handler.c index 4bb05fba..792f873c 100644 --- a/app/src/apdu_handler.c +++ b/app/src/apdu_handler.c @@ -73,7 +73,7 @@ __Z_INLINE bool process_chunk(volatile uint32_t *tx, uint32_t rx) { THROW(APDU_CODE_DATA_INVALID); } - bool is_stake_tx = parser_tx_obj.special_transfer_type == neuron_stake_transaction; + const bool is_stake_tx = parser_tx_obj.special_transfer_type == neuron_stake_transaction; uint32_t added; switch (payloadType) { @@ -128,9 +128,9 @@ __Z_INLINE bool process_chunk(volatile uint32_t *tx, uint32_t rx) { __Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { extractHDPath(rx, OFFSET_DATA); - uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1]; + const uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1]; - zxerr_t zxerr = app_fill_address(); + const zxerr_t zxerr = app_fill_address(); if (zxerr != zxerr_ok) { *tx = 0; THROW(APDU_CODE_DATA_INVALID); @@ -158,7 +158,7 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint CHECK_APP_CANARY() if (error_msg != NULL) { - int error_msg_length = strlen(error_msg); + const uint32_t error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer)); MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length); *tx += (error_msg_length); THROW(APDU_CODE_DATA_INVALID); @@ -181,7 +181,7 @@ __Z_INLINE void handleSignCombined(volatile uint32_t *flags, volatile uint32_t * CHECK_APP_CANARY() if (error_msg != NULL) { - int error_msg_length = strlen(error_msg); + const uint32_t error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer)); MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length); *tx += (error_msg_length); THROW(APDU_CODE_DATA_INVALID); @@ -202,7 +202,9 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile G_io_apdu_buffer[1] = LEDGER_MAJOR_VERSION; G_io_apdu_buffer[2] = LEDGER_MINOR_VERSION; G_io_apdu_buffer[3] = LEDGER_PATCH_VERSION; - G_io_apdu_buffer[4] = !IS_UX_ALLOWED; + // sdk won't pass the apdu message if device is locked + // keeping it for backwards compatibility + G_io_apdu_buffer[4] = 0; G_io_apdu_buffer[5] = (TARGET_ID >> 24) & 0xFF; G_io_apdu_buffer[6] = (TARGET_ID >> 16) & 0xFF; @@ -214,7 +216,7 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile } void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { - uint16_t sw = 0; + volatile uint16_t sw = 0; BEGIN_TRY { @@ -278,7 +280,7 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { break; } G_io_apdu_buffer[*tx] = sw >> 8; - G_io_apdu_buffer[*tx + 1] = sw; + G_io_apdu_buffer[*tx + 1] = sw & 0xFF; *tx += 2; } FINALLY diff --git a/app/src/crypto.c b/app/src/crypto.c index 9238e7fb..c039715a 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -22,11 +22,6 @@ uint32_t hdPath[HDPATH_LEN_DEFAULT]; -bool isTestnet() { - return hdPath[0] == HDPATH_0_TESTNET && - hdPath[1] == HDPATH_1_TESTNET; -} - uint8_t const DER_PREFIX[] = {0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00}; @@ -53,7 +48,7 @@ zxerr_t hash_sha224(uint8_t *input, uint16_t inputLen, uint8_t *output, uint16_t } cx_sha256_t ctx; cx_sha224_init(&ctx); - cx_hash_no_throw(&ctx.header, CX_LAST, input, inputLen, output, 224); + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, CX_LAST, input, inputLen, output, 224)); return zxerr_ok; } @@ -69,11 +64,11 @@ zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen) { zxerr_t err = zxerr_ledger_api_error; CATCH_CXERROR(os_derive_bip32_no_throw(CX_CURVE_256K1, hdPath, HDPATH_LEN_DEFAULT, - privateKeyData, NULL)) + privateKeyData, NULL)); - CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey)) - CATCH_CXERROR(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, NULL, 0, &cx_publicKey)) - CATCH_CXERROR(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1)) + CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey)); + CATCH_CXERROR(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1, NULL, 0, &cx_publicKey)); + CATCH_CXERROR(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1)); memcpy(pubKey, cx_publicKey.W, SECP256K1_PK_LEN); err = zxerr_ok; @@ -118,36 +113,36 @@ typedef struct { #define HASH_U64(FIELDNAME, FIELDVALUE, TMPDIGEST) { \ MEMZERO(TMPDIGEST,sizeof(TMPDIGEST)); \ cx_hash_sha256((uint8_t *)FIELDNAME, sizeof(FIELDNAME) - 1, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0)); \ uint8_t ingressbuf[10]; \ uint16_t enc_size = 0; \ CHECK_ZXERR(compressLEB128(FIELDVALUE, sizeof(ingressbuf), ingressbuf, &enc_size)); \ cx_hash_sha256((uint8_t *)ingressbuf, enc_size, tmpdigest, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0)); \ } #define HASH_BYTES_INTERMEDIATE(FIELDNAME, FIELDVALUE, TMPDIGEST) { \ MEMZERO(TMPDIGEST,sizeof(TMPDIGEST)); \ cx_hash_sha256((uint8_t *)FIELDNAME, sizeof(FIELDNAME) - 1, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0)); \ cx_hash_sha256((uint8_t *)(FIELDVALUE).data, (FIELDVALUE).len, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0)); \ } #define HASH_BYTES_END(FIELDNAME, FIELDVALUE, TMPDIGEST, ENDDIGEST) { \ MEMZERO(TMPDIGEST,sizeof(TMPDIGEST)); \ cx_hash_sha256((uint8_t *)FIELDNAME, sizeof(FIELDNAME) - 1, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0)); \ cx_hash_sha256((uint8_t *)(FIELDVALUE).data, (FIELDVALUE).len, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, CX_LAST, TMPDIGEST, CX_SHA256_SIZE, ENDDIGEST, CX_SHA256_SIZE); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, CX_LAST, TMPDIGEST, CX_SHA256_SIZE, ENDDIGEST, CX_SHA256_SIZE)); \ } #define HASH_BYTES_PTR_END(FIELDNAME, FIELDVALUE, TMPDIGEST, ENDDIGEST) { \ MEMZERO(TMPDIGEST,sizeof(TMPDIGEST)); \ cx_hash_sha256((uint8_t *)FIELDNAME, sizeof(FIELDNAME) - 1, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, TMPDIGEST, CX_SHA256_SIZE, NULL, 0)); \ cx_hash_sha256((uint8_t *)(FIELDVALUE).dataPtr, (FIELDVALUE).len, TMPDIGEST, CX_SHA256_SIZE); \ - cx_hash_no_throw(&ctx.header, CX_LAST, TMPDIGEST, CX_SHA256_SIZE, ENDDIGEST, CX_SHA256_SIZE); \ + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, CX_LAST, TMPDIGEST, CX_SHA256_SIZE, ENDDIGEST, CX_SHA256_SIZE)); \ } zxerr_t crypto_getDigest(uint8_t *digest, txtype_e txtype){ @@ -178,7 +173,7 @@ zxerr_t crypto_getDigest(uint8_t *digest, txtype_e txtype){ HASH_U64("ingress_expiry",fields->ingress_expiry, tmpdigest); cx_hash_sha256((uint8_t *)"paths", 5, tmpdigest, CX_SHA256_SIZE); - cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0); + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0)); uint8_t arrayBuffer[PATH_MAX_ARRAY * CX_SHA256_SIZE]; for (size_t index = 0; index < fields->paths.arrayLen ; index++){ @@ -186,7 +181,7 @@ zxerr_t crypto_getDigest(uint8_t *digest, txtype_e txtype){ } cx_hash_sha256(arrayBuffer, fields->paths.arrayLen*CX_SHA256_SIZE, tmpdigest, CX_SHA256_SIZE); cx_hash_sha256(tmpdigest, CX_SHA256_SIZE, tmpdigest, CX_SHA256_SIZE); - cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0); + CHECK_CX_OK(cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0)); HASH_BYTES_END("request_type", parser_tx_obj.request_type, tmpdigest, digest); return zxerr_ok; @@ -205,8 +200,7 @@ zxerr_t crypto_sign(uint8_t *signatureBuffer, return zxerr_buffer_too_small; } - uint8_t message_digest[CX_SHA256_SIZE]; - MEMZERO(message_digest,sizeof(message_digest)); + uint8_t message_digest[CX_SHA256_SIZE] = {0}; signatureBuffer[0] = 0x0a; MEMCPY(&signatureBuffer[1], (uint8_t *)"ic-request",SIGN_PREFIX_SIZE - 1); @@ -228,9 +222,9 @@ zxerr_t crypto_sign(uint8_t *signatureBuffer, CATCH_CXERROR(os_derive_bip32_no_throw(CX_CURVE_SECP256K1, hdPath, HDPATH_LEN_DEFAULT, - privateKeyData, NULL)) + privateKeyData, NULL)); - CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_SECP256K1, privateKeyData, 32, &cx_privateKey)) + CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_SECP256K1, privateKeyData, 32, &cx_privateKey)); // Sign CATCH_CXERROR(cx_ecdsa_sign_no_throw(&cx_privateKey, @@ -240,7 +234,7 @@ zxerr_t crypto_sign(uint8_t *signatureBuffer, CX_SHA256_SIZE, signature->der_signature, &signatureLength, - &info)) + &info)); err_convert_e err_c = convertDERtoRSV(signature->der_signature, info, signature->r, signature->s, &signature->v); if (err_c != no_error) { @@ -309,9 +303,9 @@ zxerr_t crypto_sign_combined(uint8_t *signatureBuffer, CATCH_CXERROR(os_derive_bip32_no_throw(CX_CURVE_SECP256K1, hdPath, HDPATH_LEN_DEFAULT, - privateKeyData, NULL)) + privateKeyData, NULL)); - CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_SECP256K1, privateKeyData, 32, &cx_privateKey)) + CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_SECP256K1, privateKeyData, 32, &cx_privateKey)); // Sign request CATCH_CXERROR(cx_ecdsa_sign_no_throw(&cx_privateKey, @@ -321,7 +315,7 @@ zxerr_t crypto_sign_combined(uint8_t *signatureBuffer, CX_SHA256_SIZE, sigma.der_signature, &sigLen, - &info)) + &info)); err_convert_e err_c = convertDERtoRSV(sigma.der_signature, info, sigma.r, sigma.s, &sigma.v); if (err_c != no_error) { @@ -343,7 +337,7 @@ zxerr_t crypto_sign_combined(uint8_t *signatureBuffer, CX_SHA256_SIZE, sigma.der_signature, &sigLen, - &info)) + &info)); err_c = convertDERtoRSV(sigma.der_signature, info, sigma.r, sigma.s, &sigma.v); if (err_c != no_error) { @@ -665,9 +659,7 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrL CHECK_ZXERR(crypto_computePrincipal(answer->publicKey, answer->principalBytes)); //For now only defeault subaccount, maybe later grab 32 bytes from the apdu buffer. - uint8_t zero_subaccount[DFINITY_SUBACCOUNT_LEN]; - MEMZERO(zero_subaccount, DFINITY_SUBACCOUNT_LEN); - + uint8_t zero_subaccount[DFINITY_SUBACCOUNT_LEN] = {0}; CHECK_ZXERR(crypto_principalToSubaccount(answer->principalBytes, sizeof_field(answer_t, principalBytes), zero_subaccount, DFINITY_SUBACCOUNT_LEN, answer->subAccountBytes, sizeof_field(answer_t, subAccountBytes))); diff --git a/app/src/crypto.h b/app/src/crypto.h index b4759327..81306e26 100644 --- a/app/src/crypto.h +++ b/app/src/crypto.h @@ -30,8 +30,6 @@ extern "C" { extern uint32_t hdPath[HDPATH_LEN_DEFAULT]; -bool isTestnet(); - zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen); zxerr_t crypto_computePrincipal(const uint8_t *pubKey, uint8_t *principal); diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 599f1b37..7aaa1ec2 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -368,31 +368,6 @@ parser_error_t readPayload(parser_tx_t *v, uint8_t *buffer, size_t bufferLen) { return parser_unexpected_type; } -static bool isCandidTransaction(parser_tx_t *v) { - char *method = v->tx_fields.call.method_name.data; - if (strcmp(method, "manage_neuron") == 0) { - return true; - } - - if (strcmp(method, "update_node_provider") == 0) { - return true; - } - - if (strcmp(method, "list_neurons") == 0) { - return true; - } - - if (strcmp(method, "icrc1_transfer") == 0) { - return true; - } - - if (strcmp(method, "transfer") == 0) { - return true; - } - - return false; -} - parser_error_t readContent(CborValue *content_map, parser_tx_t *v) { CborValue content_it; zemu_log_stack("read content"); @@ -427,15 +402,11 @@ parser_error_t readContent(CborValue *content_map, parser_tx_t *v) { READ_STRING(content_map, "method_name", fields->method_name) READ_INT64(content_map, "ingress_expiry", fields->ingress_expiry) - if (isCandidTransaction(v)) { - READ_STRING_PTR_SIZE(content_map, "arg", fields->method_args.dataPtr, fields->method_args.len) - if (fields->method_args.dataPtr == NULL) { - return parser_no_data; - } - CHECK_PARSER_ERR(readPayload(v, fields->method_args.dataPtr, fields->method_args.len)) - } else { - return parser_unexpected_type; + READ_STRING_PTR_SIZE(content_map, "arg", fields->method_args.dataPtr, fields->method_args.len) + if (fields->method_args.dataPtr == NULL) { + return parser_no_data; } + CHECK_PARSER_ERR(readPayload(v, fields->method_args.dataPtr, fields->method_args.len)) } else if (strcmp(v->request_type.data, "read_state") == 0) { state_read_t *fields = &v->tx_fields.stateRead; @@ -669,7 +640,6 @@ uint8_t getNumItemsManageNeurons(__Z_UNUSED const parser_context_t *c, const par case Configure_StartDissolving : { return 2; } - case Spawn : case Split: case Merge: case Configure_RemoveHotKey : @@ -683,10 +653,8 @@ uint8_t getNumItemsManageNeurons(__Z_UNUSED const parser_context_t *c, const par return 3; } case SNS_Configure_SetDissolveDelay: - case RegisterVote : case RegisterVoteCandid: - case DisburseCandid: - case Disburse : { + case DisburseCandid: { return 4; } case SpawnCandid: { @@ -752,7 +720,6 @@ uint8_t _getNumItems(__Z_UNUSED const parser_context_t *c, const parser_tx_t *v) return 2; } - // case pb_manageneuron : case candid_manageneuron: { return getNumItemsManageNeurons(c, v); } diff --git a/app/src/parser_txdef.h b/app/src/parser_txdef.h index 28d1f1f7..7bcdf4a4 100644 --- a/app/src/parser_txdef.h +++ b/app/src/parser_txdef.h @@ -19,8 +19,6 @@ #include #include -#define ZX_NO_CPP - #ifdef __cplusplus extern "C" { #endif @@ -36,8 +34,6 @@ extern "C" { #define METHOD_MAX_LEN 20 #define NONCE_MAX_LEN 32 -#define ARG_MAX_LEN 1000 - #define PATH_MAX_LEN 40 #define PATH_MAX_ARRAY 2 @@ -70,9 +66,6 @@ typedef enum { Configure_ChangeAutoStakeMaturity = 2009, //// - Disburse = 3, - Spawn = 4, - RegisterVote = 7, Split = 11, Merge = 1000, SpawnCandid = 1001, @@ -129,7 +122,6 @@ typedef struct { } nonce_t; typedef struct { - uint8_t data[ARG_MAX_LEN + 1]; uint8_t *dataPtr; size_t len; } method_arg_t; diff --git a/tests/ui_tests.cpp b/tests/ui_tests.cpp index b80d277d..4d04f5bf 100644 --- a/tests/ui_tests.cpp +++ b/tests/ui_tests.cpp @@ -19,7 +19,6 @@ using ::testing::TestWithParam; -class JsonTests_Phase1 : public JsonTests_Base {}; class JsonTests_Phase2 : public JsonTests_Base {}; class JsonTests_Candid_Send : public JsonTests_Base {}; class JsonTests_SNS_AddPermission : public JsonTests_Base {}; @@ -30,19 +29,6 @@ class JsonTests_SNS_SetDissolveDelay : public JsonTests_Base {}; class JsonTests_ICRC : public JsonTests_Base {}; class JsonTests_Deprecated : public JsonTests_Base {}; -// Commenting out bellow test as it uses protobuf transactions which are now -// not supported -/* INSTANTIATE_TEST_SUITE_P ( */ -/* Phase1, */ -/* JsonTests_Phase1, */ -/* ::testing::ValuesIn(GetJsonTestCases("manual.json")), */ -/* JsonTests_Phase1::PrintToStringParamName() */ -/* ); */ - -// Parametric test using current runtime: -// TEST_P(JsonTests_Phase1, Normal) { check_testcase(GetParam(), false); } - -// TEST_P(JsonTests_Phase1, Expert) { check_testcase(GetParam(), true); } //////////////////// //////////////////// diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index 4a4cc9fd..87bdb8eb 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -15,12 +15,9 @@ ******************************************************************************* */ import Zemu, { ButtonKind, zondaxMainmenuNavigation } from '@zondax/zemu' -import InternetComputerApp, { SIGN_VALUES_P2 } from '@zondax/ledger-icp' -import * as secp256k1 from 'secp256k1' +import InternetComputerApp from '@zondax/ledger-icp' import { DEFAULT_OPTIONS, DEVICE_MODELS } from './common' -import { sha256 } from 'js-sha256' - jest.setTimeout(180000) describe('Standard', function () { @@ -162,120 +159,4 @@ describe('Standard', function () { await sim.close() } }) - - // TODO: protobuf transaction which is not longer supported by ledger-application - - // test.concurrent.each(DEVICE_MODELS)('signNormalTokenTransfer', async function (m) { - // const sim = new Zemu(m.path) - // try { - // await sim.start({ ...DEFAULT_OPTIONS, model: m.name, startText: m.name === 'stax' ? '' : 'Computer' }) - // const app = new InternetComputerApp(sim.getTransport()) - // - // const respAddr = await app.getAddressAndPubKey("m/44'/223'/0'/0/0") - // console.log(respAddr) - // - // expect(respAddr.returnCode).toEqual(0x9000) - // expect(respAddr.errorMessage).toEqual('No errors') - // - // const expected_pk = - // '0410d34980a51af89d3331ad5fa80fe30d8868ad87526460b3b3e15596ee58e812422987d8589ba61098264df5bb9c2d3ff6fe061746b4b31a44ec26636632b835' - // expect((respAddr.publicKey ?? []).toString('hex')).toEqual(expected_pk) - // - // const txBlobStr = - // 'd9d9f7a367636f6e74656e74a76c726571756573745f747970656463616c6c656e6f6e636550f5390d960c6e52f489155a4309da03da6e696e67726573735f6578706972791b1674c5e29ec9c2106673656e646572581d19aa3d42c048dd7d14f0cfa0df69a1c1381780f6e9a137abaa6a82e3026b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f70626361726758560a0012050a0308e8071a0308890122220a2001010101010101010101010101010101010101010101010101010101010101012a220a2035548ec29e9d85305850e87a2d2642fe7214ff4bb36334070deafc3345c3b1276d73656e6465725f7075626b657958583056301006072a8648ce3d020106052b8104000a03420004e1142e1fbc940344d9161709196bb8bd151f94379c48dd507ab99a0776109128b94b5303cf2b2d28e25a779da175b62f8a975599b20c63d5193202640576ec5e6a73656e6465725f7369675840de5bccbb0a0173c432cd58ea4495d4d1e122d6ce04e31dcf63217f3d3a9b73130dc9bbf3b10e61c8db8bf8800bb4649e27786e5bc9418838c95864be28487a6a' - // - // const txBlob = Buffer.from(txBlobStr, 'hex') - // - // const respRequest = app.sign("m/44'/223'/0'/0/0", txBlob, SIGN_VALUES_P2.DEFAULT) - // - // // Wait until we are not in the main menu - // await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) - // - // await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic_normal`) - // - // const signatureResponse = await respRequest - // console.log(signatureResponse) - // - // expect(signatureResponse.returnCode).toEqual(0x9000) - // expect(signatureResponse.errorMessage).toEqual('No errors') - // - // const expected_preHash = '0a69632d7265717565737438d75af52910efe58a5c32b61d3343ad1a40f32d335e88cab5843ec69d7bdf6a' - // expect((signatureResponse.preSignHash ?? []).toString('hex')).toEqual(expected_preHash) - // - // const expected_hash = '3797e39b76c78c7b33f724ba7b44b28721c6318a32e608ccee3940f3cba49de3' - // const hash = sha256.hex(signatureResponse.preSignHash ?? []) - // expect(hash).toEqual(expected_hash) - // - // const pk = Uint8Array.from(respAddr.publicKey ?? []) - // expect(pk.byteLength).toEqual(65) - // const digest = Uint8Array.from(Buffer.from(hash, 'hex')) - // const signature = Uint8Array.from(signatureResponse.signatureRS ?? []) - // //const signature = secp256k1.signatureImport(Uint8Array.from(signatureResponse.signatureDER)); - // expect(signature.byteLength).toEqual(64) - // - // const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk) - // expect(signatureOk).toEqual(true) - // } finally { - // await sim.close() - // } - // }) - - // TODO: Unsupported transaction type(protobuf) - - // test.concurrent.each(DEVICE_MODELS)('signExpertTokenTransfer', async function (m) { - // const sim = new Zemu(m.path) - // try { - // await sim.start({ ...DEFAULT_OPTIONS, model: m.name, startText: m.name === 'stax' ? '' : 'Computer' }) - // const app = new InternetComputerApp(sim.getTransport()) - // - // // Enable expert mode - // console.log('Set expert mode') - // await sim.toggleExpertMode() - // - // // Get public key - // const respAddr = await app.getAddressAndPubKey("m/44'/223'/0'/0/0") - // console.log(respAddr) - // expect(respAddr.returnCode).toEqual(0x9000) - // expect(respAddr.errorMessage).toEqual('No errors') - // const expected_pk = - // '0410d34980a51af89d3331ad5fa80fe30d8868ad87526460b3b3e15596ee58e812422987d8589ba61098264df5bb9c2d3ff6fe061746b4b31a44ec26636632b835' - // expect((respAddr.publicKey ?? []).toString('hex')).toEqual(expected_pk) - // - // // Sign blob - // const txBlobStr = - // 'd9d9f7a367636f6e74656e74a76c726571756573745f747970656463616c6c656e6f6e636550f5390d960c6e52f489155a4309da03da6e696e67726573735f6578706972791b1674c5e29ec9c2106673656e646572581d19aa3d42c048dd7d14f0cfa0df69a1c1381780f6e9a137abaa6a82e3026b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f70626361726758560a0012050a0308e8071a0308890122220a2001010101010101010101010101010101010101010101010101010101010101012a220a2035548ec29e9d85305850e87a2d2642fe7214ff4bb36334070deafc3345c3b1276d73656e6465725f7075626b657958583056301006072a8648ce3d020106052b8104000a03420004e1142e1fbc940344d9161709196bb8bd151f94379c48dd507ab99a0776109128b94b5303cf2b2d28e25a779da175b62f8a975599b20c63d5193202640576ec5e6a73656e6465725f7369675840de5bccbb0a0173c432cd58ea4495d4d1e122d6ce04e31dcf63217f3d3a9b73130dc9bbf3b10e61c8db8bf8800bb4649e27786e5bc9418838c95864be28487a6a' - // const txBlob = Buffer.from(txBlobStr, 'hex') - // const respRequest = app.sign("m/44'/223'/0'/0/0", txBlob, SIGN_VALUES_P2.DEFAULT) - // - // // Wait until we are not in the main menu - // await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) - // - // await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic_expert`) - // - // const signatureResponse = await respRequest - // console.log(signatureResponse) - // - // expect(signatureResponse.returnCode).toEqual(0x9000) - // expect(signatureResponse.errorMessage).toEqual('No errors') - // - // const expected_preHash = '0a69632d7265717565737438d75af52910efe58a5c32b61d3343ad1a40f32d335e88cab5843ec69d7bdf6a' - // expect((signatureResponse.preSignHash ?? []).toString('hex')).toEqual(expected_preHash) - // - // const expected_hash = '3797e39b76c78c7b33f724ba7b44b28721c6318a32e608ccee3940f3cba49de3' - // const hash = sha256.hex(signatureResponse.preSignHash ?? []) - // expect(hash).toEqual(expected_hash) - // - // const pk = Uint8Array.from(respAddr.publicKey ?? []) - // expect(pk.byteLength).toEqual(65) - // const digest = Uint8Array.from(Buffer.from(hash, 'hex')) - // const signature = Uint8Array.from(signatureResponse.signatureRS ?? []) - // //const signature = secp256k1.signatureImport(Uint8Array.from(signatureResponse.signatureDER)); - // expect(signature.byteLength).toEqual(64) - // - // const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk) - // expect(signatureOk).toEqual(true) - // } finally { - // await sim.close() - // } - // }) })