diff --git a/tests_zemu/package.json b/tests_zemu/package.json index 90958bef0..746b6efad 100644 --- a/tests_zemu/package.json +++ b/tests_zemu/package.json @@ -12,7 +12,7 @@ "scripts": { "test": "jest --testPathIgnorePatterns='dev.*|testvectors.*|btc.*'", "test_dev": "jest", - "try": "node try.mjs", + "try": "ts-node try.ts", "debug": "node debug/debug.mjs debug" }, "dependencies": { diff --git a/tests_zemu/try.mjs b/tests_zemu/try.mjs deleted file mode 100644 index 33ca22b14..000000000 --- a/tests_zemu/try.mjs +++ /dev/null @@ -1,29 +0,0 @@ -import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' -import ledger_logs from '@ledgerhq/logs' -import AvalancheApp from '@zondax/ledger-avalanche-app' - -const APP_DERIVATION = "m/44'/9000'/0'/0/0" - -async function get_avax_address(app) { - const resp = await app.getAddressAndPubKey(APP_DERIVATION, true) - - console.log(resp) -} - -async function your_test() { - console.log('your_result') -} - -async function main() { - const transport = await TransportNodeHid.default.open() - ledger_logs.listen(log => { - console.log(`${log.type} ${log.message}`) - }) - const app = new AvalancheApp.default(transport) - - await your_test() -} - -;(async () => { - await main() -})() diff --git a/tests_zemu/try.ts b/tests_zemu/try.ts new file mode 100644 index 000000000..e79114a3e --- /dev/null +++ b/tests_zemu/try.ts @@ -0,0 +1,63 @@ +import Eth from '@ledgerhq/hw-app-eth' +import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' +// import ledger_logs from '@ledgerhq/logs' +import { log } from '@ledgerhq/logs' +import AvalancheApp from '@zondax/ledger-avalanche-app' + +const APP_DERIVATION = "m/44'/9000'/0'/0/0" +const ETH_DERIVATION = "m/44'/60'/0'/0'" + +async function get_avax_address(app: AvalancheApp) { + const resp = await app.getAddressAndPubKey(APP_DERIVATION, true) + console.log(resp) +} + +async function sign_191_message(app: Eth) { + // Initialize array to hold the message content + const msgRaw: number[] = [] + // Add content following the same pattern as the Rust test + msgRaw.push(...Buffer.from('Hello, ', 'utf8')) + msgRaw.push(0x80) + msgRaw.push(...Buffer.from('World! ', 'utf8')) + msgRaw.push(0x81) + msgRaw.push(...Buffer.from('This is a ', 'utf8')) + msgRaw.push(0x82) + msgRaw.push(...Buffer.from('complex ', 'utf8')) + msgRaw.push(0x83) + msgRaw.push(...Buffer.from('test ', 'utf8')) + msgRaw.push(0x84) + msgRaw.push(...Buffer.from('vector with ', 'utf8')) + msgRaw.push(0x85, 0x86, 0x87) + msgRaw.push(...Buffer.from(' multiple non-ASCII ', 'utf8')) + msgRaw.push(0x88, 0x89) + msgRaw.push(...Buffer.from(' characters ', 'utf8')) + msgRaw.push(0x8a) + msgRaw.push(...Buffer.from('scattered ', 'utf8')) + msgRaw.push(0x8b) + msgRaw.push(...Buffer.from('throughout. ', 'utf8')) + msgRaw.push(0x8c, 0x8d, 0x8e, 0x8f) + msgRaw.push(...Buffer.from('It should ', 'utf8')) + msgRaw.push(0x90) + msgRaw.push(...Buffer.from('properly ', 'utf8')) + msgRaw.push(0x91) + msgRaw.push(...Buffer.from('chunk ', 'utf8')) + msgRaw.push(0x92) + msgRaw.push(...Buffer.from('and format.', 'utf8')) + + const msgData = Buffer.from(msgRaw) + const respReq = await app.signPersonalMessage(ETH_DERIVATION, msgData.toString('hex')) + console.log('done!') +} + +async function main() { + const transport = await TransportNodeHid.create() // Changed from .open(null) + + log('trying to connect to device') + + const app = new Eth(transport) + await sign_191_message(app) +} + +;(async () => { + await main().catch(console.error) +})() diff --git a/tests_zemu/tsconfig.json b/tests_zemu/tsconfig.json index 9cdbe1927..ac8d5e929 100644 --- a/tests_zemu/tsconfig.json +++ b/tests_zemu/tsconfig.json @@ -1,20 +1,29 @@ { "compilerOptions": { - "module": "esnext", + "target": "ES2020", + "module": "CommonJS", "moduleResolution": "node", - "target": "esnext", - "strict": true, - "lib": [ - "es2019" - ], "esModuleInterop": true, - "declaration": true, - "forceConsistentCasingInFileNames": true, + "strict": true, "skipLibCheck": true, - "outDir": "./dist" + "forceConsistentCasingInFileNames": true, + "outDir": "./dist", + "allowJs": true }, - "exclude": [ - "node_modules", - "./dist/**" - ] + "exclude": ["node_modules", "./dist/**"] } +// { +// "compilerOptions": { +// "module": "esnext", +// "moduleResolution": "node", +// "target": "esnext", +// "strict": true, +// "lib": ["es2019"], +// "esModuleInterop": true, +// "declaration": true, +// "forceConsistentCasingInFileNames": true, +// "skipLibCheck": true, +// "outDir": "./dist" +// }, +// "exclude": ["node_modules", "./dist/**"] +// }