@ledgerhq/live-common 21.5.1-btcjs.0 → 21.7.0
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/account/addAccounts.d.ts.map +1 -1
- package/lib/account/addAccounts.js +1 -2
- package/lib/account/addAccounts.js.map +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +1 -24
- package/lib/account/support.js.map +1 -1
- package/lib/api/explorerConfig/index.js +15 -15
- package/lib/bot/index.d.ts +1 -2
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +15 -19
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/test.bot.js +1 -4
- package/lib/bot/test.bot.js.map +1 -1
- package/lib/bridge/jsHelpers.d.ts +1 -6
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +3 -11
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/env.js +1 -1
- package/lib/env.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
- package/lib/exchange/swap/getExchangeRates.js +9 -8
- package/lib/exchange/swap/getExchangeRates.js.map +1 -1
- package/lib/exchange/swap/hooks/index.d.ts +11 -0
- package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/index.js +23 -0
- package/lib/exchange/swap/hooks/index.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.js +67 -0
- package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
- package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
- package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
- package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.js +73 -0
- package/lib/exchange/swap/hooks/useToState.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.js +107 -0
- package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
- package/lib/{families/bitcoin/getAccountNetworkInfo.js → exchange/swap/hooks/useUpdateMaxAmount.js} +47 -65
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
- package/lib/exchange/swap/mock.d.ts +6 -2
- package/lib/exchange/swap/mock.d.ts.map +1 -1
- package/lib/exchange/swap/mock.js +21 -6
- package/lib/exchange/swap/mock.js.map +1 -1
- package/lib/exchange/swap/types.d.ts +1 -1
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/exchange/swap/utils/index.d.ts +16 -0
- package/lib/exchange/swap/utils/index.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.js +49 -0
- package/lib/exchange/swap/utils/index.js.map +1 -0
- package/lib/exchange/swap/utils/index.test.d.ts +2 -0
- package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.test.js +238 -0
- package/lib/exchange/swap/utils/index.test.js.map +1 -0
- package/lib/families/bitcoin/account.d.ts.map +1 -1
- package/lib/families/bitcoin/account.js +2 -3
- package/lib/families/bitcoin/account.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.js +3 -3
- package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
- package/lib/families/bitcoin/serialization.d.ts +2 -2
- package/lib/families/bitcoin/serialization.d.ts.map +1 -1
- package/lib/families/bitcoin/serialization.js +4 -8
- package/lib/families/bitcoin/serialization.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts +1 -0
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +17 -8
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
- package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
- package/lib/families/bitcoin/test-dataset.js +1 -1
- package/lib/families/bitcoin/test-dataset.js.map +1 -1
- package/lib/families/bitcoin/transaction.d.ts +3 -3
- package/lib/families/bitcoin/transaction.d.ts.map +1 -1
- package/lib/families/bitcoin/transaction.js +61 -64
- package/lib/families/bitcoin/transaction.js.map +1 -1
- package/lib/families/bitcoin/types.d.ts +36 -66
- package/lib/families/bitcoin/types.d.ts.map +1 -1
- package/lib/families/bitcoin/types.js +1 -16
- package/lib/families/bitcoin/types.js.map +1 -1
- package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
- package/lib/families/crypto_org/datasets/croeseid.js +2 -6
- package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
- package/lib/families/elrond/api/apiCalls.d.ts +0 -4
- package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
- package/lib/families/elrond/api/apiCalls.js +3 -37
- package/lib/families/elrond/api/apiCalls.js.map +1 -1
- package/lib/families/elrond/api/sdk.js +2 -2
- package/lib/families/elrond/api/sdk.js.map +1 -1
- package/lib/families/elrond/js-transaction.d.ts +2 -0
- package/lib/families/elrond/js-transaction.d.ts.map +1 -1
- package/lib/families/elrond/types.d.ts +2 -0
- package/lib/families/elrond/types.d.ts.map +1 -1
- package/lib/families/elrond/types.js.map +1 -1
- package/lib/families/tezos/bridge/js.js.map +1 -1
- package/lib/generated/bridge/js.d.ts +0 -4
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +18 -20
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/specs.d.ts +1 -0
- package/lib/generated/specs.d.ts.map +1 -1
- package/lib/migrations/accounts-dataset.d.ts.map +1 -1
- package/lib/migrations/accounts-dataset.js +2 -4
- package/lib/migrations/accounts-dataset.js.map +1 -1
- package/lib/migrations/accounts.d.ts.map +1 -1
- package/lib/migrations/accounts.js +0 -17
- package/lib/migrations/accounts.js.map +1 -1
- package/lib/mock/account.d.ts +2 -1
- package/lib/mock/account.d.ts.map +1 -1
- package/lib/mock/account.js +5 -4
- package/lib/mock/account.js.map +1 -1
- package/package.json +12 -13
- package/src/.DS_Store +0 -0
- package/src/__tests__/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
- package/src/account/addAccounts.ts +1 -2
- package/src/account/support.ts +1 -24
- package/src/api/explorerConfig/index.ts +15 -15
- package/src/bot/index.ts +3 -8
- package/src/bot/test.bot.ts +1 -6
- package/src/bridge/jsHelpers.ts +2 -22
- package/src/env.ts +1 -1
- package/src/exchange/swap/getExchangeRates.ts +8 -5
- package/src/exchange/swap/hooks/index.ts +10 -0
- package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
- package/src/exchange/swap/hooks/useFromState.ts +84 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
- package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
- package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
- package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
- package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
- package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
- package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
- package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
- package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
- package/src/exchange/swap/hooks/useToState.test.ts +53 -0
- package/src/exchange/swap/hooks/useToState.ts +86 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
- package/src/exchange/swap/mock.ts +22 -3
- package/src/exchange/swap/types.ts +2 -1
- package/src/exchange/swap/utils/index.test.ts +224 -0
- package/src/exchange/swap/utils/index.ts +67 -0
- package/src/families/bitcoin/account.ts +1 -2
- package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
- package/src/families/bitcoin/datasets/litecoin.ts +6 -6
- package/src/families/bitcoin/serialization.ts +0 -6
- package/src/families/bitcoin/specs.ts +14 -5
- package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
- package/src/families/bitcoin/test-dataset.ts +1 -1
- package/src/families/bitcoin/transaction.ts +93 -98
- package/src/families/bitcoin/types.ts +37 -95
- package/src/families/crypto_org/datasets/croeseid.ts +7 -9
- package/src/families/elrond/api/apiCalls.ts +3 -31
- package/src/families/elrond/api/sdk.ts +2 -2
- package/src/families/elrond/types.ts +2 -0
- package/src/families/tezos/bridge/js.ts +1 -1
- package/src/generated/bridge/js.ts +0 -3
- package/src/migrations/accounts-dataset.ts +0 -3
- package/src/migrations/accounts.ts +0 -18
- package/src/mock/account.ts +2 -4
- package/lib/__tests__/families/bitcoin/logic.d.ts +0 -2
- package/lib/__tests__/families/bitcoin/logic.d.ts.map +0 -1
- package/lib/__tests__/families/bitcoin/logic.js +0 -39
- package/lib/__tests__/families/bitcoin/logic.js.map +0 -1
- package/lib/families/bitcoin/bridge/js.d.ts +0 -8
- package/lib/families/bitcoin/bridge/js.d.ts.map +0 -1
- package/lib/families/bitcoin/bridge/js.js +0 -149
- package/lib/families/bitcoin/bridge/js.js.map +0 -1
- package/lib/families/bitcoin/cache.d.ts +0 -28
- package/lib/families/bitcoin/cache.d.ts.map +0 -1
- package/lib/families/bitcoin/cache.js +0 -109
- package/lib/families/bitcoin/cache.js.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +0 -6
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.js.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +0 -2
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js +0 -71
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +0 -1
- package/lib/families/bitcoin/js-broadcast.d.ts +0 -11
- package/lib/families/bitcoin/js-broadcast.d.ts.map +0 -1
- package/lib/families/bitcoin/js-broadcast.js +0 -80
- package/lib/families/bitcoin/js-broadcast.js.map +0 -1
- package/lib/families/bitcoin/js-buildTransaction.d.ts +0 -5
- package/lib/families/bitcoin/js-buildTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-buildTransaction.js +0 -106
- package/lib/families/bitcoin/js-buildTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-createTransaction.d.ts +0 -9
- package/lib/families/bitcoin/js-createTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-createTransaction.js +0 -27
- package/lib/families/bitcoin/js-createTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +0 -15
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +0 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js +0 -95
- package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +0 -1
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +0 -26
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-getFeesForTransaction.js +0 -100
- package/lib/families/bitcoin/js-getFeesForTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts +0 -5
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +0 -1
- package/lib/families/bitcoin/js-getTransactionStatus.js +0 -131
- package/lib/families/bitcoin/js-getTransactionStatus.js.map +0 -1
- package/lib/families/bitcoin/js-prepareTransaction.d.ts +0 -5
- package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-prepareTransaction.js +0 -80
- package/lib/families/bitcoin/js-prepareTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-signOperation.d.ts +0 -10
- package/lib/families/bitcoin/js-signOperation.d.ts.map +0 -1
- package/lib/families/bitcoin/js-signOperation.js +0 -212
- package/lib/families/bitcoin/js-signOperation.js.map +0 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts +0 -10
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +0 -1
- package/lib/families/bitcoin/js-synchronisation.js +0 -411
- package/lib/families/bitcoin/js-synchronisation.js.map +0 -1
- package/lib/families/bitcoin/logic.d.ts +0 -34
- package/lib/families/bitcoin/logic.d.ts.map +0 -1
- package/lib/families/bitcoin/logic.js +0 -292
- package/lib/families/bitcoin/logic.js.map +0 -1
- package/lib/families/bitcoin/networks.d.ts +0 -3
- package/lib/families/bitcoin/networks.d.ts.map +0 -1
- package/lib/families/bitcoin/networks.js +0 -379
- package/lib/families/bitcoin/networks.js.map +0 -1
- package/lib/families/bitcoin/wallet.d.ts +0 -6
- package/lib/families/bitcoin/wallet.d.ts.map +0 -1
- package/lib/families/bitcoin/wallet.js +0 -66
- package/lib/families/bitcoin/wallet.js.map +0 -1
- package/src/__tests__/families/bitcoin/logic.ts +0 -40
- package/src/families/bitcoin/bridge/js.ts +0 -76
- package/src/families/bitcoin/cache.ts +0 -76
- package/src/families/bitcoin/getAccountNetworkInfo.test.ts +0 -27
- package/src/families/bitcoin/getAccountNetworkInfo.ts +0 -61
- package/src/families/bitcoin/js-broadcast.ts +0 -30
- package/src/families/bitcoin/js-buildTransaction.ts +0 -57
- package/src/families/bitcoin/js-createTransaction.ts +0 -27
- package/src/families/bitcoin/js-estimateMaxSpendable.ts +0 -36
- package/src/families/bitcoin/js-getFeesForTransaction.ts +0 -59
- package/src/families/bitcoin/js-getTransactionStatus.ts +0 -118
- package/src/families/bitcoin/js-prepareTransaction.ts +0 -35
- package/src/families/bitcoin/js-signOperation.ts +0 -164
- package/src/families/bitcoin/js-synchronisation.ts +0 -362
- package/src/families/bitcoin/logic.ts +0 -253
- package/src/families/bitcoin/networks.ts +0 -360
- package/src/families/bitcoin/wallet.ts +0 -21
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { $Shape } from "utility-types";
|
|
2
|
-
import type {
|
|
3
|
-
TX,
|
|
4
|
-
Currency,
|
|
5
|
-
Input as WalletInput,
|
|
6
|
-
Output as WalletOutput,
|
|
7
|
-
} from "@ledgerhq/wallet-btc";
|
|
8
|
-
import { DerivationModes as WalletDerivationModes } from "@ledgerhq/wallet-btc";
|
|
9
|
-
import { BigNumber } from "bignumber.js";
|
|
10
|
-
import Btc from "@ledgerhq/hw-app-btc";
|
|
11
|
-
import { log } from "@ledgerhq/logs";
|
|
12
|
-
import type {
|
|
13
|
-
Account,
|
|
14
|
-
Operation,
|
|
15
|
-
OperationType,
|
|
16
|
-
DerivationMode,
|
|
17
|
-
} from "../../types";
|
|
18
|
-
import type { GetAccountShape } from "../../bridge/jsHelpers";
|
|
19
|
-
import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";
|
|
20
|
-
import { findCurrencyExplorer } from "../../api/Ledger";
|
|
21
|
-
import { encodeOperationId } from "../../operation";
|
|
22
|
-
import { BitcoinOutput } from "./types";
|
|
23
|
-
import { perCoinLogic } from "./logic";
|
|
24
|
-
import wallet from "./wallet";
|
|
25
|
-
|
|
26
|
-
// Map LL's DerivationMode to wallet-btc's
|
|
27
|
-
const toWalletDerivationMode = (
|
|
28
|
-
mode: DerivationMode
|
|
29
|
-
): WalletDerivationModes => {
|
|
30
|
-
switch (mode) {
|
|
31
|
-
case "segwit":
|
|
32
|
-
case "segwit_on_legacy":
|
|
33
|
-
case "segwit_unsplit":
|
|
34
|
-
case "bch_on_bitcoin_segwit":
|
|
35
|
-
case "vertcoin_128_segwit":
|
|
36
|
-
return WalletDerivationModes.SEGWIT;
|
|
37
|
-
|
|
38
|
-
case "native_segwit":
|
|
39
|
-
return WalletDerivationModes.NATIVE_SEGWIT;
|
|
40
|
-
|
|
41
|
-
default:
|
|
42
|
-
return WalletDerivationModes.LEGACY;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Map LL's currency ID to wallet-btc's Account.params.network
|
|
47
|
-
const toWalletNetwork = (currencyId: string): "testnet" | "mainnet" => {
|
|
48
|
-
return ["bitcoin_testnet"].includes(currencyId) ? "testnet" : "mainnet";
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Map wallet-btc's Output to LL's BitcoinOutput
|
|
52
|
-
const fromWalletUtxo = (utxo: WalletOutput): BitcoinOutput => {
|
|
53
|
-
return {
|
|
54
|
-
hash: utxo.output_hash,
|
|
55
|
-
outputIndex: utxo.output_index,
|
|
56
|
-
blockHeight: utxo.block_height,
|
|
57
|
-
address: utxo.address,
|
|
58
|
-
value: new BigNumber(utxo.value),
|
|
59
|
-
rbf: utxo.rbf,
|
|
60
|
-
isChange: false, // wallet-btc limitation: doesn't provide it
|
|
61
|
-
path: "",
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// wallet-btc limitation: returns all transactions twice (for each side of the tx)
|
|
66
|
-
// so we need to deduplicate them...
|
|
67
|
-
const deduplicateOperations = (
|
|
68
|
-
operations: (Operation | undefined)[]
|
|
69
|
-
): Operation[] => {
|
|
70
|
-
const seen = {};
|
|
71
|
-
const out: Operation[] = [];
|
|
72
|
-
let j = 0;
|
|
73
|
-
|
|
74
|
-
for (const operation of operations) {
|
|
75
|
-
if (operation) {
|
|
76
|
-
if (seen[operation.id] !== 1) {
|
|
77
|
-
seen[operation.id] = 1;
|
|
78
|
-
out[j++] = operation;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return out;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const mapTxToOperations = (
|
|
87
|
-
tx: TX,
|
|
88
|
-
currencyId: string,
|
|
89
|
-
accountId: string,
|
|
90
|
-
accountAddresses: string[],
|
|
91
|
-
changeAddresses: string[]
|
|
92
|
-
): $Shape<Operation[]> => {
|
|
93
|
-
const operations: Operation[] = [];
|
|
94
|
-
const hash = tx.hash;
|
|
95
|
-
const fee = new BigNumber(tx.fees);
|
|
96
|
-
const blockHeight = tx.block?.height;
|
|
97
|
-
const blockHash = tx.block?.hash;
|
|
98
|
-
const date = new Date(tx.block?.time || tx.received_at);
|
|
99
|
-
const senders: string[] = [];
|
|
100
|
-
const recipients: string[] = [];
|
|
101
|
-
let type: OperationType = "OUT";
|
|
102
|
-
let value = new BigNumber(0);
|
|
103
|
-
const hasFailed = false;
|
|
104
|
-
const accountInputs: WalletInput[] = [];
|
|
105
|
-
const accountOutputs: WalletOutput[] = [];
|
|
106
|
-
const syncReplaceAddress = perCoinLogic[currencyId]?.syncReplaceAddress;
|
|
107
|
-
|
|
108
|
-
for (const input of tx.inputs) {
|
|
109
|
-
if (input.address) {
|
|
110
|
-
senders.push(
|
|
111
|
-
syncReplaceAddress ? syncReplaceAddress(input.address) : input.address
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (input.value) {
|
|
115
|
-
if (accountAddresses.includes(input.address)) {
|
|
116
|
-
// This address is part of the account
|
|
117
|
-
value = value.plus(input.value);
|
|
118
|
-
accountInputs.push(input);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// All inputs of a same transaction have the same sequence
|
|
125
|
-
const transactionSequenceNumber =
|
|
126
|
-
(accountInputs.length > 0 && accountInputs[0].sequence) || undefined;
|
|
127
|
-
const hasSpentNothing = value.eq(0);
|
|
128
|
-
|
|
129
|
-
for (const output of tx.outputs) {
|
|
130
|
-
if (output.address) {
|
|
131
|
-
if (accountAddresses.includes(output.address)) {
|
|
132
|
-
accountOutputs.push(output);
|
|
133
|
-
|
|
134
|
-
if (changeAddresses.includes(output.address)) {
|
|
135
|
-
if (
|
|
136
|
-
(recipients.length === 0 &&
|
|
137
|
-
output.output_hash ===
|
|
138
|
-
tx.outputs[tx.outputs.length - 1].output_hash) || // Is that condition safe?
|
|
139
|
-
hasSpentNothing
|
|
140
|
-
) {
|
|
141
|
-
recipients.push(
|
|
142
|
-
syncReplaceAddress
|
|
143
|
-
? syncReplaceAddress(output.address)
|
|
144
|
-
: output.address
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
recipients.push(
|
|
149
|
-
syncReplaceAddress
|
|
150
|
-
? syncReplaceAddress(output.address)
|
|
151
|
-
: output.address
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
recipients.push(
|
|
156
|
-
syncReplaceAddress
|
|
157
|
-
? syncReplaceAddress(output.address)
|
|
158
|
-
: output.address
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (accountInputs.length > 0) {
|
|
165
|
-
// It's a SEND operation
|
|
166
|
-
for (const output of accountOutputs) {
|
|
167
|
-
if (changeAddresses.includes(output.address)) {
|
|
168
|
-
value = value.minus(output.value);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
type = "OUT";
|
|
173
|
-
operations.push({
|
|
174
|
-
id: encodeOperationId(accountId, hash, type),
|
|
175
|
-
hash,
|
|
176
|
-
type,
|
|
177
|
-
value,
|
|
178
|
-
fee,
|
|
179
|
-
senders,
|
|
180
|
-
recipients,
|
|
181
|
-
blockHeight,
|
|
182
|
-
blockHash,
|
|
183
|
-
transactionSequenceNumber,
|
|
184
|
-
accountId,
|
|
185
|
-
date,
|
|
186
|
-
hasFailed,
|
|
187
|
-
extra: {},
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (accountOutputs.length > 0) {
|
|
192
|
-
// It's a RECEIVE operation
|
|
193
|
-
const filterChangeAddresses = !!accountInputs.length;
|
|
194
|
-
let accountOutputCount = 0;
|
|
195
|
-
let finalAmount = new BigNumber(0);
|
|
196
|
-
|
|
197
|
-
for (const output of accountOutputs) {
|
|
198
|
-
if (!filterChangeAddresses || !changeAddresses.includes(output.address)) {
|
|
199
|
-
finalAmount = finalAmount.plus(output.value);
|
|
200
|
-
accountOutputCount += 1;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (accountOutputCount > 0) {
|
|
205
|
-
value = finalAmount;
|
|
206
|
-
type = "IN";
|
|
207
|
-
operations.push({
|
|
208
|
-
id: encodeOperationId(accountId, hash, type),
|
|
209
|
-
hash,
|
|
210
|
-
type,
|
|
211
|
-
value,
|
|
212
|
-
fee,
|
|
213
|
-
senders,
|
|
214
|
-
recipients,
|
|
215
|
-
blockHeight,
|
|
216
|
-
blockHash,
|
|
217
|
-
transactionSequenceNumber,
|
|
218
|
-
accountId,
|
|
219
|
-
date,
|
|
220
|
-
hasFailed,
|
|
221
|
-
extra: {},
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return operations;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const getAccountShape: GetAccountShape = async (info) => {
|
|
230
|
-
const {
|
|
231
|
-
transport,
|
|
232
|
-
currency,
|
|
233
|
-
id: accountId,
|
|
234
|
-
index,
|
|
235
|
-
derivationPath,
|
|
236
|
-
derivationMode,
|
|
237
|
-
initialAccount,
|
|
238
|
-
} = info;
|
|
239
|
-
const paramXpub = initialAccount?.xpub;
|
|
240
|
-
|
|
241
|
-
// In case we get a full derivation path, extract the seed identification part
|
|
242
|
-
// 44'/0'/0'/0/0 --> 44'/0'
|
|
243
|
-
// FIXME Only the CLI provides a full derivationPath: why?
|
|
244
|
-
const rootPath = derivationPath.split("/", 2).join("/");
|
|
245
|
-
|
|
246
|
-
const walletNetwork = toWalletNetwork(currency.id);
|
|
247
|
-
const walletDerivationMode = toWalletDerivationMode(derivationMode);
|
|
248
|
-
const explorer = findCurrencyExplorer(currency);
|
|
249
|
-
if (!explorer) {
|
|
250
|
-
throw new Error(`No explorer found for currency ${currency.name}`);
|
|
251
|
-
}
|
|
252
|
-
if (explorer.version !== "v2" && explorer.version !== "v3") {
|
|
253
|
-
throw new Error(`Unsupported explorer version ${explorer.version}`);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const walletAccount = initialAccount?.bitcoinResources?.serializedData
|
|
257
|
-
? await wallet.importFromSerializedAccount(
|
|
258
|
-
initialAccount.bitcoinResources.serializedData
|
|
259
|
-
)
|
|
260
|
-
: await wallet.generateAccount({
|
|
261
|
-
btc: (!paramXpub && transport && new Btc(transport)) || undefined,
|
|
262
|
-
xpub: paramXpub,
|
|
263
|
-
path: rootPath,
|
|
264
|
-
index,
|
|
265
|
-
currency: <Currency>currency.id,
|
|
266
|
-
network: walletNetwork,
|
|
267
|
-
derivationMode: walletDerivationMode,
|
|
268
|
-
explorer: explorer && `ledger${explorer.version}`,
|
|
269
|
-
explorerURI: `${explorer.endpoint}/blockchain/${explorer.version}/${explorer.id}`,
|
|
270
|
-
storage: "mock",
|
|
271
|
-
storageParams: [],
|
|
272
|
-
});
|
|
273
|
-
const xpub = paramXpub || walletAccount.xpub.xpub;
|
|
274
|
-
const oldOperations = initialAccount?.operations || [];
|
|
275
|
-
await wallet.syncAccount(walletAccount);
|
|
276
|
-
const balance = await wallet.getAccountBalance(walletAccount);
|
|
277
|
-
const currentBlock = await walletAccount.xpub.explorer.getCurrentBlock();
|
|
278
|
-
const blockHeight = currentBlock?.height;
|
|
279
|
-
|
|
280
|
-
// @ts-expect-error return from wallet-btc should be typed
|
|
281
|
-
const { txs: transactions } = await wallet.getAccountTransactions(
|
|
282
|
-
walletAccount
|
|
283
|
-
);
|
|
284
|
-
const accountAddressesWithInfo = await walletAccount.xpub.getXpubAddresses();
|
|
285
|
-
const accountAddresses = accountAddressesWithInfo
|
|
286
|
-
? accountAddressesWithInfo.map((a) => a.address)
|
|
287
|
-
: [];
|
|
288
|
-
const changeAddressesWithInfo =
|
|
289
|
-
await walletAccount.xpub.storage.getUniquesAddresses({
|
|
290
|
-
account: 1,
|
|
291
|
-
});
|
|
292
|
-
const changeAddresses = changeAddressesWithInfo
|
|
293
|
-
? changeAddressesWithInfo.map((a) => a.address)
|
|
294
|
-
: [];
|
|
295
|
-
const newOperations = transactions
|
|
296
|
-
?.map((tx) =>
|
|
297
|
-
mapTxToOperations(
|
|
298
|
-
tx,
|
|
299
|
-
currency.id,
|
|
300
|
-
accountId,
|
|
301
|
-
accountAddresses,
|
|
302
|
-
changeAddresses
|
|
303
|
-
)
|
|
304
|
-
)
|
|
305
|
-
.flat();
|
|
306
|
-
const newUniqueOperations = deduplicateOperations(newOperations);
|
|
307
|
-
const operations = mergeOps(oldOperations, newUniqueOperations);
|
|
308
|
-
const rawUtxos = await wallet.getAccountUnspentUtxos(walletAccount);
|
|
309
|
-
const utxos = rawUtxos.map(fromWalletUtxo);
|
|
310
|
-
const serializedData = await wallet.exportToSerializedAccount(walletAccount);
|
|
311
|
-
return {
|
|
312
|
-
id: accountId,
|
|
313
|
-
xpub,
|
|
314
|
-
balance,
|
|
315
|
-
spendableBalance: balance,
|
|
316
|
-
operations,
|
|
317
|
-
operationsCount: operations.length,
|
|
318
|
-
blockHeight,
|
|
319
|
-
bitcoinResources: {
|
|
320
|
-
utxos,
|
|
321
|
-
serializedData,
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
const postSync = (initial: Account, synced: Account) => {
|
|
327
|
-
log("bitcoin/postSync", "bitcoinResources");
|
|
328
|
-
const perCoin = perCoinLogic[synced.currency.id];
|
|
329
|
-
|
|
330
|
-
if (perCoin) {
|
|
331
|
-
const { postBuildBitcoinResources, syncReplaceAddress } = perCoin;
|
|
332
|
-
|
|
333
|
-
if (postBuildBitcoinResources) {
|
|
334
|
-
synced.bitcoinResources = postBuildBitcoinResources(
|
|
335
|
-
synced,
|
|
336
|
-
synced.bitcoinResources
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (syncReplaceAddress) {
|
|
341
|
-
synced.freshAddress = syncReplaceAddress(synced.freshAddress);
|
|
342
|
-
synced.freshAddresses = synced.freshAddresses.map((a) => ({
|
|
343
|
-
...a,
|
|
344
|
-
address: syncReplaceAddress(a.address),
|
|
345
|
-
}));
|
|
346
|
-
if (synced.bitcoinResources) {
|
|
347
|
-
synced.bitcoinResources.utxos = synced.bitcoinResources?.utxos.map(
|
|
348
|
-
(u) => ({
|
|
349
|
-
...u,
|
|
350
|
-
address: u.address && syncReplaceAddress(u.address),
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
log("bitcoin/postSync", "bitcoinResources DONE");
|
|
358
|
-
return synced;
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
export const scanAccounts = makeScanAccounts(getAccountShape);
|
|
362
|
-
export const sync = makeSync(getAccountShape, postSync);
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import cashaddr from "cashaddrjs";
|
|
2
|
-
import bchaddr from "bchaddrjs";
|
|
3
|
-
import { isValidAddress } from "@ledgerhq/wallet-btc";
|
|
4
|
-
import { RecipientRequired, InvalidAddress } from "@ledgerhq/errors";
|
|
5
|
-
import type { Account, CryptoCurrency, CryptoCurrencyIds } from "./../../types";
|
|
6
|
-
import type {
|
|
7
|
-
BitcoinOutput,
|
|
8
|
-
BitcoinResources,
|
|
9
|
-
Transaction,
|
|
10
|
-
NetworkInfo,
|
|
11
|
-
UtxoStrategy,
|
|
12
|
-
CoreBitcoinLikeOutput,
|
|
13
|
-
CoreBitcoinLikeInput,
|
|
14
|
-
BitcoinInput,
|
|
15
|
-
} from "./types";
|
|
16
|
-
import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
|
|
17
|
-
|
|
18
|
-
// correspond ~ to min relay fees but determined empirically for a tx to be accepted by network
|
|
19
|
-
const minFees = {
|
|
20
|
-
bitcoin: 1000,
|
|
21
|
-
bitcoin_gold: 1000,
|
|
22
|
-
pivx: 2000,
|
|
23
|
-
stakenet: 1000,
|
|
24
|
-
stealthcoin: 2000,
|
|
25
|
-
qtum: 4000,
|
|
26
|
-
stratis: 2000,
|
|
27
|
-
vertcoin: 2000,
|
|
28
|
-
viacoin: 2000,
|
|
29
|
-
peercoin: 2000,
|
|
30
|
-
};
|
|
31
|
-
export const getMinRelayFee = (currency: CryptoCurrency): number =>
|
|
32
|
-
minFees[currency.id] || 0;
|
|
33
|
-
export const inferFeePerByte = (t: Transaction, networkInfo: NetworkInfo) => {
|
|
34
|
-
if (t.feesStrategy) {
|
|
35
|
-
const speed = networkInfo.feeItems.items.find(
|
|
36
|
-
(item) => t.feesStrategy === item.speed
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (!speed) {
|
|
40
|
-
return networkInfo.feeItems.defaultFeePerByte;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return speed.feePerByte;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return t.feePerByte || networkInfo.feeItems.defaultFeePerByte;
|
|
47
|
-
};
|
|
48
|
-
export const isValidRecipient = async (params: {
|
|
49
|
-
currency: CryptoCurrency;
|
|
50
|
-
recipient: string;
|
|
51
|
-
}): Promise<Error | null | undefined> => {
|
|
52
|
-
if (!params.recipient) {
|
|
53
|
-
return Promise.reject(new RecipientRequired(""));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let valid: boolean;
|
|
57
|
-
try {
|
|
58
|
-
// Optimistically assume params.currency.id is an actual Currency
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
60
|
-
// @ts-ignore halp
|
|
61
|
-
valid = isValidAddress(params.recipient, params.currency.id);
|
|
62
|
-
} catch (e: any) {
|
|
63
|
-
// isValidAddress() will throw Error if c is not an actual Currency
|
|
64
|
-
return Promise.reject(new InvalidAddress(e.message));
|
|
65
|
-
}
|
|
66
|
-
if (!valid) {
|
|
67
|
-
return Promise.reject(
|
|
68
|
-
new InvalidAddress("Invalid address for currency " + params.currency.name)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
return Promise.resolve(null);
|
|
72
|
-
};
|
|
73
|
-
export function isChangeOutput(output: BitcoinOutput): boolean {
|
|
74
|
-
if (!output.path) return false;
|
|
75
|
-
const p = output.path.split("/");
|
|
76
|
-
return p[p.length - 2] === "1";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type UTXOStatus =
|
|
80
|
-
| {
|
|
81
|
-
excluded: true;
|
|
82
|
-
reason: "pickUnconfirmedRBF" | "userExclusion";
|
|
83
|
-
}
|
|
84
|
-
| {
|
|
85
|
-
excluded: false;
|
|
86
|
-
};
|
|
87
|
-
export const getUTXOStatus = (
|
|
88
|
-
utxo: BitcoinOutput,
|
|
89
|
-
utxoStrategy: UtxoStrategy
|
|
90
|
-
): UTXOStatus => {
|
|
91
|
-
if (!utxoStrategy.pickUnconfirmedRBF && utxo.rbf && !utxo.blockHeight) {
|
|
92
|
-
return {
|
|
93
|
-
excluded: true,
|
|
94
|
-
reason: "pickUnconfirmedRBF",
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
utxoStrategy.excludeUTXOs.some(
|
|
100
|
-
(u) => u.hash === utxo.hash && u.outputIndex === utxo.outputIndex
|
|
101
|
-
)
|
|
102
|
-
) {
|
|
103
|
-
return {
|
|
104
|
-
excluded: true,
|
|
105
|
-
reason: "userExclusion",
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
excluded: false,
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const bchExplicit = (str: string): string => {
|
|
115
|
-
const explicit = str.includes(":") ? str : "bitcoincash:" + str;
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
const { type } = cashaddr.decode(explicit);
|
|
119
|
-
if (type === "P2PKH") return explicit;
|
|
120
|
-
} catch (e) {
|
|
121
|
-
// ignore errors
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return str;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
type CoinLogic = {
|
|
128
|
-
hasExtraData?: boolean;
|
|
129
|
-
hasExpiryHeight?: boolean;
|
|
130
|
-
getAdditionals?: (arg0: { transaction: Transaction }) => string[];
|
|
131
|
-
asExplicitTransactionRecipient?: (arg0: string) => string;
|
|
132
|
-
onScreenTransactionRecipient?: (arg0: string) => string;
|
|
133
|
-
postBuildBitcoinResources?: (
|
|
134
|
-
arg0: Account,
|
|
135
|
-
arg1?: BitcoinResources
|
|
136
|
-
) => BitcoinResources;
|
|
137
|
-
syncReplaceAddress?: (addr: string) => string;
|
|
138
|
-
injectGetAddressParams?: (arg0: Account) => any;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const bchToCashaddrAddressWithoutPrefix = (recipient) =>
|
|
142
|
-
recipient ? bchaddr.toCashAddress(recipient).split(":")[1] : recipient;
|
|
143
|
-
|
|
144
|
-
export const perCoinLogic: Record<
|
|
145
|
-
CryptoCurrencyIds,
|
|
146
|
-
CoinLogic | null | undefined
|
|
147
|
-
> = {
|
|
148
|
-
zencash: {
|
|
149
|
-
hasExtraData: true, // FIXME (legacy) investigate why we need this here and drop
|
|
150
|
-
},
|
|
151
|
-
zcash: {
|
|
152
|
-
hasExtraData: true,
|
|
153
|
-
hasExpiryHeight: true,
|
|
154
|
-
getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
|
|
155
|
-
},
|
|
156
|
-
komodo: {
|
|
157
|
-
hasExtraData: true,
|
|
158
|
-
hasExpiryHeight: true,
|
|
159
|
-
getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
|
|
160
|
-
},
|
|
161
|
-
decred: {
|
|
162
|
-
hasExpiryHeight: true,
|
|
163
|
-
},
|
|
164
|
-
bitcoin_gold: {
|
|
165
|
-
getAdditionals: () => ["bip143"],
|
|
166
|
-
},
|
|
167
|
-
bitcoin_cash: {
|
|
168
|
-
getAdditionals: ({ transaction }) => {
|
|
169
|
-
const additionals = ["bip143"];
|
|
170
|
-
|
|
171
|
-
if (bchExplicit(transaction.recipient).startsWith("bitcoincash:")) {
|
|
172
|
-
additionals.push("cashaddr");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return additionals;
|
|
176
|
-
},
|
|
177
|
-
// Due to minimal support, we need to return the explicit format of bitcoincash:.. if it's a P2PKH
|
|
178
|
-
asExplicitTransactionRecipient: bchExplicit,
|
|
179
|
-
// to represent what happens on the device, which do not display the bitcoincash: prefix
|
|
180
|
-
onScreenTransactionRecipient: (str: string): string => {
|
|
181
|
-
const prefix = "bitcoincash:";
|
|
182
|
-
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
183
|
-
},
|
|
184
|
-
syncReplaceAddress: (addr) => bchToCashaddrAddressWithoutPrefix(addr),
|
|
185
|
-
injectGetAddressParams: () => ({
|
|
186
|
-
forceFormat: "cashaddr",
|
|
187
|
-
}),
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
|
|
192
|
-
|
|
193
|
-
export async function parseBitcoinInput(
|
|
194
|
-
input: CoreBitcoinLikeInput
|
|
195
|
-
): Promise<BitcoinInput> {
|
|
196
|
-
const address = await input.getAddress();
|
|
197
|
-
const rawValue = await input.getValue();
|
|
198
|
-
const value = rawValue ? await libcoreAmountToBigNumber(rawValue) : null;
|
|
199
|
-
const previousTxHash = await input.getPreviousTxHash();
|
|
200
|
-
const previousOutputIndex = await input.getPreviousOutputIndex();
|
|
201
|
-
return {
|
|
202
|
-
address,
|
|
203
|
-
value,
|
|
204
|
-
previousTxHash,
|
|
205
|
-
previousOutputIndex,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export async function parseBitcoinOutput(
|
|
210
|
-
output: CoreBitcoinLikeOutput
|
|
211
|
-
): Promise<BitcoinOutput> {
|
|
212
|
-
let blockHeight = await output.getBlockHeight();
|
|
213
|
-
|
|
214
|
-
if (!blockHeight || blockHeight < 0) {
|
|
215
|
-
blockHeight = undefined;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const hash = await output.getTransactionHash();
|
|
219
|
-
const outputIndex = await output.getOutputIndex();
|
|
220
|
-
const address = await output.getAddress();
|
|
221
|
-
const derivationPath = await output.getDerivationPath();
|
|
222
|
-
let path;
|
|
223
|
-
|
|
224
|
-
if (derivationPath) {
|
|
225
|
-
const isDerivationPathNull = await derivationPath.isNull();
|
|
226
|
-
|
|
227
|
-
if (!isDerivationPathNull) {
|
|
228
|
-
path = await derivationPath.toString();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const value = await libcoreAmountToBigNumber(await output.getValue());
|
|
233
|
-
const rbf = false; // this is unsafe to generically call this at the moment. libcore segfault.
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
hash,
|
|
237
|
-
outputIndex,
|
|
238
|
-
blockHeight,
|
|
239
|
-
address,
|
|
240
|
-
isChange: false,
|
|
241
|
-
path,
|
|
242
|
-
value,
|
|
243
|
-
rbf,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export async function parseBitcoinUTXO(
|
|
248
|
-
output: CoreBitcoinLikeOutput
|
|
249
|
-
): Promise<BitcoinOutput> {
|
|
250
|
-
const utxo = await parseBitcoinOutput(output);
|
|
251
|
-
utxo.rbf = await output.isReplaceable();
|
|
252
|
-
return utxo;
|
|
253
|
-
}
|