From ddad19f4f57dd4a1a511d6573d009030dc2f718c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 30 May 2018 16:50:20 +0200 Subject: [PATCH] add testApdu tool --- src/commands/index.js | 2 ++ src/commands/testApdu.js | 26 ++++++++++++++++++++++++++ src/components/modals/Debug.js | 25 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/commands/testApdu.js diff --git a/src/commands/index.js b/src/commands/index.js index 1b4e3abe..1eac723b 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -18,6 +18,7 @@ import installOsuFirmware from 'commands/installOsuFirmware' import installFinalFirmware from 'commands/installFinalFirmware' import installMcu from 'commands/installMcu' import listApps from 'commands/listApps' +import testApdu from 'commands/testApdu' import testInterval from 'commands/testInterval' import testCrash from 'commands/testCrash' @@ -38,6 +39,7 @@ const all: Array> = [ installFinalFirmware, installMcu, listApps, + testApdu, testInterval, testCrash, ] diff --git a/src/commands/testApdu.js b/src/commands/testApdu.js new file mode 100644 index 00000000..079cbcc1 --- /dev/null +++ b/src/commands/testApdu.js @@ -0,0 +1,26 @@ +// @flow + +// This is a test example for dev testing purpose. + +import { createCommand, Command } from 'helpers/ipc' +import { fromPromise } from 'rxjs/observable/fromPromise' +import { withDevice } from 'helpers/deviceAccess' + +type Input = { + devicePath: string, + apduHex: string, +} +type Result = { + responseHex: string, +} + +const cmd: Command = createCommand('testApdu', ({ apduHex, devicePath }) => + fromPromise( + withDevice(devicePath)(async transport => { + const res = await transport.exchange(Buffer.from(apduHex, 'hex')) + return { responseHex: res.toString('hex') } + }), + ), +) + +export default cmd diff --git a/src/components/modals/Debug.js b/src/components/modals/Debug.js index 98a4386c..3bea829c 100644 --- a/src/components/modals/Debug.js +++ b/src/components/modals/Debug.js @@ -5,15 +5,18 @@ import React, { Component } from 'react' import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal' import Button from 'components/base/Button' import Box from 'components/base/Box' +import Input from 'components/base/Input' import EnsureDevice from 'components/ManagerPage/EnsureDevice' import { getDerivations } from 'helpers/derivations' import getAddress from 'commands/getAddress' import testInterval from 'commands/testInterval' import testCrash from 'commands/testCrash' +import testApdu from 'commands/testApdu' class Debug extends Component<*, *> { state = { logs: [], + apdu: '', } onStartPeriod = (period: number) => () => { @@ -62,6 +65,12 @@ class Debug extends Component<*, *> { } periodSubs = [] + runApdu = (device: *) => () => { + testApdu + .send({ devicePath: device.path, apduHex: this.state.apdu }) + .subscribe(o => this.log(o.responseHex), e => this.error(e)) + } + log = (txt: string) => { this.setState(({ logs }) => ({ logs: logs.concat({ txt, type: 'log' }) })) } @@ -103,6 +112,22 @@ class Debug extends Component<*, *> { + + {device => ( + + + this.setState({ apdu })} + /> + + + + )} +