Valentin D. Pinkman
7 years ago
committed by
GitHub
35 changed files with 418 additions and 291 deletions
@ -0,0 +1,19 @@ |
|||
// @flow
|
|||
|
|||
import { createCommand, Command } from 'helpers/ipc' |
|||
import { fromPromise } from 'rxjs/observable/fromPromise' |
|||
|
|||
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware' |
|||
|
|||
type Input = { |
|||
deviceId: string | number, |
|||
version: string, |
|||
} |
|||
|
|||
type Result = * |
|||
|
|||
const cmd: Command<Input, Result> = createCommand('getCurrentFirmware', data => |
|||
fromPromise(getCurrentFirmware(data)), |
|||
) |
|||
|
|||
export default cmd |
@ -1,19 +0,0 @@ |
|||
// @flow
|
|||
|
|||
import { createCommand, Command } from 'helpers/ipc' |
|||
import { fromPromise } from 'rxjs/observable/fromPromise' |
|||
|
|||
import getFirmwareInfo from 'helpers/devices/getFirmwareInfo' |
|||
|
|||
type Input = { |
|||
targetId: string | number, |
|||
version: string, |
|||
} |
|||
|
|||
type Result = * |
|||
|
|||
const cmd: Command<Input, Result> = createCommand('getFirmwareInfo', data => |
|||
fromPromise(getFirmwareInfo(data)), |
|||
) |
|||
|
|||
export default cmd |
@ -0,0 +1,55 @@ |
|||
// @flow
|
|||
import React, { PureComponent } from 'react' |
|||
|
|||
import type { Device } from 'types/common' |
|||
import installMcu from 'commands/installMcu' |
|||
|
|||
type DeviceInfo = { |
|||
targetId: number | string, |
|||
version: string, |
|||
final: boolean, |
|||
mcu: boolean, |
|||
} |
|||
|
|||
type Props = { |
|||
device: Device, |
|||
deviceInfo: DeviceInfo, |
|||
} |
|||
|
|||
type State = { |
|||
flashing: boolean, |
|||
} |
|||
|
|||
class FlashMcu extends PureComponent<Props, State> { |
|||
state = { |
|||
flashing: false, |
|||
} |
|||
|
|||
flashMCU = async () => { |
|||
const { device, deviceInfo } = this.props |
|||
const { flashing } = this.state |
|||
|
|||
if (!flashing) { |
|||
this.setState({ flashing: true }) |
|||
await installMcu |
|||
.send({ |
|||
devicePath: device.path, |
|||
targetId: deviceInfo.targetId, |
|||
version: deviceInfo.version, |
|||
}) |
|||
.toPromise() |
|||
this.setState({ flashing: false }) |
|||
} |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<div> |
|||
<h1>Flashing MCU</h1> |
|||
<button onClick={this.flashMCU}>flash</button> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default FlashMcu |
@ -1,15 +0,0 @@ |
|||
// @flow
|
|||
import { PureComponent } from 'react' |
|||
|
|||
type Props = { |
|||
callback: () => void, |
|||
} |
|||
|
|||
class TriggerOnMount extends PureComponent<Props> { |
|||
componentDidMount() { |
|||
const { callback } = this.props |
|||
callback() |
|||
} |
|||
} |
|||
|
|||
export default TriggerOnMount |
@ -0,0 +1,26 @@ |
|||
// @flow
|
|||
import axios from 'axios' |
|||
|
|||
import { GET_CURRENT_FIRMWARE } from 'helpers/urls' |
|||
|
|||
type Input = { |
|||
version: string, |
|||
deviceId: string | number, |
|||
} |
|||
|
|||
let error |
|||
export default async (input: Input): Promise<*> => { |
|||
try { |
|||
const provider = 1 |
|||
const { data } = await axios.post(GET_CURRENT_FIRMWARE, { |
|||
device_version: input.deviceId, |
|||
version_name: input.version, |
|||
provider, |
|||
}) |
|||
return data |
|||
} catch (err) { |
|||
error = Error(err.message) |
|||
error.stack = err.stack |
|||
throw error |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
// @flow
|
|||
import axios from 'axios' |
|||
|
|||
import { GET_DEVICE_VERSION } from 'helpers/urls' |
|||
|
|||
export default async (targetId: string | number): Promise<*> => { |
|||
try { |
|||
const provider = 1 |
|||
const { data } = await axios.post(GET_DEVICE_VERSION, { |
|||
provider, |
|||
target_id: targetId, |
|||
}) |
|||
return data |
|||
} catch (err) { |
|||
const error = Error(err.message) |
|||
error.stack = err.stack |
|||
throw err |
|||
} |
|||
} |
@ -1,34 +0,0 @@ |
|||
// @flow
|
|||
import axios from 'axios' |
|||
import isEmpty from 'lodash/isEmpty' |
|||
|
|||
import { MANAGER_API_BASE } from 'config/constants' |
|||
|
|||
type Input = { |
|||
version: string, |
|||
targetId: string | number, |
|||
} |
|||
|
|||
let error |
|||
export default async (data: Input) => { |
|||
try { |
|||
const { data: seFirmwareVersion } = await axios.post( |
|||
`${MANAGER_API_BASE}/firmware_versions_name`, |
|||
{ |
|||
se_firmware_name: data.version, |
|||
target_id: data.targetId, |
|||
}, |
|||
) |
|||
|
|||
if (!isEmpty(seFirmwareVersion)) { |
|||
return seFirmwareVersion |
|||
} |
|||
|
|||
error = Error('could not retrieve firmware informations, try again later') |
|||
throw error |
|||
} catch (err) { |
|||
error = Error(err.message) |
|||
error.stack = err.stack |
|||
throw error |
|||
} |
|||
} |
@ -1,12 +1,26 @@ |
|||
// @flow
|
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
import { createSocketDialog } from 'helpers/common' |
|||
import { SKIP_GENUINE } from 'config/constants' |
|||
import { WS_GENUINE } from 'helpers/urls' |
|||
|
|||
import { createDeviceSocket } from 'helpers/socket' |
|||
import getCurrentFirmware from './getCurrentFirmware' |
|||
import getDeviceVersion from './getDeviceVersion' |
|||
|
|||
export default async ( |
|||
transport: Transport<*>, |
|||
{ targetId }: { targetId: string | number }, |
|||
): Promise<string> => |
|||
SKIP_GENUINE |
|||
app: { targetId: string | number, version: string }, |
|||
): Promise<string> => { |
|||
const { targetId, version } = app |
|||
const device = await getDeviceVersion(app.targetId) |
|||
const firmware = await getCurrentFirmware({ deviceId: device.id, version }) |
|||
const params = { |
|||
targetId, |
|||
version, |
|||
perso: firmware.perso, |
|||
} |
|||
const url = WS_GENUINE(params) |
|||
return SKIP_GENUINE |
|||
? new Promise(resolve => setTimeout(() => resolve('0000'), 1000)) |
|||
: createSocketDialog(transport, '/genuine', { targetId }, true) |
|||
: createDeviceSocket(transport, url).toPromise() |
|||
} |
|||
|
@ -0,0 +1,26 @@ |
|||
// @flow
|
|||
import axios from 'axios' |
|||
|
|||
import { GET_NEXT_MCU } from 'helpers/urls' |
|||
import createCustomErrorClass from 'helpers/createCustomErrorClass' |
|||
|
|||
const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError') |
|||
|
|||
export default async (bootloaderVersion: string): Promise<*> => { |
|||
try { |
|||
const { data } = await axios.post(GET_NEXT_MCU, { |
|||
bootloader_version: bootloaderVersion, |
|||
}) |
|||
|
|||
// FIXME: nextVersion will not be able to "default" when Error
|
|||
// handling is standardize on the API side
|
|||
if (data === 'default' || !data.name) { |
|||
throw new LatestMCUInstalledError('there is no next mcu version to install') |
|||
} |
|||
return data |
|||
} catch (err) { |
|||
const error = Error(err.message) |
|||
error.stack = err.stack |
|||
throw err |
|||
} |
|||
} |
@ -1,8 +1,23 @@ |
|||
// @flow
|
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
|
|||
type Result = Promise<boolean> |
|||
import { WS_MCU } from 'helpers/urls' |
|||
import { createDeviceSocket } from 'helpers/socket' |
|||
import getNextMCU from 'helpers/devices/getNextMCU' |
|||
|
|||
// TODO: IMPLEMENTATION FOR FLASHING FIRMWARE
|
|||
// GETTING APDUS FROM SERVER
|
|||
// SEND THE APDUS TO DEVICE
|
|||
export default async (): Result => new Promise(resolve => resolve(true)) |
|||
type Result = Promise<*> |
|||
|
|||
export default async ( |
|||
transport: Transport<*>, |
|||
args: { targetId: string | number, version: string }, |
|||
): Result => { |
|||
const { version } = args |
|||
const nextVersion = await getNextMCU(version) |
|||
|
|||
const params = { |
|||
targetId: args.targetId, |
|||
version: nextVersion.name, |
|||
} |
|||
const url = WS_MCU(params) |
|||
return createDeviceSocket(transport, url).toPromise() |
|||
} |
|||
|
@ -0,0 +1,27 @@ |
|||
// @flow
|
|||
import qs from 'qs' |
|||
|
|||
import { MANAGER_API_BASE, BASE_SOCKET_URL_SECURE } from 'config/constants' |
|||
import type { LedgerScriptParams } from 'helpers/common' |
|||
|
|||
const urlBuilder = (base: string) => (endpoint: string): string => `${base}/${endpoint}` |
|||
|
|||
const managerUrlbuilder = urlBuilder(MANAGER_API_BASE) |
|||
|
|||
const wsURLBuilder = (endpoint: string) => (params?: Object) => |
|||
`${BASE_SOCKET_URL_SECURE}/${endpoint}${params ? `?${qs.stringify(params)}` : ''}` |
|||
|
|||
// const wsURLBuilderProxy = (endpoint: string) => (params?: Object) =>
|
|||
// `ws://manager.ledger.fr:3501/${endpoint}${params ? `?${qs.stringify(params)}` : ''}`
|
|||
|
|||
export const GET_DEVICE_VERSION: string = managerUrlbuilder('get_device_version') |
|||
export const APPLICATIONS_BY_DEVICE: string = managerUrlbuilder('get_apps') |
|||
export const GET_CURRENT_FIRMWARE: string = managerUrlbuilder('get_firmware_version') |
|||
export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmware') |
|||
export const GET_NEXT_MCU: string = managerUrlbuilder('mcu_versions_bootloader') |
|||
|
|||
export const WS_INSTALL: (arg: LedgerScriptParams) => string = wsURLBuilder('install') |
|||
export const WS_GENUINE: (arg: { targetId: string | number }) => string = wsURLBuilder('genuine') |
|||
export const WS_MCU: (arg: { targetId: string | number, version: string }) => string = wsURLBuilder( |
|||
'mcu', |
|||
) |
Loading…
Reference in new issue