diff --git a/app/src/apdu_handler_legacy.c b/app/src/apdu_handler_legacy.c index efaee41..19c5509 100644 --- a/app/src/apdu_handler_legacy.c +++ b/app/src/apdu_handler_legacy.c @@ -380,14 +380,11 @@ void legacy_handleSignTransferTx(volatile uint32_t *flags, volatile uint32_t *tx tx_type = tx_type_transaction; CHECK_APP_CANARY() if (error_msg != NULL) { - const int 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); + tx_reset(); + *tx = 0; + THROW(APDU_CODE_LEGACY_PARSER_ERROR); } - THROW(APDU_CODE_OK); - view_review_init(tx_getItem, tx_getNumItems, legacy_app_sign); view_review_show(REVIEW_TXN); *flags |= IO_ASYNCH_REPLY; diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00000.png b/tests_zemu/snapshots/sp-sign_hash_1/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00001.png b/tests_zemu/snapshots/sp-sign_hash_1/00001.png new file mode 100644 index 0000000..974d2e7 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00002.png b/tests_zemu/snapshots/sp-sign_hash_1/00002.png new file mode 100644 index 0000000..a58dfd1 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00003.png b/tests_zemu/snapshots/sp-sign_hash_1/00003.png new file mode 100644 index 0000000..15de6b1 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00004.png b/tests_zemu/snapshots/sp-sign_hash_1/00004.png new file mode 100644 index 0000000..e2f1fad Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00005.png b/tests_zemu/snapshots/sp-sign_hash_1/00005.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00006.png b/tests_zemu/snapshots/sp-sign_hash_1/00006.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00007.png b/tests_zemu/snapshots/sp-sign_hash_1/00007.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_1/00008.png b/tests_zemu/snapshots/sp-sign_hash_1/00008.png new file mode 100644 index 0000000..58ec4be Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_1/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00000.png b/tests_zemu/snapshots/sp-sign_hash_2/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00001.png b/tests_zemu/snapshots/sp-sign_hash_2/00001.png new file mode 100644 index 0000000..974d2e7 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00002.png b/tests_zemu/snapshots/sp-sign_hash_2/00002.png new file mode 100644 index 0000000..a58dfd1 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00003.png b/tests_zemu/snapshots/sp-sign_hash_2/00003.png new file mode 100644 index 0000000..15de6b1 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00004.png b/tests_zemu/snapshots/sp-sign_hash_2/00004.png new file mode 100644 index 0000000..e2f1fad Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00005.png b/tests_zemu/snapshots/sp-sign_hash_2/00005.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00006.png b/tests_zemu/snapshots/sp-sign_hash_2/00006.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00007.png b/tests_zemu/snapshots/sp-sign_hash_2/00007.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_hash_2/00008.png b/tests_zemu/snapshots/sp-sign_hash_2/00008.png new file mode 100644 index 0000000..58ec4be Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_hash_2/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00000.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00001.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00001.png new file mode 100644 index 0000000..ba22ea5 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00002.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00002.png new file mode 100644 index 0000000..cb84a2b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00003.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00003.png new file mode 100644 index 0000000..e4ade64 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00004.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00004.png new file mode 100644 index 0000000..82de24c Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00005.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00005.png new file mode 100644 index 0000000..d609904 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00006.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00006.png new file mode 100644 index 0000000..99f0b15 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00007.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00007.png new file mode 100644 index 0000000..79f0c4a Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00008.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00008.png new file mode 100644 index 0000000..2bb1f90 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00009.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00009.png new file mode 100644 index 0000000..c39b28b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00009.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00010.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00010.png new file mode 100644 index 0000000..131116b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00010.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00011.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00011.png new file mode 100644 index 0000000..9eae1e4 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00011.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00012.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00012.png new file mode 100644 index 0000000..c02868b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00012.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00013.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00013.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00013.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00014.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00014.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00014.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00015.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00015.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00015.png differ diff --git a/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00016.png b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00016.png new file mode 100644 index 0000000..58ec4be Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_simple_transfer_legacy/00016.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00000.png b/tests_zemu/snapshots/sp-sign_transfer_1/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00001.png b/tests_zemu/snapshots/sp-sign_transfer_1/00001.png new file mode 100644 index 0000000..ba22ea5 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00002.png b/tests_zemu/snapshots/sp-sign_transfer_1/00002.png new file mode 100644 index 0000000..8b66af1 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00003.png b/tests_zemu/snapshots/sp-sign_transfer_1/00003.png new file mode 100644 index 0000000..e4ade64 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00004.png b/tests_zemu/snapshots/sp-sign_transfer_1/00004.png new file mode 100644 index 0000000..024f1c6 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00005.png b/tests_zemu/snapshots/sp-sign_transfer_1/00005.png new file mode 100644 index 0000000..76cd8f9 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00006.png b/tests_zemu/snapshots/sp-sign_transfer_1/00006.png new file mode 100644 index 0000000..99f0b15 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00007.png b/tests_zemu/snapshots/sp-sign_transfer_1/00007.png new file mode 100644 index 0000000..7c60378 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00008.png b/tests_zemu/snapshots/sp-sign_transfer_1/00008.png new file mode 100644 index 0000000..249687b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00009.png b/tests_zemu/snapshots/sp-sign_transfer_1/00009.png new file mode 100644 index 0000000..d82d455 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00009.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00010.png b/tests_zemu/snapshots/sp-sign_transfer_1/00010.png new file mode 100644 index 0000000..131116b Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00010.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00011.png b/tests_zemu/snapshots/sp-sign_transfer_1/00011.png new file mode 100644 index 0000000..d41cee4 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00011.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00012.png b/tests_zemu/snapshots/sp-sign_transfer_1/00012.png new file mode 100644 index 0000000..e704761 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00012.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00013.png b/tests_zemu/snapshots/sp-sign_transfer_1/00013.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00013.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00014.png b/tests_zemu/snapshots/sp-sign_transfer_1/00014.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00014.png differ diff --git a/tests_zemu/snapshots/sp-sign_transfer_1/00015.png b/tests_zemu/snapshots/sp-sign_transfer_1/00015.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_transfer_1/00015.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00000.png b/tests_zemu/snapshots/x-sign_hash_1/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00000.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00001.png b/tests_zemu/snapshots/x-sign_hash_1/00001.png new file mode 100644 index 0000000..974d2e7 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00001.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00002.png b/tests_zemu/snapshots/x-sign_hash_1/00002.png new file mode 100644 index 0000000..a58dfd1 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00002.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00003.png b/tests_zemu/snapshots/x-sign_hash_1/00003.png new file mode 100644 index 0000000..15de6b1 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00003.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00004.png b/tests_zemu/snapshots/x-sign_hash_1/00004.png new file mode 100644 index 0000000..e2f1fad Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00004.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00005.png b/tests_zemu/snapshots/x-sign_hash_1/00005.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00005.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00006.png b/tests_zemu/snapshots/x-sign_hash_1/00006.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00006.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00007.png b/tests_zemu/snapshots/x-sign_hash_1/00007.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00007.png differ diff --git a/tests_zemu/snapshots/x-sign_hash_1/00008.png b/tests_zemu/snapshots/x-sign_hash_1/00008.png new file mode 100644 index 0000000..58ec4be Binary files /dev/null and b/tests_zemu/snapshots/x-sign_hash_1/00008.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00000.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00000.png new file mode 100644 index 0000000..33a7bd8 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00000.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00001.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00001.png new file mode 100644 index 0000000..ba22ea5 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00001.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00002.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00002.png new file mode 100644 index 0000000..8b66af1 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00002.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00003.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00003.png new file mode 100644 index 0000000..e4ade64 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00003.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00004.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00004.png new file mode 100644 index 0000000..024f1c6 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00004.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00005.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00005.png new file mode 100644 index 0000000..76cd8f9 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00005.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00006.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00006.png new file mode 100644 index 0000000..99f0b15 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00006.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00007.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00007.png new file mode 100644 index 0000000..7c60378 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00007.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00008.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00008.png new file mode 100644 index 0000000..249687b Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00008.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00009.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00009.png new file mode 100644 index 0000000..d82d455 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00009.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00010.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00010.png new file mode 100644 index 0000000..131116b Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00010.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00011.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00011.png new file mode 100644 index 0000000..d41cee4 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00011.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00012.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00012.png new file mode 100644 index 0000000..e704761 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00012.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00013.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00013.png new file mode 100644 index 0000000..7234d99 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00013.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00014.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00014.png new file mode 100644 index 0000000..0c0a855 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00014.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00015.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00015.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00015.png differ diff --git a/tests_zemu/snapshots/x-sign_transfer_1_legacy/00016.png b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00016.png new file mode 100644 index 0000000..58ec4be Binary files /dev/null and b/tests_zemu/snapshots/x-sign_transfer_1_legacy/00016.png differ diff --git a/tests_zemu/tests/legacy.test.ts b/tests_zemu/tests/legacy.test.ts index efd5362..d4b25e2 100644 --- a/tests_zemu/tests/legacy.test.ts +++ b/tests_zemu/tests/legacy.test.ts @@ -21,7 +21,7 @@ import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs' import { JSON_TEST_CASES } from './testscases/json' import { HASH_TEST_CASES } from './testscases/hash' -import { TRANSACTIONS_TEST_CASES } from './testscases/transactions' +import { TRANSACTIONS_LEGACY_TEST_CASES } from './testscases/transactions' import { APDU_TEST_CASES } from './testscases/legacy_apdu' // @ts-expect-error import ed25519 from 'ed25519-supercop' @@ -181,37 +181,29 @@ describe.each(HASH_TEST_CASES)('Hash transactions', function (data) { }) }) -describe.each(TRANSACTIONS_TEST_CASES)('Tx transactions', function (data) { +describe.each(TRANSACTIONS_LEGACY_TEST_CASES)('Tx transactions', function (data) { test.only.each(models)('sign', async function (m) { const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) const app = new Kda(sim.getTransport()); - const responseAddr = await app.getPublicKey(data.txParams.path) - const pubKey = responseAddr.publicKey - console.log(pubKey) + const { publicKey } = await app.getPublicKey(data.txParams.path); - // do not wait here... we need to navigate - let signatureRequest = await app["signTransferTx"](data.txParams); + let signatureRequest = app["signTransferTx"](data.txParams); - // // Wait until we are not in the main menu - // await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) - // await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}`) - - // const signatureResponse = await signatureRequest - // console.log(signatureResponse) - - // const rawHash = - // typeof data.hash == 'string' - // ? data.hash.length == 64 - // ? Buffer.from(data.hash, 'hex') - // : Buffer.from(data.hash, 'base64') - // : Buffer.from(data.hash) - // // Now verify the signature - // const valid = ed25519.verify(signatureResponse.signature, rawHash, pubKey) - // expect(valid).toEqual(true) + await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) + await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}_legacy`) + + // Wait until we are not in the main menu + const signatureResponse = await signatureRequest + console.log("Pubkey: ", publicKey.toString('hex')) + console.log("Signature: ", signatureResponse.signature) + + // Now verify the signature + const valid = ed25519.verify(signatureResponse.signature, signatureResponse.hash, publicKey) + expect(valid).toEqual(true) } finally { await sim.close() } diff --git a/tests_zemu/tests/testscases/transactions.ts b/tests_zemu/tests/testscases/transactions.ts index 5768b3d..520eb1d 100644 --- a/tests_zemu/tests/testscases/transactions.ts +++ b/tests_zemu/tests/testscases/transactions.ts @@ -18,6 +18,7 @@ export const TRANSACTIONS_TEST_CASES = [ ttl: '600', nonce: '2022-10-13 07:56:50.893257 UTC', }, + recipient_chainId: 0, }, { name: 'transfer_create_1', diff --git a/tests_zemu/try.mjs b/tests_zemu/try.mjs index 541886d..26c19ab 100644 --- a/tests_zemu/try.mjs +++ b/tests_zemu/try.mjs @@ -4,6 +4,30 @@ import { ed25519 } from '@noble/curves/ed25519' import pkg from 'blakejs' const { blake2bFinal, blake2bInit, blake2bUpdate } = pkg +async function verifySignature(signature, message, publicKey, computeBlake2b = true) { + let hash = message + if (computeBlake2b) { + const context = blake2bInit(32) + blake2bUpdate(context, message) + hash = Buffer.from(blake2bFinal(context)) + } + + const valid = ed25519.verify(signature, hash, publicKey) + if (valid) { + console.log('Valid signature') + } else { + console.log('Invalid signature') + } +} + +function decodeHash(encodedHash) { + let base64Hash = encodedHash.replace(/-/g, '+').replace(/_/g, '/'); + while (base64Hash.length % 4) { + base64Hash += '='; + } + return Buffer.from(base64Hash, 'base64'); +} + async function main() { const transport = await TransportNodeHid.default.open() @@ -21,26 +45,59 @@ async function main() { resp = await app.getVersion() console.log('Version', resp) + // Sign a transaction + console.log("Signing a transaction") const blob = '{"networkId":"mainnet01","payload":{"exec":{"data":{"ks":{"pred":"keys-all","keys":["368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"]}},"code":"(coin.transfer-create \\"alice\\" \\"bob\\" (read-keyset \\"ks\\") 100.1)\\n(coin.transfer \\"bob\\" \\"alice\\" 0.1)"}},"signers":[{"pubKey":"6be2f485a7af75fedb4b7f153a903f7e6000ca4aa501179c91a2450b777bd2a7","clist":[{"args":["alice","bob",100.1],"name":"coin.TRANSFER"},{"args":[],"name":"coin.GAS"}]},{"pubKey":"368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca","clist":[{"args":["bob","alice",0.1],"name":"coin.TRANSFER"}]}],"meta":{"creationTime":1580316382,"ttl":7200,"gasLimit":1200,"chainId":"0","gasPrice":1.0e-5,"sender":"alice"},"nonce":"2020-01-29 16:46:22.916695 UTC"}' - const messageToSign = Buffer.from(blob) + let messageToSign = Buffer.from(blob) console.log(messageToSign.toString()) - const signatureRequest = app.sign(PATH, messageToSign) + let signatureRequest = app.sign(PATH, messageToSign) - const signatureResponse = await signatureRequest + let signatureResponse = await signatureRequest console.log(signatureResponse.signature.toString('hex')) - const context = blake2bInit(32) - blake2bUpdate(context, messageToSign) - const hash = Buffer.from(blake2bFinal(context)) + await verifySignature(signatureResponse.signature, messageToSign, pubKey) - // Now verify the signature - const valid = ed25519.verify(signatureResponse.signature, hash, pubKey) - if (valid) { - console.log('Valid signature') - } else { - console.log('Invalid signature') - } + // Sign a hash + console.log("Signing a hash") + messageToSign = 'ffd8cd79deb956fa3c7d9be0f836f20ac84b140168a087a842be4760e40e2b1c' + console.log(messageToSign.toString()) + signatureRequest = app.signHash(PATH, messageToSign); + + signatureResponse = await signatureRequest + console.log(signatureResponse.signature.toString('hex')) + + const rawHash = + typeof messageToSign== 'string' + ? messageToSign.length == 64 + ? Buffer.from(messageToSign, 'hex') + : Buffer.from(messageToSign, 'base64') + : Buffer.from(messageToSign) + + await verifySignature(signatureResponse.signature, rawHash, pubKey, false) + + console.log("Signing a transfer") + const txParams = { + path: PATH, + recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790', + amount: '1.23', + network: 'testnet04', + chainId: 0, + gasPrice: '1.0e-6', + gasLimit: '2300', + creationTime: 1665647810, + ttl: '600', + nonce: '2022-10-13 07:56:50.893257 UTC', + }; + + signatureRequest = app.signTransferTx(txParams.path, txParams) + signatureResponse = await signatureRequest + const decodedHash = decodeHash(signatureResponse.hash) + + console.log(signatureResponse.signature.toString('hex')) + console.log(decodedHash.toString('hex')) + + await verifySignature(signatureResponse.signature, decodedHash, pubKey, false) } ;(async () => { diff --git a/tests_zemu/try_legacy.mjs b/tests_zemu/try_legacy.mjs index 1bd25f1..367759f 100644 --- a/tests_zemu/try_legacy.mjs +++ b/tests_zemu/try_legacy.mjs @@ -4,10 +4,13 @@ import { ed25519 } from '@noble/curves/ed25519' import pkg from 'blakejs' const { blake2bFinal, blake2bInit, blake2bUpdate } = pkg -async function verifySignature(signature, message, publicKey) { - const context = blake2bInit(32) - blake2bUpdate(context, message) - const hash = Buffer.from(blake2bFinal(context)) +async function verifySignature(signature, message, publicKey, computeBlake2b = true) { + let hash = message + if (computeBlake2b) { + const context = blake2bInit(32) + blake2bUpdate(context, message) + hash = Buffer.from(blake2bFinal(context)) + } const valid = ed25519.verify(signature, hash, publicKey) if (valid) { @@ -17,6 +20,16 @@ async function verifySignature(signature, message, publicKey) { } } +function decodeHash(encodedHash) { + let base64Hash = encodedHash.replace(/-/g, '+').replace(/_/g, '/'); + + while (base64Hash.length % 4) { + base64Hash += '='; + } + + return Buffer.from(base64Hash, 'base64'); +} + async function main() { const transport = await TransportNodeHid.default.open() const app = new Kda.default(transport);; @@ -46,12 +59,42 @@ async function main() { signatureRequest = app.signHash(PATH, messageToSign); signatureResponse = await signatureRequest + console.log(messageToSign.toString()) console.log(signatureResponse.signature.toString('hex')) - await verifySignature(signatureResponse.signature, messageToSign, publicKey) - + await verifySignature(signatureResponse.signature, messageToSign, publicKey, false) + + // Sign a hash + console.log("Signing a transfer") + const txParams = { + path: PATH, + recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790', + amount: '1.23', + network: 'testnet04', + chainId: 0, + gasPrice: '1.0e-6', + gasLimit: '2300', + creationTime: 1665647810, + ttl: '600', + nonce: '2022-10-13 07:56:50.893257 UTC', + }; + + signatureRequest = app["signTransferTx"](txParams); + signatureResponse = await signatureRequest + + // Convert hex string signature to Uint8Array + const signatureHex = signatureResponse.pact_command.sigs[0].sig; + const signatureBytes = new Uint8Array(Buffer.from(signatureHex, 'hex')); + + const hashBytes = decodeHash(signatureResponse.pact_command.hash) + + console.log(signatureResponse.pact_command.sigs[0].sig.toString('hex')) + console.log(hashBytes.toString('hex')) + + await verifySignature(signatureBytes, hashBytes, publicKey, false) } ;(async () => { await main() })() +