Browse Source

use errors from live-common

gre-patch-1
Gaëtan Renaudeau 6 years ago
parent
commit
71f0098572
No known key found for this signature in database GPG Key ID: 7B66B85F042E5451
  1. 1
      .flowconfig
  2. 2
      package.json
  3. 2
      src/api/Ethereum.js
  4. 2
      src/api/Fees.js
  5. 6
      src/api/network.js
  6. 2
      src/bridge/EthereumJSBridge.js
  7. 2
      src/bridge/LibcoreBridge.js
  8. 2
      src/bridge/RippleJSBridge.js
  9. 21
      src/commands/getAddress.js
  10. 2
      src/commands/libcoreGetFees.js
  11. 2
      src/commands/libcoreSignAndBroadcast.js
  12. 6
      src/components/EnsureDeviceApp.js
  13. 2
      src/components/FeesField/BitcoinKind.js
  14. 2
      src/components/FeesField/EthereumKind.js
  15. 2
      src/components/FeesField/RippleKind.js
  16. 6
      src/components/GenuineCheck.js
  17. 2
      src/components/IsUnlocked.js
  18. 2
      src/components/SettingsPage/DisablePasswordModal.js
  19. 2
      src/components/SettingsPage/PasswordForm.js
  20. 2
      src/components/SettingsPage/PasswordModal.js
  21. 2
      src/components/modals/AccountSettingRenderBody.js
  22. 19
      src/components/modals/Receive/steps/04-step-receive-funds.js
  23. 4
      src/components/modals/Send/fields/RecipientField.js
  24. 2
      src/components/modals/Send/index.js
  25. 53
      src/config/errors.js
  26. 2
      src/helpers/apps/installApp.js
  27. 2
      src/helpers/apps/uninstallApp.js
  28. 2
      src/helpers/db/index.js
  29. 96
      src/helpers/errors.js
  30. 2
      src/helpers/firmware/getNextMCU.js
  31. 2
      src/helpers/firmware/installFinalFirmware.js
  32. 2
      src/helpers/firmware/installMcu.js
  33. 2
      src/helpers/firmware/installOsuFirmware.js
  34. 44
      src/helpers/getAddressForCurrency/btc.js
  35. 18
      src/helpers/getAddressForCurrency/ethereum.js
  36. 32
      src/helpers/getAddressForCurrency/index.js
  37. 16
      src/helpers/getAddressForCurrency/ripple.js
  38. 2
      src/helpers/init-libcore.js
  39. 2
      src/helpers/ipc.js
  40. 4
      src/helpers/libcore.js
  41. 3
      src/helpers/live-common-setup-internal-hw.js
  42. 2
      src/helpers/promise.js
  43. 2
      src/helpers/reset.js
  44. 2
      src/helpers/socket.js
  45. 2
      src/internals/index.js
  46. 2
      src/main/bridge.js
  47. 8
      yarn.lock

1
.flowconfig

@ -5,6 +5,7 @@
[untyped]
.*/node_modules/react-select
<PROJECT_ROOT>/node_modules/qrloop/lib/Buffer.js*
[include]

2
package.json

@ -41,7 +41,7 @@
"@ledgerhq/hw-transport": "^4.32.0",
"@ledgerhq/hw-transport-node-hid": "^4.32.0",
"@ledgerhq/ledger-core": "2.0.0-rc.12",
"@ledgerhq/live-common": "4.8.0-beta.3",
"@ledgerhq/live-common": "4.8.0-beta.4",
"animated": "^0.2.2",
"async": "^2.6.1",
"axios": "^0.18.0",

2
src/api/Ethereum.js

@ -1,7 +1,7 @@
// @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import { BigNumber } from 'bignumber.js'
import { LedgerAPINotAvailable } from 'config/errors'
import { LedgerAPINotAvailable } from '@ledgerhq/live-common/lib/errors'
import network from './network'
import { blockchainBaseURL } from './Ledger'

2
src/api/Fees.js

@ -2,7 +2,7 @@
import invariant from 'invariant'
import LRU from 'lru-cache'
import type { Currency } from '@ledgerhq/live-common/lib/types'
import { FeeEstimationFailed } from 'config/errors'
import { FeeEstimationFailed } from '@ledgerhq/live-common/lib/errors'
import { blockchainBaseURL } from './Ledger'
import network from './network'

6
src/api/network.js

@ -3,7 +3,11 @@ import axios from 'axios'
import { GET_CALLS_RETRY, GET_CALLS_TIMEOUT } from 'config/constants'
import { retry } from 'helpers/promise'
import logger from 'logger'
import { LedgerAPIErrorWithMessage, LedgerAPIError, NetworkDown } from 'config/errors'
import {
LedgerAPIErrorWithMessage,
LedgerAPIError,
NetworkDown,
} from '@ledgerhq/live-common/lib/errors'
import anonymizer from 'helpers/anonymizer'
const userFriendlyError = <A>(p: Promise<A>, { url, method, startTime, ...rest }): Promise<A> =>

2
src/bridge/EthereumJSBridge.js

@ -25,7 +25,7 @@ import { apiForCurrency } from 'api/Ethereum'
import type { Tx } from 'api/Ethereum'
import getAddressCommand from 'commands/getAddress'
import signTransactionCommand from 'commands/signTransaction'
import { NotEnoughBalance, FeeNotLoaded, ETHAddressNonEIP } from 'config/errors'
import { NotEnoughBalance, FeeNotLoaded, ETHAddressNonEIP } from '@ledgerhq/live-common/lib/errors'
import type { EditProps, WalletBridge } from './types'
type Transaction = {

2
src/bridge/LibcoreBridge.js

@ -11,7 +11,7 @@ import libcoreSyncAccount from 'commands/libcoreSyncAccount'
import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import libcoreGetFees, { extractGetFeesInputFromAccount } from 'commands/libcoreGetFees'
import libcoreValidAddress from 'commands/libcoreValidAddress'
import { NotEnoughBalance, FeeNotLoaded } from 'config/errors'
import { NotEnoughBalance, FeeNotLoaded } from '@ledgerhq/live-common/lib/errors'
import type { WalletBridge, EditProps } from './types'
const NOT_ENOUGH_FUNDS = 52

2
src/bridge/RippleJSBridge.js

@ -32,7 +32,7 @@ import {
NotEnoughBalance,
FeeNotLoaded,
NotEnoughBalanceBecauseDestinationNotCreated,
} from 'config/errors'
} from '@ledgerhq/live-common/lib/errors'
import type { WalletBridge, EditProps } from './types'
type Transaction = {

21
src/commands/getAddress.js

@ -4,16 +4,13 @@ import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies'
import { createCommand, Command } from 'helpers/ipc'
import { from } from 'rxjs'
import { withDevice } from '@ledgerhq/live-common/lib/hw/deviceAccess'
import getAddressForCurrency from 'helpers/getAddressForCurrency'
import { DeviceAppVerifyNotSupported, UserRefusedAddress } from 'config/errors'
import getAddress from '@ledgerhq/live-common/lib/hw/getAddress'
type Input = {
currencyId: string,
devicePath: string,
path: string,
verify?: boolean,
segwit?: boolean,
}
type Result = {
@ -26,21 +23,7 @@ const cmd: Command<Input, Result> = createCommand(
'getAddress',
({ currencyId, devicePath, path, ...options }) =>
withDevice(devicePath)(transport =>
from(
getAddressForCurrency(transport, getCryptoCurrencyById(currencyId), path, options).catch(
e => {
if (e && e.name === 'TransportStatusError') {
if (e.statusCode === 0x6b00 && options.verify) {
throw new DeviceAppVerifyNotSupported()
}
if (e.statusCode === 0x6985) {
throw new UserRefusedAddress()
}
}
throw e
},
),
),
from(getAddress(transport, getCryptoCurrencyById(currencyId), path, options.verify)),
),
)

2
src/commands/libcoreGetFees.js

@ -13,7 +13,7 @@ import {
bigNumberToLibcoreAmount,
getOrCreateWallet,
} from 'helpers/libcore'
import { InvalidAddress } from 'config/errors'
import { InvalidAddress } from '@ledgerhq/live-common/lib/errors'
type BitcoinLikeTransaction = {
// TODO we rename this Transaction concept into transactionInput

2
src/commands/libcoreSignAndBroadcast.js

@ -14,7 +14,7 @@ import {
bigNumberToLibcoreAmount,
getOrCreateWallet,
} from 'helpers/libcore'
import { UpdateYourApp } from 'config/errors'
import { UpdateYourApp } from '@ledgerhq/live-common/lib/errors'
import withLibcore from 'helpers/withLibcore'
import { createCommand, Command } from 'helpers/ipc'

6
src/components/EnsureDeviceApp.js

@ -23,7 +23,11 @@ import IconUsb from 'icons/Usb'
import type { Device } from 'types/common'
import { WrongDeviceForAccount, CantOpenDevice, UpdateYourApp } from 'config/errors'
import {
WrongDeviceForAccount,
CantOpenDevice,
UpdateYourApp,
} from '@ledgerhq/live-common/lib/errors'
import { getCurrentDevice } from 'reducers/devices'
const usbIcon = <IconUsb size={16} />

2
src/components/FeesField/BitcoinKind.js

@ -8,7 +8,7 @@ import { translate } from 'react-i18next'
import type { T } from 'types/common'
import { FeeNotLoaded } from 'config/errors'
import { FeeNotLoaded } from '@ledgerhq/live-common/lib/errors'
import InputCurrency from 'components/base/InputCurrency'
import Select from 'components/base/Select'
import type { Fees } from 'api/Fees'

2
src/components/FeesField/EthereumKind.js

@ -4,7 +4,7 @@ import React, { Component } from 'react'
import { BigNumber } from 'bignumber.js'
import type { Account } from '@ledgerhq/live-common/lib/types'
import { FeeNotLoaded } from 'config/errors'
import { FeeNotLoaded } from '@ledgerhq/live-common/lib/errors'
import InputCurrency from 'components/base/InputCurrency'
import type { Fees } from 'api/Fees'
import WithFeesAPI from '../WithFeesAPI'

2
src/components/FeesField/RippleKind.js

@ -4,7 +4,7 @@ import React, { Component } from 'react'
import type { BigNumber } from 'bignumber.js'
import type { Account } from '@ledgerhq/live-common/lib/types'
import { apiForEndpointConfig, parseAPIValue } from 'api/Ripple'
import { FeeNotLoaded } from 'config/errors'
import { FeeNotLoaded } from '@ledgerhq/live-common/lib/errors'
import InputCurrency from 'components/base/InputCurrency'
import GenericContainer from './GenericContainer'

6
src/components/GenuineCheck.js

@ -14,7 +14,11 @@ import type { DeviceInfo } from 'helpers/types'
import { GENUINE_TIMEOUT, DEVICE_INFOS_TIMEOUT, GENUINE_CACHE_DELAY } from 'config/constants'
import { getCurrentDevice } from 'reducers/devices'
import { CantOpenDevice, DeviceNotGenuineError, DeviceGenuineSocketEarlyClose } from 'config/errors'
import {
CantOpenDevice,
DeviceNotGenuineError,
DeviceGenuineSocketEarlyClose,
} from '@ledgerhq/live-common/lib/errors'
import getDeviceInfo from 'commands/getDeviceInfo'
import getIsGenuine from 'commands/getIsGenuine'

2
src/components/IsUnlocked.js

@ -17,7 +17,7 @@ import { hardReset } from 'helpers/reset'
import { fetchAccounts } from 'actions/accounts'
import { isLocked, unlock } from 'reducers/application'
import { PasswordIncorrectError } from 'config/errors'
import { PasswordIncorrectError } from '@ledgerhq/live-common/lib/errors'
import Box from 'components/base/Box'
import InputPassword from 'components/base/InputPassword'

2
src/components/SettingsPage/DisablePasswordModal.js

@ -1,7 +1,7 @@
// @flow
import React, { PureComponent } from 'react'
import { PasswordIncorrectError } from 'config/errors'
import { PasswordIncorrectError } from '@ledgerhq/live-common/lib/errors'
import db from 'helpers/db'
import Box from 'components/base/Box'

2
src/components/SettingsPage/PasswordForm.js

@ -6,7 +6,7 @@ import Box from 'components/base/Box'
import InputPassword from 'components/base/InputPassword'
import Label from 'components/base/Label'
import { PasswordsDontMatchError } from 'config/errors'
import { PasswordsDontMatchError } from '@ledgerhq/live-common/lib/errors'
import type { T } from 'types/common'

2
src/components/SettingsPage/PasswordModal.js

@ -5,7 +5,7 @@ import React, { PureComponent } from 'react'
import type { T } from 'types/common'
import db from 'helpers/db'
import { PasswordIncorrectError } from 'config/errors'
import { PasswordIncorrectError } from '@ledgerhq/live-common/lib/errors'
import Box from 'components/base/Box'
import Button from 'components/base/Button'
import { Modal, ModalContent, ModalBody, ModalTitle, ModalFooter } from 'components/base/Modal'

2
src/components/modals/AccountSettingRenderBody.js

@ -17,7 +17,7 @@ import { setDataModal } from 'reducers/modals'
import { getBridgeForCurrency } from 'bridge'
import { AccountNameRequiredError, EnpointConfigError } from 'config/errors'
import { AccountNameRequiredError, EnpointConfigError } from '@ledgerhq/live-common/lib/errors'
import TrackPage from 'analytics/TrackPage'
import Spoiler from 'components/base/Spoiler'

19
src/components/modals/Receive/steps/04-step-receive-funds.js

@ -5,10 +5,9 @@ import React, { PureComponent } from 'react'
import TrackPage from 'analytics/TrackPage'
import getAddress from 'commands/getAddress'
import { isSegwitDerivationMode } from '@ledgerhq/live-common/lib/derivation'
import Box from 'components/base/Box'
import CurrentAddressForAccount from 'components/CurrentAddressForAccount'
import { DisconnectedDevice, WrongDeviceForAccount } from 'config/errors'
import { DisconnectedDevice, WrongDeviceForAccount } from '@ledgerhq/live-common/lib/errors'
import type { StepProps } from '..'
@ -25,14 +24,14 @@ export default class StepReceiveFunds extends PureComponent<StepProps> {
if (!device || !account) {
throw new DisconnectedDevice()
}
const params = {
currencyId: account.currency.id,
devicePath: device.path,
path: account.freshAddressPath,
segwit: isSegwitDerivationMode(account.derivationMode),
verify: true,
}
const { address } = await getAddress.send(params).toPromise()
const { address } = await getAddress
.send({
currencyId: account.currency.id,
devicePath: device.path,
path: account.freshAddressPath,
verify: true,
})
.toPromise()
if (address !== account.freshAddress) {
throw new WrongDeviceForAccount(`WrongDeviceForAccount ${account.name}`, {

4
src/components/modals/Send/fields/RecipientField.js

@ -9,8 +9,8 @@ import Box from 'components/base/Box'
import LabelWithExternalIcon from 'components/base/LabelWithExternalIcon'
import RecipientAddress from 'components/RecipientAddress'
import { track } from 'analytics/segment'
import { createCustomErrorClass } from 'helpers/errors'
import { CantScanQRCode } from 'config/errors'
import { createCustomErrorClass } from '@ledgerhq/live-common/lib/errors/helpers'
import { CantScanQRCode } from '@ledgerhq/live-common/lib/errors'
type Props<Transaction> = {
t: T,

2
src/components/modals/Send/index.js

@ -20,7 +20,7 @@ import type { StepProps as DefaultStepProps } from 'components/base/Stepper'
import { getCurrentDevice } from 'reducers/devices'
import { accountsSelector } from 'reducers/accounts'
import { closeModal, openModal } from 'reducers/modals'
import { DisconnectedDevice, UserRefusedOnDevice } from 'config/errors'
import { DisconnectedDevice, UserRefusedOnDevice } from '@ledgerhq/live-common/lib/errors'
import Modal from 'components/base/Modal'
import Stepper from 'components/base/Stepper'

53
src/config/errors.js

@ -1,53 +0,0 @@
// @flow
// TODO we need to start porting all custom errors here.
import { createCustomErrorClass } from 'helpers/errors'
export const AccountNameRequiredError = createCustomErrorClass('AccountNameRequired')
export const BtcUnmatchedApp = createCustomErrorClass('BtcUnmatchedApp')
export const CantOpenDevice = createCustomErrorClass('CantOpenDevice')
export const DeviceAppVerifyNotSupported = createCustomErrorClass('DeviceAppVerifyNotSupported')
export const DeviceGenuineSocketEarlyClose = createCustomErrorClass('DeviceGenuineSocketEarlyClose')
export const DeviceNotGenuineError = createCustomErrorClass('DeviceNotGenuine')
export const DeviceSocketFail = createCustomErrorClass('DeviceSocketFail')
export const DeviceSocketNoBulkStatus = createCustomErrorClass('DeviceSocketNoBulkStatus')
export const DeviceSocketNoHandler = createCustomErrorClass('DeviceSocketNoHandler')
export const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice')
export const EnpointConfigError = createCustomErrorClass('EnpointConfig')
export const FeeEstimationFailed = createCustomErrorClass('FeeEstimationFailed')
export const HardResetFail = createCustomErrorClass('HardResetFail')
export const InvalidAddress = createCustomErrorClass('InvalidAddress')
export const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError')
export const LedgerAPIError = createCustomErrorClass('LedgerAPIError')
export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage')
export const LedgerAPINotAvailable = createCustomErrorClass('LedgerAPINotAvailable')
export const ManagerAppAlreadyInstalledError = createCustomErrorClass('ManagerAppAlreadyInstalled')
export const ManagerAppRelyOnBTCError = createCustomErrorClass('ManagerAppRelyOnBTC')
export const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked')
export const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace')
export const ManagerUninstallBTCDep = createCustomErrorClass('ManagerUninstallBTCDep')
export const NetworkDown = createCustomErrorClass('NetworkDown')
export const NoAddressesFound = createCustomErrorClass('NoAddressesFound')
export const NotEnoughBalance = createCustomErrorClass('NotEnoughBalance')
export const NotEnoughBalanceBecauseDestinationNotCreated = createCustomErrorClass(
'NotEnoughBalanceBecauseDestinationNotCreated',
)
export const PasswordsDontMatchError = createCustomErrorClass('PasswordsDontMatch')
export const PasswordIncorrectError = createCustomErrorClass('PasswordIncorrect')
export const TimeoutTagged = createCustomErrorClass('TimeoutTagged')
export const UpdateYourApp = createCustomErrorClass('UpdateYourApp')
export const UserRefusedAddress = createCustomErrorClass('UserRefusedAddress')
export const UserRefusedFirmwareUpdate = createCustomErrorClass('UserRefusedFirmwareUpdate')
export const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice') // TODO rename because it's just for transaction refusal
export const WebsocketConnectionError = createCustomErrorClass('WebsocketConnectionError')
export const WebsocketConnectionFailed = createCustomErrorClass('WebsocketConnectionFailed')
export const WrongDeviceForAccount = createCustomErrorClass('WrongDeviceForAccount')
export const ETHAddressNonEIP = createCustomErrorClass('ETHAddressNonEIP')
export const CantScanQRCode = createCustomErrorClass('CantScanQRCode')
export const FeeNotLoaded = createCustomErrorClass('FeeNotLoaded')
// db stuff, no need to translate
export const NoDBPathGiven = createCustomErrorClass('NoDBPathGiven')
export const DBWrongPassword = createCustomErrorClass('DBWrongPassword')
export const DBNotReset = createCustomErrorClass('DBNotReset')

2
src/helpers/apps/installApp.js

@ -11,7 +11,7 @@ import {
ManagerDeviceLockedError,
ManagerAppAlreadyInstalledError,
ManagerAppRelyOnBTCError,
} from 'config/errors'
} from '@ledgerhq/live-common/lib/errors'
function remapError(promise) {
return promise.catch((e: Error) => {

2
src/helpers/apps/uninstallApp.js

@ -4,7 +4,7 @@ import type Transport from '@ledgerhq/hw-transport'
import { createDeviceSocket } from 'helpers/socket'
import type { ApplicationVersion } from 'helpers/types'
import { ManagerDeviceLockedError, ManagerUninstallBTCDep } from 'config/errors'
import { ManagerDeviceLockedError, ManagerUninstallBTCDep } from '@ledgerhq/live-common/lib/errors'
import { WS_INSTALL } from 'helpers/urls'
function remapError(promise) {

2
src/helpers/db/index.js

@ -11,7 +11,7 @@ import logger from 'logger'
import { fsReadFile, fsUnlink } from 'helpers/fs'
import { promisify, debounce } from 'helpers/promise'
import { NoDBPathGiven, DBWrongPassword } from 'config/errors'
import { NoDBPathGiven, DBWrongPassword } from '@ledgerhq/live-common/lib/errors'
type Transform = {
get: any => any,

96
src/helpers/errors.js

@ -1,96 +0,0 @@
// @flow
/* eslint-disable no-continue */
// TODO we need to centralize the error in one place. so all are recorded
const errorClasses = {}
export const createCustomErrorClass = (name: string): Class<any> => {
const C = function CustomError(message?: string, fields?: Object) {
Object.assign(this, fields)
this.name = name
this.message = message || name
this.stack = new Error().stack
}
// $FlowFixMe
C.prototype = new Error()
errorClasses[name] = C
// $FlowFixMe we can't easily type a subset of Error for now...
return C
}
// inspired from https://github.com/programble/errio/blob/master/index.js
export const deserializeError = (object: mixed): Error => {
if (typeof object === 'object' && object) {
try {
// $FlowFixMe FIXME HACK
const msg = JSON.parse(object.message)
if (msg.message && msg.name) {
object = msg
}
} catch (e) {
// nothing
}
const constructor =
object.name === 'Error'
? Error
: typeof object.name === 'string'
? errorClasses[object.name] || createCustomErrorClass(object.name)
: Error
const error = Object.create(constructor.prototype)
for (const prop in object) {
if (object.hasOwnProperty(prop)) {
error[prop] = object[prop]
}
}
if (!error.stack && Error.captureStackTrace) {
Error.captureStackTrace(error, deserializeError)
}
return error
}
return new Error(String(object))
}
// inspired from https://github.com/sindresorhus/serialize-error/blob/master/index.js
export const serializeError = (value: mixed) => {
if (!value) return value
if (typeof value === 'object') {
return destroyCircular(value, [])
}
if (typeof value === 'function') {
return `[Function: ${value.name || 'anonymous'}]`
}
return value
}
// https://www.npmjs.com/package/destroy-circular
function destroyCircular(from: Object, seen) {
const to = {}
seen.push(from)
for (const key of Object.keys(from)) {
const value = from[key]
if (typeof value === 'function') {
continue
}
if (!value || typeof value !== 'object') {
to[key] = value
continue
}
if (seen.indexOf(from[key]) === -1) {
to[key] = destroyCircular(from[key], seen.slice(0))
continue
}
to[key] = '[Circular]'
}
if (typeof from.name === 'string') {
to.name = from.name
}
if (typeof from.message === 'string') {
to.message = from.message
}
if (typeof from.stack === 'string') {
to.stack = from.stack
}
return to
}

2
src/helpers/firmware/getNextMCU.js

@ -3,7 +3,7 @@ import network from 'api/network'
import { GET_NEXT_MCU } from 'helpers/urls'
import type { OsuFirmware } from 'helpers/types'
import { LatestMCUInstalledError } from 'config/errors'
import { LatestMCUInstalledError } from '@ledgerhq/live-common/lib/errors'
type NetworkResponse = { data: OsuFirmware | 'default' }

2
src/helpers/firmware/installFinalFirmware.js

@ -7,7 +7,7 @@ import { createDeviceSocket } from 'helpers/socket'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getOsuFirmware from 'helpers/devices/getOsuFirmware'
import getDeviceInfo from 'helpers/devices/getDeviceInfo'
import { ManagerDeviceLockedError } from 'config/errors'
import { ManagerDeviceLockedError } from '@ledgerhq/live-common/lib/errors'
import getFinalFirmwareById from './getFinalFirmwareById'

2
src/helpers/firmware/installMcu.js

@ -5,7 +5,7 @@ import { WS_MCU } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket'
import getNextMCU from 'helpers/firmware/getNextMCU'
import getDeviceInfo from 'helpers/devices/getDeviceInfo'
import { ManagerDeviceLockedError } from 'config/errors'
import { ManagerDeviceLockedError } from '@ledgerhq/live-common/lib/errors'
import type { DeviceInfo } from 'helpers/types'

2
src/helpers/firmware/installOsuFirmware.js

@ -10,7 +10,7 @@ import {
ManagerNotEnoughSpaceError,
ManagerDeviceLockedError,
UserRefusedFirmwareUpdate,
} from 'config/errors'
} from '@ledgerhq/live-common/lib/errors'
function remapError(promise) {
return promise.catch((e: Error) => {

44
src/helpers/getAddressForCurrency/btc.js

@ -1,44 +0,0 @@
// @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import Btc from '@ledgerhq/hw-app-btc'
import type Transport from '@ledgerhq/hw-transport'
import { BtcUnmatchedApp, UpdateYourApp } from 'config/errors'
import getBitcoinLikeInfo from '../devices/getBitcoinLikeInfo'
const oldP2SH = {
digibyte: 5,
}
export default async (
transport: Transport<*>,
currency: CryptoCurrency,
path: string,
{
segwit = true,
verify = false,
}: {
segwit?: boolean,
verify?: boolean,
},
) => {
const btc = new Btc(transport)
const { bitcoinAddress, publicKey } = await btc.getWalletPublicKey(path, verify, segwit)
const { bitcoinLikeInfo } = currency
if (bitcoinLikeInfo) {
const { P2SH, P2PKH } = await getBitcoinLikeInfo(transport)
if (P2SH !== bitcoinLikeInfo.P2SH || P2PKH !== bitcoinLikeInfo.P2PKH) {
if (
currency.id in oldP2SH &&
P2SH === oldP2SH[currency.id] &&
P2PKH === bitcoinLikeInfo.P2PKH
) {
throw new UpdateYourApp(`UpdateYourApp ${currency.id}`, currency)
}
throw new BtcUnmatchedApp(`BtcUnmatchedApp ${currency.id}`, currency)
}
}
return { address: bitcoinAddress, path, publicKey }
}

18
src/helpers/getAddressForCurrency/ethereum.js

@ -1,18 +0,0 @@
// @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import Eth from '@ledgerhq/hw-app-eth'
import type Transport from '@ledgerhq/hw-transport'
import eip55 from 'eip55'
export default async (
transport: Transport<*>,
currency: CryptoCurrency,
path: string,
{ verify = false }: *,
) => {
const eth = new Eth(transport)
const r = await eth.getAddress(path, verify)
const address = eip55.encode(r.address)
return { path, address, publicKey: r.publicKey }
}

32
src/helpers/getAddressForCurrency/index.js

@ -1,32 +0,0 @@
// @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import invariant from 'invariant'
import type Transport from '@ledgerhq/hw-transport'
import bitcoin from './btc'
import ethereum from './ethereum'
import ripple from './ripple'
type Resolver = (
transport: Transport<*>,
currency: CryptoCurrency,
path: string,
options: {
segwit?: boolean,
verify?: boolean,
},
) => Promise<{ address: string, path: string, publicKey: string }>
const perFamily: { [_: string]: Resolver } = {
bitcoin,
ethereum,
ripple,
}
const proxy: Resolver = (transport, currency, path, options) => {
const getAddress = perFamily[currency.family]
invariant(getAddress, `getAddress not implemented for ${currency.id}`)
return getAddress(transport, currency, path, options)
}
export default proxy

16
src/helpers/getAddressForCurrency/ripple.js

@ -1,16 +0,0 @@
// @flow
import Xrp from '@ledgerhq/hw-app-xrp'
import type Transport from '@ledgerhq/hw-transport'
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
export default async (
transport: Transport<*>,
currency: CryptoCurrency,
path: string,
{ verify = false }: *,
) => {
const xrp = new Xrp(transport)
const { address, publicKey } = await xrp.getAddress(path, verify)
return { path, address, publicKey }
}

2
src/helpers/init-libcore.js

@ -3,7 +3,7 @@
import logger from 'logger'
import invariant from 'invariant'
import network from 'api/network'
import { serializeError } from './errors'
import { serializeError } from '@ledgerhq/live-common/lib/errors/helpers'
const lib = require('@ledgerhq/ledger-core')

2
src/helpers/ipc.js

@ -2,7 +2,7 @@
import logger from 'logger'
import { Observable } from 'rxjs'
import uuidv4 from 'uuid/v4'
import { deserializeError } from './errors'
import { deserializeError } from '@ledgerhq/live-common/lib/errors/helpers'
export function createCommand<In, A>(id: string, impl: In => Observable<A>): Command<In, A> {
return new Command(id, impl)

4
src/helpers/libcore.js

@ -32,8 +32,8 @@ import type {
} from '@ledgerhq/live-common/lib/types'
import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc'
import { NoAddressesFound } from 'config/errors'
import { deserializeError } from './errors'
import { NoAddressesFound } from '@ledgerhq/live-common/lib/errors'
import { deserializeError } from '@ledgerhq/live-common/lib/errors/helpers'
import { timeoutTagged } from './promise'
export function isValidAddress(core: *, currency: *, address: string): boolean {

3
src/helpers/live-common-setup-internal-hw.js

@ -4,9 +4,8 @@ import { throwError } from 'rxjs'
import { registerTransportModule } from '@ledgerhq/live-common/lib/hw'
import { addAccessHook, setErrorRemapping } from '@ledgerhq/live-common/lib/hw/deviceAccess'
import throttle from 'lodash/throttle'
import type Transport from '@ledgerhq/hw-transport'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { DisconnectedDevice, CantOpenDevice } from 'config/errors'
import { DisconnectedDevice } from '@ledgerhq/live-common/lib/errors'
import { retry } from './promise'
let busy = false

2
src/helpers/promise.js

@ -2,7 +2,7 @@
// small utilities for Promises
import logger from 'logger'
import { TimeoutTagged } from 'config/errors'
import { TimeoutTagged } from '@ledgerhq/live-common/lib/errors'
export const delay = (ms: number): Promise<void> => new Promise(f => setTimeout(f, ms))

2
src/helpers/reset.js

@ -9,7 +9,7 @@ import { disable as disableDBMiddleware } from 'middlewares/db'
import db from 'helpers/db'
import { delay } from 'helpers/promise'
import killInternalProcess from 'commands/killInternalProcess'
import { DBNotReset } from 'config/errors'
import { DBNotReset } from '@ledgerhq/live-common/lib/errors'
async function resetLibcoreDatabase() {
await killInternalProcess.send().toPromise()

2
src/helpers/socket.js

@ -11,7 +11,7 @@ import {
DeviceSocketFail,
DeviceSocketNoBulkStatus,
DeviceSocketNoHandler,
} from 'config/errors'
} from '@ledgerhq/live-common/lib/errors'
/**
* use Ledger WebSocket API to exchange data with the device

2
src/internals/index.js

@ -10,7 +10,7 @@ import uuid from 'uuid/v4'
import { setImplementation } from 'api/network'
import sentry from 'sentry/node'
import { EXPERIMENTAL_HTTP_ON_RENDERER } from 'config/constants'
import { serializeError } from 'helpers/errors'
import { serializeError } from '@ledgerhq/live-common/lib/errors/helpers'
require('../env')

2
src/main/bridge.js

@ -11,7 +11,7 @@ import LoggerTransport from 'logger/logger-transport-main'
import sentry, { captureException } from 'sentry/node'
import user from 'helpers/user'
import { cleanUpBeforeClosingSync } from 'helpers/log'
import { deserializeError } from 'helpers/errors'
import { deserializeError } from '@ledgerhq/live-common/lib/errors/helpers'
import setupAutoUpdater, { quitAndInstall } from './autoUpdate'
import { setInternalProcessPID } from './terminator'

8
yarn.lock

@ -1759,10 +1759,10 @@
bindings "^1.3.0"
nan "^2.6.2"
"@ledgerhq/live-common@4.8.0-beta.3":
version "4.8.0-beta.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.8.0-beta.3.tgz#eca9a9cb55f28523696fb76c7682a8705c1fb123"
integrity sha512-GBi4V0eeu9WQA2eFK0RwTrSI9r6ZWPjkU2d9pTptVCNlHUAOl/9aFZdc2nDVWobfbNFCchWwA636XJj80bF6ZA==
"@ledgerhq/live-common@4.8.0-beta.4":
version "4.8.0-beta.4"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.8.0-beta.4.tgz#291641f42a5cac8c26cf3baf0c303542509df86c"
integrity sha512-xmNLrljtCPSDJDiJndIlSX+wsgVQBNEZH25c+Dz3/uaZVtOVldE4iav7r7qKkGVNoUwvEhoqSAcjSuqKEFiBhg==
dependencies:
"@aeternity/ledger-app-api" "0.0.4"
"@ledgerhq/hw-app-btc" "^4.32.0"

Loading…
Cancel
Save