diff --git a/app/src/apdu_handler.c b/app/src/apdu_handler.c index 741d0c0d..852c5145 100644 --- a/app/src/apdu_handler.c +++ b/app/src/apdu_handler.c @@ -41,7 +41,6 @@ static uint32_t msg_counter = 0; void extractHDPath(uint32_t rx, uint32_t offset, uint32_t path_len) { - if ((rx - offset) < sizeof(uint32_t) * path_len) { THROW(APDU_CODE_WRONG_LENGTH); } @@ -383,7 +382,7 @@ handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) break; default: - THROW(APDU_CODE_COMMAND_NOT_ALLOWED); + THROW(APDU_CODE_COMMAND_NOT_ALLOWED); break; } CHECK_APP_CANARY() diff --git a/deps/ledger-zxlib b/deps/ledger-zxlib index 9e9cb2b2..df81cb76 160000 --- a/deps/ledger-zxlib +++ b/deps/ledger-zxlib @@ -1 +1 @@ -Subproject commit 9e9cb2b21fdf94a6b1f7d71ee6f89ca8101712ce +Subproject commit df81cb767d464995327218f0fb92eaa2dd3b4db3 diff --git a/tests_zemu/tests/eth_tests.test.ts b/tests_zemu/tests/eth_tests.test.ts index 40217f38..a14252fe 100644 --- a/tests_zemu/tests/eth_tests.test.ts +++ b/tests_zemu/tests/eth_tests.test.ts @@ -94,23 +94,21 @@ describe.each(models)('ETH', function (m) { await sim.start({...defaultOptions, model: m.name,}); const app = new FilecoinApp(sim.getTransport()); const msg = data.op - + // Put the app in expert mode await sim.toggleExpertMode(); - const testcase = `${m.prefix.toLowerCase()}-eth-sign-${data.name}` - let eth = new Eth(sim.getTransport()) - // eth pubkey used for ETH_PATH: "m/44'/60'/0'/0'/5" // to verify signature const EXPECTED_PUBLIC_KEY = '024f1dd50f180bfd546339e75410b127331469837fa618d950f7cfb8be351b0020'; // do not wait here.. - const signatureRequest = app.signETHTransaction(ETH_PATH, msg, null); + + const signatureRequest = app.signETHTransaction(ETH_PATH, msg.toString('hex'), null); // Wait until we are not in the main menu await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()); @@ -151,11 +149,11 @@ describe('EthAddress', function () { console.log(resp) - console.log(resp.publicKey.toString('hex')) + console.log(resp.publicKey.toString()) console.log(resp.address) - expect(resp.publicKey.toString('hex')).toEqual(EXPECTED_ETH_PK); - expect(resp.address.toString('hex')).toEqual(EXPECTED_ETH_ADDRESS); + expect(resp.publicKey.toString()).toEqual(EXPECTED_ETH_PK); + expect(resp.address.toString()).toEqual(EXPECTED_ETH_ADDRESS); } finally { await sim.close(); diff --git a/tests_zemu/tests/multisig.test.ts b/tests_zemu/tests/multisig.test.ts index d2e2acf6..763c9aee 100644 --- a/tests_zemu/tests/multisig.test.ts +++ b/tests_zemu/tests/multisig.test.ts @@ -59,8 +59,8 @@ describe.each(models)('Multisig', function (m) { const pkResponse = await app.getAddressAndPubKey(PATH_TESTNET); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here so we can get snapshots and interact with the app const signatureRequest = app.sign(PATH_TESTNET, txBlob); @@ -72,13 +72,13 @@ describe.each(models)('Multisig', function (m) { let resp = await signatureRequest; console.log(resp, m.name, name) - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index d6bfa7d7..e60e8bb3 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -56,9 +56,9 @@ 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.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); + expect(resp).toHaveProperty("testMode"); expect(resp).toHaveProperty("major"); expect(resp).toHaveProperty("minor"); expect(resp).toHaveProperty("patch"); @@ -77,14 +77,17 @@ describe('Standard', function () { console.log(resp) - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); const expected_address_string = "f1mk3zcefvlgpay4f32c5vmruk5gqig6dumc7pz6q"; const expected_pk = "0425d0dbeedb2053e690a58e9456363158836b1361f30dba0332f440558fa803d056042b50d0e70e4a2940428e82c7cea54259d65254aed4663e4d0cffd649f4fb"; expect(resp.addrString).toEqual(expected_address_string); - expect(resp.compressed_pk.toString('hex')).toEqual(expected_pk); + + const compressedPk = resp.compressedPk ?? Buffer.alloc(0) + expect(compressedPk.toString('hex')).toEqual(expected_pk) + } finally { await sim.close(); @@ -111,14 +114,17 @@ describe('Standard', function () { const resp = await respRequest; - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); const expected_address_string = "f1mk3zcefvlgpay4f32c5vmruk5gqig6dumc7pz6q"; const expected_pk = "0425d0dbeedb2053e690a58e9456363158836b1361f30dba0332f440558fa803d056042b50d0e70e4a2940428e82c7cea54259d65254aed4663e4d0cffd649f4fb"; expect(resp.addrString).toEqual(expected_address_string); - expect(resp.compressed_pk.toString('hex')).toEqual(expected_pk); + + const compressedPk = resp.compressedPk ?? Buffer.alloc(0) + expect(compressedPk.toString('hex')).toEqual(expected_pk) + } finally { await sim.close(); } @@ -137,8 +143,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureRequest = app.sign(PATH, txBlob); @@ -150,13 +156,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -178,15 +184,15 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureResponse = await app.sign(PATH, invalidMessage); console.log(signatureResponse); - expect(signatureResponse.return_code).toEqual(0x6984); - expect(signatureResponse.error_message).toEqual("Data is invalid : Unexpected data type"); + expect(signatureResponse.returnCode).toEqual(0x6984); + expect(signatureResponse.errorMessage).toEqual("Data is invalid : Unexpected data type"); } finally { await sim.close(); } @@ -208,8 +214,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here so we can get snapshots and interact with the app const signatureRequest = app.sign(PATH, txBlob); @@ -221,13 +227,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -235,7 +241,6 @@ describe('Standard', function () { } }); - test.concurrent.each(models)('sign proposal -- unsupported method', async function (m) { const sim = new Zemu(m.path); try { @@ -249,15 +254,15 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureResponse = await app.sign(PATH, invalidMessage); console.log(signatureResponse); - expect(signatureResponse.return_code).toEqual(0x6984); - expect(signatureResponse.error_message).toEqual("Data is invalid : Unexpected data type"); + expect(signatureResponse.returnCode).toEqual(0x6984); + expect(signatureResponse.errorMessage).toEqual("Data is invalid : Unexpected data type"); } finally { await sim.close(); @@ -282,8 +287,8 @@ describe('Standard', function () { await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()); let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x6984); - expect(resp.error_message).toEqual("Data is invalid : Unexpected data type"); + expect(resp.returnCode).toEqual(0x6984); + expect(resp.errorMessage).toEqual("Data is invalid : Unexpected data type"); } finally { await sim.close(); } @@ -302,8 +307,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here so we can get snapshots and interact with the app const signatureRequest = app.sign(PATH, txBlob); @@ -315,13 +320,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -342,8 +347,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureRequest = app.sign(PATH, txBlob); @@ -354,13 +359,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -384,8 +389,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureRequest = app.signRemoveDataCap(PATH, txBlob); @@ -396,13 +401,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -433,11 +438,10 @@ describe('Standard', function () { const txBlob = Buffer.from("8bd82a582500017112209fe4ccc6de16724f3a30c7e8f254f3c6471986acb1f8d8cf8e96ce2ad7dbe7fb1a012a174ff555011eaf1c8a4bbfeeb0870b1745b1f57503470b71165501dfe49184d46adc8f89d44638beb45f78fcad259071636c69656e745f6465616c5f6c6162656c1a05f5e1001a0bebc2004044001ea7ad40", 'hex') - const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureRequest = app.signClientDeal(PATH, txBlob); @@ -448,13 +452,13 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk) + const pk = Uint8Array.from(pkResponse.compressedPk ?? []) const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally { @@ -483,8 +487,8 @@ describe('Standard', function () { const pkResponse = await app.getAddressAndPubKey(PATH); console.log(pkResponse); - expect(pkResponse.return_code).toEqual(0x9000); - expect(pkResponse.error_message).toEqual("No errors"); + expect(pkResponse.returnCode).toEqual(0x9000); + expect(pkResponse.errorMessage).toEqual("No errors"); // do not wait here.. const signatureRequest = app.signRawBytes(PATH, txBlob); @@ -495,14 +499,14 @@ describe('Standard', function () { let resp = await signatureRequest; console.log(resp); - expect(resp.return_code).toEqual(0x9000); - expect(resp.error_message).toEqual("No errors"); + expect(resp.returnCode).toEqual(0x9000); + expect(resp.errorMessage).toEqual("No errors"); // Verify signature - const pk = Uint8Array.from(pkResponse.compressed_pk); + const pk = Uint8Array.from(pkResponse.compressedPk ?? []); const digest = getDigest(txBlob); - const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der)); + const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? [])); const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk); expect(signatureOk).toEqual(true); } finally {