Skip to content

Commit

Permalink
Merge pull request #84 from cosmos/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ftheirs authored Mar 27, 2023
2 parents e24a884 + 67d3a96 commit b470589
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=35
# This is the patch version of this release
APPVERSION_P=3
APPVERSION_P=4
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 181 additions & 2 deletions tests_zemu/tests/standard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Zemu from '@zondax/zemu'
// @ts-ignore
import { CosmosApp } from '@zondax/ledger-cosmos-js'
import { DEFAULT_OPTIONS, DEVICE_MODELS } from './common'
import { DEFAULT_OPTIONS, DEVICE_MODELS, example_tx_str_basic, example_tx_str_basic2, ibc_denoms } from './common'

// @ts-ignore
import secp256k1 from 'secp256k1/elliptic'
Expand Down Expand Up @@ -173,4 +173,183 @@ describe('Standard', function () {
await sim.close()
}
})
})

test.concurrent.each(DEVICE_MODELS)('sign basic normal', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(JSON.stringify(example_tx_str_basic), 'utf-8')

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')
expect(resp).toHaveProperty('signature')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})

test.concurrent.each(DEVICE_MODELS)('sign basic normal2', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(JSON.stringify(example_tx_str_basic2), 'utf-8')

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic2`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})

test.concurrent.each(DEVICE_MODELS)('sign basic with extra fields', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(JSON.stringify(example_tx_str_basic), 'utf-8')

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic_extra_fields`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')
expect(resp).toHaveProperty('signature')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})

test.concurrent.each(DEVICE_MODELS)('ibc denoms', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(JSON.stringify(ibc_denoms), 'utf-8')

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-ibc_denoms`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')
expect(resp).toHaveProperty('signature')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})
})

0 comments on commit b470589

Please sign in to comment.