diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..1f7d1915 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 125 +DerivePointerAlignment: false +PointerAlignment: Right diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..2cefa098 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,22 @@ +Checks: "-*, + clang-diagnostic-*, + clang-analyzer-*, + cppcoreguidelines-init-variables, + google-runtime-int, + google-readability-avoid-underscore-in-googletest-name, + misc-*, + performance-*, + portability-*, + readability-*, + -misc-no-recursion, + -readability-function-cognitive-complexity" +WarningsAsErrors: "*" +CheckOptions: + - key: readability-identifier-length.MinimumVariableNameLength + value: 2 + - key: readability-identifier-length.MinimumParameterNameLength + value: 2 + - key: readability-identifier-length.MinimumLoopCounterNameLength + value: 1 + - key: readability-magic-numbers.IgnorePowersOf2IntegerValues + value: true diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 2d7db14f..00000000 --- a/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -# top-most EditorConfig file -root = true - -[*] -charset = utf-8 -trim_trailing_whitespace = true -end_of_line = lf -insert_final_newline = true - -[*.{c,h,cpp,hpp}] -indent_style = space -indent_size = 4 - -[*.{yml,sh}] -indent_style = space -indent_size = 2 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml deleted file mode 100644 index 1f9ca750..00000000 --- a/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Sonarcloud - -on: - push: - branches: - - disable - pull_request: - branches: - - disable - types: [opened, synchronize, reopened] - -jobs: - build: - name: SonarQube analyze - runs-on: ubuntu-latest - container: - image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder@sha256:877adc3ff619222aaf03a490d546ea9001f02faa0c6ac7c06c876c99584f9cdb - env: - SONAR_SCANNER_VERSION: 4.7.0.2747 - SONAR_SERVER_URL: "https://sonarcloud.io" - BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Download and set up sonar-scanner - env: - SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip - run: | - apt-get update -y - apt-get upgrade -y - curl -sL https://deb.nodesource.com/setup_16.x | bash - - apt-get install -y gcovr nodejs unzip - mkdir -p $HOME/.sonar - curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH - - name: Download and set up build-wrapper - env: - BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip - run: | - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH - - name: Run build-wrapper - run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make clean all - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" diff --git a/.gitignore b/.gitignore index 48621352..0dec6a16 100644 --- a/.gitignore +++ b/.gitignore @@ -47,55 +47,36 @@ # Kernel Module Compile Results *.mod* *.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf - -\cmake-build-debug -\.idea/ -/tmp/ -/deps/nano2-sdk/ - -# Created by cmake -googletest-download/ -googletest-src/ -googletest-build/ -CMakeFiles/ -CMakeCache.txt -unittests -*.cmake -Testing/ -cmake-build-fuzz/ - -# Others -/cmake-build-debug/ -/cmake-build-fuzz/ -\.idea -/app/bin/ -/app/debug/ -/app/obj/ - -\deps/* -!\deps/nanos-secure-sdk -!\deps/nanox-secure-sdk -!\deps/ledger-zxlib -!\deps/tinycbor -!\deps/tinycbor-ledger -!\deps/BLAKE - -app/src/glyphs.c - -app/src/glyphs.h -/build -.vscode/dryrun.log -.vscode/targets.log + +########################## + +tests_zemu/.yarn/* +tests_zemu/!.yarn/patches +tests_zemu/!.yarn/releases +tests_zemu/!.yarn/plugins +tests_zemu/!.yarn/sdks +tests_zemu/!.yarn/versions +tests_zemu/.pnp.* +######################### + +.vscode +.idea + +node_modules +fuzz/corpora + +!build/.gitkeep + + +build/* +cmake-build-debug app/build/* -.DS_Store +tests_zemu/snapshots-tmp +tests_zemu/yarn.lock +tests_tools/target fuzz-*.log -/fuzz/corpora -.vscode/ -tests_zemu/yarn.lock +/scan-build + +tests_zemu/bun.lockb diff --git a/.gitmodules b/.gitmodules index 168786d1..24e1e14d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,3 @@ -[submodule "deps/nanos-secure-sdk"] - path = deps/nanos-secure-sdk - url = https://github.com/LedgerHQ/ledger-secure-sdk.git -[submodule "deps/nanox-secure-sdk"] - path = deps/nanox-secure-sdk - url = https://github.com/LedgerHQ/ledger-secure-sdk.git -[submodule "deps/nanosplus-secure-sdk"] - path = deps/nanosplus-secure-sdk - url = https://github.com/LedgerHQ/ledger-secure-sdk.git [submodule "deps/ledger-zxlib"] path = deps/ledger-zxlib - url = https://github.com/Zondax/ledger-zxlib.git -[submodule "deps/stax-secure-sdk"] - path = deps/stax-secure-sdk - url = https://github.com/LedgerHQ/ledger-secure-sdk -[submodule "deps/ledger-secure-sdk"] - path = deps/ledger-secure-sdk - url = https://github.com/LedgerHQ/ledger-secure-sdk + url = https://github.com/Zondax/ledger-zxlib.git \ No newline at end of file diff --git a/.sonarcloud.properties b/.sonarcloud.properties deleted file mode 100644 index c5d2136c..00000000 --- a/.sonarcloud.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Path to sources -# sonar.sources= -# sonar.exclusions= -# sonar.inclusions= - -# Path to tests -# sonar.tests= -# sonar.test.exclusions= -# sonar.test.inclusions= - -# Source encoding -# sonar.sourceEncoding= - -# Exclusions for copy-paste detection -# sonar.cpd.exclusions= -# Python version (for python projects only) -# sonar.python.version= \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0faeae86..b58baaec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ #* See the License for the specific language governing permissions and #* limitations under the License. #******************************************************************************** -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.28) include("cmake/HunterGate.cmake") HunterGate( URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz" @@ -21,15 +21,25 @@ HunterGate( LOCAL ) -project(ledger-cosmos VERSION 0.0.0) -enable_testing() +if(CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR "This project does not support the Ninja generator. " + "Please use Unix Makefiles or another supported generator. " + "This error is typical in CLion. In this case, switch to generator Unix Makefiles.") +endif() + +######################################################## +project(ledger-spacemesh VERSION 0.0.0) + +set(CMAKE_CXX_STANDARD 17) cmake_policy(SET CMP0025 NEW) -set(CMAKE_CXX_STANDARD 11) +cmake_policy(SET CMP0144 NEW) set(HUNTER_STATUS_DEBUG ON) set(HUNTER_TLS_VERIFY OFF) +enable_testing() + option(ENABLE_FUZZING "Build with fuzzing instrumentation and build fuzz targets" OFF) option(ENABLE_COVERAGE "Build with source code coverage instrumentation" OFF) option(ENABLE_SANITIZERS "Build with ASAN and UBSAN" OFF) @@ -42,8 +52,10 @@ add_definitions(-DAPP_STANDARD) hunter_add_package(fmt) find_package(fmt CONFIG REQUIRED) + hunter_add_package(jsoncpp) find_package(jsoncpp CONFIG REQUIRED) + hunter_add_package(GTest) find_package(GTest CONFIG REQUIRED) @@ -66,9 +78,9 @@ if(ENABLE_FUZZING) endif() else() message(FATAL_ERROR - "You are using an unsupported compiler! Fuzzing only works with Clang 10.\n" + "Unsupported compiler! Fuzzing requires Clang 10.\n" "1. Install clang-10 \n" - "2. Pass -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10") + "2. Use -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10") endif() string(APPEND CMAKE_C_FLAGS " -fsanitize=fuzzer-no-link") @@ -88,12 +100,37 @@ if(ENABLE_SANITIZERS) string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address,undefined -fsanitize-recover=address,undefined") endif() +set (RETRIEVE_MAJOR_CMD + "cat ${CMAKE_CURRENT_SOURCE_DIR}/app/Makefile.version | grep APPVERSION_M | cut -b 14- | tr -d '\n'" +) +set (RETRIEVE_MINOR_CMD + "cat ${CMAKE_CURRENT_SOURCE_DIR}/app/Makefile.version | grep APPVERSION_N | cut -b 14- | tr -d '\n'" +) +execute_process( + COMMAND bash "-c" ${RETRIEVE_MAJOR_CMD} + RESULT_VARIABLE MAJOR_RESULT + OUTPUT_VARIABLE MAJOR_VERSION +) +execute_process( + COMMAND bash "-c" ${RETRIEVE_MINOR_CMD} + RESULT_VARIABLE MINOR_RESULT + OUTPUT_VARIABLE MINOR_VERSION +) + +message(STATUS "LEDGER_MAJOR_VERSION [${MAJOR_RESULT}]: ${MAJOR_VERSION}" ) +message(STATUS "LEDGER_MINOR_VERSION [${MINOR_RESULT}]: ${MINOR_VERSION}" ) + +add_definitions( + -DLEDGER_MAJOR_VERSION=${MAJOR_VERSION} + -DLEDGER_MINOR_VERSION=${MINOR_VERSION} +) + string(APPEND CMAKE_CXX_FLAGS " -fsanitize=address -fno-omit-frame-pointer") string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address -fno-omit-frame-pointer") ############################################################## ############################################################## -# static libs +# Static Libraries file(GLOB_RECURSE JSMN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/deps/jsmn/src/jsmn.c ) @@ -142,6 +179,19 @@ target_include_directories(app_lib PUBLIC target_link_libraries(app_lib PUBLIC) ############################################################## +# Fuzz Targets +if(ENABLE_FUZZING) + set(FUZZ_TARGETS + parser_parse + parser_message_parse + ) + + foreach(target ${FUZZ_TARGETS}) + add_executable(fuzz-${target} ${CMAKE_CURRENT_SOURCE_DIR}/fuzz/${target}.cpp) + target_link_libraries(fuzz-${target} PRIVATE app_lib) + target_link_options(fuzz-${target} PRIVATE "-fsanitize=fuzzer") + endforeach() +else() ############################################################## # Tests file(GLOB_RECURSE TESTS_SRC @@ -149,13 +199,15 @@ file(GLOB_RECURSE TESTS_SRC add_executable(unittests ${TESTS_SRC}) target_include_directories(unittests PRIVATE + ${gtest_SOURCE_DIR}/include + ${gmock_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/deps/jsmn/src ${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src ) target_link_libraries(unittests PRIVATE - GTest::gtest_main app_lib + GTest::gtest_main fmt::fmt JsonCpp::JsonCpp) @@ -164,18 +216,4 @@ add_compile_definitions(APP_TESTING=1) add_compile_definitions(COMPILE_TEXTUAL=1) add_test(NAME unittests COMMAND unittests) set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests) - -############################################################## -############################################################## -# Fuzz Targets -if(ENABLE_FUZZING) - set(FUZZ_TARGETS - parser_parse - ) - - foreach(target ${FUZZ_TARGETS}) - add_executable(fuzz-${target} ${CMAKE_CURRENT_SOURCE_DIR}/fuzz/${target}.cpp) - target_link_libraries(fuzz-${target} PRIVATE app_lib) - target_link_options(fuzz-${target} PRIVATE "-fsanitize=fuzzer") - endforeach() endif() diff --git a/app/Makefile.version b/app/Makefile.version index ade301ef..29648da5 100644 --- a/app/Makefile.version +++ b/app/Makefile.version @@ -3,4 +3,5 @@ APPVERSION_M=2 # This is the `spec_version` field of `Runtime` APPVERSION_N=35 # This is the patch version of this release -APPVERSION_P=24 +APPVERSION_P=25 + diff --git a/deps/ledger-secure-sdk b/deps/ledger-secure-sdk deleted file mode 160000 index b46b4b51..00000000 --- a/deps/ledger-secure-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b46b4b516650c08dfe913054dc7535dd52e2503a diff --git a/deps/ledger-zxlib b/deps/ledger-zxlib index 271f40ce..50df5b5c 160000 --- a/deps/ledger-zxlib +++ b/deps/ledger-zxlib @@ -1 +1 @@ -Subproject commit 271f40ce03219eac8396a309ce9704977cf59caa +Subproject commit 50df5b5c1551ff99ad06716d0772a4a4be2cbb35 diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index da91272d..00000000 --- a/sonar-project.properties +++ /dev/null @@ -1,2 +0,0 @@ -sonar.projectKey=Cosmos_ledger-cosmos -sonar.organization=cosmos \ No newline at end of file diff --git a/tests_zemu/.editorconfig b/tests_zemu/.editorconfig deleted file mode 100644 index 4a7ea303..00000000 --- a/tests_zemu/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/tests_zemu/.eslintrc.js b/tests_zemu/.eslintrc.js deleted file mode 100644 index caf98057..00000000 --- a/tests_zemu/.eslintrc.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint', 'jest'], - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:jest/recommended', 'prettier'], - env: { - browser: true, - es6: true, - node: true, - }, - settings: {}, - globals: { - Atomics: 'readonly', - SharedArrayBuffer: 'readonly', - }, - parserOptions: {}, - rules: { - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-var-requires': 0, - '@typescript-eslint/ban-ts-comment': 'off', - }, -} diff --git a/tests_zemu/.npmignore b/tests_zemu/.npmignore deleted file mode 100644 index 3c3629e6..00000000 --- a/tests_zemu/.npmignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/tests_zemu/eslint.config.js b/tests_zemu/eslint.config.js new file mode 100644 index 00000000..27568347 --- /dev/null +++ b/tests_zemu/eslint.config.js @@ -0,0 +1,36 @@ +module.exports = { + languageOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + globals: { + window: 'readonly', + document: 'readonly', + process: 'readonly', + require: 'readonly', + }, + parserOptions: { + project: 'tsconfig.json', + }, + }, + ignores: ['dist/*', 'node_modules/*'], + plugins: { + 'unused-imports': require('eslint-plugin-unused-imports'), + '@typescript-eslint': require('@typescript-eslint/eslint-plugin'), + 'eslint-plugin-tsdoc': require('eslint-plugin-tsdoc'), + }, + rules: { + curly: 'warn', + 'prefer-const': 'warn', + 'no-else-return': 'warn', + complexity: ['warn', 1000], + 'no-unneeded-ternary': 'warn', + 'no-alert': 'warn', + 'no-empty': 'warn', + 'no-useless-catch': 'error', + 'require-await': 'warn', + 'no-continue': 'warn', + 'no-console': 'warn', + 'unused-imports/no-unused-imports': 'warn', + 'no-magic-numbers': 'off', + }, +} diff --git a/tests_zemu/globalsetup.js b/tests_zemu/globalsetup.js index a7875ea2..5837308b 100644 --- a/tests_zemu/globalsetup.js +++ b/tests_zemu/globalsetup.js @@ -1,16 +1,21 @@ -import Zemu from '@zondax/zemu' +const Zemu = require('@zondax/zemu') -const catchExit = async () => { - process.on('SIGINT', () => { - Zemu.stopAllEmuContainers(function () { - process.exit() - }) +/** + * Sets up a handler to stop all emulator containers when a SIGINT is received. + */ +const catchExit = () => { + process.on('SIGINT', async () => { + await Zemu.default.stopAllEmuContainers() + process.exit() }) } +/** + * Initializes the emulator environment by setting up exit handlers, + * pulling the latest emulator image, and stopping any running emulator containers. + */ module.exports = async () => { - await catchExit() - await Zemu.checkAndPullImage() - await Zemu.stopAllEmuContainers() + catchExit() + await Zemu.default.checkAndPullImage() + await Zemu.default.stopAllEmuContainers() } -// diff --git a/tests_zemu/jest.config.js b/tests_zemu/jest.config.js index c4a20eb0..0f3cac0a 100644 --- a/tests_zemu/jest.config.js +++ b/tests_zemu/jest.config.js @@ -2,4 +2,6 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', transformIgnorePatterns: ['^.+\\.js$'], + reporters: ['default', ['summary', { summaryThreshold: 1 }]], + globalSetup: './globalsetup.js', } diff --git a/tests_zemu/jest.js b/tests_zemu/jest.js deleted file mode 100644 index 2fa397e7..00000000 --- a/tests_zemu/jest.js +++ /dev/null @@ -1,2 +0,0 @@ -export default jest; -export const { expect, test } = global; diff --git a/tests_zemu/package.json b/tests_zemu/package.json index 873e82ac..e48084ad 100644 --- a/tests_zemu/package.json +++ b/tests_zemu/package.json @@ -1,47 +1,53 @@ { "name": "integration-tests", - "author": "Zondax AG", - "license": "Apache-2.0", "version": "1.0.0", "description": "", - "types": "./dist/index.d.ts", - "repository": { - "type": "git", - "url": "git+https://github.com/Zondax/ledger-cosmos" - }, "keywords": [ "Zondax", "Ledger" ], + "repository": { + "type": "git", + "url": "git+https://github.com/Zondax/ledger-cosmos" + }, + "license": "Apache-2.0", + "author": "Zondax AG", + "types": "./dist/index.d.ts", "scripts": { "clean": "ts-node tests/pullImageKillOld.ts", - "test": "yarn clean && jest --maxConcurrency 2" + "format": "FORCE_COLOR=1 prettier --write . && sort-package-json", + "format:check": "FORCE_COLOR=1 prettier --check .", + "lint": "eslint .", + "lint:fix": "eslint --fix .", + "test": "yarn clean && jest --maxConcurrency 3", + "try": "node try.mjs", + "upgrade": "bunx npm-check-updates -i" }, "dependencies": { - "@zondax/ledger-cosmos-js": "^3.0.3", + "@zondax/ledger-cosmos-js": "^3", "@zondax/zemu": "^0.50.2" }, "devDependencies": { + "@ledgerhq/hw-transport-node-hid": "^6.29.3", + "@ledgerhq/logs": "^6.12.0", + "@noble/curves": "^1.5.0", + "@scure/base": "^1.1.7", + "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/jest": "^29.5.12", "@types/ledgerhq__hw-transport": "^4.21.8", - "@typescript-eslint/eslint-plugin": "^7.17.0", - "@typescript-eslint/parser": "^7.17.0", - "bech32": "^2.0.0", - "blakejs": "^1.1.1", - "crypto-js": "4.2.0", - "eslint": "^9.7.0", + "@typescript-eslint/eslint-plugin": "^8.4.0", + "@typescript-eslint/parser": "^8.4.0", + "eslint": "^9.9.1", "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-jest": "^28.6.0", + "eslint-plugin-jest": "^28.8.2", "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-promise": "^7.1.0", + "eslint-plugin-tsdoc": "^0.3.0", + "eslint-plugin-unused-imports": "^4.1.3", "jest": "29.7.0", - "jest-serial-runner": "^1.1.0", - "js-sha3": "0.9.3", - "jssha": "^3.2.0", - "keccak256": "^1.0.6", "prettier": "^3.3.3", - "secp256k1": "^5.0.0", - "ts-jest": "^29.2.3", + "ts-jest": "^29.2.5", "ts-node": "^10.9.2", "typescript": "^5.5.4" } diff --git a/tests_zemu/snapshots/fl-mainmenu/00004.png b/tests_zemu/snapshots/fl-mainmenu/00004.png index 7750dc1a..1b198c66 100644 Binary files a/tests_zemu/snapshots/fl-mainmenu/00004.png and b/tests_zemu/snapshots/fl-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index 9399f8f0..e33c90db 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00004.png and b/tests_zemu/snapshots/s-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00010.png b/tests_zemu/snapshots/s-mainmenu/00010.png index 9399f8f0..e33c90db 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00010.png and b/tests_zemu/snapshots/s-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00004.png b/tests_zemu/snapshots/sp-mainmenu/00004.png index d6bbafe3..8047ea9a 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00004.png and b/tests_zemu/snapshots/sp-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00010.png b/tests_zemu/snapshots/sp-mainmenu/00010.png index d6bbafe3..8047ea9a 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00010.png and b/tests_zemu/snapshots/sp-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/st-govDeposit/00001.png b/tests_zemu/snapshots/st-govDeposit/00001.png index 43b520de..538238fa 100644 Binary files a/tests_zemu/snapshots/st-govDeposit/00001.png and b/tests_zemu/snapshots/st-govDeposit/00001.png differ diff --git a/tests_zemu/snapshots/st-govDeposit/00002.png b/tests_zemu/snapshots/st-govDeposit/00002.png index 80996b3c..a487a698 100644 Binary files a/tests_zemu/snapshots/st-govDeposit/00002.png and b/tests_zemu/snapshots/st-govDeposit/00002.png differ diff --git a/tests_zemu/snapshots/st-govDeposit/00005.png b/tests_zemu/snapshots/st-govDeposit/00005.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-govDeposit/00005.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-ibc_denoms/00005.png b/tests_zemu/snapshots/st-ibc_denoms/00005.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-ibc_denoms/00005.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-mainmenu/00004.png b/tests_zemu/snapshots/st-mainmenu/00004.png index c87b962e..e68baef0 100644 Binary files a/tests_zemu/snapshots/st-mainmenu/00004.png and b/tests_zemu/snapshots/st-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/st-msgMultiSend/00001.png b/tests_zemu/snapshots/st-msgMultiSend/00001.png index cb6d36bf..77c914a1 100644 Binary files a/tests_zemu/snapshots/st-msgMultiSend/00001.png and b/tests_zemu/snapshots/st-msgMultiSend/00001.png differ diff --git a/tests_zemu/snapshots/st-msgMultiSend/00003.png b/tests_zemu/snapshots/st-msgMultiSend/00003.png index a42c95f2..5b7f51bb 100644 Binary files a/tests_zemu/snapshots/st-msgMultiSend/00003.png and b/tests_zemu/snapshots/st-msgMultiSend/00003.png differ diff --git a/tests_zemu/snapshots/st-msgMultiSend/00006.png b/tests_zemu/snapshots/st-msgMultiSend/00006.png deleted file mode 100644 index 5cc4bafc..00000000 Binary files a/tests_zemu/snapshots/st-msgMultiSend/00006.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-msgMultiSend/00007.png b/tests_zemu/snapshots/st-msgMultiSend/00007.png deleted file mode 100644 index f618d705..00000000 Binary files a/tests_zemu/snapshots/st-msgMultiSend/00007.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-msgMultiSend/00008.png b/tests_zemu/snapshots/st-msgMultiSend/00008.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-msgMultiSend/00008.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-setWithdrawAddress-eth/00001.png b/tests_zemu/snapshots/st-setWithdrawAddress-eth/00001.png index 2e97fb41..f51165e5 100644 Binary files a/tests_zemu/snapshots/st-setWithdrawAddress-eth/00001.png and b/tests_zemu/snapshots/st-setWithdrawAddress-eth/00001.png differ diff --git a/tests_zemu/snapshots/st-setWithdrawAddress-eth/00006.png b/tests_zemu/snapshots/st-setWithdrawAddress-eth/00006.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-setWithdrawAddress-eth/00006.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-setWithdrawAddress/00001.png b/tests_zemu/snapshots/st-setWithdrawAddress/00001.png index 2e97fb41..f51165e5 100644 Binary files a/tests_zemu/snapshots/st-setWithdrawAddress/00001.png and b/tests_zemu/snapshots/st-setWithdrawAddress/00001.png differ diff --git a/tests_zemu/snapshots/st-setWithdrawAddress/00006.png b/tests_zemu/snapshots/st-setWithdrawAddress/00006.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-setWithdrawAddress/00006.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-sign_basic/00005.png b/tests_zemu/snapshots/st-sign_basic/00005.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-sign_basic/00005.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-sign_basic_eth/00001.png b/tests_zemu/snapshots/st-sign_basic_eth/00001.png index 1b55db72..a8e130e2 100644 Binary files a/tests_zemu/snapshots/st-sign_basic_eth/00001.png and b/tests_zemu/snapshots/st-sign_basic_eth/00001.png differ diff --git a/tests_zemu/snapshots/st-sign_basic_eth/00006.png b/tests_zemu/snapshots/st-sign_basic_eth/00006.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-sign_basic_eth/00006.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-sign_basic_extra_fields/00005.png b/tests_zemu/snapshots/st-sign_basic_extra_fields/00005.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-sign_basic_extra_fields/00005.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic/00001.png b/tests_zemu/snapshots/st-textual-sign_basic/00001.png index 625eca89..6c44de87 100644 Binary files a/tests_zemu/snapshots/st-textual-sign_basic/00001.png and b/tests_zemu/snapshots/st-textual-sign_basic/00001.png differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic/00006.png b/tests_zemu/snapshots/st-textual-sign_basic/00006.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-textual-sign_basic/00006.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic_eth/00008.png b/tests_zemu/snapshots/st-textual-sign_basic_eth/00008.png deleted file mode 100644 index bcafe5ca..00000000 Binary files a/tests_zemu/snapshots/st-textual-sign_basic_eth/00008.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic_eth/00009.png b/tests_zemu/snapshots/st-textual-sign_basic_eth/00009.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-textual-sign_basic_eth/00009.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic_expert/00008.png b/tests_zemu/snapshots/st-textual-sign_basic_expert/00008.png deleted file mode 100644 index bcafe5ca..00000000 Binary files a/tests_zemu/snapshots/st-textual-sign_basic_expert/00008.png and /dev/null differ diff --git a/tests_zemu/snapshots/st-textual-sign_basic_expert/00009.png b/tests_zemu/snapshots/st-textual-sign_basic_expert/00009.png deleted file mode 100644 index ba2e8a92..00000000 Binary files a/tests_zemu/snapshots/st-textual-sign_basic_expert/00009.png and /dev/null differ diff --git a/tests_zemu/snapshots/x-mainmenu/00004.png b/tests_zemu/snapshots/x-mainmenu/00004.png index d6bbafe3..8047ea9a 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00004.png and b/tests_zemu/snapshots/x-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00010.png b/tests_zemu/snapshots/x-mainmenu/00010.png index d6bbafe3..8047ea9a 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00010.png and b/tests_zemu/snapshots/x-mainmenu/00010.png differ diff --git a/tests_zemu/tests/amino.test.ts b/tests_zemu/tests/amino.test.ts index 7dc50337..e9a0d040 100644 --- a/tests_zemu/tests/amino.test.ts +++ b/tests_zemu/tests/amino.test.ts @@ -15,7 +15,6 @@ ******************************************************************************* */ import Zemu, { ClickNavigation, TouchNavigation, isTouchDevice } from '@zondax/zemu' -// @ts-ignore import { CosmosApp } from '@zondax/ledger-cosmos-js' import { defaultOptions, @@ -29,11 +28,10 @@ import { example_tx_str_msgMultiSend, } from './common' -// @ts-ignore -import secp256k1 from 'secp256k1/elliptic' -// @ts-ignore -import crypto from 'crypto' import { ButtonKind, IButton, SwipeDirection } from '@zondax/zemu/dist/types' +import { secp256k1 } from '@noble/curves/secp256k1' +import { sha256 } from '@noble/hashes/sha256' +import { keccak_256 } from '@noble/hashes/sha3' jest.setTimeout(120000) @@ -55,7 +53,7 @@ describe('Amino', function () { const app = new CosmosApp(sim.getTransport()) const path = [44, 118, 0, 0, 0] - const tx = Buffer.from(JSON.stringify(example_tx_str_basic), "utf-8") + const tx = Buffer.from(JSON.stringify(example_tx_str_basic), 'utf-8') const hrp = 'cosmos' // get address / publickey @@ -79,15 +77,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -124,15 +120,13 @@ describe('Amino', function () { expect(resp.error_message).toEqual('No errors') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -170,15 +164,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -216,15 +208,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -262,15 +252,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -308,15 +296,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -330,7 +316,7 @@ describe('Amino', function () { const app = new CosmosApp(sim.getTransport()) // Activate expert mode - await sim.toggleExpertMode(); + await sim.toggleExpertMode() const path = [44, 118, 0, 0, 0] const tx = Buffer.from(JSON.stringify(example_tx_str_msgMultiSend)) @@ -357,15 +343,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) + const msgHash = sha256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -379,7 +363,7 @@ describe('Amino', function () { const app = new CosmosApp(sim.getTransport()) // Change to expert mode so we can skip fields - await sim.toggleExpertMode(); + await sim.toggleExpertMode() const path = [44, 60, 0, 0, 0] const tx = Buffer.from(JSON.stringify(setWithdrawAddress)) @@ -406,15 +390,13 @@ describe('Amino', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const sha3 = require('js-sha3') - const msgHash = Buffer.from(sha3.keccak256(tx), 'hex') + const msgHash = keccak_256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -428,10 +410,10 @@ describe('Amino', function () { const app = new CosmosApp(sim.getTransport()) // Enable expert to allow sign with eth path - await sim.toggleExpertMode(); + await sim.toggleExpertMode() const path = [44, 60, 0, 0, 0] - const tx = Buffer.from(JSON.stringify(example_tx_str_basic), "utf-8") + const tx = Buffer.from(JSON.stringify(example_tx_str_basic), 'utf-8') const hrp = 'inj' // check with invalid HRP @@ -460,15 +442,13 @@ describe('Amino', function () { console.log(respPk) // Now verify the signature - const sha3 = require('js-sha3') - const msgHash = Buffer.from(sha3.keccak256(tx), 'hex') + const msgHash = keccak_256(tx) - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) + const signature = secp256k1.Signature.fromDER(resp.signature) const pk = Uint8Array.from(respPk.compressed_pk) - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -482,7 +462,7 @@ describe('Amino', function () { const app = new CosmosApp(sim.getTransport()) const path = [44, 60, 0, 0, 0] - const tx = Buffer.from(JSON.stringify(example_tx_str_basic), "utf-8") + const tx = Buffer.from(JSON.stringify(example_tx_str_basic), 'utf-8') // get address / publickey const respPk = await app.getAddressAndPubKey(path, 'inj') @@ -495,22 +475,20 @@ describe('Amino', function () { // Wait until we are not in the main menu await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) - let nav = undefined; + let nav = undefined if (isTouchDevice(m.name)) { const okButton: IButton = { x: 200, y: 540, delay: 0.25, direction: SwipeDirection.NoSwipe, - }; - nav = new TouchNavigation(m.name, [ - ButtonKind.ConfirmYesButton, - ]); - nav.schedule[0].button = okButton; + } + nav = new TouchNavigation(m.name, [ButtonKind.ConfirmYesButton]) + nav.schedule[0].button = okButton } else { - nav = new ClickNavigation([1, 0]); + nav = new ClickNavigation([1, 0]) } - await sim.navigate('.', `${m.prefix.toLowerCase()}-sign_basic_eth_warning`, nav.schedule); + await sim.navigate('.', `${m.prefix.toLowerCase()}-sign_basic_eth_warning`, nav.schedule) const resp = await signatureRequest console.log(resp) diff --git a/tests_zemu/tests/common.ts b/tests_zemu/tests/common.ts index ec158cae..c3a3a50b 100644 --- a/tests_zemu/tests/common.ts +++ b/tests_zemu/tests/common.ts @@ -42,64 +42,65 @@ export const DEVICE_MODELS: IDeviceModel[] = [ { name: 'flex', prefix: 'FL', path: APP_PATH_FL }, ] -export const tx_sign_textual = 'a10192a20168436861696e20696402686d792d636861696ea2016e4163636f756e74206e756d626572026131a2016853657175656e6365026132a301674164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a3016a5075626c6963206b657902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657904f5a3026d5075624b6579206f626a656374030104f5a401634b657902785230324542204444374620453446442045423736204443384120323035452046363544203739304320443330452038413337203541354320323532382045423341203932334120463146422034443739203444030204f5a102781e54686973207472616e73616374696f6e206861732031204d657373616765a3016d4d6573736167652028312f312902781c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e640301a2026e4d736753656e64206f626a6563740302a3016c46726f6d206164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730303a3016a546f206164647265737302782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b6835740303a30166416d6f756e74026731302041544f4d0303a1026e456e64206f66204d657373616765a201644d656d6f0278193e20e29a9befb88f5c7532363942e29a9befb88f2020202020a2016446656573026a302e3030322041544f4da30169476173206c696d697402673130302730303004f5a3017148617368206f66207261772062797465730278403963303433323930313039633237306232666661396633633066613535613039306330313235656265663838316637646135333937386462663933663733383504f5' +export const tx_sign_textual = + 'a10192a20168436861696e20696402686d792d636861696ea2016e4163636f756e74206e756d626572026131a2016853657175656e6365026132a301674164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a3016a5075626c6963206b657902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657904f5a3026d5075624b6579206f626a656374030104f5a401634b657902785230324542204444374620453446442045423736204443384120323035452046363544203739304320443330452038413337203541354320323532382045423341203932334120463146422034443739203444030204f5a102781e54686973207472616e73616374696f6e206861732031204d657373616765a3016d4d6573736167652028312f312902781c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e640301a2026e4d736753656e64206f626a6563740302a3016c46726f6d206164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730303a3016a546f206164647265737302782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b6835740303a30166416d6f756e74026731302041544f4d0303a1026e456e64206f66204d657373616765a201644d656d6f0278193e20e29a9befb88f5c7532363942e29a9befb88f2020202020a2016446656573026a302e3030322041544f4da30169476173206c696d697402673130302730303004f5a3017148617368206f66207261772062797465730278403963303433323930313039633237306232666661396633633066613535613039306330313235656265663838316637646135333937386462663933663733383504f5' export const example_tx_str_msgMultiSend = { - "account_number": "10", - "chain_id": "chain-WiONzW", - "fee": { - "amount": [], - "gas": "200000" + account_number: '10', + chain_id: 'chain-WiONzW', + fee: { + amount: [], + gas: '200000', }, - "memo": "", - "msgs": [ + memo: '', + msgs: [ { - "type": "cosmos-sdk/MsgMultiSend", - "value": { - "inputs": [ + type: 'cosmos-sdk/MsgMultiSend', + value: { + inputs: [ { - "address": "cosmos1w4efqfklkezgyt6lncjdwxncrzyzpr2efzcqal", - "coins": [ + address: 'cosmos1w4efqfklkezgyt6lncjdwxncrzyzpr2efzcqal', + coins: [ { - "amount": "30", - "denom": "stake" - } - ] - } + amount: '30', + denom: 'stake', + }, + ], + }, ], - "outputs": [ + outputs: [ { - "address": "cosmos184hgxlzat3qhm7p28563w4jyw4aa3wcgnj6gtv", - "coins": [ + address: 'cosmos184hgxlzat3qhm7p28563w4jyw4aa3wcgnj6gtv', + coins: [ { - "amount": "10", - "denom": "stake" - } - ] + amount: '10', + denom: 'stake', + }, + ], }, { - "address": "cosmos1pfyz36qx8z8dm8ktd75mwx5j5vsmkzfn7wrgp9", - "coins": [ + address: 'cosmos1pfyz36qx8z8dm8ktd75mwx5j5vsmkzfn7wrgp9', + coins: [ { - "amount": "10", - "denom": "stake" - } - ] + amount: '10', + denom: 'stake', + }, + ], }, { - "address": "cosmos1xu388ml6krya3ysmlrup2ylxjtzhl4hlaem3ng", - "coins": [ + address: 'cosmos1xu388ml6krya3ysmlrup2ylxjtzhl4hlaem3ng', + coins: [ { - "amount": "10", - "denom": "stake" - } - ] - } - ] - } - } + amount: '10', + denom: 'stake', + }, + ], + }, + ], + }, + }, ], - "sequence": "16", + sequence: '16', } export const example_tx_str_basic = { @@ -260,34 +261,34 @@ export const example_tx_str_basic_extra_fields = { }, ], sequence: '106', - unknown_field: 123456 + unknown_field: 123456, } export const ibc_denoms = { - account_number: "0", - chain_id: "cosmoshub-4", + account_number: '0', + chain_id: 'cosmoshub-4', fee: { amount: [ { - "amount": '5', - "denom": 'uatom', - } + amount: '5', + denom: 'uatom', + }, ], gas: '10000', }, - memo: "testmemo", + memo: 'testmemo', msgs: [ { inputs: [ { - address: "cosmosaccaddr1d9h8qat5e4ehc5", + address: 'cosmosaccaddr1d9h8qat5e4ehc5', coins: [ { amount: '10', - denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2' - } - ] - } + denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2', + }, + ], + }, ], outputs: [ { @@ -295,14 +296,14 @@ export const ibc_denoms = { coins: [ { amount: '10', - denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2' - } - ] - } - ] - } + denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2', + }, + ], + }, + ], + }, ], - sequence: '1' + sequence: '1', } export const setWithdrawAddress = { @@ -312,10 +313,10 @@ export const setWithdrawAddress = { amount: [ { amount: '5000', - denom: 'uatom' - } + denom: 'uatom', + }, ], - gas: '200000' + gas: '200000', }, memo: '', msgs: [ @@ -323,18 +324,18 @@ export const setWithdrawAddress = { type: 'cosmos-sdk/MsgSetWithdrawAddress', value: { delegator_address: 'cosmos1hr9x0sjvel6z3vt9qny8sdd5gnnlgk0p69d6cv', - withdraw_address: 'cosmos12d64j98tjjpqkx70r08aspc4nvntqp2w6wr2de' - } + withdraw_address: 'cosmos12d64j98tjjpqkx70r08aspc4nvntqp2w6wr2de', + }, }, { type: 'cosmos-sdk/MsgWithdrawDelegationReward', value: { delegator_address: 'cosmos1hr9x0sjvel6z3vt9qny8sdd5gnnlgk0p69d6cv', - validator_address: 'cosmosvaloper13dr26wdygna3s8fdl5tlc45m2le2ydyddxzj49' - } - } + validator_address: 'cosmosvaloper13dr26wdygna3s8fdl5tlc45m2le2ydyddxzj49', + }, + }, ], - sequence: '7' + sequence: '7', } export const cliGovDeposit = { @@ -342,21 +343,23 @@ export const cliGovDeposit = { chain_id: 'my-chain', fee: { amount: [], - gas: '200000' + gas: '200000', }, memo: 'A B C', msgs: [ { type: 'cosmos-sdk/MsgDeposit', value: { - amount: [{ - amount: '10', - denom: 'stake', - }], + amount: [ + { + amount: '10', + denom: 'stake', + }, + ], depositor: 'cosmos1xl2256vdh0j68khz9wq88hnyqcq0f5f4za2480', - proposal_id: '1' - } + proposal_id: '1', + }, }, ], - sequence: '2' + sequence: '2', } diff --git a/tests_zemu/tests/pullImageKillOld.ts b/tests_zemu/tests/pullImageKillOld.ts index ddd30b71..12b86dcf 100644 --- a/tests_zemu/tests/pullImageKillOld.ts +++ b/tests_zemu/tests/pullImageKillOld.ts @@ -1,4 +1,7 @@ import Zemu from '@zondax/zemu' -Zemu.checkAndPullImage() -Zemu.stopAllEmuContainers() +async function main() { + await Zemu.checkAndPullImage() + await Zemu.stopAllEmuContainers() +} +main().catch(console.error) diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index 2983ddef..d68a1338 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -17,9 +17,9 @@ import Zemu, { zondaxMainmenuNavigation, ButtonKind, isTouchDevice } from '@zondax/zemu' import { CosmosApp } from '@zondax/ledger-cosmos-js' import { defaultOptions, DEVICE_MODELS } from './common' - -// @ts-ignore -// import secp256k1 from 'secp256k1/elliptic' +import { secp256k1 } from '@noble/curves/secp256k1' +import { keccak_256 } from '@noble/hashes/sha3' +import { bech32 } from '@scure/base' jest.setTimeout(90000) @@ -53,8 +53,6 @@ describe('Standard', function () { console.log(resp) - expect(resp.return_code).toEqual(0x9000) - expect(resp.error_message).toEqual('No errors') expect(resp).toHaveProperty('test_mode') expect(resp).toHaveProperty('major') expect(resp).toHaveProperty('minor') @@ -84,7 +82,7 @@ describe('Standard', function () { expect(resp.bech32_address).toEqual('cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65') expect(resp.compressed_pk.length).toEqual(33) - expect(resp.compressed_pk.toString("hex")).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') + expect(resp.compressed_pk.toString('hex')).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') } finally { await sim.close() } @@ -119,7 +117,7 @@ describe('Standard', function () { expect(resp.bech32_address).toEqual('cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65') expect(resp.compressed_pk.length).toEqual(33) - expect(resp.compressed_pk.toString("hex")).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') + expect(resp.compressed_pk.toString('hex')).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') } finally { await sim.close() } @@ -162,14 +160,9 @@ describe('Standard', function () { expect(resp.compressed_pk.length).toEqual(33) // Verify address - const secp256k1 = require("secp256k1"); - const keccak = require("keccak256"); - const { bech32 } = require("bech32"); - - // Take the compressed pubkey and verify that the expected address can be computed - const uncompressPubKeyUint8Array = secp256k1.publicKeyConvert(resp.compressed_pk, false).subarray(1); - const ethereumAddressBuffer = Buffer.from(keccak(Buffer.from(uncompressPubKeyUint8Array))).subarray(-20); - const eth_address = bech32.encode(hrp, bech32.toWords(ethereumAddressBuffer)); // "cosmos15n2h0lzvfgc8x4fm6fdya89n78x6ee2fm7fxr3" + const uncompressPubKeyUint8Array = secp256k1.ProjectivePoint.fromHex(resp.compressed_pk).toRawBytes(false).subarray(1) + const ethereumAddressBuffer = Buffer.from(keccak_256(uncompressPubKeyUint8Array)).subarray(-20) + const eth_address = bech32.encode(hrp, bech32.toWords(ethereumAddressBuffer)) // "cosmos15n2h0lzvfgc8x4fm6fdya89n78x6ee2fm7fxr3" expect(resp.bech32_address).toEqual(eth_address) expect(resp.bech32_address).toEqual('inj15n2h0lzvfgc8x4fm6fdya89n78x6ee2f3h7z3f') @@ -213,7 +206,7 @@ describe('Standard', function () { const app = new CosmosApp(sim.getTransport()) // Activate expert mode - await sim.toggleExpertMode(); + await sim.toggleExpertMode() // Derivation path. First 3 items are automatically hardened! const path = [44, 118, 2147483647, 0, 4294967295] diff --git a/tests_zemu/tests/textual.test.ts b/tests_zemu/tests/textual.test.ts index 06a26816..84964b73 100644 --- a/tests_zemu/tests/textual.test.ts +++ b/tests_zemu/tests/textual.test.ts @@ -15,13 +15,11 @@ ******************************************************************************* */ import Zemu, { ClickNavigation, TouchNavigation, isTouchDevice } from '@zondax/zemu' -// @ts-ignore import { CosmosApp } from '@zondax/ledger-cosmos-js' import { defaultOptions, DEVICE_MODELS, tx_sign_textual, TEXTUAL_TX } from './common' -// @ts-ignore -import secp256k1 from 'secp256k1/elliptic' -// @ts-ignore -import crypto from 'crypto' +import { secp256k1 } from '@noble/curves/secp256k1' +import { sha256 } from '@noble/hashes/sha256' +import { keccak_256 } from '@noble/hashes/sha3' import { ButtonKind, IButton, SwipeDirection } from '@zondax/zemu/dist/types' jest.setTimeout(90000) @@ -71,15 +69,10 @@ describe('Textual', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) - - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) - - const pk = Uint8Array.from(respPk.compressed_pk) - - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const hash = sha256(tx) + const signature = secp256k1.Signature.fromDER(resp.signature) + const pk = secp256k1.ProjectivePoint.fromHex(respPk.compressed_pk) + const signatureOk = secp256k1.verify(signature, hash, pk.toRawBytes()) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -120,29 +113,24 @@ describe('Textual', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const hash = crypto.createHash('sha256') - const msgHash = Uint8Array.from(hash.update(tx).digest()) - - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) - - const pk = Uint8Array.from(respPk.compressed_pk) - - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const hash = sha256(tx) + const signature = secp256k1.Signature.fromDER(resp.signature) + const pk = secp256k1.ProjectivePoint.fromHex(respPk.compressed_pk) + const signatureOk = secp256k1.verify(signature, hash, pk.toRawBytes()) expect(signatureOk).toEqual(true) } finally { await sim.close() } }) - test.concurrent.each(TEXTUAL_MODELS)('sign basic textual eth ', async function (m) { + test.concurrent.each(TEXTUAL_MODELS)('sign basic textual eth', async function (m) { const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) const app = new CosmosApp(sim.getTransport()) // Enable expert to allow sign with eth path - await sim.toggleExpertMode(); + await sim.toggleExpertMode() const path = [44, 60, 0, 0, 0] const tx = Buffer.from(tx_sign_textual, 'hex') @@ -169,15 +157,10 @@ describe('Textual', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const sha3 = require('js-sha3') - const msgHash = Buffer.from(sha3.keccak256(tx), 'hex') - - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) - - const pk = Uint8Array.from(respPk.compressed_pk) - - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const msgHash = keccak_256(tx) + const signature = secp256k1.Signature.fromDER(resp.signature) + const pk = secp256k1.ProjectivePoint.fromHex(respPk.compressed_pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk.toRawBytes()) expect(signatureOk).toEqual(true) } finally { await sim.close() @@ -205,22 +188,20 @@ describe('Textual', function () { // Wait until we are not in the main menu await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) - let nav = undefined; + let nav = undefined if (isTouchDevice(m.name)) { const okButton: IButton = { x: 200, y: 540, delay: 0.25, direction: SwipeDirection.NoSwipe, - }; - nav = new TouchNavigation(m.name, [ - ButtonKind.ConfirmYesButton, - ]); - nav.schedule[0].button = okButton; + } + nav = new TouchNavigation(m.name, [ButtonKind.ConfirmYesButton]) + nav.schedule[0].button = okButton } else { - nav = new ClickNavigation([1, 0]); + nav = new ClickNavigation([1, 0]) } - await sim.navigate('.', `${m.prefix.toLowerCase()}-textual-sign_basic_eth_warning`, nav.schedule); + await sim.navigate('.', `${m.prefix.toLowerCase()}-textual-sign_basic_eth_warning`, nav.schedule) const resp = await signatureRequest console.log(resp) @@ -271,15 +252,10 @@ describe('Textual', function () { expect(resp).toHaveProperty('signature') // Now verify the signature - const sha3 = require('js-sha3') - const msgHash = Buffer.from(sha3.keccak256(tx), 'hex') - - const signatureDER = resp.signature - const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER)) - - const pk = Uint8Array.from(respPk.compressed_pk) - - const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk) + const msgHash = keccak_256(tx) + const signature = secp256k1.Signature.fromDER(resp.signature) + const pk = secp256k1.ProjectivePoint.fromHex(respPk.compressed_pk) + const signatureOk = secp256k1.verify(signature, msgHash, pk.toRawBytes()) expect(signatureOk).toEqual(true) } finally { await sim.close() diff --git a/tests_zemu/tsconfig.json b/tests_zemu/tsconfig.json index 3435f95c..014ae6be 100644 --- a/tests_zemu/tsconfig.json +++ b/tests_zemu/tsconfig.json @@ -8,8 +8,5 @@ "skipLibCheck": true, "outDir": "./dist" }, - "exclude": [ - "node_modules", - "./dist/**" - ] + "exclude": ["node_modules", "./dist/**"] }