diff --git a/tests_zemu/package-lock.json b/tests_zemu/package-lock.json index 1b8e42e5..ce2f6df5 100644 --- a/tests_zemu/package-lock.json +++ b/tests_zemu/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "Apache-2.0", "devDependencies": { - "@ledgerhq/hw-app-str": "github:overcat/hw-ledger-str-dev", + "@ledgerhq/hw-app-str": "^7.0.0", "@ledgerhq/hw-transport-http": "^6.28.6", "@stellar/stellar-base": "^11.0.0", "@types/jest": "^29.2.1", @@ -23,6 +23,7 @@ } }, "../tests_common_js": { + "name": "tests-common", "version": "1.0.0", "dev": true, "license": "Apache-2.0", @@ -1034,15 +1035,13 @@ "dev": true }, "node_modules/@ledgerhq/hw-app-str": { - "version": "6.27.20", - "resolved": "git+ssh://git@github.com/overcat/hw-ledger-str-dev.git#134b60c16398ea38dd26d788009fa76011bd1d74", + "version": "7.0.0", + "resolved": "git+ssh://git@github.com/overcat/hw-ledger-str-dev.git#4eef2f5b61cd06fe19b7e2ccacf17db93c32d1fe", "dev": true, - "license": "Apache-2.0", "dependencies": { - "@ledgerhq/hw-transport": "^6.30.3", - "base32.js": "^0.1.0", - "sha.js": "^2.3.6", - "tweetnacl": "^1.0.3" + "@ledgerhq/errors": "^6.16.4", + "@ledgerhq/hw-transport": "^6.30.6", + "bip32-path": "^0.4.2" } }, "node_modules/@ledgerhq/hw-transport": { @@ -1612,6 +1611,12 @@ "node": "*" } }, + "node_modules/bip32-path": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/bip32-path/-/bip32-path-0.4.2.tgz", + "integrity": "sha512-ZBMCELjJfcNMkz5bDuJ1WrYvjlhEF5k6mQ8vUr4N7MbVRsXei7ZOg8VhhwMfNiW68NWmLkgkc6WvTickrLGprQ==", + "dev": true + }, "node_modules/bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", diff --git a/tests_zemu/package.json b/tests_zemu/package.json index 2ea39bad..74a44ab5 100644 --- a/tests_zemu/package.json +++ b/tests_zemu/package.json @@ -11,7 +11,7 @@ "test": "jest" }, "devDependencies": { - "@ledgerhq/hw-app-str": "github:overcat/hw-ledger-str-dev", + "@ledgerhq/hw-app-str": "^7.0.0", "@ledgerhq/hw-transport-http": "^6.28.6", "@stellar/stellar-base": "^11.0.0", "@types/jest": "^29.2.1", diff --git a/tests_zemu/tests/main.test.ts b/tests_zemu/tests/main.test.ts index 3251b1d1..8626d7d9 100644 --- a/tests_zemu/tests/main.test.ts +++ b/tests_zemu/tests/main.test.ts @@ -1,8 +1,9 @@ import { DEFAULT_START_OPTIONS, ButtonKind, TouchNavigation } from "@zondax/zemu"; import { APP_SEED, models } from "./common"; import * as testCasesFunction from "tests-common"; -import { Keypair } from "@stellar/stellar-base"; +import { Keypair, StrKey } from "@stellar/stellar-base"; import Str from "@ledgerhq/hw-app-str"; +import { StellarUserRefusedError, StellarHashSigningNotEnabledError } from "@ledgerhq/hw-app-str"; import Zemu from "@zondax/zemu"; import { sha256 } from 'sha.js' @@ -35,13 +36,10 @@ describe("get public key", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText }); const transport = await sim.getTransport(); const str = new Str(transport); - const result = await str.getPublicKey("44'/148'/0'", false, false); + const { rawPublicKey } = await str.getPublicKey("44'/148'/0'", false); + const result = StrKey.encodeEd25519PublicKey(rawPublicKey); const kp = Keypair.fromSecret("SAIYWGGWU2WMXYDSK33UBQBMBDKU4TTJVY3ZIFF24H2KQDR7RQW5KAEK"); - - expect(result).toStrictEqual({ - publicKey: kp.publicKey(), - raw: kp.rawPublicKey(), - }); + expect(result).toEqual(kp.publicKey()); } finally { await sim.close(); } @@ -57,15 +55,13 @@ describe("get public key", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText, approveAction: ButtonKind.ApproveTapButton }); const transport = await sim.getTransport(); const str = new Str(transport); - const result = str.getPublicKey("44'/148'/0'", false, true); + const result = str.getPublicKey("44'/148'/0'", true); const kp = Keypair.fromSecret("SAIYWGGWU2WMXYDSK33UBQBMBDKU4TTJVY3ZIFF24H2KQDR7RQW5KAEK"); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); await sim.navigateAndCompareUntilText(".", `${dev.prefix.toLowerCase()}-public-key-approve`, confirmText, true); - expect(result).resolves.toStrictEqual({ - publicKey: kp.publicKey(), - raw: kp.rawPublicKey(), - }); + const pk = StrKey.encodeEd25519PublicKey((await result).rawPublicKey); + expect(pk).toEqual(kp.publicKey()); } finally { await sim.close(); } @@ -82,10 +78,7 @@ describe("get public key", () => { const transport = await sim.getTransport(); const str = new Str(transport); - // TODO: Maybe we should throw a more specific exception in @ledgerhq/hw-app-str - expect(() => str.getPublicKey("44'/148'/0'", false, true)).rejects.toThrow( - "Ledger device: Condition of use not satisfied (denied by the user?) (0x6985)" - ); + expect(() => str.getPublicKey("44'/148'/0'", true)).rejects.toThrow(StellarUserRefusedError); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); @@ -104,9 +97,7 @@ describe("hash signing", () => { const transport = await sim.getTransport(); const str = new Str(transport); const hash = Buffer.from("3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889", "hex"); - expect(() => str.signHash("44'/148'/0'", hash)).rejects.toThrow( - new Error("Hash signing not allowed. Have you enabled it in the app settings?") - ); + expect(() => str.signHash("44'/148'/0'", hash)).rejects.toThrow(StellarHashSigningNotEnabledError); } finally { await sim.close(); } @@ -172,7 +163,7 @@ describe("hash signing", () => { } const hash = Buffer.from("3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889", "hex"); - expect(() => str.signHash("44'/148'/0'", hash)).rejects.toThrow(new Error("Transaction approval request was rejected")); + expect(() => str.signHash("44'/148'/0'", hash)).rejects.toThrow(StellarUserRefusedError); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); @@ -258,9 +249,7 @@ describe("transactions", () => { await sim.clickBoth(undefined, false); } - expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow( - new Error("Transaction approval request was rejected") - ); + expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow(StellarUserRefusedError); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); @@ -306,9 +295,7 @@ describe("transactions", () => { await sim.clickBoth(undefined, false); } - expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow( - new Error("Transaction approval request was rejected") - ); + expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow(StellarUserRefusedError); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); @@ -402,7 +389,7 @@ describe("soroban auth", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText }); const transport = await sim.getTransport(); const str = new Str(transport); - const result = str.signSorobanAuthoration("44'/148'/0'", hashIdPreimage.toXDR("raw")); + const result = str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage.toXDR("raw")); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); let textToFind = /\bSign\b/; @@ -433,9 +420,7 @@ describe("soroban auth", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText, approveAction: ButtonKind.RejectButton }); const transport = await sim.getTransport(); const str = new Str(transport); - expect(() => str.signSorobanAuthoration("44'/148'/0'", hashIdPreimage.toXDR("raw"))).rejects.toThrow( - new Error("Soroban authoration approval request was rejected") - ); + expect(() => str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage.toXDR("raw"))).rejects.toThrow(StellarUserRefusedError); let textToFind = "Reject"; if (dev.name == "stax") { @@ -534,9 +519,7 @@ describe("plugin", () => { await sim.clickBoth(undefined, false); } - expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow( - new Error("Transaction approval request was rejected") - ); + expect(() => str.signTransaction("44'/148'/0'", tx.signatureBase())).rejects.toThrow(StellarUserRefusedError); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); @@ -567,7 +550,7 @@ describe("plugin", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText }); const transport = await sim.getTransport(); const str = new Str(transport); - const result = str.signSorobanAuthoration("44'/148'/0'", hashIdPreimage.toXDR("raw")); + const result = str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage.toXDR("raw")); const events = await sim.getEvents(); await sim.waitForScreenChanges(events); let textToFind = /\bSign\b/; @@ -600,9 +583,7 @@ describe("plugin", () => { await sim.start({ ...defaultOptions, model: dev.name, startText: startText, approveAction: ButtonKind.RejectButton }); const transport = await sim.getTransport(); const str = new Str(transport); - expect(() => str.signSorobanAuthoration("44'/148'/0'", hashIdPreimage.toXDR("raw"))).rejects.toThrow( - new Error("Soroban authoration approval request was rejected") - ); + expect(() => str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage.toXDR("raw"))).rejects.toThrow(StellarUserRefusedError); let textToFind = "Reject"; if (dev.name == "stax") {