From b400ba7264933b59a25fd8ca53d48a5ddec15269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 25 Oct 2018 15:59:15 +0200 Subject: [PATCH] add new derivations & isIterable system --- package.json | 4 ++-- src/bridge/EthereumJSBridge.js | 4 +++- src/bridge/RippleJSBridge.js | 4 +++- src/commands/libcoreGetFees.js | 4 ++-- src/commands/libcoreScanFromXPUB.js | 4 ++-- src/commands/libcoreSignAndBroadcast.js | 8 +++---- src/commands/libcoreSyncAccount.js | 4 ++-- .../AddAccounts/steps/03-step-import.js | 4 +++- src/helpers/countervalues.js | 2 ++ src/helpers/libcore.js | 20 +++++++++------- yarn.lock | 24 ++++++++++++++----- 11 files changed, 52 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 9fd9547f..0e7fb9f4 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,11 @@ "dependencies": { "@ledgerhq/hw-app-btc": "4.24.0", "@ledgerhq/hw-app-eth": "^4.24.0", - "@ledgerhq/hw-app-xrp": "^4.24.0", + "@ledgerhq/hw-app-xrp": "^4.25.0", "@ledgerhq/hw-transport": "^4.24.0", "@ledgerhq/hw-transport-node-hid": "4.24.0", "@ledgerhq/ledger-core": "2.0.0-rc.8", - "@ledgerhq/live-common": "4.0.0-beta.1", + "@ledgerhq/live-common": "4.1.3", "animated": "^0.2.2", "async": "^2.6.1", "axios": "^0.18.0", diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index 9713910c..e7ecd750 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -12,6 +12,7 @@ import { getDerivationModesForCurrency, getDerivationScheme, runDerivationScheme, + isIterableDerivationMode, getMandatoryEmptyAccountSkip, } from '@ledgerhq/live-common/lib/derivation' import { @@ -304,7 +305,8 @@ const EthereumBridge: WalletBridge = { let emptyCount = 0 const mandatoryEmptyAccountSkip = getMandatoryEmptyAccountSkip(derivationMode) const derivationScheme = getDerivationScheme({ derivationMode, currency }) - for (let index = 0; index < 255; index++) { + const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1 + for (let index = 0; index < stopAt; index++) { const freshAddressPath = runDerivationScheme(derivationScheme, currency, { account: index, }) diff --git a/src/bridge/RippleJSBridge.js b/src/bridge/RippleJSBridge.js index 31744b63..3204cd39 100644 --- a/src/bridge/RippleJSBridge.js +++ b/src/bridge/RippleJSBridge.js @@ -11,6 +11,7 @@ import { getDerivationModesForCurrency, getDerivationScheme, runDerivationScheme, + isIterableDerivationMode, } from '@ledgerhq/live-common/lib/derivation' import { getAccountPlaceholderName, @@ -299,7 +300,8 @@ const RippleJSBridge: WalletBridge = { const derivationModes = getDerivationModesForCurrency(currency) for (const derivationMode of derivationModes) { const derivationScheme = getDerivationScheme({ derivationMode, currency }) - for (let index = 0; index < 255; index++) { + const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1 + for (let index = 0; index < stopAt; index++) { const freshAddressPath = runDerivationScheme(derivationScheme, currency, { account: index, }) diff --git a/src/commands/libcoreGetFees.js b/src/commands/libcoreGetFees.js index ef66bcb2..c3eb9f7d 100644 --- a/src/commands/libcoreGetFees.js +++ b/src/commands/libcoreGetFees.js @@ -6,7 +6,7 @@ import withLibcore from 'helpers/withLibcore' import { createCommand, Command } from 'helpers/ipc' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { getWalletName } from '@ledgerhq/live-common/lib/account' -import type { Account } from '@ledgerhq/live-common/lib/types' +import type { Account, DerivationMode } from '@ledgerhq/live-common/lib/types' import { isValidAddress, libcoreAmountToBigNumber, @@ -26,7 +26,7 @@ type Input = { accountIndex: number, transaction: BitcoinLikeTransaction, currencyId: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, } diff --git a/src/commands/libcoreScanFromXPUB.js b/src/commands/libcoreScanFromXPUB.js index 0444f501..998e5c98 100644 --- a/src/commands/libcoreScanFromXPUB.js +++ b/src/commands/libcoreScanFromXPUB.js @@ -1,7 +1,7 @@ // @flow import { fromPromise } from 'rxjs/observable/fromPromise' -import type { AccountRaw } from '@ledgerhq/live-common/lib/types' +import type { AccountRaw, DerivationMode } from '@ledgerhq/live-common/lib/types' import { createCommand, Command } from 'helpers/ipc' import withLibcore from 'helpers/withLibcore' @@ -10,7 +10,7 @@ import { scanAccountsFromXPUB } from 'helpers/libcore' type Input = { currencyId: string, xpub: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, } diff --git a/src/commands/libcoreSignAndBroadcast.js b/src/commands/libcoreSignAndBroadcast.js index 98cd8ff5..e4a183da 100644 --- a/src/commands/libcoreSignAndBroadcast.js +++ b/src/commands/libcoreSignAndBroadcast.js @@ -6,7 +6,7 @@ import Btc from '@ledgerhq/hw-app-btc' import { Observable } from 'rxjs' import { isSegwitDerivationMode } from '@ledgerhq/live-common/lib/derivation' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' -import type { OperationRaw, CryptoCurrency } from '@ledgerhq/live-common/lib/types' +import type { OperationRaw, DerivationMode, CryptoCurrency } from '@ledgerhq/live-common/lib/types' import { getWalletName } from '@ledgerhq/live-common/lib/account' import { libcoreAmountToBigNumber, @@ -27,7 +27,7 @@ type BitcoinLikeTransaction = { type Input = { accountId: string, currencyId: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, xpub: string, index: number, @@ -87,7 +87,7 @@ async function signTransaction({ hwApp: Btc, currency: CryptoCurrency, transaction: *, - derivationMode: string, + derivationMode: DerivationMode, sigHashType: number, hasTimestamp: boolean, }) { @@ -178,7 +178,7 @@ export async function doSignAndBroadcast({ onOperationBroadcasted, }: { accountId: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, currency: CryptoCurrency, xpub: string, diff --git a/src/commands/libcoreSyncAccount.js b/src/commands/libcoreSyncAccount.js index 802428fa..e274ce62 100644 --- a/src/commands/libcoreSyncAccount.js +++ b/src/commands/libcoreSyncAccount.js @@ -1,6 +1,6 @@ // @flow -import type { AccountRaw } from '@ledgerhq/live-common/lib/types' +import type { AccountRaw, DerivationMode } from '@ledgerhq/live-common/lib/types' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { fromPromise } from 'rxjs/observable/fromPromise' @@ -12,7 +12,7 @@ type Input = { accountId: string, currencyId: string, xpub: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, index: number, } diff --git a/src/components/modals/AddAccounts/steps/03-step-import.js b/src/components/modals/AddAccounts/steps/03-step-import.js index 4d2ef811..227e5f00 100644 --- a/src/components/modals/AddAccounts/steps/03-step-import.js +++ b/src/components/modals/AddAccounts/steps/03-step-import.js @@ -144,7 +144,9 @@ class StepImport extends PureComponent { }) } }, - complete: () => setScanStatus('finished'), + complete: () => { + setScanStatus('finished') + }, error: err => { logger.critical(err) setScanStatus('error', err) diff --git a/src/helpers/countervalues.js b/src/helpers/countervalues.js index fd5fc37e..7ec06d56 100644 --- a/src/helpers/countervalues.js +++ b/src/helpers/countervalues.js @@ -14,6 +14,7 @@ import { import logger from 'logger' import { listCryptoCurrencies } from '@ledgerhq/live-common/lib/currencies' import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' +import network from '../api/network' const pairsSelector = createSelector( currenciesSelector, @@ -62,6 +63,7 @@ const CounterValues = createCounterValues({ pairsSelector, setExchangePairsAction, addExtraPollingHooks, + network, }) let sortCache diff --git a/src/helpers/libcore.js b/src/helpers/libcore.js index 93467443..a27e3550 100644 --- a/src/helpers/libcore.js +++ b/src/helpers/libcore.js @@ -11,6 +11,7 @@ import { getDerivationScheme, isSegwitDerivationMode, isUnsplitDerivationMode, + isIterableDerivationMode, } from '@ledgerhq/live-common/lib/derivation' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { @@ -26,6 +27,7 @@ import type { AccountRaw, OperationRaw, OperationType, + DerivationMode, } from '@ledgerhq/live-common/lib/types' import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc' @@ -89,7 +91,7 @@ async function scanAccountsOnDeviceBySegwit({ currency: CryptoCurrency, onAccountScanned: AccountRaw => void, isUnsubscribed: () => boolean, - derivationMode: string, + derivationMode: DerivationMode, showNewAccount: boolean, }): Promise { const isSegwit = isSegwitDerivationMode(derivationMode) @@ -201,7 +203,7 @@ async function scanNextAccount(props: { devicePath: string, currency: CryptoCurrency, seedIdentifier: string, - derivationMode: string, + derivationMode: DerivationMode, accountsCount: number, accountIndex: number, accounts: AccountRaw[], @@ -259,15 +261,15 @@ async function scanNextAccount(props: { if (isUnsubscribed()) return [] - const isEmpty = ops.length === 0 + const isLast = ops.length === 0 || !isIterableDerivationMode(derivationMode) - if (!isEmpty || showNewAccount) { + if (!isLast || showNewAccount) { onAccountScanned(account) accounts.push(account) } // returns if the current index points on an account with no ops - if (isEmpty) { + if (isLast) { return accounts } @@ -292,7 +294,7 @@ export async function getOrCreateWallet( derivationMode, }: { currency: CryptoCurrency, - derivationMode: string, + derivationMode: DerivationMode, }, ): NJSWallet { const pool = core.getPoolInstance() @@ -335,7 +337,7 @@ async function buildAccountRaw({ seedIdentifier: string, walletName: string, currency: CryptoCurrency, - derivationMode: string, + derivationMode: DerivationMode, accountIndex: number, core: *, ops: NJSOperation[], @@ -475,7 +477,7 @@ export async function syncAccount({ }: { core: *, xpub: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, currency: CryptoCurrency, index: number, @@ -551,7 +553,7 @@ export async function scanAccountsFromXPUB({ core: *, currencyId: string, xpub: string, - derivationMode: string, + derivationMode: DerivationMode, seedIdentifier: string, }) { const currency = getCryptoCurrencyById(currencyId) diff --git a/yarn.lock b/yarn.lock index e076ec19..465af28a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1670,7 +1670,7 @@ camelcase "^5.0.0" prettier "^1.13.7" -"@ledgerhq/hw-app-btc@4.24.0": +"@ledgerhq/hw-app-btc@4.24.0", "@ledgerhq/hw-app-btc@^4.24.0": version "4.24.0" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-btc/-/hw-app-btc-4.24.0.tgz#8889b2bc9b9583209ed24f832c96ea8d23e1dc74" integrity sha512-OEc8UCcdAWp10PPM9Keoh8imuusmNVe2o/89ujMT5UIWOGCu7duezpsnCY11jGNxf2hyos6lezUMlUAOHBuISQ== @@ -1701,6 +1701,14 @@ "@ledgerhq/hw-transport" "^4.24.0" bip32-path "0.4.2" +"@ledgerhq/hw-app-xrp@^4.25.0": + version "4.25.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-xrp/-/hw-app-xrp-4.25.0.tgz#d97d7e85290dd2d1ec99f85747a26145e7a7383e" + integrity sha512-kG9S8CxUFMG1hbLBiKtoPMquzlTigndDsxhoXB8oywAdbGsoCi2cufMHV2p5Bek6YlGfn5J5p49Hx5iNIf2y5Q== + dependencies: + "@ledgerhq/hw-transport" "^4.24.0" + bip32-path "0.4.2" + "@ledgerhq/hw-transport-node-hid@4.24.0": version "4.24.0" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid/-/hw-transport-node-hid-4.24.0.tgz#8457969d66819e8f7f50d5dd96527ab26cd3787d" @@ -1745,13 +1753,17 @@ bindings "^1.3.0" nan "^2.6.2" -"@ledgerhq/live-common@4.0.0-beta.1": - version "4.0.0-beta.1" - resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.0.0-beta.1.tgz#52ed90757761a08a5f5c9c40c1fed0cb2f1fb4ca" - integrity sha512-Ms06Za/EI8yP/4GOAziCMecqIssZbkS5tjSCgaqd1h0zHLzM6i6PvgjhJyvG5SrET6+uQVp4YM4qbo2tc6irjQ== +"@ledgerhq/live-common@4.1.3": + version "4.1.3" + resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.1.3.tgz#dbd5be04925b11b4bf646520fe01a8959554c561" + integrity sha512-4FZ6th8ZtpC0B20olsyqF9hb0VUhVkLeiO/QyWzKa+bdn7jt4PgOyUdaKbRuoW2w9UKj2qkXgIgBIaZ+l0AlJA== dependencies: - axios "^0.18.0" + "@ledgerhq/hw-app-btc" "^4.24.0" + "@ledgerhq/hw-app-eth" "^4.24.0" + "@ledgerhq/hw-app-xrp" "^4.24.0" + "@ledgerhq/hw-transport" "^4.24.0" bignumber.js "^7.2.1" + eip55 "^1.0.3" invariant "^2.2.2" lodash "^4.17.4" node-lzw "^0.3.1"