From 26d564b2de6208c4b5af2080f25b502af6879181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 25 Jan 2019 10:46:44 +0100 Subject: [PATCH] ETH: also scan for metamask accounts derivation paths typically will allow to discover more than the first account of a metamask seed --- .eslintrc | 38 +++++++++++++++++++--------------- package.json | 2 +- src/bridge/EthereumJSBridge.js | 2 ++ src/bridge/RippleJSBridge.js | 2 ++ src/helpers/libcore.js | 4 +++- yarn.lock | 8 +++---- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/.eslintrc b/.eslintrc index e22c8543..8dc74d37 100644 --- a/.eslintrc +++ b/.eslintrc @@ -38,6 +38,7 @@ "jsx-a11y/label-has-for": 0, "prefer-destructuring": 0, "new-cap": 0, + "no-continue": 0, "no-await-in-loop": 0, "no-restricted-globals": 0, "no-unused-expressions": 0, @@ -48,7 +49,10 @@ "no-shadow": 0, "no-underscore-dangle": 0, "no-console": 2, - "no-unused-vars": ["error", { "argsIgnorePattern": "^_", "vars": "all", "args": "after-used", "ignoreRestSiblings": true }], + "no-unused-vars": [ + "error", + { "argsIgnorePattern": "^_", "vars": "all", "args": "after-used", "ignoreRestSiblings": true } + ], "no-use-before-define": 0, "no-restricted-syntax": 0, "no-prototype-builtins": 0, @@ -57,31 +61,31 @@ "react/jsx-curly-brace-presence": 0, "react/jsx-filename-extension": 0, "react/jsx-no-target-blank": 0, - "react/jsx-no-literals": [1, {"noStrings": false}], + "react/jsx-no-literals": [1, { "noStrings": false }], "react/prefer-stateless-function": 0, "react/require-default-props": 0, "react/no-multi-comp": 0, - "react/sort-comp": [1, { - order: [ - 'static-methods', - 'lifecycle', - 'everything-else', - 'render' - ] - }] + "react/sort-comp": [ + 1, + { + "order": ["static-methods", "lifecycle", "everything-else", "render"] + } + ] }, "settings": { "import/resolver": { - "babel-module": {}, + "babel-module": {} }, "flowtype": { - "onlyFilesWithFlowAnnotation": true, + "onlyFilesWithFlowAnnotation": true } }, - "overrides": [{ - "files": [ "*stories.js" ], - "rules": { - "react/jsx-no-literals": 0 + "overrides": [ + { + "files": ["*stories.js"], + "rules": { + "react/jsx-no-literals": 0 + } } - }] + ] } diff --git a/package.json b/package.json index ac7bfe6c..54659a1a 100644 --- a/package.json +++ b/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.16", - "@ledgerhq/live-common": "4.13.0", + "@ledgerhq/live-common": "4.14.0", "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 1eeeca8f..3282d1b4 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -13,6 +13,7 @@ import { getDerivationScheme, runDerivationScheme, isIterableDerivationMode, + derivationModeSupportsIndex, getMandatoryEmptyAccountSkip, } from '@ledgerhq/live-common/lib/derivation' import { @@ -314,6 +315,7 @@ const EthereumBridge: WalletBridge = { const derivationScheme = getDerivationScheme({ derivationMode, currency }) const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1 for (let index = 0; index < stopAt; index++) { + if (!derivationModeSupportsIndex(derivationMode, index)) continue const freshAddressPath = runDerivationScheme(derivationScheme, currency, { account: index, }) diff --git a/src/bridge/RippleJSBridge.js b/src/bridge/RippleJSBridge.js index 88f83531..eff799e6 100644 --- a/src/bridge/RippleJSBridge.js +++ b/src/bridge/RippleJSBridge.js @@ -12,6 +12,7 @@ import { getDerivationScheme, runDerivationScheme, isIterableDerivationMode, + derivationModeSupportsIndex, } from '@ledgerhq/live-common/lib/derivation' import { getAccountPlaceholderName, @@ -314,6 +315,7 @@ const RippleJSBridge: WalletBridge = { const derivationScheme = getDerivationScheme({ derivationMode, currency }) const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1 for (let index = 0; index < stopAt; index++) { + if (!derivationModeSupportsIndex(derivationMode, index)) continue const freshAddressPath = runDerivationScheme(derivationScheme, currency, { account: index, }) diff --git a/src/helpers/libcore.js b/src/helpers/libcore.js index 6e05e7fb..29a209dd 100644 --- a/src/helpers/libcore.js +++ b/src/helpers/libcore.js @@ -13,6 +13,7 @@ import { isSegwitDerivationMode, isUnsplitDerivationMode, isIterableDerivationMode, + derivationModeSupportsIndex, } from '@ledgerhq/live-common/lib/derivation' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/currencies' import { @@ -258,8 +259,9 @@ async function scanNextAccount(props: { if (isUnsubscribed()) return [] const isLast = ops.length === 0 || !isIterableDerivationMode(derivationMode) + const skipIndex = !derivationModeSupportsIndex(derivationMode, accountIndex) - if (!isLast || showNewAccount) { + if ((!isLast || showNewAccount) && !skipIndex) { onAccountScanned(account) accounts.push(account) } diff --git a/yarn.lock b/yarn.lock index de3d8312..5de18eda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1738,10 +1738,10 @@ bindings "^1.3.0" nan "^2.6.2" -"@ledgerhq/live-common@4.13.0": - version "4.13.0" - resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.13.0.tgz#7e5eeaf8af2937cd30649b3f6e2094878980f557" - integrity sha512-DSO3CLVdZav7QC2DarbfAXW14z3omRvDFFfwF3URDwKH6nPIVJsE5WqiMpnQ1SL+a1qnevGkF5NLrvwv5bdRmQ== +"@ledgerhq/live-common@4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.14.0.tgz#56ecac0a21f0d77a66a57d5ce9e2159b426e0ec7" + integrity sha512-oKvb/QZrG2XzVvq/IM+73lyw33VlyDu03hmYFCR48U2DGao/SCFOH8J0vQZK/U9VTSqpnC8mEZKQhNOQkf5hoA== dependencies: "@aeternity/ledger-app-api" "0.0.4" "@ledgerhq/errors" "^4.32.0"