Skip to content

Commit

Permalink
change hw-app-kda dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Sep 11, 2024
1 parent d5a5e14 commit 06247f6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-linux-x86_64.sh
sudo mkdir /opt/cmake
sudo sh cmake-3.28.0-linux-x86_64.sh --skip-license --prefix=/opt/cmake
sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
sudo ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
sudo ln -sf /opt/cmake/bin/cmake /usr/local/bin/cmake
sudo ln -sf /opt/cmake/bin/ctest /usr/local/bin/ctest
- name: Verify CMake version
run: cmake --version
- name: Install deps
Expand Down
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-tsdoc": "^0.3.0",
"eslint-plugin-unused-imports": "^4.1.3",
"hw-app-kda": "git+https://github.com/obsidiansystems/hw-app-kda",
"@zondax/hw-app-kda": "^0.1.1",
"jest": "29.7.0",
"jssha": "^3.3.1",
"prettier": "^3.3.3",
Expand Down
62 changes: 34 additions & 28 deletions tests_zemu/tests/legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
******************************************************************************* */

import Zemu, { ButtonKind, isTouchDevice } from '@zondax/zemu'
import Kda from 'hw-app-kda'
import Kda from '@zondax/hw-app-kda'
import { PATH, defaultOptions, models } from './common'
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'

Expand Down Expand Up @@ -69,7 +69,7 @@ test.concurrent.each(models)('get address', async function (m) {
console.log(pubKey)

// The address is not checked because the public key is used as an address in the app
expect(pubKey.toString('hex')).toEqual(expected_pk)
expect(Buffer.from(pubKey).toString('hex')).toEqual(expected_pk)
} catch {
throw new Error('legacy getAddress error')
}
Expand Down Expand Up @@ -99,7 +99,7 @@ test.concurrent.each(models)('legacy show address', async function (m) {
console.log(resp)

// The address is not checked because the public key is used as an address in the app
expect(resp.publicKey.toString('hex')).toEqual(expected_pk)
expect(Buffer.from(resp.publicKey).toString('hex')).toEqual(expected_pk)
} finally {
await sim.close()
}
Expand Down Expand Up @@ -150,8 +150,8 @@ describe.each(JSON_TEST_CASES)('Tx json', function (data) {

const signatureResponse = await signatureRequest

console.log('Pubkey: ', publicKey.toString('hex'))
console.log('Signature: ', signatureResponse.signature.toString('hex'))
console.log('Pubkey: ', Buffer.from(publicKey).toString('hex'))
console.log('Signature: ', Buffer.from(signatureResponse.signature).toString('hex'))

const context = blake2bInit(32)
blake2bUpdate(context, txBlob)
Expand Down Expand Up @@ -187,8 +187,8 @@ describe.each(HASH_TEST_CASES)('Hash transactions', function (data) {

const rawHash = data.hash.length == 64 ? Buffer.from(data.hash, 'hex') : Buffer.from(data.hash, 'base64')

console.log('Pubkey: ', publicKey.toString('hex'))
console.log('Signature: ', signatureResponse.signature.toString('hex'))
console.log('Pubkey: ', Buffer.from(publicKey).toString('hex'))
console.log('Signature: ', Buffer.from(signatureResponse.signature).toString('hex'))
console.log('Raw Hash: ', rawHash.toString('hex'))

// Now verify the signature
Expand All @@ -201,7 +201,7 @@ describe.each(HASH_TEST_CASES)('Hash transactions', function (data) {
})

describe.each(TRANSACTIONS_TEST_CASES)('Tx transfer', function (data) {
test.concurrent.each(models)('sign transfer tx', async function (m) {
test.only.each(models)('sign transfer tx', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
Expand All @@ -227,16 +227,19 @@ describe.each(TRANSACTIONS_TEST_CASES)('Tx transfer', function (data) {

console.log(signatureResponse)

const signatureHex = signatureResponse.pact_command.sigs[0].sig
const decodedHash = decodeHash(signatureResponse.pact_command.hash)

console.log('Pubkey: ', publicKey.toString('hex'))
console.log('Signature: ', signatureHex.toString('hex'))
console.log('Decoded Hash: ', decodedHash.toString('hex'))

// Now verify the signature
const valid = ed25519.verify(signatureHex, decodedHash, publicKey)
expect(valid).toEqual(true)
if (signatureResponse) {
const signatureHex = signatureResponse.pact_command.sigs[0].sig
const decodedHash = decodeHash(signatureResponse.pact_command.hash)
console.log('Pubkey: ', Buffer.from(publicKey).toString('hex'))
console.log('Signature: ', Buffer.from(signatureHex).toString('hex'))
console.log('Decoded Hash: ', Buffer.from(decodedHash).toString('hex'))

// Now verify the signature
const valid = ed25519.verify(signatureHex, decodedHash, publicKey)
expect(valid).toEqual(true)
} else {
throw new Error('signatureResponse is null')
}
} finally {
await sim.close()
}
Expand Down Expand Up @@ -270,16 +273,19 @@ describe.each(HANDLER_LEGACY_TEST_CASES)('Tx transfer', function (data) {

console.log(signatureResponse)

const signatureHex = signatureResponse.pact_command.sigs[0].sig
const decodedHash = decodeHash(signatureResponse.pact_command.hash)

console.log('Pubkey: ', publicKey.toString('hex'))
console.log('Signature: ', signatureHex.toString('hex'))
console.log('Decoded Hash: ', decodedHash.toString('hex'))

// Now verify the signature
const valid = ed25519.verify(signatureHex, decodedHash, publicKey)
expect(valid).toEqual(true)
if (signatureResponse) {
const signatureHex = signatureResponse.pact_command.sigs[0].sig
const decodedHash = decodeHash(signatureResponse.pact_command.hash)
console.log('Pubkey: ', Buffer.from(publicKey).toString('hex'))
console.log('Signature: ', Buffer.from(signatureHex).toString('hex'))
console.log('Decoded Hash: ', Buffer.from(decodedHash).toString('hex'))

// Now verify the signature
const valid = ed25519.verify(signatureHex, decodedHash, publicKey)
expect(valid).toEqual(true)
} else {
throw new Error('signatureResponse is null')
}
} finally {
await sim.close()
}
Expand Down
12 changes: 8 additions & 4 deletions tests_zemu/tests/testscases/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PATH } from '../common'
import { TransferTxType } from '@zondax/ledger-kadena'
import Kda from 'hw-app-kda'

export const TRANSACTIONS_TEST_CASES = [
{
Expand All @@ -17,6 +16,7 @@ export const TRANSACTIONS_TEST_CASES = [
creationTime: 1665647810,
ttl: '600',
nonce: '2022-10-13 07:56:50.893257 UTC',
recipient_chainId: 0,
},
},
{
Expand All @@ -33,6 +33,7 @@ export const TRANSACTIONS_TEST_CASES = [
creationTime: 1665722463,
ttl: '600',
nonce: '2022-10-14 04:41:03.193557 UTC',
recipient_chainId: 0,
},
},
{
Expand Down Expand Up @@ -70,7 +71,8 @@ export const HANDLER_LEGACY_TEST_CASES = [
ttl: "60000000000000000000",
nonce: "2022-10-13 07:56:50.893257 UTC",
namespace: "testnamespace012",
module: "testmoduletestmoduletestmodule01"
module: "testmoduletestmoduletestmodule01",
recipient_chainId: 0
},
},
{
Expand All @@ -88,7 +90,8 @@ export const HANDLER_LEGACY_TEST_CASES = [
ttl: "60000000000000000000",
nonce: "2022-10-13 07:56:50.893257 UTC",
namespace: "testnamespace012",
module: "testmoduletestmoduletestmodule01"
module: "testmoduletestmoduletestmodule01",
recipient_chainId: 0
},
},
{
Expand All @@ -106,7 +109,8 @@ export const HANDLER_LEGACY_TEST_CASES = [
ttl: "60000000000000000000",
nonce: "2022-10-13 07:56:50.893257 UTC",
namespace: "testnamespace012",
module: "testmoduletestmoduletestmodule01"
module: "testmoduletestmoduletestmodule01",
recipient_chainId: 0
},
},
]
2 changes: 1 addition & 1 deletion tests_zemu/try_legacy.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import Kda from 'hw-app-kda'
import Kda from '@zondax/hw-app-kda'
import { ed25519 } from '@noble/curves/ed25519'
import pkg from 'blakejs'
const { blake2bFinal, blake2bInit, blake2bUpdate } = pkg
Expand Down
6 changes: 1 addition & 5 deletions tests_zemu/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
"skipLibCheck": true,
"outDir": "./dist"
},
"exclude": ["node_modules", "./dist/**"],
"include": ["src", "tests", "types"],
"ts-node": {
"files": true
}
"exclude": ["node_modules", "./dist/**"]
}
1 change: 0 additions & 1 deletion tests_zemu/types/hw-app-kda.d.ts

This file was deleted.

0 comments on commit 06247f6

Please sign in to comment.