@ledgerhq/live-common 21.8.2 → 21.10.0-btcjs.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/currencies.js +1 -0
- package/lib/__tests__/currencies.js.map +1 -1
- package/lib/__tests__/families/bitcoin/logic.js +7 -7
- package/lib/__tests__/families/bitcoin/logic.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js +1 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +5 -3
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +9 -7
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js +2 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js +2 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js +4 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.litecoin.test.js +2 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.litecoin.test.js.map +1 -1
- package/lib/account/helpers.d.ts.map +1 -1
- package/lib/account/helpers.js +8 -1
- package/lib/account/helpers.js.map +1 -1
- package/lib/account/pending.d.ts +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +2 -1
- package/lib/account/support.js.map +1 -1
- package/lib/api/explorerConfig/index.d.ts.map +1 -1
- package/lib/api/explorerConfig/index.js +0 -36
- package/lib/api/explorerConfig/index.js.map +1 -1
- package/lib/bridge/jsHelpers.d.ts +2 -1
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +56 -43
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/derivation.d.ts +12 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +32 -4
- package/lib/derivation.js.map +1 -1
- package/lib/env.d.ts +5 -10
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +2 -7
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/errors.d.ts +3 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -1
- package/lib/errors.js.map +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js +48 -26
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -1
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +20 -37
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -1
- package/lib/families/bitcoin/bridge/libcore.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/libcore.js +8 -1
- package/lib/families/bitcoin/bridge/libcore.js.map +1 -1
- package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/mock.js +3 -1
- package/lib/families/bitcoin/bridge/mock.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.scanAccounts.1.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.scanAccounts.1.js +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.scanAccounts.1.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.js +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.js +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
- package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dash.js +1 -1
- package/lib/families/bitcoin/datasets/dash.js.map +1 -1
- package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/decred.js +1 -1
- package/lib/families/bitcoin/datasets/decred.js.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.scanAccounts.1.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.scanAccounts.1.js +1 -1
- package/lib/families/bitcoin/datasets/digibyte.scanAccounts.1.js.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.js +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.js +1 -1
- package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.scanAccounts.1.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.scanAccounts.1.js +1 -1
- package/lib/families/bitcoin/datasets/litecoin.scanAccounts.1.js.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.js +1 -1
- package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.js +1 -1
- package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.js +1 -1
- package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.js +1 -1
- package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.js +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.js +1 -1
- package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.js +1 -1
- package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.js +1 -1
- package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
- package/lib/families/bitcoin/exchange.d.ts +1 -1
- package/lib/families/bitcoin/exchange.d.ts.map +1 -1
- package/lib/families/bitcoin/exchange.js +2 -1
- package/lib/families/bitcoin/exchange.js.map +1 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts +5 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts.map +1 -1
- package/lib/families/bitcoin/hw-getAddress.js +34 -18
- package/lib/families/bitcoin/hw-getAddress.js.map +1 -1
- package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-signOperation.js +3 -0
- package/lib/families/bitcoin/js-signOperation.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts +2 -2
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +24 -16
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/logic.d.ts.map +1 -1
- package/lib/families/bitcoin/logic.js +4 -2
- package/lib/families/bitcoin/logic.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +1 -1
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/types.d.ts +3 -0
- package/lib/families/bitcoin/types.d.ts.map +1 -1
- package/lib/families/bitcoin/types.js +4 -1
- package/lib/families/bitcoin/types.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +1 -2
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js +6 -11
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts +1 -2
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +1 -4
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts +2 -3
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +6 -11
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +0 -5
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +1 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +1 -4
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +1 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +1 -4
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +3 -0
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +2 -0
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +2 -0
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +6 -0
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +2 -4
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +24 -75
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.js +1 -3
- package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
- package/lib/families/crypto_org/js-synchronisation.d.ts +2 -2
- package/lib/families/elrond/js-synchronisation.d.ts +2 -2
- package/lib/families/elrond/js-synchronisation.d.ts.map +1 -1
- package/lib/families/elrond/js-synchronisation.js +1 -3
- package/lib/families/elrond/js-synchronisation.js.map +1 -1
- package/lib/families/elrond/test-dataset.js +4 -4
- package/lib/families/elrond/test-dataset.js.map +1 -1
- package/lib/families/polkadot/js-synchronisation.d.ts +2 -2
- package/lib/families/polkadot/test-dataset.d.ts.map +1 -1
- package/lib/families/polkadot/test-dataset.js +606 -604
- package/lib/families/polkadot/test-dataset.js.map +1 -1
- package/lib/families/stellar/js-synchronization.d.ts +2 -2
- package/lib/families/tezos/bakers.whitelist-default.d.ts.map +1 -1
- package/lib/families/tezos/bakers.whitelist-default.js +1 -1
- package/lib/families/tezos/bakers.whitelist-default.js.map +1 -1
- package/lib/families/tron/bridge/js.d.ts.map +1 -1
- package/lib/families/tron/bridge/js.js +14 -5
- package/lib/families/tron/bridge/js.js.map +1 -1
- package/lib/generated/exchange.d.ts +1 -1
- package/lib/hw/getAddress/types.d.ts +2 -10
- package/lib/hw/getAddress/types.d.ts.map +1 -1
- package/lib/libcore/createAccountFromDevice.d.ts +2 -2
- package/lib/libcore/createAccountFromDevice.d.ts.map +1 -1
- package/lib/libcore/createAccountFromDevice.js +2 -6
- package/lib/libcore/createAccountFromDevice.js.map +1 -1
- package/lib/libcore/scanAccounts.d.ts +4 -1
- package/lib/libcore/scanAccounts.d.ts.map +1 -1
- package/lib/libcore/scanAccounts.js +35 -32
- package/lib/libcore/scanAccounts.js.map +1 -1
- package/lib/network.d.ts.map +1 -1
- package/lib/network.js +7 -7
- package/lib/network.js.map +1 -1
- package/package.json +31 -31
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +352 -527
- package/src/__tests__/__snapshots__/csvExport.ts.snap +237 -237
- package/src/__tests__/__snapshots__/portfolio.ts.snap +12 -12
- package/src/__tests__/currencies.ts +1 -0
- package/src/__tests__/families/bitcoin/logic.ts +14 -21
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.ts +1 -2
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +3 -1
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +2 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.ts +1 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.ts +1 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.ts +2 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.litecoin.test.ts +1 -0
- package/src/account/helpers.ts +13 -6
- package/src/account/support.ts +2 -1
- package/src/api/explorerConfig/index.ts +0 -36
- package/src/bridge/jsHelpers.ts +28 -8
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +2897 -68
- package/src/derivation.ts +33 -2
- package/src/env.ts +2 -7
- package/src/errors.ts +5 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +20 -45
- package/src/exchange/swap/hooks/usePickDefaultAccount.ts +23 -35
- package/src/families/bitcoin/bridge/libcore.ts +11 -1
- package/src/families/bitcoin/bridge/mock.ts +3 -1
- package/src/families/bitcoin/datasets/bitcoin.scanAccounts.1.ts +100 -20
- package/src/families/bitcoin/datasets/bitcoin_cash.ts +22 -8
- package/src/families/bitcoin/datasets/bitcoin_gold.ts +92 -18
- package/src/families/bitcoin/datasets/dash.ts +32 -2
- package/src/families/bitcoin/datasets/decred.ts +12 -2
- package/src/families/bitcoin/datasets/digibyte.scanAccounts.1.ts +84 -18
- package/src/families/bitcoin/datasets/dogecoin.ts +32 -2
- package/src/families/bitcoin/datasets/komodo.ts +42 -2
- package/src/families/bitcoin/datasets/litecoin.scanAccounts.1.ts +83 -19
- package/src/families/bitcoin/datasets/peercoin.ts +32 -2
- package/src/families/bitcoin/datasets/pivx.ts +33 -3
- package/src/families/bitcoin/datasets/qtum.ts +70 -12
- package/src/families/bitcoin/datasets/stakenet.ts +20 -4
- package/src/families/bitcoin/datasets/vertcoin.ts +86 -20
- package/src/families/bitcoin/datasets/viacoin.ts +48 -10
- package/src/families/bitcoin/datasets/zcash.ts +12 -2
- package/src/families/bitcoin/datasets/zencash.ts +10 -2
- package/src/families/bitcoin/exchange.ts +1 -0
- package/src/families/bitcoin/hw-getAddress.ts +41 -19
- package/src/families/bitcoin/js-signOperation.ts +4 -0
- package/src/families/bitcoin/js-synchronisation.ts +32 -22
- package/src/families/bitcoin/logic.ts +4 -2
- package/src/families/bitcoin/specs.ts +2 -1
- package/src/families/bitcoin/types.ts +4 -0
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +7 -13
- package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +1 -5
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +2 -6
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +7 -13
- package/src/families/bitcoin/wallet-btc/crypto/types.ts +0 -8
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +3 -6
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +2 -6
- package/src/families/bitcoin/wallet-btc/explorer/index.ts +2 -2
- package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +3 -1
- package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +2 -0
- package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +2 -0
- package/src/families/bitcoin/wallet-btc/storage/types.ts +1 -1
- package/src/families/bitcoin/wallet-btc/utils.ts +6 -1
- package/src/families/bitcoin/wallet-btc/wallet.ts +14 -82
- package/src/families/bitcoin/wallet-btc/xpub.ts +2 -5
- package/src/families/elrond/js-synchronisation.ts +2 -4
- package/src/families/elrond/test-dataset.ts +3 -3
- package/src/families/polkadot/test-dataset.ts +627 -623
- package/src/families/tezos/bakers.whitelist-default.ts +0 -1
- package/src/families/tron/bridge/js.ts +18 -6
- package/src/hw/getAddress/types.ts +3 -11
- package/src/libcore/createAccountFromDevice.ts +4 -5
- package/src/libcore/scanAccounts.ts +20 -9
- package/src/network.ts +13 -11
- package/lib/families/bitcoin/datasets/stratis.d.ts +0 -5
- package/lib/families/bitcoin/datasets/stratis.d.ts.map +0 -1
- package/lib/families/bitcoin/datasets/stratis.js +0 -12
- package/lib/families/bitcoin/datasets/stratis.js.map +0 -1
- package/src/families/bitcoin/datasets/stratis.ts +0 -24
|
@@ -9,6 +9,7 @@ import { DerivationModes as WalletDerivationModes } from "./wallet-btc";
|
|
|
9
9
|
import { BigNumber } from "bignumber.js";
|
|
10
10
|
import Btc from "@ledgerhq/hw-app-btc";
|
|
11
11
|
import { log } from "@ledgerhq/logs";
|
|
12
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
12
13
|
import type {
|
|
13
14
|
Account,
|
|
14
15
|
Operation,
|
|
@@ -20,29 +21,30 @@ import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";
|
|
|
20
21
|
import { findCurrencyExplorer } from "../../api/Ledger";
|
|
21
22
|
import { encodeAccountId } from "../../account";
|
|
22
23
|
import { encodeOperationId } from "../../operation";
|
|
24
|
+
import {
|
|
25
|
+
isSegwitDerivationMode,
|
|
26
|
+
isNativeSegwitDerivationMode,
|
|
27
|
+
isTaprootDerivationMode,
|
|
28
|
+
} from "../../derivation";
|
|
23
29
|
import { BitcoinOutput } from "./types";
|
|
24
30
|
import { perCoinLogic } from "./logic";
|
|
25
31
|
import wallet from "./wallet-btc";
|
|
26
|
-
import {
|
|
32
|
+
import { getAddressWithBtcInstance } from "./hw-getAddress";
|
|
27
33
|
|
|
28
34
|
// Map LL's DerivationMode to wallet-btc's
|
|
29
35
|
const toWalletDerivationMode = (
|
|
30
36
|
mode: DerivationMode
|
|
31
37
|
): WalletDerivationModes => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
case "vertcoin_128_segwit":
|
|
38
|
-
return WalletDerivationModes.SEGWIT;
|
|
39
|
-
|
|
40
|
-
case "native_segwit":
|
|
41
|
-
return WalletDerivationModes.NATIVE_SEGWIT;
|
|
42
|
-
|
|
43
|
-
default:
|
|
44
|
-
return WalletDerivationModes.LEGACY;
|
|
38
|
+
if (isTaprootDerivationMode(mode)) {
|
|
39
|
+
return WalletDerivationModes.TAPROOT;
|
|
40
|
+
}
|
|
41
|
+
if (isNativeSegwitDerivationMode(mode)) {
|
|
42
|
+
return WalletDerivationModes.NATIVE_SEGWIT;
|
|
45
43
|
}
|
|
44
|
+
if (isSegwitDerivationMode(mode)) {
|
|
45
|
+
return WalletDerivationModes.SEGWIT;
|
|
46
|
+
}
|
|
47
|
+
return WalletDerivationModes.LEGACY;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
// Map LL's currency ID to wallet-btc's Account.params.network
|
|
@@ -241,6 +243,7 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
241
243
|
// 44'/0'/0'/0/0 --> 44'/0'
|
|
242
244
|
// FIXME Only the CLI provides a full derivationPath: why?
|
|
243
245
|
const rootPath = derivationPath.split("/", 2).join("/");
|
|
246
|
+
const accountPath = `${rootPath}/${index}'`;
|
|
244
247
|
|
|
245
248
|
const paramXpub = initialAccount?.xpub;
|
|
246
249
|
|
|
@@ -250,14 +253,16 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
250
253
|
|
|
251
254
|
if (!transport) {
|
|
252
255
|
// hwapp not provided
|
|
253
|
-
throw new Error("
|
|
256
|
+
throw new Error("hwapp required to generate the xpub");
|
|
254
257
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
const btc = new Btc(transport);
|
|
259
|
+
const { bitcoinLikeInfo } = currency;
|
|
260
|
+
const { XPUBVersion: xpubVersion } = bitcoinLikeInfo as {
|
|
261
|
+
// FIXME It's supposed to be optional
|
|
262
|
+
//XPUBVersion?: number;
|
|
263
|
+
XPUBVersion: number;
|
|
264
|
+
};
|
|
265
|
+
generatedXpub = await btc.getWalletXpub({ path: accountPath, xpubVersion });
|
|
261
266
|
}
|
|
262
267
|
const xpub = paramXpub || generatedXpub;
|
|
263
268
|
|
|
@@ -380,5 +385,10 @@ const postSync = (initial: Account, synced: Account) => {
|
|
|
380
385
|
return synced;
|
|
381
386
|
};
|
|
382
387
|
|
|
383
|
-
|
|
388
|
+
const getAddressFn = (transport) => {
|
|
389
|
+
const btc = new Btc(transport);
|
|
390
|
+
return (opts) => getAddressWithBtcInstance(transport, btc, opts);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
export const scanAccounts = makeScanAccounts(getAccountShape, getAddressFn);
|
|
384
394
|
export const sync = makeSync(getAccountShape, postSync);
|
|
@@ -59,11 +59,13 @@ export const isValidRecipient = async (params: {
|
|
|
59
59
|
valid = isValidAddress(params.recipient, <Currency>params.currency.id);
|
|
60
60
|
} catch (e: any) {
|
|
61
61
|
// isValidAddress() will throw Error if c is not an actual Currency
|
|
62
|
-
|
|
62
|
+
valid = false;
|
|
63
63
|
}
|
|
64
64
|
if (!valid) {
|
|
65
65
|
return Promise.reject(
|
|
66
|
-
new InvalidAddress("
|
|
66
|
+
new InvalidAddress("", {
|
|
67
|
+
currencyName: params.currency.name,
|
|
68
|
+
})
|
|
67
69
|
);
|
|
68
70
|
}
|
|
69
71
|
return Promise.resolve(null);
|
|
@@ -270,13 +270,14 @@ const bitcoin: AppSpec<Transaction> = {
|
|
|
270
270
|
mutations: bitcoinLikeMutations(),
|
|
271
271
|
};
|
|
272
272
|
const bitcoinTestnet: AppSpec<Transaction> = {
|
|
273
|
-
multipleRuns:
|
|
273
|
+
multipleRuns: 2,
|
|
274
274
|
name: "Bitcoin Testnet",
|
|
275
275
|
currency: getCryptoCurrencyById("bitcoin_testnet"),
|
|
276
276
|
dependency: "Bitcoin",
|
|
277
277
|
appQuery: {
|
|
278
278
|
model: DeviceModelId.nanoS,
|
|
279
279
|
appName: "Bitcoin Test",
|
|
280
|
+
// appVersion: "2.0.0-alpha",
|
|
280
281
|
},
|
|
281
282
|
test: genericTest,
|
|
282
283
|
mutations: bitcoinLikeMutations({
|
|
@@ -56,6 +56,10 @@ export type BitcoinResourcesRaw = {
|
|
|
56
56
|
walletAccount?: WalletAccountRaw;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
export const initialBitcoinResourcesValue = {
|
|
60
|
+
utxos: [],
|
|
61
|
+
};
|
|
62
|
+
|
|
59
63
|
export const BitcoinLikeFeePolicy = Object.freeze({
|
|
60
64
|
PER_BYTE: "PER_BYTE",
|
|
61
65
|
PER_KBYTE: "PER_KBYTE",
|
|
@@ -7,7 +7,7 @@ import * as bip32 from "bip32";
|
|
|
7
7
|
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
8
8
|
import bs58check from "bs58check";
|
|
9
9
|
import { DerivationModes } from "../types";
|
|
10
|
-
import {
|
|
10
|
+
import { ICrypto } from "./types";
|
|
11
11
|
|
|
12
12
|
export function fallbackValidateAddress(address: string): boolean {
|
|
13
13
|
try {
|
|
@@ -28,12 +28,6 @@ class Base implements ICrypto {
|
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
29
|
network: any;
|
|
30
30
|
|
|
31
|
-
derivationMode: DerivationMode = {
|
|
32
|
-
LEGACY: DerivationModes.LEGACY,
|
|
33
|
-
SEGWIT: DerivationModes.SEGWIT,
|
|
34
|
-
NATIVE_SEGWIT: DerivationModes.NATIVE_SEGWIT,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
32
|
constructor({ network }: { network: any }) {
|
|
39
33
|
this.network = network;
|
|
@@ -85,11 +79,11 @@ class Base implements ICrypto {
|
|
|
85
79
|
index: number
|
|
86
80
|
): string {
|
|
87
81
|
switch (derivationMode) {
|
|
88
|
-
case
|
|
82
|
+
case DerivationModes.LEGACY:
|
|
89
83
|
return this.getLegacyAddress(xpub, account, index);
|
|
90
|
-
case
|
|
84
|
+
case DerivationModes.SEGWIT:
|
|
91
85
|
return this.getSegWitAddress(xpub, account, index);
|
|
92
|
-
case
|
|
86
|
+
case DerivationModes.NATIVE_SEGWIT:
|
|
93
87
|
return this.getNativeSegWitAddress(xpub, account, index);
|
|
94
88
|
default:
|
|
95
89
|
throw new Error(`Invalid derivation Mode: ${derivationMode}`);
|
|
@@ -99,13 +93,13 @@ class Base implements ICrypto {
|
|
|
99
93
|
// infer address type from its syntax
|
|
100
94
|
getDerivationMode(address: string): DerivationModes {
|
|
101
95
|
if (address.match("^(bc1|tb1).*")) {
|
|
102
|
-
return
|
|
96
|
+
return DerivationModes.NATIVE_SEGWIT;
|
|
103
97
|
}
|
|
104
98
|
if (address.match("^(3|2|M).*")) {
|
|
105
|
-
return
|
|
99
|
+
return DerivationModes.SEGWIT;
|
|
106
100
|
}
|
|
107
101
|
if (address.match("^(1|n|m|L).*")) {
|
|
108
|
-
return
|
|
102
|
+
return DerivationModes.LEGACY;
|
|
109
103
|
}
|
|
110
104
|
throw new Error(
|
|
111
105
|
"INVALID ADDRESS: ".concat(address).concat(" is not a valid address")
|
|
@@ -49,11 +49,7 @@ function fromBech32(address: string): {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function toBech32(
|
|
53
|
-
data: Buffer,
|
|
54
|
-
version: number,
|
|
55
|
-
prefix: string,
|
|
56
|
-
): string {
|
|
52
|
+
function toBech32(data: Buffer, version: number, prefix: string): string {
|
|
57
53
|
const words = bech32.toWords(data);
|
|
58
54
|
words.unshift(version);
|
|
59
55
|
|
|
@@ -6,17 +6,13 @@ import bchaddr from "bchaddrjs";
|
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
8
8
|
import { DerivationModes } from "../types";
|
|
9
|
-
import { ICrypto
|
|
9
|
+
import { ICrypto } from "./types";
|
|
10
10
|
|
|
11
11
|
// a mock explorer class that just use js objects
|
|
12
12
|
class BitcoinCash implements ICrypto {
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
network: any;
|
|
15
15
|
|
|
16
|
-
derivationMode: DerivationMode = {
|
|
17
|
-
LEGACY: DerivationModes.LEGACY,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
17
|
constructor({ network }: { network: any }) {
|
|
22
18
|
this.network = network;
|
|
@@ -59,7 +55,7 @@ class BitcoinCash implements ICrypto {
|
|
|
59
55
|
// could match a native Bitcoin address type for instance)
|
|
60
56
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
61
57
|
getDerivationMode(address: string) {
|
|
62
|
-
return
|
|
58
|
+
return DerivationModes.LEGACY;
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
toOutputScript(address: string) {
|
|
@@ -5,7 +5,7 @@ import * as bip32 from "bip32";
|
|
|
5
5
|
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
6
6
|
import { bech32 } from "bech32";
|
|
7
7
|
import { DerivationModes } from "../types";
|
|
8
|
-
import { ICrypto
|
|
8
|
+
import { ICrypto } from "./types";
|
|
9
9
|
import Base from "./base";
|
|
10
10
|
|
|
11
11
|
// Todo copy paste from bitcoin.ts. we can merge them later
|
|
@@ -13,12 +13,6 @@ class Litecoin extends Base implements ICrypto {
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
network: any;
|
|
15
15
|
|
|
16
|
-
derivationMode: DerivationMode = {
|
|
17
|
-
LEGACY: DerivationModes.LEGACY,
|
|
18
|
-
SEGWIT: DerivationModes.SEGWIT,
|
|
19
|
-
NATIVE_SEGWIT: DerivationModes.NATIVE_SEGWIT,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
17
|
constructor({ network }: { network: any }) {
|
|
24
18
|
super({ network });
|
|
@@ -66,11 +60,11 @@ class Litecoin extends Base implements ICrypto {
|
|
|
66
60
|
index: number
|
|
67
61
|
): string {
|
|
68
62
|
switch (derivationMode) {
|
|
69
|
-
case
|
|
63
|
+
case DerivationModes.LEGACY:
|
|
70
64
|
return this.getLegacyAddress(xpub, account, index);
|
|
71
|
-
case
|
|
65
|
+
case DerivationModes.SEGWIT:
|
|
72
66
|
return this.getSegWitAddress(xpub, account, index);
|
|
73
|
-
case
|
|
67
|
+
case DerivationModes.NATIVE_SEGWIT:
|
|
74
68
|
return this.getNativeSegWitAddress(xpub, account, index);
|
|
75
69
|
default:
|
|
76
70
|
throw new Error("Should not be reachable");
|
|
@@ -80,13 +74,13 @@ class Litecoin extends Base implements ICrypto {
|
|
|
80
74
|
// infer address type from its syntax
|
|
81
75
|
getDerivationMode(address: string) {
|
|
82
76
|
if (address.match("^(ltc1).*")) {
|
|
83
|
-
return
|
|
77
|
+
return DerivationModes.NATIVE_SEGWIT;
|
|
84
78
|
}
|
|
85
79
|
if (address.match("^(3|2|M).*")) {
|
|
86
|
-
return
|
|
80
|
+
return DerivationModes.SEGWIT;
|
|
87
81
|
}
|
|
88
82
|
if (address.match("^(1|n|m|L).*")) {
|
|
89
|
-
return
|
|
83
|
+
return DerivationModes.LEGACY;
|
|
90
84
|
}
|
|
91
85
|
throw new Error(
|
|
92
86
|
"INVALID ADDRESS: ".concat(address).concat(" is not a valid address")
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { DerivationModes } from "../types";
|
|
2
|
-
|
|
3
|
-
// all things derivation
|
|
4
|
-
export interface DerivationMode {
|
|
5
|
-
[index: string]: DerivationModes;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
1
|
export interface ICrypto {
|
|
9
2
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
3
|
network: any;
|
|
11
|
-
derivationMode: DerivationMode;
|
|
12
4
|
getAddress(
|
|
13
5
|
derivationMode: string,
|
|
14
6
|
xpub: string,
|
|
@@ -6,12 +6,13 @@ import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
|
6
6
|
import zec from "zcash-bitcore-lib";
|
|
7
7
|
import bs58check from "bs58check";
|
|
8
8
|
import { DerivationModes } from "../types";
|
|
9
|
-
import { ICrypto
|
|
9
|
+
import { ICrypto } from "./types";
|
|
10
10
|
import coininfo from "coininfo";
|
|
11
11
|
|
|
12
12
|
class ZCash implements ICrypto {
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
network: any;
|
|
15
|
+
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
17
|
constructor({ network }: { network: any }) {
|
|
17
18
|
this.network = network;
|
|
@@ -20,10 +21,6 @@ class ZCash implements ICrypto {
|
|
|
20
21
|
this.network.usesTimestampedTransaction = false;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
derivationMode: DerivationMode = {
|
|
24
|
-
LEGACY: DerivationModes.LEGACY,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
24
|
// eslint-disable-next-line
|
|
28
25
|
baddrToTaddr(baddrStr: string) {
|
|
29
26
|
const baddr = bs58check.decode(baddrStr).slice(1);
|
|
@@ -59,7 +56,7 @@ class ZCash implements ICrypto {
|
|
|
59
56
|
|
|
60
57
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
61
58
|
getDerivationMode(address: string) {
|
|
62
|
-
return
|
|
59
|
+
return DerivationModes.LEGACY;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
toOutputScript(address: string) {
|
|
@@ -6,7 +6,7 @@ import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
|
6
6
|
import zec from "zcash-bitcore-lib";
|
|
7
7
|
import bs58check from "bs58check";
|
|
8
8
|
import { DerivationModes } from "../types";
|
|
9
|
-
import { ICrypto
|
|
9
|
+
import { ICrypto } from "./types";
|
|
10
10
|
import coininfo from "coininfo";
|
|
11
11
|
|
|
12
12
|
class Zen implements ICrypto {
|
|
@@ -38,10 +38,6 @@ class Zen implements ICrypto {
|
|
|
38
38
|
this.network.usesTimestampedTransaction = false;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
derivationMode: DerivationMode = {
|
|
42
|
-
LEGACY: DerivationModes.LEGACY,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
41
|
// eslint-disable-next-line
|
|
46
42
|
baddrToTaddr(baddrStr: string) {
|
|
47
43
|
const baddr = bs58check.decode(baddrStr).slice(1);
|
|
@@ -80,7 +76,7 @@ class Zen implements ICrypto {
|
|
|
80
76
|
|
|
81
77
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
78
|
getDerivationMode(address: string) {
|
|
83
|
-
return
|
|
79
|
+
return DerivationModes.LEGACY;
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
toOutputScript(address: string) {
|
|
@@ -200,7 +200,7 @@ class BitcoinLikeExplorer extends EventEmitter implements IExplorer {
|
|
|
200
200
|
|
|
201
201
|
// TODO add a test for failure (at the sync level)
|
|
202
202
|
const client = await this.client.acquire();
|
|
203
|
-
const res
|
|
203
|
+
const res = (
|
|
204
204
|
await client.client.get(url, {
|
|
205
205
|
params,
|
|
206
206
|
// some altcoin may have outputs with values > MAX_SAFE_INTEGER
|
|
@@ -217,7 +217,7 @@ class BitcoinLikeExplorer extends EventEmitter implements IExplorer {
|
|
|
217
217
|
return value;
|
|
218
218
|
}),
|
|
219
219
|
})
|
|
220
|
-
).data;
|
|
220
|
+
).data as { txs: TX[] };
|
|
221
221
|
await this.client.release(client);
|
|
222
222
|
|
|
223
223
|
this.emit("fetched-address-transaction", { url, params, res });
|
|
@@ -6,6 +6,7 @@ import Xpub from "../xpub";
|
|
|
6
6
|
import { PickingStrategy } from "./types";
|
|
7
7
|
import * as utils from "../utils";
|
|
8
8
|
import { DeepFirst } from "./DeepFirst";
|
|
9
|
+
import { log } from "@ledgerhq/logs";
|
|
9
10
|
|
|
10
11
|
export class CoinSelect extends PickingStrategy {
|
|
11
12
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -18,6 +19,7 @@ export class CoinSelect extends PickingStrategy {
|
|
|
18
19
|
// get the utxos to use as input
|
|
19
20
|
// from all addresses of the account
|
|
20
21
|
const addresses = await xpub.getXpubAddresses();
|
|
22
|
+
log("picking strategy", "Coinselect");
|
|
21
23
|
|
|
22
24
|
const unspentUtxos = flatten(
|
|
23
25
|
await Promise.all(
|
|
@@ -30,7 +32,7 @@ export class CoinSelect extends PickingStrategy {
|
|
|
30
32
|
).length
|
|
31
33
|
);
|
|
32
34
|
const TOTAL_TRIES = 100000;
|
|
33
|
-
|
|
35
|
+
log("picking strategy", "utxos", unspentUtxos);
|
|
34
36
|
// Compute cost of change
|
|
35
37
|
const fixedSize = utils.estimateTxSize(
|
|
36
38
|
0,
|
|
@@ -5,6 +5,7 @@ import { Output } from "../storage/types";
|
|
|
5
5
|
import Xpub from "../xpub";
|
|
6
6
|
import { PickingStrategy } from "./types";
|
|
7
7
|
import * as utils from "../utils";
|
|
8
|
+
import { log } from "@ledgerhq/logs";
|
|
8
9
|
|
|
9
10
|
export class DeepFirst extends PickingStrategy {
|
|
10
11
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -17,6 +18,7 @@ export class DeepFirst extends PickingStrategy {
|
|
|
17
18
|
// get the utxos to use as input
|
|
18
19
|
// from all addresses of the account
|
|
19
20
|
const addresses = await xpub.getXpubAddresses();
|
|
21
|
+
log("picking strategy", "Deepfirst");
|
|
20
22
|
|
|
21
23
|
let unspentUtxos = flatten(
|
|
22
24
|
await Promise.all(
|
|
@@ -5,6 +5,7 @@ import { Output } from "../storage/types";
|
|
|
5
5
|
import Xpub from "../xpub";
|
|
6
6
|
import { PickingStrategy } from "./types";
|
|
7
7
|
import * as utils from "../utils";
|
|
8
|
+
import { log } from "@ledgerhq/logs";
|
|
8
9
|
|
|
9
10
|
export class Merge extends PickingStrategy {
|
|
10
11
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -17,6 +18,7 @@ export class Merge extends PickingStrategy {
|
|
|
17
18
|
// get the utxos to use as input
|
|
18
19
|
// from all addresses of the account
|
|
19
20
|
const addresses = await xpub.getXpubAddresses();
|
|
21
|
+
log("picking strategy", "Merge");
|
|
20
22
|
|
|
21
23
|
let unspentUtxos = flatten(
|
|
22
24
|
await Promise.all(
|
|
@@ -106,7 +106,12 @@ export function estimateTxSize(
|
|
|
106
106
|
fixedSize += byteSize(inputCount); // Number of inputs
|
|
107
107
|
fixedSize += byteSize(outputCount); // Number of outputs
|
|
108
108
|
fixedSize += 4; // Timelock
|
|
109
|
-
|
|
109
|
+
// refer to https://medium.com/coinmonks/on-bitcoin-transaction-sizes-part-2-9445373d17f4
|
|
110
|
+
// and https://bitcoin.stackexchange.com/questions/96017/what-are-the-sizes-of-single-sig-and-2-of-3-multisig-taproot-inputs
|
|
111
|
+
if (derivationMode === DerivationModes.TAPROOT) {
|
|
112
|
+
txSize = fixedSize + 57.5 * inputCount + 43 * outputCount;
|
|
113
|
+
return Math.ceil(txSize);
|
|
114
|
+
}
|
|
110
115
|
const isSegwit =
|
|
111
116
|
derivationMode === DerivationModes.NATIVE_SEGWIT ||
|
|
112
117
|
derivationMode === DerivationModes.SEGWIT;
|
|
@@ -5,7 +5,6 @@ import BigNumber from "bignumber.js";
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import { BufferWriter } from "bitcoinjs-lib/src/bufferutils";
|
|
8
|
-
import * as bitcoin from "bitcoinjs-lib";
|
|
9
8
|
|
|
10
9
|
import Btc from "@ledgerhq/hw-app-btc";
|
|
11
10
|
import { log } from "@ledgerhq/logs";
|
|
@@ -52,54 +51,8 @@ class BitcoinLikeWallet {
|
|
|
52
51
|
return this.explorerInstances[id];
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
async generateXpub(
|
|
56
|
-
btc: Btc,
|
|
57
|
-
currency: Currency,
|
|
58
|
-
path: string,
|
|
59
|
-
index: number
|
|
60
|
-
): Promise<string> {
|
|
61
|
-
const parentDerivation = await btc.getWalletPublicKey(`${path}`);
|
|
62
|
-
const accountDerivation = await btc.getWalletPublicKey(`${path}/${index}'`);
|
|
63
|
-
|
|
64
|
-
// parent
|
|
65
|
-
const publicKeyParentCompressed = utils.compressPublicKey(
|
|
66
|
-
parentDerivation.publicKey
|
|
67
|
-
);
|
|
68
|
-
const publicKeyParentCompressedHex = utils.parseHexString(
|
|
69
|
-
publicKeyParentCompressed
|
|
70
|
-
);
|
|
71
|
-
let result = bitcoin.crypto.sha256(
|
|
72
|
-
Buffer.from(publicKeyParentCompressedHex)
|
|
73
|
-
);
|
|
74
|
-
result = bitcoin.crypto.ripemd160(result);
|
|
75
|
-
// eslint-disable-next-line no-bitwise
|
|
76
|
-
const fingerprint =
|
|
77
|
-
((result[0] << 24) | (result[1] << 16) | (result[2] << 8) | result[3]) >>>
|
|
78
|
-
0;
|
|
79
|
-
|
|
80
|
-
// account
|
|
81
|
-
const publicKeyAccountCompressed = utils.compressPublicKey(
|
|
82
|
-
accountDerivation.publicKey
|
|
83
|
-
);
|
|
84
|
-
// eslint-disable-next-line no-bitwise
|
|
85
|
-
const childnum = (0x80000000 | index) >>> 0;
|
|
86
|
-
|
|
87
|
-
const { network } = cryptoFactory(currency);
|
|
88
|
-
const xpubRaw = utils.createXPUB(
|
|
89
|
-
3,
|
|
90
|
-
fingerprint,
|
|
91
|
-
childnum,
|
|
92
|
-
accountDerivation.chainCode,
|
|
93
|
-
publicKeyAccountCompressed,
|
|
94
|
-
network.bip32.public
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return utils.encodeBase58Check(xpubRaw);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
54
|
async generateAccount(params: {
|
|
101
|
-
xpub
|
|
102
|
-
btc?: Btc;
|
|
55
|
+
xpub: string;
|
|
103
56
|
path: string;
|
|
104
57
|
index: number;
|
|
105
58
|
currency: Currency;
|
|
@@ -113,28 +66,6 @@ class BitcoinLikeWallet {
|
|
|
113
66
|
}): Promise<Account> {
|
|
114
67
|
const crypto = cryptoFactory(params.currency);
|
|
115
68
|
|
|
116
|
-
let { xpub } = params;
|
|
117
|
-
|
|
118
|
-
if (!xpub) {
|
|
119
|
-
// Xpub not provided, generate it using the hwapp
|
|
120
|
-
|
|
121
|
-
if (!params.btc) {
|
|
122
|
-
// hwapp not provided
|
|
123
|
-
throw new Error("generateAccount need either a hwapp or xpub");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
xpub = await this.generateXpub(
|
|
127
|
-
params.btc,
|
|
128
|
-
params.currency,
|
|
129
|
-
params.path,
|
|
130
|
-
params.index
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!xpub) {
|
|
135
|
-
throw new Error("Error while generating the xpub");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
69
|
const storage = this.accountStorages[params.storage](
|
|
139
70
|
...params.storageParams
|
|
140
71
|
);
|
|
@@ -145,7 +76,7 @@ class BitcoinLikeWallet {
|
|
|
145
76
|
storage,
|
|
146
77
|
explorer,
|
|
147
78
|
crypto,
|
|
148
|
-
xpub,
|
|
79
|
+
xpub: params.xpub,
|
|
149
80
|
derivationMode: params.derivationMode,
|
|
150
81
|
}),
|
|
151
82
|
};
|
|
@@ -251,7 +182,7 @@ class BitcoinLikeWallet {
|
|
|
251
182
|
amount: BigNumber;
|
|
252
183
|
feePerByte: number;
|
|
253
184
|
utxoPickingStrategy: PickingStrategy;
|
|
254
|
-
sequence
|
|
185
|
+
sequence: number;
|
|
255
186
|
}): Promise<TransactionInfo> {
|
|
256
187
|
const changeAddress = await params.fromAccount.xpub.getNewAddress(1, 1);
|
|
257
188
|
const txInfo = await params.fromAccount.xpub.buildTx({
|
|
@@ -287,11 +218,7 @@ class BitcoinLikeWallet {
|
|
|
287
218
|
btc,
|
|
288
219
|
fromAccount,
|
|
289
220
|
txInfo,
|
|
290
|
-
lockTime,
|
|
291
|
-
sigHashType,
|
|
292
|
-
segwit,
|
|
293
221
|
additionals,
|
|
294
|
-
expiryHeight,
|
|
295
222
|
onDeviceSignatureRequested,
|
|
296
223
|
onDeviceSignatureGranted,
|
|
297
224
|
onDeviceStreaming,
|
|
@@ -327,18 +254,23 @@ class BitcoinLikeWallet {
|
|
|
327
254
|
null,
|
|
328
255
|
]);
|
|
329
256
|
|
|
257
|
+
const lastOutputIndex = txInfo.outputs.length - 1;
|
|
258
|
+
|
|
330
259
|
log("hw", `createPaymentTransactionNew`, {
|
|
260
|
+
inputs,
|
|
331
261
|
associatedKeysets,
|
|
332
262
|
outputScriptHex,
|
|
333
|
-
lockTime,
|
|
334
|
-
sigHashType,
|
|
335
|
-
segwit,
|
|
263
|
+
...(params.lockTime && { lockTime: params.lockTime }),
|
|
264
|
+
...(params.sigHashType && { sigHashType: params.sigHashType }),
|
|
265
|
+
...(params.segwit && { segwit: params.segwit }),
|
|
266
|
+
// initialTimestamp,
|
|
267
|
+
...(params.expiryHeight && { expiryHeight: params.expiryHeight }),
|
|
268
|
+
...(txInfo.outputs[lastOutputIndex]?.isChange && {
|
|
269
|
+
changePath: `${fromAccount.params.path}/${fromAccount.params.index}'/${txInfo.changeAddress.account}/${txInfo.changeAddress.index}`,
|
|
270
|
+
}),
|
|
336
271
|
additionals: additionals || [],
|
|
337
|
-
expiryHeight: expiryHeight && expiryHeight.toString("hex"),
|
|
338
272
|
});
|
|
339
273
|
|
|
340
|
-
const lastOutputIndex = txInfo.outputs.length - 1;
|
|
341
|
-
|
|
342
274
|
const tx = await btc.createPaymentTransactionNew({
|
|
343
275
|
inputs,
|
|
344
276
|
associatedKeysets,
|
|
@@ -252,7 +252,7 @@ class Xpub extends EventEmitter {
|
|
|
252
252
|
feePerByte: number;
|
|
253
253
|
changeAddress: Address;
|
|
254
254
|
utxoPickingStrategy: PickingStrategy;
|
|
255
|
-
sequence
|
|
255
|
+
sequence: number;
|
|
256
256
|
}): Promise<TransactionInfo> {
|
|
257
257
|
await this.whenSynced("all");
|
|
258
258
|
|
|
@@ -315,10 +315,7 @@ class Xpub extends EventEmitter {
|
|
|
315
315
|
address: utxo.address,
|
|
316
316
|
output_hash: utxo.output_hash,
|
|
317
317
|
output_index: utxo.output_index,
|
|
318
|
-
sequence:
|
|
319
|
-
params.sequence && Number.isInteger(params.sequence)
|
|
320
|
-
? params.sequence
|
|
321
|
-
: null,
|
|
318
|
+
sequence: params.sequence,
|
|
322
319
|
};
|
|
323
320
|
});
|
|
324
321
|
const associatedDerivations: [number, number][] = unspentUtxoSelected.map(
|
|
@@ -15,10 +15,8 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
15
15
|
});
|
|
16
16
|
const oldOperations = initialAccount?.operations || [];
|
|
17
17
|
// Needed for incremental synchronisation
|
|
18
|
-
const startAt =
|
|
19
|
-
|
|
20
|
-
? (new Date(oldOperations[0].date).getTime() / 1000 || 0) + 1
|
|
21
|
-
: 0;
|
|
18
|
+
const startAt = 0;
|
|
19
|
+
|
|
22
20
|
// get the current account balance state depending your api implementation
|
|
23
21
|
const { blockHeight, balance, nonce } = await getAccount(address);
|
|
24
22
|
// Merge new operations with the previously synced ones
|