Skip to content

Commit

Permalink
Add try scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Oct 28, 2024
1 parent 598a157 commit 26a42e0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 0 additions & 29 deletions tests_zemu/try.mjs

This file was deleted.

63 changes: 63 additions & 0 deletions tests_zemu/try.ts
Original file line number Diff line number Diff line change
@@ -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)
})()
35 changes: 22 additions & 13 deletions tests_zemu/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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/**"]
// }

0 comments on commit 26a42e0

Please sign in to comment.