Skip to content

Commit

Permalink
update zemu
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Sep 19, 2024
1 parent 1fbd14a commit 2d3800a
Show file tree
Hide file tree
Showing 4 changed files with 1,571 additions and 2,074 deletions.
68 changes: 34 additions & 34 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@
},
"dependencies": {
"@ethersproject/wallet": "^5.7.0",
"@types/node": "^18.14.6",
"@types/node": "^22.5.5",
"@zondax/ledger-avalanche-app": "link:../js",
"@zondax/zemu": "0.50.2",
"ethers": "^6.12.1"
"@zondax/zemu": "0.50.3",
"ethers": "^6.13.2"
},
"devDependencies": {
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/rlp": "^4.0.1",
"@ethereumjs/tx": "^4.1.1",
"@ethereumjs/util": "^8.0.5",
"@ledgerhq/hw-app-eth": "6.32.1",
"@ledgerhq/hw-transport-node-hid": "^6.27.2",
"@ledgerhq/logs": "^6.10.0",
"@matteoh2o1999/github-actions-jest-reporter": "^2.0.0",
"@types/bs58": "^4.0.1",
"@types/elliptic": "^6.4.14",
"@types/jest": "^29.4.0",
"@types/ledgerhq__hw-transport": "^4.21.3",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"bn.js": "^5.2.0",
"bs58": "^5.0.0",
"crypto-js": "4.1.1",
"elliptic": "^6.5.4",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.5.0",
"jest-serial-runner": "^1.2.0",
"js-sha256": "0.9.0",
"jssha": "^3.1.1",
"prettier": "^2.4.1",
"@ethereumjs/common": "^4.4.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/tx": "^5.4.0",
"@ethereumjs/util": "^9.1.0",
"@ledgerhq/hw-app-eth": "6.38.1",
"@ledgerhq/hw-transport-node-hid": "^6.29.4",
"@ledgerhq/logs": "^6.12.0",
"@matteoh2o1999/github-actions-jest-reporter": "^3.0.0",
"@types/bs58": "^4.0.4",
"@types/elliptic": "^6.4.18",
"@types/jest": "^29.5.13",
"@types/ledgerhq__hw-transport": "^4.21.8",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@typescript-eslint/parser": "^8.6.0",
"bn.js": "^5.2.1",
"bs58": "^6.0.0",
"crypto-js": "4.2.0",
"elliptic": "^6.5.7",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"jest-serial-runner": "^1.2.1",
"js-sha256": "0.11.0",
"jssha": "^3.3.1",
"prettier": "^3.3.3",
"secp256k1": "^5.0.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
}
}
6 changes: 3 additions & 3 deletions tests_zemu/tests/addr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Zemu from '@zondax/zemu'
import { APP_DERIVATION, defaultOptions as commonOpts, models } from './common'
import AvalancheApp from '@zondax/ledger-avalanche-app'
import { encode as bs58_encode } from 'bs58'
import bs58 from 'bs58'

const defaultOptions = (model: any) => {
return commonOpts(model, true)
Expand Down Expand Up @@ -77,7 +77,7 @@ describe.each(models)('StandardPubKey [%s] - pubkey', function (m) {
try {
await sim.start(defaultOptions(m))
const app = new AvalancheApp(sim.getTransport())
const resp = await app.getAddressAndPubKey(APP_DERIVATION, false, 'zemu', bs58_encode(Buffer.alloc(32, 42)))
const resp = await app.getAddressAndPubKey(APP_DERIVATION, false, 'zemu', bs58.encode(Buffer.alloc(32, 42)))

console.log(resp, m.name)

Expand All @@ -97,7 +97,7 @@ describe.each(models)('StandardPubKey [%s] - pubkey', function (m) {
try {
await sim.start(defaultOptions(m))
const app = new AvalancheApp(sim.getTransport())
const respReq = app.getAddressAndPubKey(APP_DERIVATION, true, 'zemu', bs58_encode(Buffer.alloc(32, 42)))
const respReq = app.getAddressAndPubKey(APP_DERIVATION, true, 'zemu', bs58.encode(Buffer.alloc(32, 42)))

await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-zemu-addr`)
Expand Down
30 changes: 13 additions & 17 deletions tests_zemu/tests/eth_legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import Zemu from '@zondax/zemu'
import { ETH_DERIVATION, defaultOptions as commonOpts, models } from './common'
import AvalancheApp from '@zondax/ledger-avalanche-app'

import { Transaction } from '@ethereumjs/tx'
import { LegacyTransaction } from '@ethereumjs/tx'
import { Common } from '@ethereumjs/common'
import { bufArrToArr } from '@ethereumjs/util'
import { RLP } from '@ethereumjs/rlp'
// import { ec } from 'elliptic'

Expand Down Expand Up @@ -92,12 +91,12 @@ const SIGN_TEST_DATA: TestData[] = [

const rawUnsignedLegacyTransaction = (params: Op, chainId?: number) => {
const txParams = {
nonce: '0x00',
gasPrice: '0x6d6e2edc00',
gasLimit: '0x2dc6c0',
to: params.to !== undefined ? '0x' + params.to : undefined,
value: '0x' + params.value,
data: params.data !== undefined ? '0x' + params.data : undefined,
nonce: BigInt(0),
gasPrice: BigInt('0x6d6e2edc00'),
gasLimit: BigInt('0x2dc6c0'),
to: params.to !== undefined ? Buffer.from(params.to, 'hex') : undefined,
value: BigInt('0x' + params.value),
data: params.data !== undefined ? Buffer.from(params.data, 'hex') : undefined,
}

const chain = Common.custom({
Expand All @@ -109,13 +108,10 @@ const rawUnsignedLegacyTransaction = (params: Op, chainId?: number) => {
const options = { common: chain }

// legacy
const tx = Transaction.fromTxData(txParams, options)
const tx = LegacyTransaction.fromTxData(txParams, options)

let unsignedTx: Buffer[] | Buffer
unsignedTx = tx.getMessageToSign(false)
unsignedTx = Buffer.from(RLP.encode(bufArrToArr(unsignedTx)))

return unsignedTx
let unsignedTx = tx.getMessageToSign()
return new Uint8Array(RLP.encode(unsignedTx))
}

// an alternative verification method for legacy transactions, taken from obsidian
Expand All @@ -136,7 +132,7 @@ function check_legacy_signature(hexTx: string, signature: any, chainId: number |

const txnBufs = txnBufsDecoded.concat(txnBufsMap)

const ethTxObj = Transaction.fromValuesArray(txnBufs, tx_options)
const ethTxObj = LegacyTransaction.fromValuesArray(txnBufs, tx_options)

return ethTxObj.verifySignature()
}
Expand All @@ -154,7 +150,7 @@ describe.each(models)('EthereumLegacy [%s]; sign', function (m) {
const currentScreen = await sim.snapshot()
const msg = rawUnsignedLegacyTransaction(data.op, data.chainId)

const respReq = app.signEVMTransaction(ETH_DERIVATION, msg.toString('hex'), null)
const respReq = app.signEVMTransaction(ETH_DERIVATION, Buffer.from(msg).toString('hex'), null)
await sim.waitUntilScreenIsNot(currentScreen, 60000)

await sim.compareSnapshotsAndApprove('.', `${testcase}`)
Expand All @@ -167,7 +163,7 @@ describe.each(models)('EthereumLegacy [%s]; sign', function (m) {
expect(resp).toHaveProperty('r')
expect(resp).toHaveProperty('v')

const test = check_legacy_signature(msg.toString('hex'), resp, data.chainId)
const test = check_legacy_signature(Buffer.from(msg).toString('hex'), resp, data.chainId)
expect(test).toEqual(true)
} finally {
await sim.close()
Expand Down
Loading

0 comments on commit 2d3800a

Please sign in to comment.