Browse Source

Merge pull request #1599 from gre/new-derivations

add new derivations & isIterable system
gre-patch-1
Gaëtan Renaudeau 6 years ago
committed by GitHub
parent
commit
240dfab3f9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      package.json
  2. 4
      src/bridge/EthereumJSBridge.js
  3. 4
      src/bridge/RippleJSBridge.js
  4. 4
      src/commands/libcoreGetFees.js
  5. 4
      src/commands/libcoreScanFromXPUB.js
  6. 8
      src/commands/libcoreSignAndBroadcast.js
  7. 4
      src/commands/libcoreSyncAccount.js
  8. 4
      src/components/DevToolsPage/AccountImporter.js
  9. 2
      src/helpers/countervalues.js
  10. 20
      src/helpers/libcore.js
  11. 32
      yarn.lock

6
package.json

@ -37,11 +37,11 @@
"dependencies": { "dependencies": {
"@ledgerhq/hw-app-btc": "^4.27.0", "@ledgerhq/hw-app-btc": "^4.27.0",
"@ledgerhq/hw-app-eth": "^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": "^4.24.0",
"@ledgerhq/hw-transport-node-hid": "4.24.0", "@ledgerhq/hw-transport-node-hid": "4.24.0",
"@ledgerhq/ledger-core": "2.0.0-rc.10", "@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", "animated": "^0.2.2",
"async": "^2.6.1", "async": "^2.6.1",
"axios": "^0.18.0", "axios": "^0.18.0",

4
src/bridge/EthereumJSBridge.js

@ -12,6 +12,7 @@ import {
getDerivationModesForCurrency, getDerivationModesForCurrency,
getDerivationScheme, getDerivationScheme,
runDerivationScheme, runDerivationScheme,
isIterableDerivationMode,
getMandatoryEmptyAccountSkip, getMandatoryEmptyAccountSkip,
} from '@ledgerhq/live-common/lib/derivation' } from '@ledgerhq/live-common/lib/derivation'
import { import {
@ -304,7 +305,8 @@ const EthereumBridge: WalletBridge<Transaction> = {
let emptyCount = 0 let emptyCount = 0
const mandatoryEmptyAccountSkip = getMandatoryEmptyAccountSkip(derivationMode) const mandatoryEmptyAccountSkip = getMandatoryEmptyAccountSkip(derivationMode)
const derivationScheme = getDerivationScheme({ derivationMode, currency }) 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, { const freshAddressPath = runDerivationScheme(derivationScheme, currency, {
account: index, account: index,
}) })

4
src/bridge/RippleJSBridge.js

@ -11,6 +11,7 @@ import {
getDerivationModesForCurrency, getDerivationModesForCurrency,
getDerivationScheme, getDerivationScheme,
runDerivationScheme, runDerivationScheme,
isIterableDerivationMode,
} from '@ledgerhq/live-common/lib/derivation' } from '@ledgerhq/live-common/lib/derivation'
import { import {
getAccountPlaceholderName, getAccountPlaceholderName,
@ -299,7 +300,8 @@ const RippleJSBridge: WalletBridge<Transaction> = {
const derivationModes = getDerivationModesForCurrency(currency) const derivationModes = getDerivationModesForCurrency(currency)
for (const derivationMode of derivationModes) { for (const derivationMode of derivationModes) {
const derivationScheme = getDerivationScheme({ derivationMode, currency }) 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, { const freshAddressPath = runDerivationScheme(derivationScheme, currency, {
account: index, account: index,
}) })

4
src/commands/libcoreGetFees.js

@ -6,7 +6,7 @@ import withLibcore from 'helpers/withLibcore'
import { createCommand, Command } from 'helpers/ipc' import { createCommand, Command } from 'helpers/ipc'
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies'
import { getWalletName } from '@ledgerhq/live-common/lib/account' 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 { import {
isValidAddress, isValidAddress,
libcoreAmountToBigNumber, libcoreAmountToBigNumber,
@ -26,7 +26,7 @@ type Input = {
accountIndex: number, accountIndex: number,
transaction: BitcoinLikeTransaction, transaction: BitcoinLikeTransaction,
currencyId: string, currencyId: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
} }

4
src/commands/libcoreScanFromXPUB.js

@ -1,7 +1,7 @@
// @flow // @flow
import { fromPromise } from 'rxjs/observable/fromPromise' 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 { createCommand, Command } from 'helpers/ipc'
import withLibcore from 'helpers/withLibcore' import withLibcore from 'helpers/withLibcore'
@ -10,7 +10,7 @@ import { scanAccountsFromXPUB } from 'helpers/libcore'
type Input = { type Input = {
currencyId: string, currencyId: string,
xpub: string, xpub: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
} }

8
src/commands/libcoreSignAndBroadcast.js

@ -7,7 +7,7 @@ import Btc from '@ledgerhq/hw-app-btc'
import { Observable } from 'rxjs' import { Observable } from 'rxjs'
import { isSegwitDerivationMode } from '@ledgerhq/live-common/lib/derivation' import { isSegwitDerivationMode } from '@ledgerhq/live-common/lib/derivation'
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' 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 { getWalletName } from '@ledgerhq/live-common/lib/account'
import { import {
libcoreAmountToBigNumber, libcoreAmountToBigNumber,
@ -30,7 +30,7 @@ type Input = {
accountId: string, accountId: string,
blockHeight: number, blockHeight: number,
currencyId: string, currencyId: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
xpub: string, xpub: string,
index: number, index: number,
@ -103,7 +103,7 @@ async function signTransaction({
currency: CryptoCurrency, currency: CryptoCurrency,
blockHeight: number, blockHeight: number,
transaction: *, transaction: *,
derivationMode: string, derivationMode: DerivationMode,
sigHashType: number, sigHashType: number,
hasTimestamp: boolean, hasTimestamp: boolean,
}) { }) {
@ -200,7 +200,7 @@ export async function doSignAndBroadcast({
onOperationBroadcasted, onOperationBroadcasted,
}: { }: {
accountId: string, accountId: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
blockHeight: number, blockHeight: number,
currency: CryptoCurrency, currency: CryptoCurrency,

4
src/commands/libcoreSyncAccount.js

@ -1,6 +1,6 @@
// @flow // @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 { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies'
import { fromPromise } from 'rxjs/observable/fromPromise' import { fromPromise } from 'rxjs/observable/fromPromise'
@ -12,7 +12,7 @@ type Input = {
accountId: string, accountId: string,
currencyId: string, currencyId: string,
xpub: string, xpub: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
index: number, index: number,
} }

4
src/components/DevToolsPage/AccountImporter.js

@ -6,7 +6,7 @@ import React, { PureComponent, Fragment } from 'react'
import invariant from 'invariant' import invariant from 'invariant'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import type { Currency, Account } from '@ledgerhq/live-common/lib/types' import type { Currency, Account, DerivationMode } from '@ledgerhq/live-common/lib/types'
import { decodeAccount } from 'reducers/accounts' import { decodeAccount } from 'reducers/accounts'
import { addAccount } from 'actions/accounts' import { addAccount } from 'actions/accounts'
@ -38,7 +38,7 @@ type Props = {
type ImportableAccountType = { type ImportableAccountType = {
name: string, name: string,
currency: Currency, currency: Currency,
derivationMode: string, derivationMode: DerivationMode,
xpub: string, xpub: string,
} }

2
src/helpers/countervalues.js

@ -14,6 +14,7 @@ import {
import logger from 'logger' import logger from 'logger'
import { listCryptoCurrencies } from '@ledgerhq/live-common/lib/currencies' import { listCryptoCurrencies } from '@ledgerhq/live-common/lib/currencies'
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import network from '../api/network'
const pairsSelector = createSelector( const pairsSelector = createSelector(
currenciesSelector, currenciesSelector,
@ -62,6 +63,7 @@ const CounterValues = createCounterValues({
pairsSelector, pairsSelector,
setExchangePairsAction, setExchangePairsAction,
addExtraPollingHooks, addExtraPollingHooks,
network,
}) })
let sortCache let sortCache

20
src/helpers/libcore.js

@ -11,6 +11,7 @@ import {
getDerivationScheme, getDerivationScheme,
isSegwitDerivationMode, isSegwitDerivationMode,
isUnsplitDerivationMode, isUnsplitDerivationMode,
isIterableDerivationMode,
} from '@ledgerhq/live-common/lib/derivation' } from '@ledgerhq/live-common/lib/derivation'
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies'
import { import {
@ -26,6 +27,7 @@ import type {
AccountRaw, AccountRaw,
OperationRaw, OperationRaw,
OperationType, OperationType,
DerivationMode,
} from '@ledgerhq/live-common/lib/types' } from '@ledgerhq/live-common/lib/types'
import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc' import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc'
@ -89,7 +91,7 @@ async function scanAccountsOnDeviceBySegwit({
currency: CryptoCurrency, currency: CryptoCurrency,
onAccountScanned: AccountRaw => void, onAccountScanned: AccountRaw => void,
isUnsubscribed: () => boolean, isUnsubscribed: () => boolean,
derivationMode: string, derivationMode: DerivationMode,
showNewAccount: boolean, showNewAccount: boolean,
}): Promise<AccountRaw[]> { }): Promise<AccountRaw[]> {
const isSegwit = isSegwitDerivationMode(derivationMode) const isSegwit = isSegwitDerivationMode(derivationMode)
@ -199,7 +201,7 @@ async function scanNextAccount(props: {
devicePath: string, devicePath: string,
currency: CryptoCurrency, currency: CryptoCurrency,
seedIdentifier: string, seedIdentifier: string,
derivationMode: string, derivationMode: DerivationMode,
accountIndex: number, accountIndex: number,
accounts: AccountRaw[], accounts: AccountRaw[],
onAccountScanned: AccountRaw => void, onAccountScanned: AccountRaw => void,
@ -254,15 +256,15 @@ async function scanNextAccount(props: {
if (isUnsubscribed()) return [] if (isUnsubscribed()) return []
const isEmpty = ops.length === 0 const isLast = ops.length === 0 || !isIterableDerivationMode(derivationMode)
if (!isEmpty || showNewAccount) { if (!isLast || showNewAccount) {
onAccountScanned(account) onAccountScanned(account)
accounts.push(account) accounts.push(account)
} }
// returns if the current index points on an account with no ops // returns if the current index points on an account with no ops
if (isEmpty) { if (isLast) {
return accounts return accounts
} }
@ -287,7 +289,7 @@ export async function getOrCreateWallet(
derivationMode, derivationMode,
}: { }: {
currency: CryptoCurrency, currency: CryptoCurrency,
derivationMode: string, derivationMode: DerivationMode,
}, },
): NJSWallet { ): NJSWallet {
const pool = core.getPoolInstance() const pool = core.getPoolInstance()
@ -330,7 +332,7 @@ async function buildAccountRaw({
seedIdentifier: string, seedIdentifier: string,
walletName: string, walletName: string,
currency: CryptoCurrency, currency: CryptoCurrency,
derivationMode: string, derivationMode: DerivationMode,
accountIndex: number, accountIndex: number,
core: *, core: *,
ops: NJSOperation[], ops: NJSOperation[],
@ -470,7 +472,7 @@ export async function syncAccount({
}: { }: {
core: *, core: *,
xpub: string, xpub: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
currency: CryptoCurrency, currency: CryptoCurrency,
index: number, index: number,
@ -546,7 +548,7 @@ export async function scanAccountsFromXPUB({
core: *, core: *,
currencyId: string, currencyId: string,
xpub: string, xpub: string,
derivationMode: string, derivationMode: DerivationMode,
seedIdentifier: string, seedIdentifier: string,
}) { }) {
const currency = getCryptoCurrencyById(currencyId) const currency = getCryptoCurrencyById(currencyId)

32
yarn.lock

@ -1670,7 +1670,7 @@
camelcase "^5.0.0" camelcase "^5.0.0"
prettier "^1.13.7" prettier "^1.13.7"
"@ledgerhq/hw-app-btc@^4.27.0": "@ledgerhq/hw-app-btc@^4.24.0", "@ledgerhq/hw-app-btc@^4.27.0":
version "4.27.0" version "4.27.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-btc/-/hw-app-btc-4.27.0.tgz#11fc822bd34a47a39b1a7ae03ced69cf1d432796" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-btc/-/hw-app-btc-4.27.0.tgz#11fc822bd34a47a39b1a7ae03ced69cf1d432796"
integrity sha512-7Ck48wCBb6nd9UXarNeGOsOqbOTi2cs4AxFhbDNrVLvPiBSH0yEiNQEF95J6u5BxKkAdM1GV9LoRumR4KhZGqQ== integrity sha512-7Ck48wCBb6nd9UXarNeGOsOqbOTi2cs4AxFhbDNrVLvPiBSH0yEiNQEF95J6u5BxKkAdM1GV9LoRumR4KhZGqQ==
@ -1701,6 +1701,14 @@
"@ledgerhq/hw-transport" "^4.24.0" "@ledgerhq/hw-transport" "^4.24.0"
bip32-path "0.4.2" 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": "@ledgerhq/hw-transport-node-hid@4.24.0":
version "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" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid/-/hw-transport-node-hid-4.24.0.tgz#8457969d66819e8f7f50d5dd96527ab26cd3787d"
@ -1733,10 +1741,10 @@
dependencies: dependencies:
events "^3.0.0" events "^3.0.0"
"@ledgerhq/ledger-core@2.0.0-rc.10": "@ledgerhq/ledger-core@2.0.0-rc.8":
version "2.0.0-rc.10" version "2.0.0-rc.8"
resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.10.tgz#55b7261924df8ed5a33fcc51fdfafc8d6a323fc4" resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.8.tgz#618ff2ca091464c71890678d3912921ee46f98af"
integrity sha512-PbT6y8lwpVfbD5DZIH8CsOZoipNSGHY7BVHNTS+55QsQ6wAPf7sztZjZ8fk6TM0SfdbdIr7Cc5bFQ6cgljTNIA== integrity sha512-UYEwlw7+JfRCPw1z2kw9EGs88wsk5XBGxMPpNPF1cdpE7extEL63Gr+4h4ibU6kXEeEIpfI0lZ2l/6HwzMw6EQ==
dependencies: dependencies:
"@ledgerhq/hw-app-btc" "^4.7.3" "@ledgerhq/hw-app-btc" "^4.7.3"
"@ledgerhq/hw-transport-node-hid" "^4.7.6" "@ledgerhq/hw-transport-node-hid" "^4.7.6"
@ -1745,13 +1753,17 @@
bindings "^1.3.0" bindings "^1.3.0"
nan "^2.6.2" nan "^2.6.2"
"@ledgerhq/live-common@4.0.0-beta.1": "@ledgerhq/live-common@4.1.3":
version "4.0.0-beta.1" version "4.1.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.0.0-beta.1.tgz#52ed90757761a08a5f5c9c40c1fed0cb2f1fb4ca" resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.1.3.tgz#dbd5be04925b11b4bf646520fe01a8959554c561"
integrity sha512-Ms06Za/EI8yP/4GOAziCMecqIssZbkS5tjSCgaqd1h0zHLzM6i6PvgjhJyvG5SrET6+uQVp4YM4qbo2tc6irjQ== integrity sha512-4FZ6th8ZtpC0B20olsyqF9hb0VUhVkLeiO/QyWzKa+bdn7jt4PgOyUdaKbRuoW2w9UKj2qkXgIgBIaZ+l0AlJA==
dependencies: 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" bignumber.js "^7.2.1"
eip55 "^1.0.3"
invariant "^2.2.2" invariant "^2.2.2"
lodash "^4.17.4" lodash "^4.17.4"
node-lzw "^0.3.1" node-lzw "^0.3.1"

Loading…
Cancel
Save