From 1e39c4df5853513b88ec722f806ea881e23bb469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 9 Jun 2018 10:41:24 +0200 Subject: [PATCH] Deprecate usage of Account#isSegwit field in future, we probably even want to go farther: introducing a purpose field as in `m/purpose'/coinType'/index'` of bip3Z --- src/commands/libcoreSignAndBroadcast.js | 5 +++-- src/components/EnsureDeviceApp/index.js | 3 ++- src/components/modals/Receive/index.js | 3 ++- src/helpers/bip32.js | 7 +++++++ src/helpers/libcore.js | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/helpers/bip32.js diff --git a/src/commands/libcoreSignAndBroadcast.js b/src/commands/libcoreSignAndBroadcast.js index d2627830..3f0cc9e2 100644 --- a/src/commands/libcoreSignAndBroadcast.js +++ b/src/commands/libcoreSignAndBroadcast.js @@ -5,6 +5,7 @@ import type { AccountRaw, OperationRaw } from '@ledgerhq/live-common/lib/types' import Btc from '@ledgerhq/hw-app-btc' import { Observable } from 'rxjs' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies' +import { isSegwitAccount } from 'helpers/bip32' import withLibcore from 'helpers/withLibcore' import { createCommand, Command } from 'helpers/ipc' @@ -158,7 +159,7 @@ export async function doSignAndBroadcast({ const WALLET_IDENTIFIER = await getWalletIdentifier({ hwApp, - isSegwit: !!account.isSegwit, + isSegwit: isSegwitAccount(account), currencyId: account.currencyId, devicePath: deviceId, }) @@ -197,7 +198,7 @@ export async function doSignAndBroadcast({ transaction: builded, sigHashType: parseInt(sigHashType, 16), supportsSegwit: !!currency.supportsSegwit, - isSegwit: !!account.isSegwit, + isSegwit: isSegwitAccount(account), hasTimestamp, }) }) diff --git a/src/components/EnsureDeviceApp/index.js b/src/components/EnsureDeviceApp/index.js index e21fdd3e..f49fc810 100644 --- a/src/components/EnsureDeviceApp/index.js +++ b/src/components/EnsureDeviceApp/index.js @@ -2,6 +2,7 @@ import { PureComponent } from 'react' import { connect } from 'react-redux' import logger from 'logger' +import { isSegwitAccount } from 'helpers/bip32' import type { Account, CryptoCurrency } from '@ledgerhq/live-common/lib/types' import type { Device } from 'types/common' @@ -121,7 +122,7 @@ class EnsureDeviceApp extends PureComponent { devicePath: deviceSelected.path, currencyId: account.currency.id, path: account.freshAddressPath, - segwit: !!account.isSegwit, + segwit: isSegwitAccount(account), }) .toPromise() const { freshAddress } = account diff --git a/src/components/modals/Receive/index.js b/src/components/modals/Receive/index.js index 2b643d6b..382843b6 100644 --- a/src/components/modals/Receive/index.js +++ b/src/components/modals/Receive/index.js @@ -7,6 +7,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types' import type { T, Device } from 'types/common' import { MODAL_RECEIVE } from 'config/constants' +import { isSegwitAccount } from 'helpers/bip32' import getAddress from 'commands/getAddress' import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority' @@ -202,7 +203,7 @@ class ReceiveModal extends PureComponent { currencyId: account.currency.id, devicePath: device.path, path: account.freshAddressPath, - segwit: !!account.isSegwit, + segwit: isSegwitAccount(account), verify: true, }) .toPromise() diff --git a/src/helpers/bip32.js b/src/helpers/bip32.js new file mode 100644 index 00000000..12438290 --- /dev/null +++ b/src/helpers/bip32.js @@ -0,0 +1,7 @@ +// @flow +import type { Account, AccountRaw } from '@ledgerhq/live-common/lib/types' + +export const isSegwitPath = (path: string): boolean => path.startsWith("49'") + +export const isSegwitAccount = (account: Account | AccountRaw): boolean => + isSegwitPath(account.freshAddressPath) diff --git a/src/helpers/libcore.js b/src/helpers/libcore.js index d0a047e5..c9ca6df2 100644 --- a/src/helpers/libcore.js +++ b/src/helpers/libcore.js @@ -8,6 +8,7 @@ import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currenc import type { AccountRaw, OperationRaw, OperationType } from '@ledgerhq/live-common/lib/types' import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc' +import { isSegwitAccount } from 'helpers/bip32' import * as accountIdHelper from 'helpers/accountId' import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName' @@ -368,7 +369,7 @@ export async function syncAccount({ const syncedRawAccount = await buildAccountRaw({ njsAccount, - isSegwit: rawAccount.isSegwit === true, + isSegwit: isSegwitAccount(rawAccount), accountIndex: rawAccount.index, wallet: njsWallet, currencyId: rawAccount.currencyId,