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": {
"@ledgerhq/hw-app-btc": "^4.27.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.10",
"@ledgerhq/live-common": "4.0.0-beta.1",
"@ledgerhq/ledger-core": "2.0.0-rc.8",
"@ledgerhq/live-common": "4.1.3",
"animated": "^0.2.2",
"async": "^2.6.1",
"axios": "^0.18.0",

4
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<Transaction> = {
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,
})

4
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<Transaction> = {
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,
})

4
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,
}

4
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,
}

8
src/commands/libcoreSignAndBroadcast.js

@ -7,7 +7,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,
@ -30,7 +30,7 @@ type Input = {
accountId: string,
blockHeight: number,
currencyId: string,
derivationMode: string,
derivationMode: DerivationMode,
seedIdentifier: string,
xpub: string,
index: number,
@ -103,7 +103,7 @@ async function signTransaction({
currency: CryptoCurrency,
blockHeight: number,
transaction: *,
derivationMode: string,
derivationMode: DerivationMode,
sigHashType: number,
hasTimestamp: boolean,
}) {
@ -200,7 +200,7 @@ export async function doSignAndBroadcast({
onOperationBroadcasted,
}: {
accountId: string,
derivationMode: string,
derivationMode: DerivationMode,
seedIdentifier: string,
blockHeight: number,
currency: CryptoCurrency,

4
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,
}

4
src/components/DevToolsPage/AccountImporter.js

@ -6,7 +6,7 @@ import React, { PureComponent, Fragment } from 'react'
import invariant from 'invariant'
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 { addAccount } from 'actions/accounts'
@ -38,7 +38,7 @@ type Props = {
type ImportableAccountType = {
name: string,
currency: Currency,
derivationMode: string,
derivationMode: DerivationMode,
xpub: string,
}

2
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

20
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<AccountRaw[]> {
const isSegwit = isSegwitDerivationMode(derivationMode)
@ -199,7 +201,7 @@ async function scanNextAccount(props: {
devicePath: string,
currency: CryptoCurrency,
seedIdentifier: string,
derivationMode: string,
derivationMode: DerivationMode,
accountIndex: number,
accounts: AccountRaw[],
onAccountScanned: AccountRaw => void,
@ -254,15 +256,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
}
@ -287,7 +289,7 @@ export async function getOrCreateWallet(
derivationMode,
}: {
currency: CryptoCurrency,
derivationMode: string,
derivationMode: DerivationMode,
},
): NJSWallet {
const pool = core.getPoolInstance()
@ -330,7 +332,7 @@ async function buildAccountRaw({
seedIdentifier: string,
walletName: string,
currency: CryptoCurrency,
derivationMode: string,
derivationMode: DerivationMode,
accountIndex: number,
core: *,
ops: NJSOperation[],
@ -470,7 +472,7 @@ export async function syncAccount({
}: {
core: *,
xpub: string,
derivationMode: string,
derivationMode: DerivationMode,
seedIdentifier: string,
currency: CryptoCurrency,
index: number,
@ -546,7 +548,7 @@ export async function scanAccountsFromXPUB({
core: *,
currencyId: string,
xpub: string,
derivationMode: string,
derivationMode: DerivationMode,
seedIdentifier: string,
}) {
const currency = getCryptoCurrencyById(currencyId)

32
yarn.lock

@ -1670,7 +1670,7 @@
camelcase "^5.0.0"
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"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-btc/-/hw-app-btc-4.27.0.tgz#11fc822bd34a47a39b1a7ae03ced69cf1d432796"
integrity sha512-7Ck48wCBb6nd9UXarNeGOsOqbOTi2cs4AxFhbDNrVLvPiBSH0yEiNQEF95J6u5BxKkAdM1GV9LoRumR4KhZGqQ==
@ -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"
@ -1733,10 +1741,10 @@
dependencies:
events "^3.0.0"
"@ledgerhq/ledger-core@2.0.0-rc.10":
version "2.0.0-rc.10"
resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.10.tgz#55b7261924df8ed5a33fcc51fdfafc8d6a323fc4"
integrity sha512-PbT6y8lwpVfbD5DZIH8CsOZoipNSGHY7BVHNTS+55QsQ6wAPf7sztZjZ8fk6TM0SfdbdIr7Cc5bFQ6cgljTNIA==
"@ledgerhq/ledger-core@2.0.0-rc.8":
version "2.0.0-rc.8"
resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.8.tgz#618ff2ca091464c71890678d3912921ee46f98af"
integrity sha512-UYEwlw7+JfRCPw1z2kw9EGs88wsk5XBGxMPpNPF1cdpE7extEL63Gr+4h4ibU6kXEeEIpfI0lZ2l/6HwzMw6EQ==
dependencies:
"@ledgerhq/hw-app-btc" "^4.7.3"
"@ledgerhq/hw-transport-node-hid" "^4.7.6"
@ -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"

Loading…
Cancel
Save