Browse Source

Merge pull request #408 from gre/sanity-check-at-boot

add libcoreGetVersion & use it at boot
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
24606af01e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 34
      src/commands/index.js
  3. 22
      src/commands/libcoreGetVersion.js
  4. 19
      src/renderer/init.js
  5. 6
      yarn.lock

2
package.json

@ -41,7 +41,7 @@
"@ledgerhq/hw-app-xrp": "^4.12.0",
"@ledgerhq/hw-transport": "^4.12.0",
"@ledgerhq/hw-transport-node-hid": "^4.12.0",
"@ledgerhq/ledger-core": "^1.3.0",
"@ledgerhq/ledger-core": "1.4.1",
"@ledgerhq/live-common": "2.15.0",
"axios": "^0.18.0",
"babel-runtime": "^6.26.0",

34
src/commands/index.js

@ -2,46 +2,48 @@
import type { Command } from 'helpers/ipc'
import getMemInfo from 'commands/getMemInfo'
import libcoreScanAccounts from 'commands/libcoreScanAccounts'
import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import getAddress from 'commands/getAddress'
import signTransaction from 'commands/signTransaction'
import getDeviceInfo from 'commands/getDeviceInfo'
import getFirmwareInfo from 'commands/getFirmwareInfo'
import getIsGenuine from 'commands/getIsGenuine'
import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice'
import getMemInfo from 'commands/getMemInfo'
import installApp from 'commands/installApp'
import listenDevices from 'commands/listenDevices'
import uninstallApp from 'commands/uninstallApp'
import installOsuFirmware from 'commands/installOsuFirmware'
import installFinalFirmware from 'commands/installFinalFirmware'
import installMcu from 'commands/installMcu'
import installOsuFirmware from 'commands/installOsuFirmware'
import libcoreGetVersion from 'commands/libcoreGetVersion'
import libcoreScanAccounts from 'commands/libcoreScanAccounts'
import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import listApps from 'commands/listApps'
import listenDevices from 'commands/listenDevices'
import signTransaction from 'commands/signTransaction'
import testApdu from 'commands/testApdu'
import testInterval from 'commands/testInterval'
import testCrash from 'commands/testCrash'
import testInterval from 'commands/testInterval'
import uninstallApp from 'commands/uninstallApp'
const all: Array<Command<any, any>> = [
getMemInfo,
libcoreScanAccounts,
libcoreSignAndBroadcast,
getAddress,
signTransaction,
getDeviceInfo,
getFirmwareInfo,
getIsGenuine,
getLatestFirmwareForDevice,
getMemInfo,
installApp,
listenDevices,
uninstallApp,
installOsuFirmware,
installFinalFirmware,
installMcu,
installOsuFirmware,
libcoreGetVersion,
libcoreScanAccounts,
libcoreSignAndBroadcast,
listApps,
listenDevices,
signTransaction,
testApdu,
testInterval,
testCrash,
testInterval,
uninstallApp,
]
all.forEach(cmd => {

22
src/commands/libcoreGetVersion.js

@ -0,0 +1,22 @@
// @flow
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
type Input = void
type Result = { stringVersion: string, intVersion: number }
const cmd: Command<Input, Result> = createCommand('libcoreGetVersion', () =>
fromPromise(
Promise.resolve().then(() => {
const ledgerCore = require('init-ledger-core')()
const core = new ledgerCore.NJSLedgerCore()
const stringVersion = core.getStringVersion()
const intVersion = core.getIntVersion()
return { stringVersion, intVersion }
}),
),
)
export default cmd

19
src/renderer/init.js

@ -6,6 +6,7 @@ import { render } from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import createHistory from 'history/createHashHistory'
import moment from 'moment'
import { delay } from 'helpers/promise'
import createStore from 'renderer/createStore'
import events from 'renderer/events'
@ -14,6 +15,7 @@ import { fetchAccounts } from 'actions/accounts'
import { fetchSettings } from 'actions/settings'
import { isLocked } from 'reducers/application'
import { getLanguage } from 'reducers/settings'
import libcoreGetVersion from 'commands/libcoreGetVersion'
import db from 'helpers/db'
import dbMiddleware from 'middlewares/db'
@ -57,6 +59,9 @@ function r(Comp) {
}
async function init() {
// FIXME IMO init() really should only be for window. any other case is a hack!
const isMainWindow = remote.getCurrentWindow().name === 'MainWindow'
if (!locked) {
// Init accounts with defaults if needed
db.init('accounts', [])
@ -67,9 +72,19 @@ async function init() {
r(<App store={store} history={history} language={language} />)
// Only init events on MainWindow
if (remote.getCurrentWindow().name === 'MainWindow') {
if (isMainWindow) {
events({ store, locked })
const libcoreVersion = await Promise.race([
libcoreGetVersion.send().toPromise(),
delay(10000).then(() => Promise.reject(new Error("timeout: can't load libcore"))),
])
console.log('libcore', libcoreVersion)
}
}
init()
init().catch(e => {
// for now we make the app crash instead of pending forever. later we can render the error OR try to recover, but probably this is unrecoverable cases.
console.error(e)
process.exit(1)
})

6
yarn.lock

@ -1451,9 +1451,9 @@
dependencies:
events "^2.0.0"
"@ledgerhq/ledger-core@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-1.3.0.tgz#2b26d43c4a8973e00e0c6671a2da5183ef0ce229"
"@ledgerhq/ledger-core@1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-1.4.1.tgz#c12d4a9140765731458ff1c68112818948c7f91d"
dependencies:
"@ledgerhq/hw-app-btc" "^4.7.3"
"@ledgerhq/hw-transport-node-hid" "^4.7.6"

Loading…
Cancel
Save