From 11cb5abeeaf6332caee8133436f86a6e2774cb84 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Fri, 29 Dec 2023 09:52:50 -0300 Subject: [PATCH] update deps & fix warning --- .github/workflows/guidelines_enforcer.yml | 2 -- app/Makefile | 1 - app/src/crypto.c | 37 ++++++++++++----------- deps/ledger-zxlib | 2 +- deps/nanos-secure-sdk | 2 +- deps/nanosplus-secure-sdk | 2 +- deps/nanox-secure-sdk | 2 +- ledger_app.toml | 7 +++++ tests_zemu/package.json | 24 +++++++-------- 9 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 ledger_app.toml diff --git a/.github/workflows/guidelines_enforcer.yml b/.github/workflows/guidelines_enforcer.yml index 0b958e52..fdaf9f27 100644 --- a/.github/workflows/guidelines_enforcer.yml +++ b/.github/workflows/guidelines_enforcer.yml @@ -21,5 +21,3 @@ jobs: guidelines_enforcer: name: Call Ledger guidelines_enforcer uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_guidelines_enforcer.yml@v1 - with: - relative_app_directory: 'app' diff --git a/app/Makefile b/app/Makefile index e60abb9c..247db685 100755 --- a/app/Makefile +++ b/app/Makefile @@ -52,7 +52,6 @@ endif APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH) -NANOS_STACK_SIZE:=1815 include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices $(info TARGET_NAME = [$(TARGET_NAME)]) diff --git a/app/src/crypto.c b/app/src/crypto.c index eb3c280e..945686cf 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -51,11 +51,11 @@ static zxerr_t crypto_extractUncompressedPublicKey(uint8_t *pubKey, uint16_t pub privateKeyData, NULL, NULL, - 0)) + 0)); - 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, PK_LEN_SECP256K1_UNCOMPRESSED); error = zxerr_ok; @@ -122,7 +122,7 @@ zxerr_t crypto_sign(uint8_t *output, const uint8_t *message = tx_get_buffer(); const uint16_t messageLen = tx_get_buffer_length(); - CHECK_ZXERR(crypto_hashBuffer(message, messageLen, messageDigest, CX_SHA256_SIZE)) + CHECK_ZXERR(crypto_hashBuffer(message, messageLen, messageDigest, CX_SHA256_SIZE)); CHECK_APP_CANARY() cx_ecfp_private_key_t cx_privateKey; @@ -140,15 +140,15 @@ zxerr_t crypto_sign(uint8_t *output, privateKeyData, NULL, NULL, - 0)) - CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey)) + 0)); + CATCH_CXERROR(cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey)); CATCH_CXERROR(cx_ecdsa_sign_no_throw(&cx_privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, messageDigest, CX_SHA256_SIZE, output, - &signatureLength, &tmpInfo)) + &signatureLength, &tmpInfo)); *sigSize = signatureLength; error = zxerr_ok; @@ -163,10 +163,11 @@ zxerr_t crypto_sign(uint8_t *output, return error; } -void ripemd160_32(uint8_t *out, uint8_t *in) { +static zxerr_t ripemd160_32(uint8_t *out, uint8_t *in) { cx_ripemd160_t rip160; - cx_ripemd160_init(&rip160); - cx_hash_no_throw(&rip160.header, CX_LAST, in, CX_SHA256_SIZE, out, CX_RIPEMD160_SIZE); + CHECK_CX_OK(cx_ripemd160_init(&rip160)); + CHECK_CX_OK(cx_hash_no_throw(&rip160.header, CX_LAST, in, CX_SHA256_SIZE, out, CX_RIPEMD160_SIZE)); + return zxerr_ok; } zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrResponseLen) { @@ -176,8 +177,8 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR // extract pubkey uint8_t uncompressedPubkey [PK_LEN_SECP256K1_UNCOMPRESSED] = {0}; - CHECK_ZXERR(crypto_extractUncompressedPublicKey(uncompressedPubkey, sizeof(uncompressedPubkey))) - CHECK_ZXERR(compressPubkey(uncompressedPubkey, sizeof(uncompressedPubkey), buffer, buffer_len)) + CHECK_ZXERR(crypto_extractUncompressedPublicKey(uncompressedPubkey, sizeof(uncompressedPubkey))); + CHECK_ZXERR(compressPubkey(uncompressedPubkey, sizeof(uncompressedPubkey), buffer, buffer_len)); char *addr = (char *) (buffer + PK_LEN_SECP256K1); uint8_t hashed1_pk[CX_SHA256_SIZE] = {0}; @@ -185,10 +186,10 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR switch (encoding) { case BECH32_COSMOS: { // Hash it - cx_hash_sha256(buffer, PK_LEN_SECP256K1, hashed1_pk, CX_SHA256_SIZE); + CHECK_CX_OK(cx_hash_sha256(buffer, PK_LEN_SECP256K1, hashed1_pk, CX_SHA256_SIZE)); uint8_t hashed2_pk[CX_RIPEMD160_SIZE] = {0}; - ripemd160_32(hashed2_pk, hashed1_pk); - CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1, BECH32_ENCODING_BECH32)) + CHECK_ZXERR(ripemd160_32(hashed2_pk, hashed1_pk)); + CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1, BECH32_ENCODING_BECH32)); break; } @@ -197,8 +198,8 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR if (cx_keccak_init_no_throw(&ctx, 256) != CX_OK) { return zxerr_unknown; } - cx_hash_no_throw((cx_hash_t *)&ctx, CX_LAST, uncompressedPubkey+1, sizeof(uncompressedPubkey)-1, hashed1_pk, sizeof(hashed1_pk)); - CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed1_pk + 12, sizeof(hashed1_pk) - 12, 1, BECH32_ENCODING_BECH32)) + CHECK_CX_OK(cx_hash_no_throw((cx_hash_t *)&ctx, CX_LAST, uncompressedPubkey+1, sizeof(uncompressedPubkey)-1, hashed1_pk, sizeof(hashed1_pk))); + CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed1_pk + 12, sizeof(hashed1_pk) - 12, 1, BECH32_ENCODING_BECH32)); break; } diff --git a/deps/ledger-zxlib b/deps/ledger-zxlib index 7f80d18a..df81cb76 160000 --- a/deps/ledger-zxlib +++ b/deps/ledger-zxlib @@ -1 +1 @@ -Subproject commit 7f80d18afcf509f5028d226e36bc206624601229 +Subproject commit df81cb767d464995327218f0fb92eaa2dd3b4db3 diff --git a/deps/nanos-secure-sdk b/deps/nanos-secure-sdk index 30189cfd..0532bf20 160000 --- a/deps/nanos-secure-sdk +++ b/deps/nanos-secure-sdk @@ -1 +1 @@ -Subproject commit 30189cfd070040e5c144d4dab103d549302dcfff +Subproject commit 0532bf20fbbb11dd08dada62060f8337097b6078 diff --git a/deps/nanosplus-secure-sdk b/deps/nanosplus-secure-sdk index 80309475..86e20d8d 160000 --- a/deps/nanosplus-secure-sdk +++ b/deps/nanosplus-secure-sdk @@ -1 +1 @@ -Subproject commit 803094754f77f23c556b065317bceda3b6d2c002 +Subproject commit 86e20d8dbcee181e11bc2ad7ac3f638eb7dc7b08 diff --git a/deps/nanox-secure-sdk b/deps/nanox-secure-sdk index 80309475..86e20d8d 160000 --- a/deps/nanox-secure-sdk +++ b/deps/nanox-secure-sdk @@ -1 +1 @@ -Subproject commit 803094754f77f23c556b065317bceda3b6d2c002 +Subproject commit 86e20d8dbcee181e11bc2ad7ac3f638eb7dc7b08 diff --git a/ledger_app.toml b/ledger_app.toml new file mode 100644 index 00000000..3e4cbb1f --- /dev/null +++ b/ledger_app.toml @@ -0,0 +1,7 @@ +[app] +build_directory = "./app/" +sdk = "C" +devices = ["nanos", "nanox", "nanos+", "stax"] + +[tests] +unit_directory = "./tests/" diff --git a/tests_zemu/package.json b/tests_zemu/package.json index 5e659e4d..bd8feec2 100644 --- a/tests_zemu/package.json +++ b/tests_zemu/package.json @@ -19,30 +19,30 @@ }, "dependencies": { "@zondax/ledger-cosmos-js": "^3.0.3", - "@zondax/zemu": "^0.45.0" + "@zondax/zemu": "^0.46.0" }, "devDependencies": { - "@types/jest": "^29.5.10", + "@types/jest": "^29.5.11", "@types/ledgerhq__hw-transport": "^4.21.8", - "@typescript-eslint/eslint-plugin": "^6.13.1", - "@typescript-eslint/parser": "^6.13.1", + "@typescript-eslint/eslint-plugin": "^6.16.0", + "@typescript-eslint/parser": "^6.16.0", "bech32": "^2.0.0", "blakejs": "^1.1.1", "crypto-js": "4.2.0", - "eslint": "^8.54.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.29.0", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", "eslint-plugin-jest": "^27.6.0", - "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-prettier": "^5.1.2", "jest": "29.7.0", "jest-serial-runner": "^1.1.0", - "js-sha3": "0.9.2", + "js-sha3": "0.9.3", "jssha": "^3.2.0", "keccak256": "^1.0.6", - "prettier": "^3.1.0", + "prettier": "^3.1.1", "secp256k1": "^5.0.0", "ts-jest": "^29.1.1", - "ts-node": "^10.9.1", - "typescript": "^5.3.2" + "ts-node": "^10.9.2", + "typescript": "^5.3.3" } }