From bc8aa90e8465d284e1857f67b9bd58e7d43deb1f Mon Sep 17 00:00:00 2001 From: amougel Date: Fri, 22 Jun 2018 13:56:10 +0200 Subject: [PATCH 1/5] refactoring device information --- src/commands/getDeviceInfo.js | 10 +- src/components/ManagerPage/FlashMcu.js | 9 +- src/components/ManagerPage/index.js | 10 +- src/components/Workflow/EnsureDashboard.js | 7 +- src/components/Workflow/EnsureGenuine.js | 12 +- src/components/Workflow/index.js | 12 +- src/helpers/common.js | 17 +- src/helpers/devices/getDeviceInfo.js | 198 +++++++++++++++++++-- 8 files changed, 218 insertions(+), 57 deletions(-) diff --git a/src/commands/getDeviceInfo.js b/src/commands/getDeviceInfo.js index 767f27f9..67c585fd 100644 --- a/src/commands/getDeviceInfo.js +++ b/src/commands/getDeviceInfo.js @@ -5,19 +5,13 @@ import { fromPromise } from 'rxjs/observable/fromPromise' import { withDevice } from 'helpers/deviceAccess' import getDeviceInfo from 'helpers/devices/getDeviceInfo' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' type Input = { devicePath: string, } -type Result = { - targetId: number | string, - version: string, - final: boolean, - mcu: boolean, -} - -const cmd: Command = createCommand('getDeviceInfo', ({ devicePath }) => +const cmd: Command = createCommand('getDeviceInfo', ({ devicePath }) => fromPromise(withDevice(devicePath)(transport => getDeviceInfo(transport))), ) diff --git a/src/components/ManagerPage/FlashMcu.js b/src/components/ManagerPage/FlashMcu.js index 5edeacd4..0cb9905d 100644 --- a/src/components/ManagerPage/FlashMcu.js +++ b/src/components/ManagerPage/FlashMcu.js @@ -4,12 +4,7 @@ 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, -} +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' type Props = { device: Device, @@ -35,7 +30,7 @@ class FlashMcu extends PureComponent { .send({ devicePath: device.path, targetId: deviceInfo.targetId, - version: deviceInfo.version, + version: deviceInfo.seVersion, }) .toPromise() this.setState({ flashing: false }) diff --git a/src/components/ManagerPage/index.js b/src/components/ManagerPage/index.js index d7399013..49a7312b 100644 --- a/src/components/ManagerPage/index.js +++ b/src/components/ManagerPage/index.js @@ -4,19 +4,13 @@ import React, { PureComponent } from 'react' import type { Device } from 'types/common' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import Workflow from 'components/Workflow' import WorkflowWithIcon from 'components/Workflow/WorkflowWithIcon' import Dashboard from './Dashboard' import FlashMcu from './FlashMcu' -type DeviceInfo = { - targetId: number | string, - version: string, - final: boolean, - mcu: boolean, -} - type Error = { message: string, stack: string, @@ -27,7 +21,7 @@ class ManagerPage extends PureComponent<*, *> { return ( ( -

UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.final}

+

UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.isOSU}

)} renderMcuUpdate={(device: Device, deviceInfo: DeviceInfo) => ( diff --git a/src/components/Workflow/EnsureDashboard.js b/src/components/Workflow/EnsureDashboard.js index e7b86416..bc762558 100644 --- a/src/components/Workflow/EnsureDashboard.js +++ b/src/components/Workflow/EnsureDashboard.js @@ -7,12 +7,7 @@ import type { Device } from 'types/common' import getDeviceInfo from 'commands/getDeviceInfo' -type DeviceInfo = { - targetId: number | string, - version: string, - final: boolean, - mcu: boolean, -} +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' type Error = { message: string, diff --git a/src/components/Workflow/EnsureGenuine.js b/src/components/Workflow/EnsureGenuine.js index a1890480..2ebc5729 100644 --- a/src/components/Workflow/EnsureGenuine.js +++ b/src/components/Workflow/EnsureGenuine.js @@ -15,7 +15,8 @@ type Error = { type DeviceInfos = { targetId: number | string, - version: string, + seVersion: string, + providerName: string, } type Props = { @@ -60,8 +61,15 @@ class EnsureGenuine extends PureComponent { if (device && infos && !this._checking) { this._checking = true try { + const versionName = `${infos.seVersion}${ + infos.providerName ? `-${infos.providerName}` : '' + }` const res = await getIsGenuine - .send({ devicePath: device.path, targetId: infos.targetId, version: infos.version }) + .send({ + devicePath: device.path, + targetId: infos.targetId, + version: versionName, + }) .pipe(timeout(GENUINE_TIMEOUT)) .toPromise() if (this._unmounting) return diff --git a/src/components/Workflow/index.js b/src/components/Workflow/index.js index e3db974f..7c778f63 100644 --- a/src/components/Workflow/index.js +++ b/src/components/Workflow/index.js @@ -1,6 +1,7 @@ // @flow import React, { PureComponent } from 'react' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import type { Node } from 'react' import type { Device } from 'types/common' @@ -9,13 +10,6 @@ import EnsureDevice from './EnsureDevice' import EnsureDashboard from './EnsureDashboard' import EnsureGenuine from './EnsureGenuine' -type DeviceInfo = { - targetId: number | string, - version: string, - final: boolean, - mcu: boolean, -} - type Error = { message: string, stack: string, @@ -55,11 +49,11 @@ class Workflow extends PureComponent { {(device: Device) => ( {(deviceInfo: ?DeviceInfo, dashboardError: ?Error) => { - if (deviceInfo && deviceInfo.mcu && renderMcuUpdate) { + if (deviceInfo && deviceInfo.isBootloader && renderMcuUpdate) { return renderMcuUpdate(device, deviceInfo) } - if (deviceInfo && deviceInfo.final && renderFinalUpdate) { + if (deviceInfo && deviceInfo.isOSU && renderFinalUpdate) { return renderFinalUpdate(device, deviceInfo) } diff --git a/src/helpers/common.js b/src/helpers/common.js index 3d5a9c30..a8e4bb13 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -32,9 +32,20 @@ export async function getFirmwareInfo(transport: Transport<*>) { const data = byteArray.slice(0, byteArray.length - 2) const targetIdStr = Buffer.from(data.slice(0, 4)) const targetId = targetIdStr.readUIntBE(0, 4) - const versionLength = data[4] - const version = Buffer.from(data.slice(5, 5 + versionLength)).toString() - return { targetId, version } + const seVersionLength = data[4] + const seVersion = Buffer.from(data.slice(5, 5 + seVersionLength)).toString() + const flagsLength = data[5 + seVersionLength] + const flags = Buffer.from( + data.slice(5 + seVersionLength + 1, 5 + seVersionLength + 1 + flagsLength), + ).toString() + const mcuVersionLength = data[5 + seVersionLength + 1 + flagsLength] + const mcuVersion = Buffer.from( + data.slice( + 7 + seVersionLength + flagsLength, + 7 + seVersionLength + flagsLength + mcuVersionLength, + ), + ).toString() + return { targetId, seVersion, flags, mcuVersion } } catch (err) { const error = new Error(err.message) error.stack = err.stack diff --git a/src/helpers/devices/getDeviceInfo.js b/src/helpers/devices/getDeviceInfo.js index 06a1e2be..34bf6fe6 100644 --- a/src/helpers/devices/getDeviceInfo.js +++ b/src/helpers/devices/getDeviceInfo.js @@ -4,23 +4,193 @@ import type Transport from '@ledgerhq/hw-transport' import { getFirmwareInfo } from 'helpers/common' -type Result = { +export type DeviceInfo = { targetId: string | number, - version: string, - mcu: boolean, - final: boolean, + seVersion: string, + isBootloader: boolean, + flags: string, + mcuVersion: string, + isOSU: boolean, + providerName: string, } -export default async (transport: Transport<*>): Promise => { - try { - const { targetId, version } = await getFirmwareInfo(transport) - const finalReady = version.endsWith('-osu') - const mcuReady = targetId === 0x01000001 +const DETECT_CLUBCOIN = [ + [0xe0, 0x04, 0x00, 0x00, 0x04, 0x31, 0x10, 0x00, 0x02], + [0xe0, 0x50, 0x00, 0x00, 0x08, 0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7], + [ + 0xe0, + 0x51, + 0x80, + 0x00, + 0x8a, + 0x41, + 0x04, + 0xc9, + 0x8c, + 0xa0, + 0x99, + 0x53, + 0x47, + 0x2b, + 0x36, + 0x06, + 0x1e, + 0x0e, + 0x40, + 0xc9, + 0x3d, + 0x50, + 0x52, + 0x34, + 0x09, + 0x0e, + 0xfd, + 0x74, + 0xf1, + 0xd7, + 0xa2, + 0x93, + 0xe8, + 0x28, + 0x15, + 0x9a, + 0x97, + 0x71, + 0x1b, + 0x33, + 0xd1, + 0x8a, + 0xfc, + 0x17, + 0xad, + 0x15, + 0x6e, + 0xae, + 0xd9, + 0x9c, + 0xf4, + 0x3b, + 0x20, + 0xe1, + 0x5d, + 0x64, + 0xaf, + 0x39, + 0xa5, + 0x51, + 0x3b, + 0x4e, + 0x3c, + 0x5f, + 0x43, + 0x17, + 0xe6, + 0x42, + 0x70, + 0x2f, + 0x05, + 0x47, + 0x30, + 0x45, + 0x02, + 0x21, + 0x00, + 0xf1, + 0xd2, + 0xb8, + 0x34, + 0x99, + 0x4a, + 0x0c, + 0x1f, + 0x25, + 0xea, + 0x20, + 0xcf, + 0x33, + 0xe3, + 0x2b, + 0xd0, + 0x6b, + 0xcf, + 0x7c, + 0x42, + 0x4a, + 0x02, + 0xee, + 0xe8, + 0xf6, + 0x96, + 0x99, + 0x20, + 0xe1, + 0xe8, + 0xc2, + 0xb3, + 0x02, + 0x20, + 0x63, + 0x2d, + 0x19, + 0xbd, + 0x30, + 0xab, + 0x20, + 0x76, + 0x18, + 0x78, + 0x78, + 0xae, + 0xaa, + 0x0f, + 0x4d, + 0x48, + 0x04, + 0x01, + 0x32, + 0x79, + 0xd0, + 0x16, + 0xde, + 0xca, + 0x66, + 0x93, + 0xf3, + 0x7b, + 0x4e, + 0x50, + 0x7f, + 0x43, + ], +] - return { targetId, version, final: finalReady, mcu: mcuReady } - } catch (err) { - const error = Error(err.message) - error.stack = err.stack - throw error +export default async (transport: Transport<*>): Promise => { + const res = await getFirmwareInfo(transport) + let { seVersion } = res + const { targetId, mcuVersion, flags } = res + if (seVersion === '1.2') { + try { + DETECT_CLUBCOIN.forEach(async apdus => { + await transport.send(...apdus) + }) + seVersion = '1.2.0-club' + } catch (e) { + seVersion = '1.2.0' + } + } + const parsedVersion = seVersion.match(/[0-9]+.[0-9]+(.[0-9]+)?(-[a-z]+)?(-osu)?/) || [] + const isOSU = typeof parsedVersion[5] !== 'undefined' + const providerName = parsedVersion[4] || '' + const isBootloader = targetId === 0x01000001 + const majMin = parsedVersion[1] + const patch = parsedVersion[2] || '.0' + return { + targetId, + seVersion: majMin + patch, + isOSU, + mcuVersion, + isBootloader, + providerName, + flags, } } From 7317c8d6055a089766ab4e7dacff29f2df319f95 Mon Sep 17 00:00:00 2001 From: amougel Date: Fri, 22 Jun 2018 17:14:15 +0200 Subject: [PATCH 2/5] using provider --- src/commands/getCurrentFirmware.js | 3 ++- src/commands/getIsGenuine.js | 12 ++++------ src/commands/getLatestFirmwareForDevice.js | 8 ++----- src/commands/listApps.js | 8 ++++--- src/components/EnsureDeviceApp/index.js | 2 +- src/components/ManagerPage/AppsList.js | 7 +++--- src/components/ManagerPage/Dashboard.js | 5 +--- src/components/ManagerPage/FirmwareUpdate.js | 23 +++++++------------ src/components/Workflow/EnsureGenuine.js | 19 ++++----------- src/components/Workflow/index.js | 2 +- src/helpers/apps/listApps.js | 11 +++++---- src/helpers/devices/getCurrentFirmware.js | 8 +++---- src/helpers/devices/getDeviceInfo.js | 13 +++++++++++ src/helpers/devices/getDeviceVersion.js | 3 +-- src/helpers/devices/getIsGenuine.js | 18 +++++++-------- .../devices/getLatestFirmwareForDevice.js | 20 ++++++++-------- src/helpers/devices/isDashboardOpen.js | 4 ++-- src/helpers/urls.js | 5 +++- 18 files changed, 82 insertions(+), 89 deletions(-) diff --git a/src/commands/getCurrentFirmware.js b/src/commands/getCurrentFirmware.js index d0dfc329..773220ae 100644 --- a/src/commands/getCurrentFirmware.js +++ b/src/commands/getCurrentFirmware.js @@ -7,7 +7,8 @@ import getCurrentFirmware from 'helpers/devices/getCurrentFirmware' type Input = { deviceId: string | number, - version: string, + fullVersion: string, + provider: number, } type Result = * diff --git a/src/commands/getIsGenuine.js b/src/commands/getIsGenuine.js index c34f4693..a1bb645d 100644 --- a/src/commands/getIsGenuine.js +++ b/src/commands/getIsGenuine.js @@ -2,23 +2,19 @@ import { createCommand, Command } from 'helpers/ipc' import { fromPromise } from 'rxjs/observable/fromPromise' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import getIsGenuine from 'helpers/devices/getIsGenuine' import { withDevice } from 'helpers/deviceAccess' type Input = { devicePath: string, - targetId: string | number, - version: string, + deviceInfo: DeviceInfo, } type Result = string -const cmd: Command = createCommand( - 'getIsGenuine', - ({ devicePath, targetId, version }) => - fromPromise( - withDevice(devicePath)(transport => getIsGenuine(transport, { targetId, version })), - ), +const cmd: Command = createCommand('getIsGenuine', ({ devicePath, deviceInfo }) => + fromPromise(withDevice(devicePath)(transport => getIsGenuine(transport, deviceInfo))), ) export default cmd diff --git a/src/commands/getLatestFirmwareForDevice.js b/src/commands/getLatestFirmwareForDevice.js index 7a9621c1..d216d2eb 100644 --- a/src/commands/getLatestFirmwareForDevice.js +++ b/src/commands/getLatestFirmwareForDevice.js @@ -2,17 +2,13 @@ import { createCommand, Command } from 'helpers/ipc' import { fromPromise } from 'rxjs/observable/fromPromise' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import getLatestFirmwareForDevice from '../helpers/devices/getLatestFirmwareForDevice' -type Input = { - targetId: string | number, - version: string, -} - type Result = * -const cmd: Command = createCommand('getLatestFirmwareForDevice', data => +const cmd: Command = createCommand('getLatestFirmwareForDevice', data => fromPromise(getLatestFirmwareForDevice(data)), ) diff --git a/src/commands/listApps.js b/src/commands/listApps.js index e4d5a153..d9e28ee2 100644 --- a/src/commands/listApps.js +++ b/src/commands/listApps.js @@ -7,13 +7,15 @@ import listApps from 'helpers/apps/listApps' type Input = { targetId: string | number, - version: string, + fullVersion: string, + provider: number, } type Result = * -const cmd: Command = createCommand('listApps', ({ targetId, version }) => - fromPromise(listApps(targetId, version)), +const cmd: Command = createCommand( + 'listApps', + ({ targetId, fullVersion, provider }) => fromPromise(listApps(targetId, fullVersion, provider)), ) export default cmd diff --git a/src/components/EnsureDeviceApp/index.js b/src/components/EnsureDeviceApp/index.js index 964f3ad5..0893cb02 100644 --- a/src/components/EnsureDeviceApp/index.js +++ b/src/components/EnsureDeviceApp/index.js @@ -159,7 +159,7 @@ class EnsureDeviceApp extends PureComponent { } } else { logger.warn('EnsureDeviceApp for using dashboard is DEPRECATED !!!') - // FIXME REMOVE THIS ! should use EnsureDashboard dedicated component. + // TODO: FIXME REMOVE THIS ! should use EnsureDashboard dedicated component. const isDashboard = isDashboardOpen.send({ devicePath: deviceSelected.path }).toPromise() if (!isDashboard) { diff --git a/src/components/ManagerPage/AppsList.js b/src/components/ManagerPage/AppsList.js index 0ba3dea5..78736e7f 100644 --- a/src/components/ManagerPage/AppsList.js +++ b/src/components/ManagerPage/AppsList.js @@ -48,7 +48,8 @@ type Props = { device: Device, targetId: string | number, t: T, - version: string, + fullVersion: string, + provider: number, } type State = { @@ -82,8 +83,8 @@ class AppsList extends PureComponent { async fetchAppList() { try { - const { targetId, version } = this.props - const appsList = await listApps.send({ targetId, version }).toPromise() + const { targetId, fullVersion, provider } = this.props + const appsList = await listApps.send({ targetId, fullVersion, provider }).toPromise() if (!this._unmounted) { this.setState({ appsList, status: 'idle', appsLoaded: true }) } diff --git a/src/components/ManagerPage/Dashboard.js b/src/components/ManagerPage/Dashboard.js index f64df243..f0bc1ae9 100644 --- a/src/components/ManagerPage/Dashboard.js +++ b/src/components/ManagerPage/Dashboard.js @@ -34,10 +34,7 @@ const Dashboard = ({ device, deviceInfo, t }: Props) => ( - + diff --git a/src/components/ManagerPage/FirmwareUpdate.js b/src/components/ManagerPage/FirmwareUpdate.js index b1f80c93..e6b80de1 100644 --- a/src/components/ManagerPage/FirmwareUpdate.js +++ b/src/components/ManagerPage/FirmwareUpdate.js @@ -14,6 +14,7 @@ import type { LedgerScriptParams } from 'helpers/common' import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice' import installOsuFirmware from 'commands/installOsuFirmware' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import Box, { Card } from 'components/base/Box' import Text from 'components/base/Text' @@ -32,17 +33,12 @@ let CACHED_LATEST_FIRMWARE = null export const getCleanVersion = (input: string): string => input.endsWith('-osu') ? input.replace('-osu', '') : input -type DeviceInfos = { - targetId: number | string, - version: string, -} - type ModalStatus = 'closed' | 'disclaimer' | 'installing' | 'error' | 'success' type Props = { t: T, device: Device, - infos: DeviceInfos, + deviceInfo: DeviceInfo, } type State = { @@ -73,12 +69,9 @@ class FirmwareUpdate extends PureComponent { _unmounting = false fetchLatestFirmware = async () => { - const { infos } = this.props + const { deviceInfo } = this.props const latestFirmware = - CACHED_LATEST_FIRMWARE || - (await getLatestFirmwareForDevice - .send({ targetId: infos.targetId, version: infos.version }) - .toPromise()) + CACHED_LATEST_FIRMWARE || (await getLatestFirmwareForDevice.send(deviceInfo).toPromise()) if ( !isEmpty(latestFirmware) && !isEqual(this.state.latestFirmware, latestFirmware) && @@ -92,14 +85,14 @@ class FirmwareUpdate extends PureComponent { installFirmware = async () => { try { const { latestFirmware } = this.state - const { infos } = this.props + const { deviceInfo } = this.props invariant(latestFirmware, 'did not find a new firmware or firmware is not set') const { device: { path: devicePath }, } = this.props this.setState({ modal: 'installing' }) const { success } = await installOsuFirmware - .send({ devicePath, firmware: latestFirmware, targetId: infos.targetId }) + .send({ devicePath, firmware: latestFirmware, targetId: deviceInfo.targetId }) .toPromise() if (success) { this.fetchLatestFirmware() @@ -150,7 +143,7 @@ class FirmwareUpdate extends PureComponent { } render() { - const { infos, t } = this.props + const { deviceInfo, t } = this.props const { latestFirmware, modal } = this.state return ( @@ -170,7 +163,7 @@ class FirmwareUpdate extends PureComponent { {t('app:manager.firmware.installed', { - version: infos.version, + version: deviceInfo.fullVersion, })} diff --git a/src/components/Workflow/EnsureGenuine.js b/src/components/Workflow/EnsureGenuine.js index 2ebc5729..3be90a83 100644 --- a/src/components/Workflow/EnsureGenuine.js +++ b/src/components/Workflow/EnsureGenuine.js @@ -5,6 +5,7 @@ import isEqual from 'lodash/isEqual' import { GENUINE_TIMEOUT } from 'config/constants' import type { Device } from 'types/common' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import getIsGenuine from 'commands/getIsGenuine' @@ -13,15 +14,9 @@ type Error = { stack: string, } -type DeviceInfos = { - targetId: number | string, - seVersion: string, - providerName: string, -} - type Props = { device: ?Device, - infos: ?DeviceInfos, + deviceInfo: ?DeviceInfo, children: (isGenuine: ?boolean, error: ?Error) => *, } @@ -57,18 +52,14 @@ class EnsureGenuine extends PureComponent { _unmounting = false async checkIsGenuine() { - const { device, infos } = this.props - if (device && infos && !this._checking) { + const { device, deviceInfo } = this.props + if (device && deviceInfo && !this._checking) { this._checking = true try { - const versionName = `${infos.seVersion}${ - infos.providerName ? `-${infos.providerName}` : '' - }` const res = await getIsGenuine .send({ devicePath: device.path, - targetId: infos.targetId, - version: versionName, + deviceInfo, }) .pipe(timeout(GENUINE_TIMEOUT)) .toPromise() diff --git a/src/components/Workflow/index.js b/src/components/Workflow/index.js index 7c778f63..728ff9ec 100644 --- a/src/components/Workflow/index.js +++ b/src/components/Workflow/index.js @@ -58,7 +58,7 @@ class Workflow extends PureComponent { } return ( - + {(isGenuine: ?boolean, genuineError: ?Error) => { if (dashboardError || genuineError) { return renderError diff --git a/src/helpers/apps/listApps.js b/src/helpers/apps/listApps.js index 2e7449fe..46333447 100644 --- a/src/helpers/apps/listApps.js +++ b/src/helpers/apps/listApps.js @@ -5,11 +5,14 @@ import { APPLICATIONS_BY_DEVICE } from 'helpers/urls' import getDeviceVersion from 'helpers/devices/getDeviceVersion' import getCurrentFirmware from 'helpers/devices/getCurrentFirmware' -export default async (targetId: string | number, version: string) => { +export default async (targetId: string | number, fullVersion: string, provider: number) => { try { - const provider = 1 - const deviceData = await getDeviceVersion(targetId) - const firmwareData = await getCurrentFirmware({ deviceId: deviceData.id, version }) + const deviceData = await getDeviceVersion(targetId, provider) + const firmwareData = await getCurrentFirmware({ + deviceId: deviceData.id, + fullVersion, + provider, + }) const params = { provider, current_se_firmware_final_version: firmwareData.id, diff --git a/src/helpers/devices/getCurrentFirmware.js b/src/helpers/devices/getCurrentFirmware.js index d9f4c32f..1aa48a3f 100644 --- a/src/helpers/devices/getCurrentFirmware.js +++ b/src/helpers/devices/getCurrentFirmware.js @@ -4,21 +4,21 @@ import network from 'api/network' import { GET_CURRENT_FIRMWARE } from 'helpers/urls' type Input = { - version: string, + fullVersion: string, deviceId: string | number, + provider: number, } let error export default async (input: Input): Promise<*> => { try { - const provider = 1 const { data } = await network({ method: 'POST', url: GET_CURRENT_FIRMWARE, data: { device_version: input.deviceId, - version_name: input.version, - provider, + version_name: input.fullVersion, + provider: input.provider, }, }) return data diff --git a/src/helpers/devices/getDeviceInfo.js b/src/helpers/devices/getDeviceInfo.js index 34bf6fe6..1c4cce27 100644 --- a/src/helpers/devices/getDeviceInfo.js +++ b/src/helpers/devices/getDeviceInfo.js @@ -12,6 +12,8 @@ export type DeviceInfo = { mcuVersion: string, isOSU: boolean, providerName: string, + providerId: number, + fullVersion: string, } const DETECT_CLUBCOIN = [ @@ -164,6 +166,13 @@ const DETECT_CLUBCOIN = [ ], ] +const PROVIDERS = { + '': 1, + das: 2, + club: 3, + shitcoins: 4, +} + export default async (transport: Transport<*>): Promise => { const res = await getFirmwareInfo(transport) let { seVersion } = res @@ -181,9 +190,11 @@ export default async (transport: Transport<*>): Promise => { const parsedVersion = seVersion.match(/[0-9]+.[0-9]+(.[0-9]+)?(-[a-z]+)?(-osu)?/) || [] const isOSU = typeof parsedVersion[5] !== 'undefined' const providerName = parsedVersion[4] || '' + const providerId = PROVIDERS[providerName] const isBootloader = targetId === 0x01000001 const majMin = parsedVersion[1] const patch = parsedVersion[2] || '.0' + const fullVersion = `${seVersion}${providerName ? `-${providerName}` : ''}` return { targetId, seVersion: majMin + patch, @@ -191,6 +202,8 @@ export default async (transport: Transport<*>): Promise => { mcuVersion, isBootloader, providerName, + providerId, flags, + fullVersion, } } diff --git a/src/helpers/devices/getDeviceVersion.js b/src/helpers/devices/getDeviceVersion.js index a66a8421..698bc1fa 100644 --- a/src/helpers/devices/getDeviceVersion.js +++ b/src/helpers/devices/getDeviceVersion.js @@ -2,8 +2,7 @@ import { GET_DEVICE_VERSION } from 'helpers/urls' import network from 'api/network' -export default async (targetId: string | number): Promise<*> => { - const provider = 1 +export default async (targetId: string | number, provider: number): Promise<*> => { const { data } = await network({ method: 'POST', url: GET_DEVICE_VERSION, diff --git a/src/helpers/devices/getIsGenuine.js b/src/helpers/devices/getIsGenuine.js index 4fa98804..9ea7c56d 100644 --- a/src/helpers/devices/getIsGenuine.js +++ b/src/helpers/devices/getIsGenuine.js @@ -2,21 +2,21 @@ import type Transport from '@ledgerhq/hw-transport' import { SKIP_GENUINE } from 'config/constants' import { WS_GENUINE } from 'helpers/urls' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import { createDeviceSocket } from 'helpers/socket' import getCurrentFirmware from './getCurrentFirmware' import getDeviceVersion from './getDeviceVersion' -export default async ( - transport: Transport<*>, - app: { targetId: string | number, version: string }, -): Promise => { - const { targetId, version } = app - const device = await getDeviceVersion(app.targetId) - const firmware = await getCurrentFirmware({ deviceId: device.id, version }) +export default async (transport: Transport<*>, deviceInfo: DeviceInfo): Promise => { + const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) + const firmware = await getCurrentFirmware({ + deviceId: deviceVersion.id, + fullVersion: deviceInfo.fullVersion, + provider: deviceInfo.providerId, + }) const params = { - targetId, - version, + targetId: deviceInfo.targetId, perso: firmware.perso, } const url = WS_GENUINE(params) diff --git a/src/helpers/devices/getLatestFirmwareForDevice.js b/src/helpers/devices/getLatestFirmwareForDevice.js index 71fa3598..6a0a2624 100644 --- a/src/helpers/devices/getLatestFirmwareForDevice.js +++ b/src/helpers/devices/getLatestFirmwareForDevice.js @@ -1,24 +1,22 @@ // @flow import network from 'api/network' import { GET_LATEST_FIRMWARE } from 'helpers/urls' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import getCurrentFirmware from './getCurrentFirmware' import getDeviceVersion from './getDeviceVersion' -type Input = { - version: string, - targetId: string | number, -} - -export default async (input: Input) => { +export default async (deviceInfo: DeviceInfo) => { try { - const provider = 1 - const { targetId, version } = input // Get device infos from targetId - const deviceVersion = await getDeviceVersion(targetId) + const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) // Get firmware infos with firmware name and device version - const seFirmwareVersion = await getCurrentFirmware({ version, deviceId: deviceVersion.id }) + const seFirmwareVersion = await getCurrentFirmware({ + fullVersion: deviceInfo.fullVersion, + deviceId: deviceVersion.id, + provider: deviceInfo.providerId, + }) // Fetch next possible firmware const { data } = await network({ @@ -27,7 +25,7 @@ export default async (input: Input) => { data: { current_se_firmware_final_version: seFirmwareVersion.id, device_version: deviceVersion.id, - provider, + provider: deviceInfo.providerId, }, }) diff --git a/src/helpers/devices/isDashboardOpen.js b/src/helpers/devices/isDashboardOpen.js index 5f5cc619..e3663e5f 100644 --- a/src/helpers/devices/isDashboardOpen.js +++ b/src/helpers/devices/isDashboardOpen.js @@ -8,8 +8,8 @@ type Result = boolean export default async (transport: Transport<*>): Promise => { try { - const { targetId, version } = await getFirmwareInfo(transport) - if (targetId && version) { + const { targetId, seVersion } = await getFirmwareInfo(transport) + if (targetId && seVersion) { return true } diff --git a/src/helpers/urls.js b/src/helpers/urls.js index 4cc4b313..448eb7c3 100644 --- a/src/helpers/urls.js +++ b/src/helpers/urls.js @@ -23,7 +23,10 @@ export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmwar 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_GENUINE: (arg: { + targetId: string | number, + perso: string, +}) => string = wsURLBuilder('genuine') export const WS_MCU: (arg: { targetId: string | number, version: string }) => string = wsURLBuilder( 'mcu', ) From 0576e1ce8c5d6139c3c32667a62397ce55089e69 Mon Sep 17 00:00:00 2001 From: amougel Date: Fri, 22 Jun 2018 18:10:29 +0200 Subject: [PATCH 3/5] refactor firmware update --- src/commands/installFinalFirmware.js | 8 ++++---- src/components/ManagerPage/FirmwareFinalUpdate.js | 12 ++++-------- src/helpers/devices/getOsuFirmware.js | 2 +- src/helpers/firmware/installFinalFirmware.js | 14 +++++--------- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/commands/installFinalFirmware.js b/src/commands/installFinalFirmware.js index 921665ea..54fda5c5 100644 --- a/src/commands/installFinalFirmware.js +++ b/src/commands/installFinalFirmware.js @@ -3,13 +3,13 @@ import { createCommand, Command } from 'helpers/ipc' import { fromPromise } from 'rxjs/observable/fromPromise' import { withDevice } from 'helpers/deviceAccess' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import installFinalFirmware from 'helpers/firmware/installFinalFirmware' type Input = { devicePath: string, - targetId: string | number, - version: string, + deviceInfo: DeviceInfo, } type Result = { @@ -18,8 +18,8 @@ type Result = { const cmd: Command = createCommand( 'installFinalFirmware', - ({ devicePath, ...rest }) => - fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport, { ...rest }))), + ({ devicePath, deviceInfo }) => + fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport, deviceInfo))), ) export default cmd diff --git a/src/components/ManagerPage/FirmwareFinalUpdate.js b/src/components/ManagerPage/FirmwareFinalUpdate.js index 7fa1b702..f1498929 100644 --- a/src/components/ManagerPage/FirmwareFinalUpdate.js +++ b/src/components/ManagerPage/FirmwareFinalUpdate.js @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react' import { translate } from 'react-i18next' import logger from 'logger' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import type { Device, T } from 'types/common' @@ -11,15 +12,10 @@ import installFinalFirmware from 'commands/installFinalFirmware' import Box, { Card } from 'components/base/Box' // import Button from 'components/base/Button' -type DeviceInfos = { - targetId: number, - version: string, -} - type Props = { t: T, device: Device, - infos: DeviceInfos, + deviceInfo: DeviceInfo, } type State = {} @@ -35,9 +31,9 @@ class FirmwareFinalUpdate extends PureComponent { installFinalFirmware = async () => { try { - const { device, infos } = this.props + const { device, deviceInfo } = this.props const { success } = await installFinalFirmware - .send({ devicePath: device.path, targetId: infos.targetId, version: infos.version }) + .send({ devicePath: device.path, deviceInfo }) .toPromise() if (success) { this.setState() diff --git a/src/helpers/devices/getOsuFirmware.js b/src/helpers/devices/getOsuFirmware.js index eaf8344f..4cc666de 100644 --- a/src/helpers/devices/getOsuFirmware.js +++ b/src/helpers/devices/getOsuFirmware.js @@ -15,7 +15,7 @@ export default async (input: Input): Promise<*> => { url: GET_CURRENT_OSU, data: { device_version: input.deviceId, - version_name: input.version, + version_name: `${input.version}-osu`, provider, }, }) diff --git a/src/helpers/firmware/installFinalFirmware.js b/src/helpers/firmware/installFinalFirmware.js index f2c3c885..e4d5269b 100644 --- a/src/helpers/firmware/installFinalFirmware.js +++ b/src/helpers/firmware/installFinalFirmware.js @@ -1,5 +1,6 @@ // @flow import type Transport from '@ledgerhq/hw-transport' +import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import { WS_INSTALL } from 'helpers/urls' import { createDeviceSocket } from 'helpers/socket' @@ -7,22 +8,17 @@ import getDeviceVersion from 'helpers/devices/getDeviceVersion' import getOsuFirmware from 'helpers/devices/getOsuFirmware' import getFinalFirmwareById from './getFinalFirmwareById' -type Input = { - targetId: number | string, - version: string, -} type Result = * -export default async (transport: Transport<*>, app: Input): Result => { +export default async (transport: Transport<*>, deviceInfo: DeviceInfo): Result => { try { - const { targetId, version } = app - const device = await getDeviceVersion(targetId) - const firmware = await getOsuFirmware({ deviceId: device.id, version }) + const device = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) + const firmware = await getOsuFirmware({ deviceId: device.id, version: deviceInfo.fullVersion }) const { next_se_firmware_final_version } = firmware const nextFirmware = await getFinalFirmwareById(next_se_firmware_final_version) const params = { - targetId, + targetId: deviceInfo.targetId, ...nextFirmware, firmwareKey: nextFirmware.firmware_key, } From bdbc018e9b70c2d63784b48fc07fb7346c42de55 Mon Sep 17 00:00:00 2001 From: amougel Date: Mon, 25 Jun 2018 10:30:30 +0200 Subject: [PATCH 4/5] trimming mcu version --- src/helpers/common.js | 15 ++- src/helpers/devices/getDeviceInfo.js | 163 +++------------------------ 2 files changed, 26 insertions(+), 152 deletions(-) diff --git a/src/helpers/common.js b/src/helpers/common.js index a8e4bb13..34532418 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -30,21 +30,32 @@ export async function getFirmwareInfo(transport: Transport<*>) { const res = await transport.send(...APDUS.GET_FIRMWARE) const byteArray = [...res] const data = byteArray.slice(0, byteArray.length - 2) + console.log('data', data) const targetIdStr = Buffer.from(data.slice(0, 4)) const targetId = targetIdStr.readUIntBE(0, 4) + console.log(targetId) const seVersionLength = data[4] const seVersion = Buffer.from(data.slice(5, 5 + seVersionLength)).toString() + console.log('seversion', seVersion) const flagsLength = data[5 + seVersionLength] + console.log('flagel', flagsLength) const flags = Buffer.from( data.slice(5 + seVersionLength + 1, 5 + seVersionLength + 1 + flagsLength), ).toString() + console.log('flags', flags) + const mcuVersionLength = data[5 + seVersionLength + 1 + flagsLength] - const mcuVersion = Buffer.from( + let mcuVersion = Buffer.from( data.slice( 7 + seVersionLength + flagsLength, 7 + seVersionLength + flagsLength + mcuVersionLength, ), - ).toString() + ) + if (mcuVersion[mcuVersion.length - 1] === 0) { + mcuVersion = mcuVersion.slice(0, mcuVersion.length - 1) + } + mcuVersion = mcuVersion.toString() + console.log('mcu', mcuVersion) return { targetId, seVersion, flags, mcuVersion } } catch (err) { const error = new Error(err.message) diff --git a/src/helpers/devices/getDeviceInfo.js b/src/helpers/devices/getDeviceInfo.js index 1c4cce27..e033b6b9 100644 --- a/src/helpers/devices/getDeviceInfo.js +++ b/src/helpers/devices/getDeviceInfo.js @@ -16,154 +16,11 @@ export type DeviceInfo = { fullVersion: string, } +// prettier-ignore const DETECT_CLUBCOIN = [ [0xe0, 0x04, 0x00, 0x00, 0x04, 0x31, 0x10, 0x00, 0x02], [0xe0, 0x50, 0x00, 0x00, 0x08, 0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7], - [ - 0xe0, - 0x51, - 0x80, - 0x00, - 0x8a, - 0x41, - 0x04, - 0xc9, - 0x8c, - 0xa0, - 0x99, - 0x53, - 0x47, - 0x2b, - 0x36, - 0x06, - 0x1e, - 0x0e, - 0x40, - 0xc9, - 0x3d, - 0x50, - 0x52, - 0x34, - 0x09, - 0x0e, - 0xfd, - 0x74, - 0xf1, - 0xd7, - 0xa2, - 0x93, - 0xe8, - 0x28, - 0x15, - 0x9a, - 0x97, - 0x71, - 0x1b, - 0x33, - 0xd1, - 0x8a, - 0xfc, - 0x17, - 0xad, - 0x15, - 0x6e, - 0xae, - 0xd9, - 0x9c, - 0xf4, - 0x3b, - 0x20, - 0xe1, - 0x5d, - 0x64, - 0xaf, - 0x39, - 0xa5, - 0x51, - 0x3b, - 0x4e, - 0x3c, - 0x5f, - 0x43, - 0x17, - 0xe6, - 0x42, - 0x70, - 0x2f, - 0x05, - 0x47, - 0x30, - 0x45, - 0x02, - 0x21, - 0x00, - 0xf1, - 0xd2, - 0xb8, - 0x34, - 0x99, - 0x4a, - 0x0c, - 0x1f, - 0x25, - 0xea, - 0x20, - 0xcf, - 0x33, - 0xe3, - 0x2b, - 0xd0, - 0x6b, - 0xcf, - 0x7c, - 0x42, - 0x4a, - 0x02, - 0xee, - 0xe8, - 0xf6, - 0x96, - 0x99, - 0x20, - 0xe1, - 0xe8, - 0xc2, - 0xb3, - 0x02, - 0x20, - 0x63, - 0x2d, - 0x19, - 0xbd, - 0x30, - 0xab, - 0x20, - 0x76, - 0x18, - 0x78, - 0x78, - 0xae, - 0xaa, - 0x0f, - 0x4d, - 0x48, - 0x04, - 0x01, - 0x32, - 0x79, - 0xd0, - 0x16, - 0xde, - 0xca, - 0x66, - 0x93, - 0xf3, - 0x7b, - 0x4e, - 0x50, - 0x7f, - 0x43, - ], + [0xe0, 0x51, 0x80, 0x00, 0x8a, 0x41, 0x04, 0xc9, 0x8c, 0xa0, 0x99, 0x53, 0x47, 0x2b, 0x36, 0x06, 0x1e, 0x0e, 0x40, 0xc9, 0x3d, 0x50, 0x52, 0x34, 0x09, 0x0e, 0xfd, 0x74, 0xf1, 0xd7, 0xa2, 0x93, 0xe8, 0x28, 0x15, 0x9a, 0x97, 0x71, 0x1b, 0x33, 0xd1, 0x8a, 0xfc, 0x17, 0xad, 0x15, 0x6e, 0xae, 0xd9, 0x9c, 0xf4, 0x3b, 0x20, 0xe1, 0x5d, 0x64, 0xaf, 0x39, 0xa5, 0x51, 0x3b, 0x4e, 0x3c, 0x5f, 0x43, 0x17, 0xe6, 0x42, 0x70, 0x2f, 0x05, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xf1, 0xd2, 0xb8, 0x34, 0x99, 0x4a, 0x0c, 0x1f, 0x25, 0xea, 0x20, 0xcf, 0x33, 0xe3, 0x2b, 0xd0, 0x6b, 0xcf, 0x7c, 0x42, 0x4a, 0x02, 0xee, 0xe8, 0xf6, 0x96, 0x99, 0x20, 0xe1, 0xe8, 0xc2, 0xb3, 0x02, 0x20, 0x63, 0x2d, 0x19, 0xbd, 0x30, 0xab, 0x20, 0x76, 0x18, 0x78, 0x78, 0xae, 0xaa, 0x0f, 0x4d, 0x48, 0x04, 0x01, 0x32, 0x79, 0xd0, 0x16, 0xde, 0xca, 0x66, 0x93, 0xf3, 0x7b, 0x4e, 0x50, 0x7f, 0x43], ] const PROVIDERS = { @@ -179,22 +36,28 @@ export default async (transport: Transport<*>): Promise => { const { targetId, mcuVersion, flags } = res if (seVersion === '1.2') { try { - DETECT_CLUBCOIN.forEach(async apdus => { - await transport.send(...apdus) - }) + for (let i = 0; i < DETECT_CLUBCOIN.length; i++) { + const instructions = DETECT_CLUBCOIN[i] + console.log('i, dsfdf', i, instructions) + await transport.send(...instructions) // TODO type wrong + } + console.log('ici club') seVersion = '1.2.0-club' } catch (e) { + console.log('failed club', e) seVersion = '1.2.0' } } - const parsedVersion = seVersion.match(/[0-9]+.[0-9]+(.[0-9]+)?(-[a-z]+)?(-osu)?/) || [] + const parsedVersion = + seVersion.match(/([0-9]+.[0-9])+(.[0-9]+)?((?!-osu)-([a-z]+))?(-osu)?/) || [] + console.log('parsed', seVersion, parsedVersion) const isOSU = typeof parsedVersion[5] !== 'undefined' const providerName = parsedVersion[4] || '' const providerId = PROVIDERS[providerName] const isBootloader = targetId === 0x01000001 const majMin = parsedVersion[1] const patch = parsedVersion[2] || '.0' - const fullVersion = `${seVersion}${providerName ? `-${providerName}` : ''}` + const fullVersion = `${majMin}${patch}${providerName ? `-${providerName}` : ''}` return { targetId, seVersion: majMin + patch, From c89a1cd2feeb956c41ff9adc2ff1be941bf52074 Mon Sep 17 00:00:00 2001 From: amougel Date: Tue, 26 Jun 2018 10:57:12 +0200 Subject: [PATCH 5/5] fix apdus --- src/helpers/common.js | 6 ------ src/helpers/devices/getDeviceInfo.js | 14 ++++++-------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/helpers/common.js b/src/helpers/common.js index 34532418..0015c91d 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -30,19 +30,14 @@ export async function getFirmwareInfo(transport: Transport<*>) { const res = await transport.send(...APDUS.GET_FIRMWARE) const byteArray = [...res] const data = byteArray.slice(0, byteArray.length - 2) - console.log('data', data) const targetIdStr = Buffer.from(data.slice(0, 4)) const targetId = targetIdStr.readUIntBE(0, 4) - console.log(targetId) const seVersionLength = data[4] const seVersion = Buffer.from(data.slice(5, 5 + seVersionLength)).toString() - console.log('seversion', seVersion) const flagsLength = data[5 + seVersionLength] - console.log('flagel', flagsLength) const flags = Buffer.from( data.slice(5 + seVersionLength + 1, 5 + seVersionLength + 1 + flagsLength), ).toString() - console.log('flags', flags) const mcuVersionLength = data[5 + seVersionLength + 1 + flagsLength] let mcuVersion = Buffer.from( @@ -55,7 +50,6 @@ export async function getFirmwareInfo(transport: Transport<*>) { mcuVersion = mcuVersion.slice(0, mcuVersion.length - 1) } mcuVersion = mcuVersion.toString() - console.log('mcu', mcuVersion) return { targetId, seVersion, flags, mcuVersion } } catch (err) { const error = new Error(err.message) diff --git a/src/helpers/devices/getDeviceInfo.js b/src/helpers/devices/getDeviceInfo.js index e033b6b9..a87a2e7a 100644 --- a/src/helpers/devices/getDeviceInfo.js +++ b/src/helpers/devices/getDeviceInfo.js @@ -18,9 +18,9 @@ export type DeviceInfo = { // prettier-ignore const DETECT_CLUBCOIN = [ - [0xe0, 0x04, 0x00, 0x00, 0x04, 0x31, 0x10, 0x00, 0x02], - [0xe0, 0x50, 0x00, 0x00, 0x08, 0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7], - [0xe0, 0x51, 0x80, 0x00, 0x8a, 0x41, 0x04, 0xc9, 0x8c, 0xa0, 0x99, 0x53, 0x47, 0x2b, 0x36, 0x06, 0x1e, 0x0e, 0x40, 0xc9, 0x3d, 0x50, 0x52, 0x34, 0x09, 0x0e, 0xfd, 0x74, 0xf1, 0xd7, 0xa2, 0x93, 0xe8, 0x28, 0x15, 0x9a, 0x97, 0x71, 0x1b, 0x33, 0xd1, 0x8a, 0xfc, 0x17, 0xad, 0x15, 0x6e, 0xae, 0xd9, 0x9c, 0xf4, 0x3b, 0x20, 0xe1, 0x5d, 0x64, 0xaf, 0x39, 0xa5, 0x51, 0x3b, 0x4e, 0x3c, 0x5f, 0x43, 0x17, 0xe6, 0x42, 0x70, 0x2f, 0x05, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xf1, 0xd2, 0xb8, 0x34, 0x99, 0x4a, 0x0c, 0x1f, 0x25, 0xea, 0x20, 0xcf, 0x33, 0xe3, 0x2b, 0xd0, 0x6b, 0xcf, 0x7c, 0x42, 0x4a, 0x02, 0xee, 0xe8, 0xf6, 0x96, 0x99, 0x20, 0xe1, 0xe8, 0xc2, 0xb3, 0x02, 0x20, 0x63, 0x2d, 0x19, 0xbd, 0x30, 0xab, 0x20, 0x76, 0x18, 0x78, 0x78, 0xae, 0xaa, 0x0f, 0x4d, 0x48, 0x04, 0x01, 0x32, 0x79, 0xd0, 0x16, 0xde, 0xca, 0x66, 0x93, 0xf3, 0x7b, 0x4e, 0x50, 0x7f, 0x43], + [0xe0, 0x04, 0x00, 0x00, Buffer.from([0x31, 0x10, 0x00, 0x02])], + [0xe0, 0x50, 0x00, 0x00, Buffer.from([0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7])], + [0xe0, 0x51, 0x80, 0x00, Buffer.from([0x41, 0x04, 0xc9, 0x8c, 0xa0, 0x99, 0x53, 0x47, 0x2b, 0x36, 0x06, 0x1e, 0x0e, 0x40, 0xc9, 0x3d, 0x50, 0x52, 0x34, 0x09, 0x0e, 0xfd, 0x74, 0xf1, 0xd7, 0xa2, 0x93, 0xe8, 0x28, 0x15, 0x9a, 0x97, 0x71, 0x1b, 0x33, 0xd1, 0x8a, 0xfc, 0x17, 0xad, 0x15, 0x6e, 0xae, 0xd9, 0x9c, 0xf4, 0x3b, 0x20, 0xe1, 0x5d, 0x64, 0xaf, 0x39, 0xa5, 0x51, 0x3b, 0x4e, 0x3c, 0x5f, 0x43, 0x17, 0xe6, 0x42, 0x70, 0x2f, 0x05, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xf1, 0xd2, 0xb8, 0x34, 0x99, 0x4a, 0x0c, 0x1f, 0x25, 0xea, 0x20, 0xcf, 0x33, 0xe3, 0x2b, 0xd0, 0x6b, 0xcf, 0x7c, 0x42, 0x4a, 0x02, 0xee, 0xe8, 0xf6, 0x96, 0x99, 0x20, 0xe1, 0xe8, 0xc2, 0xb3, 0x02, 0x20, 0x63, 0x2d, 0x19, 0xbd, 0x30, 0xab, 0x20, 0x76, 0x18, 0x78, 0x78, 0xae, 0xaa, 0x0f, 0x4d, 0x48, 0x04, 0x01, 0x32, 0x79, 0xd0, 0x16, 0xde, 0xca, 0x66, 0x93, 0xf3, 0x7b, 0x4e, 0x50, 0x7f, 0x43])], ] const PROVIDERS = { @@ -34,23 +34,21 @@ export default async (transport: Transport<*>): Promise => { const res = await getFirmwareInfo(transport) let { seVersion } = res const { targetId, mcuVersion, flags } = res + console.log('raw seVersion', seVersion) if (seVersion === '1.2') { try { for (let i = 0; i < DETECT_CLUBCOIN.length; i++) { const instructions = DETECT_CLUBCOIN[i] - console.log('i, dsfdf', i, instructions) - await transport.send(...instructions) // TODO type wrong + await transport.send(...instructions) } - console.log('ici club') + console.log('club 1.2 detected') seVersion = '1.2.0-club' } catch (e) { - console.log('failed club', e) seVersion = '1.2.0' } } const parsedVersion = seVersion.match(/([0-9]+.[0-9])+(.[0-9]+)?((?!-osu)-([a-z]+))?(-osu)?/) || [] - console.log('parsed', seVersion, parsedVersion) const isOSU = typeof parsedVersion[5] !== 'undefined' const providerName = parsedVersion[4] || '' const providerId = PROVIDERS[providerName]