@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,27 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import { avoidDups } from "./getAccountNetworkInfo";
|
|
3
|
-
test("avoidFeeDupsInFeePerByte [3,2,2] => [4,3,2]", async () => {
|
|
4
|
-
expect(
|
|
5
|
-
avoidDups([new BigNumber(3), new BigNumber(3), new BigNumber(2)])
|
|
6
|
-
).toEqual([new BigNumber(4), new BigNumber(3), new BigNumber(2)]);
|
|
7
|
-
});
|
|
8
|
-
test("avoidFeeDupsInFeePerByte [2,2,1] => [3,2,1]", async () => {
|
|
9
|
-
expect(
|
|
10
|
-
avoidDups([new BigNumber(2), new BigNumber(2), new BigNumber(1)])
|
|
11
|
-
).toEqual([new BigNumber(3), new BigNumber(2), new BigNumber(1)]);
|
|
12
|
-
});
|
|
13
|
-
test("avoidFeeDupsInFeePerByte [3,3,3] => [5,4,3]", async () => {
|
|
14
|
-
expect(
|
|
15
|
-
avoidDups([new BigNumber(3), new BigNumber(3), new BigNumber(3)])
|
|
16
|
-
).toEqual([new BigNumber(5), new BigNumber(4), new BigNumber(3)]);
|
|
17
|
-
});
|
|
18
|
-
test("avoidFeeDupsInFeePerByte [3,2,1] => [3,2,1]", async () => {
|
|
19
|
-
expect(
|
|
20
|
-
avoidDups([new BigNumber(3), new BigNumber(2), new BigNumber(1)])
|
|
21
|
-
).toEqual([new BigNumber(3), new BigNumber(2), new BigNumber(1)]);
|
|
22
|
-
});
|
|
23
|
-
test("avoidFeeDupsInFeePerByte [100,100,1] => [101,100,1]", async () => {
|
|
24
|
-
expect(
|
|
25
|
-
avoidDups([new BigNumber(100), new BigNumber(100), new BigNumber(1)])
|
|
26
|
-
).toEqual([new BigNumber(101), new BigNumber(100), new BigNumber(1)]);
|
|
27
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import flow from "lodash/flow";
|
|
2
|
-
import { BigNumber } from "bignumber.js";
|
|
3
|
-
import type { Account } from "../../types";
|
|
4
|
-
import type { NetworkInfo } from "./types";
|
|
5
|
-
import { getWalletAccount } from "./wallet";
|
|
6
|
-
const speeds = ["fast", "medium", "slow"];
|
|
7
|
-
export function avoidDups(nums: Array<BigNumber>): Array<BigNumber> {
|
|
8
|
-
nums = nums.slice(0);
|
|
9
|
-
|
|
10
|
-
for (let i = nums.length - 2; i >= 0; i--) {
|
|
11
|
-
if (nums[i + 1].gte(nums[i])) {
|
|
12
|
-
nums[i] = nums[i + 1].plus(1);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return nums;
|
|
17
|
-
}
|
|
18
|
-
export async function getAccountNetworkInfo(
|
|
19
|
-
account: Account
|
|
20
|
-
): Promise<NetworkInfo> {
|
|
21
|
-
const walletAccount = await getWalletAccount(account);
|
|
22
|
-
const rawFees = await walletAccount.xpub.explorer.getFees();
|
|
23
|
-
// Convoluted logic to convert from:
|
|
24
|
-
// { "2": 2435, "3": 1241, "6": 1009, "last_updated": 1627973170 }
|
|
25
|
-
// to:
|
|
26
|
-
// { 2435, 1241, 1009 }
|
|
27
|
-
const feesPerByte = flow([
|
|
28
|
-
// Remove the 'last_updated' key
|
|
29
|
-
Object.entries,
|
|
30
|
-
(entries) => entries.filter(([key]) => !isNaN(key)),
|
|
31
|
-
// Reconstruct the array with only the values
|
|
32
|
-
Object.fromEntries,
|
|
33
|
-
Object.values,
|
|
34
|
-
// Safety against invalid data
|
|
35
|
-
(f) => f.filter((f) => f != null && typeof f === "number"),
|
|
36
|
-
// Normalize values
|
|
37
|
-
(f) =>
|
|
38
|
-
f.map((f) =>
|
|
39
|
-
new BigNumber(f).div(1000).integerValue(BigNumber.ROUND_CEIL)
|
|
40
|
-
),
|
|
41
|
-
avoidDups,
|
|
42
|
-
])(rawFees);
|
|
43
|
-
|
|
44
|
-
if (feesPerByte.length !== 3) {
|
|
45
|
-
throw new Error("cardinality of feesPerByte should be exactly 3");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const feeItems = {
|
|
49
|
-
items: feesPerByte.map((feePerByte, i) => ({
|
|
50
|
-
key: String(i),
|
|
51
|
-
speed: speeds[i],
|
|
52
|
-
feePerByte,
|
|
53
|
-
})),
|
|
54
|
-
defaultFeePerByte:
|
|
55
|
-
feesPerByte[Math.floor(feesPerByte.length / 2)] || new BigNumber(0),
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
family: "bitcoin",
|
|
59
|
-
feeItems,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { patchOperationWithHash } from "./../../operation";
|
|
2
|
-
import type { Account, Operation, SignedOperation } from "./../../types";
|
|
3
|
-
import wallet from "./wallet";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Broadcast a signed transaction
|
|
7
|
-
* @param {signature: string, operation: string} signedOperation
|
|
8
|
-
*/
|
|
9
|
-
const broadcast = async ({
|
|
10
|
-
account,
|
|
11
|
-
signedOperation,
|
|
12
|
-
}: {
|
|
13
|
-
account: Account;
|
|
14
|
-
signedOperation: SignedOperation;
|
|
15
|
-
}): Promise<Operation> => {
|
|
16
|
-
const { signature, operation } = signedOperation;
|
|
17
|
-
const walletData = account.bitcoinResources?.serializedData;
|
|
18
|
-
if (!walletData) {
|
|
19
|
-
throw new Error("bitcoin wallet account expected");
|
|
20
|
-
}
|
|
21
|
-
const walletAccount = await wallet.importFromSerializedAccount(walletData);
|
|
22
|
-
try {
|
|
23
|
-
const hash = await wallet.broadcastTx(walletAccount, signature);
|
|
24
|
-
return patchOperationWithHash(operation, hash);
|
|
25
|
-
} catch (error: any) {
|
|
26
|
-
throw new Error(error); // TODO Improve error message for broadcast failure cases
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default broadcast;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Account as WalletAccount } from "@ledgerhq/wallet-btc";
|
|
2
|
-
import { CoinSelect, DeepFirst, Merge } from "@ledgerhq/wallet-btc";
|
|
3
|
-
import type { TransactionInfo as WalletTxInfo } from "@ledgerhq/wallet-btc";
|
|
4
|
-
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
5
|
-
|
|
6
|
-
import type { Account } from "../../types";
|
|
7
|
-
import type { Transaction, UtxoStrategy } from "./types";
|
|
8
|
-
import { bitcoinPickingStrategy } from "./types";
|
|
9
|
-
import wallet, { getWalletAccount } from "./wallet";
|
|
10
|
-
|
|
11
|
-
const selectUtxoPickingStrategy = (
|
|
12
|
-
walletAccount: WalletAccount,
|
|
13
|
-
utxoStrategy: UtxoStrategy
|
|
14
|
-
) => {
|
|
15
|
-
const handler = {
|
|
16
|
-
[bitcoinPickingStrategy.MERGE_OUTPUTS]: Merge,
|
|
17
|
-
[bitcoinPickingStrategy.DEEP_OUTPUTS_FIRST]: DeepFirst,
|
|
18
|
-
[bitcoinPickingStrategy.OPTIMIZE_SIZE]: CoinSelect,
|
|
19
|
-
}[utxoStrategy.strategy];
|
|
20
|
-
if (!handler) throw new Error("Unsupported Bitcoin UTXO picking strategy");
|
|
21
|
-
|
|
22
|
-
return new handler(
|
|
23
|
-
walletAccount.xpub.crypto,
|
|
24
|
-
walletAccount.xpub.derivationMode,
|
|
25
|
-
utxoStrategy.excludeUTXOs
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const buildTransaction = async (
|
|
30
|
-
account: Account,
|
|
31
|
-
transaction: Transaction
|
|
32
|
-
): Promise<WalletTxInfo> => {
|
|
33
|
-
if (!transaction.feePerByte) {
|
|
34
|
-
throw new FeeNotLoaded();
|
|
35
|
-
}
|
|
36
|
-
const walletAccount = await getWalletAccount(account);
|
|
37
|
-
const utxoPickingStrategy = selectUtxoPickingStrategy(
|
|
38
|
-
walletAccount,
|
|
39
|
-
transaction.utxoStrategy
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const maxSpendable = await wallet.estimateAccountMaxSpendable(
|
|
43
|
-
walletAccount,
|
|
44
|
-
transaction.feePerByte.toNumber() //!\ wallet-btc handles fees as JS number
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const txInfo = await wallet.buildAccountTx({
|
|
48
|
-
fromAccount: walletAccount,
|
|
49
|
-
dest: transaction.recipient,
|
|
50
|
-
amount: transaction.useAllAmount ? maxSpendable : transaction.amount,
|
|
51
|
-
feePerByte: transaction.feePerByte.toNumber(), //!\ wallet-btc handles fees as JS number
|
|
52
|
-
utxoPickingStrategy,
|
|
53
|
-
// Definition of replaceable, per the standard: https://github.com/bitcoin/bips/blob/61ccc84930051e5b4a99926510d0db4a8475a4e6/bip-0125.mediawiki#summary
|
|
54
|
-
sequence: transaction.rbf ? 0 : 0xffffffff,
|
|
55
|
-
});
|
|
56
|
-
return txInfo;
|
|
57
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import type { Transaction } from "./types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create an empty transaction
|
|
6
|
-
*
|
|
7
|
-
* @returns {Transaction}
|
|
8
|
-
*/
|
|
9
|
-
const createTransaction = (): Transaction => {
|
|
10
|
-
return {
|
|
11
|
-
family: "bitcoin",
|
|
12
|
-
amount: new BigNumber(0),
|
|
13
|
-
utxoStrategy: {
|
|
14
|
-
strategy: 0,
|
|
15
|
-
pickUnconfirmedRBF: false,
|
|
16
|
-
excludeUTXOs: [],
|
|
17
|
-
},
|
|
18
|
-
recipient: "",
|
|
19
|
-
rbf: false,
|
|
20
|
-
feePerByte: null,
|
|
21
|
-
networkInfo: null,
|
|
22
|
-
useAllAmount: false,
|
|
23
|
-
feesStrategy: "medium",
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default createTransaction;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import type { AccountLike, Account } from "../../types";
|
|
3
|
-
import type { Transaction } from "./types";
|
|
4
|
-
import { getMainAccount } from "../../account";
|
|
5
|
-
import wallet, { getWalletAccount } from "./wallet";
|
|
6
|
-
import { getAccountNetworkInfo } from "./getAccountNetworkInfo";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns the maximum possible amount for transaction
|
|
10
|
-
*
|
|
11
|
-
* @param {Object} param - the account, parentAccount and transaction
|
|
12
|
-
*/
|
|
13
|
-
const estimateMaxSpendable = async ({
|
|
14
|
-
account,
|
|
15
|
-
parentAccount,
|
|
16
|
-
transaction,
|
|
17
|
-
}: {
|
|
18
|
-
account: AccountLike;
|
|
19
|
-
parentAccount: Account | null | undefined;
|
|
20
|
-
transaction: Transaction | null | undefined;
|
|
21
|
-
}): Promise<BigNumber> => {
|
|
22
|
-
const mainAccount = getMainAccount(account, parentAccount);
|
|
23
|
-
const walletAccount = await getWalletAccount(mainAccount);
|
|
24
|
-
let feePerByte = transaction?.feePerByte;
|
|
25
|
-
if (!feePerByte) {
|
|
26
|
-
const networkInfo = await getAccountNetworkInfo(mainAccount);
|
|
27
|
-
feePerByte = networkInfo.feeItems.defaultFeePerByte;
|
|
28
|
-
}
|
|
29
|
-
const maxSpendable = await wallet.estimateAccountMaxSpendable(
|
|
30
|
-
walletAccount,
|
|
31
|
-
feePerByte.toNumber() //!\ wallet-btc handles fees as JS number
|
|
32
|
-
);
|
|
33
|
-
return maxSpendable.lt(0) ? new BigNumber(0) : maxSpendable;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default estimateMaxSpendable;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import type { Account } from "./../../types";
|
|
3
|
-
import type { Transaction } from "./types";
|
|
4
|
-
import { buildTransaction } from "./js-buildTransaction";
|
|
5
|
-
import { perCoinLogic } from "./logic";
|
|
6
|
-
|
|
7
|
-
const getFeesForTransaction = async ({
|
|
8
|
-
account,
|
|
9
|
-
transaction,
|
|
10
|
-
}: {
|
|
11
|
-
account: Account;
|
|
12
|
-
transaction: Transaction;
|
|
13
|
-
}) => {
|
|
14
|
-
const walletTx = await buildTransaction(account, transaction);
|
|
15
|
-
const fees = new BigNumber(walletTx.fee).integerValue();
|
|
16
|
-
let txInputs = walletTx.inputs.map((i) => {
|
|
17
|
-
return {
|
|
18
|
-
address: i.address,
|
|
19
|
-
value: new BigNumber(i.value),
|
|
20
|
-
previousTxHash: i.output_hash,
|
|
21
|
-
previousOutputIndex: i.output_index,
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
let txOutputs = walletTx.outputs.map((o) => {
|
|
25
|
-
return {
|
|
26
|
-
outputIndex: walletTx.outputs.indexOf(o),
|
|
27
|
-
address: o.address,
|
|
28
|
-
isChange: o.isChange,
|
|
29
|
-
value: new BigNumber(o.value),
|
|
30
|
-
hash: undefined,
|
|
31
|
-
blockHeight: undefined,
|
|
32
|
-
rbf: transaction.rbf,
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
const perCoin = perCoinLogic[account.currency.id];
|
|
36
|
-
|
|
37
|
-
if (perCoin) {
|
|
38
|
-
const { syncReplaceAddress } = perCoin;
|
|
39
|
-
|
|
40
|
-
if (syncReplaceAddress) {
|
|
41
|
-
txInputs = txInputs.map((i) => ({
|
|
42
|
-
...i,
|
|
43
|
-
address: i.address && syncReplaceAddress(i.address),
|
|
44
|
-
}));
|
|
45
|
-
txOutputs = txOutputs.map((o) => ({
|
|
46
|
-
...o,
|
|
47
|
-
address: o.address && syncReplaceAddress(o.address),
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
fees,
|
|
54
|
-
txInputs,
|
|
55
|
-
txOutputs,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default getFeesForTransaction;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import { log } from "@ledgerhq/logs";
|
|
3
|
-
import {
|
|
4
|
-
AmountRequired,
|
|
5
|
-
NotEnoughBalance,
|
|
6
|
-
FeeNotLoaded,
|
|
7
|
-
FeeTooHigh,
|
|
8
|
-
FeeRequired,
|
|
9
|
-
} from "@ledgerhq/errors";
|
|
10
|
-
import { LowerThanMinimumRelayFee } from "./../../errors";
|
|
11
|
-
import type { Account, TransactionStatus } from "./../../types";
|
|
12
|
-
import type { Transaction } from "./types";
|
|
13
|
-
import { calculateFees, validateRecipient } from "./cache";
|
|
14
|
-
import { getMinRelayFee } from "./logic";
|
|
15
|
-
|
|
16
|
-
const getTransactionStatus = async (
|
|
17
|
-
a: Account,
|
|
18
|
-
t: Transaction
|
|
19
|
-
): Promise<TransactionStatus> => {
|
|
20
|
-
const errors: any = {};
|
|
21
|
-
const warnings: any = {};
|
|
22
|
-
const useAllAmount = !!t.useAllAmount;
|
|
23
|
-
const { recipientError, recipientWarning } = await validateRecipient(
|
|
24
|
-
a.currency,
|
|
25
|
-
t.recipient
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (recipientError) {
|
|
29
|
-
errors.recipient = recipientError;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (recipientWarning) {
|
|
33
|
-
warnings.recipient = recipientWarning;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let txInputs;
|
|
37
|
-
let txOutputs;
|
|
38
|
-
let estimatedFees = new BigNumber(0);
|
|
39
|
-
|
|
40
|
-
if (!t.feePerByte) {
|
|
41
|
-
errors.feePerByte = new FeeNotLoaded();
|
|
42
|
-
} else if (t.feePerByte.eq(0)) {
|
|
43
|
-
errors.feePerByte = new FeeRequired();
|
|
44
|
-
} else if (t.recipient && !errors.recipient) {
|
|
45
|
-
await calculateFees({
|
|
46
|
-
account: a,
|
|
47
|
-
transaction: t,
|
|
48
|
-
}).then(
|
|
49
|
-
(res) => {
|
|
50
|
-
txInputs = res.txInputs;
|
|
51
|
-
txOutputs = res.txOutputs;
|
|
52
|
-
estimatedFees = res.fees;
|
|
53
|
-
},
|
|
54
|
-
(error) => {
|
|
55
|
-
if (error.name === "NotEnoughBalance") {
|
|
56
|
-
errors.amount = error;
|
|
57
|
-
} else {
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const sumOfInputs = (txInputs || []).reduce(
|
|
65
|
-
(sum, input) => sum.plus(input.value),
|
|
66
|
-
new BigNumber(0)
|
|
67
|
-
);
|
|
68
|
-
const sumOfChanges = (txOutputs || [])
|
|
69
|
-
.filter((o) => o.isChange)
|
|
70
|
-
.reduce((sum, output) => sum.plus(output.value), new BigNumber(0));
|
|
71
|
-
|
|
72
|
-
if (txInputs) {
|
|
73
|
-
log("bitcoin", `${txInputs.length} inputs, sum: ${sumOfInputs.toString()}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (txOutputs) {
|
|
77
|
-
log(
|
|
78
|
-
"bitcoin",
|
|
79
|
-
`${txOutputs.length} outputs, sum of changes: ${sumOfChanges.toString()}`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const totalSpent = sumOfInputs.minus(sumOfChanges);
|
|
84
|
-
const amount = useAllAmount ? totalSpent.minus(estimatedFees) : t.amount;
|
|
85
|
-
log(
|
|
86
|
-
"bitcoin",
|
|
87
|
-
`totalSpent ${totalSpent.toString()} amount ${amount.toString()}`
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
if (!errors.amount && !amount.gt(0)) {
|
|
91
|
-
errors.amount = useAllAmount
|
|
92
|
-
? new NotEnoughBalance()
|
|
93
|
-
: new AmountRequired();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
process.env.EXPERIMENTAL_MIN_RELAY_FEE &&
|
|
98
|
-
estimatedFees &&
|
|
99
|
-
estimatedFees.gt(0) &&
|
|
100
|
-
estimatedFees.lt(getMinRelayFee(a.currency))
|
|
101
|
-
) {
|
|
102
|
-
warnings.feePerByte = new LowerThanMinimumRelayFee();
|
|
103
|
-
} else if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
|
|
104
|
-
warnings.feeTooHigh = new FeeTooHigh();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return Promise.resolve({
|
|
108
|
-
errors,
|
|
109
|
-
warnings,
|
|
110
|
-
estimatedFees,
|
|
111
|
-
amount,
|
|
112
|
-
totalSpent,
|
|
113
|
-
txInputs,
|
|
114
|
-
txOutputs,
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export default getTransactionStatus;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import invariant from "invariant";
|
|
2
|
-
import type { Account } from "../../types";
|
|
3
|
-
import type { Transaction } from "./types";
|
|
4
|
-
import { getAccountNetworkInfo } from "./getAccountNetworkInfo";
|
|
5
|
-
import { inferFeePerByte } from "./logic";
|
|
6
|
-
|
|
7
|
-
const prepareTransaction = async (
|
|
8
|
-
a: Account,
|
|
9
|
-
t: Transaction
|
|
10
|
-
): Promise<Transaction> => {
|
|
11
|
-
let networkInfo = t.networkInfo;
|
|
12
|
-
|
|
13
|
-
if (!networkInfo) {
|
|
14
|
-
networkInfo = await getAccountNetworkInfo(a);
|
|
15
|
-
invariant(networkInfo.family === "bitcoin", "bitcoin networkInfo expected");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const feePerByte = inferFeePerByte(t, networkInfo);
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
t.networkInfo === networkInfo &&
|
|
22
|
-
(feePerByte === t.feePerByte || feePerByte.eq(t.feePerByte || 0))
|
|
23
|
-
) {
|
|
24
|
-
// nothing changed
|
|
25
|
-
return t;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
...t,
|
|
30
|
-
networkInfo,
|
|
31
|
-
feePerByte,
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default prepareTransaction;
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import { Observable } from "rxjs";
|
|
3
|
-
import Btc from "@ledgerhq/hw-app-btc";
|
|
4
|
-
import { log } from "@ledgerhq/logs";
|
|
5
|
-
import type { Account, Operation, SignOperationEvent } from "./../../types";
|
|
6
|
-
import { isSegwitDerivationMode } from "./../../derivation";
|
|
7
|
-
import { encodeOperationId } from "./../../operation";
|
|
8
|
-
import { open, close } from "./../../hw";
|
|
9
|
-
import type { Transaction } from "./types";
|
|
10
|
-
import { getNetworkParameters } from "./networks";
|
|
11
|
-
import { buildTransaction } from "./js-buildTransaction";
|
|
12
|
-
import { calculateFees } from "./cache";
|
|
13
|
-
import wallet, { getWalletAccount } from "./wallet";
|
|
14
|
-
import { perCoinLogic } from "./logic";
|
|
15
|
-
|
|
16
|
-
const signOperation = ({
|
|
17
|
-
account,
|
|
18
|
-
deviceId,
|
|
19
|
-
transaction,
|
|
20
|
-
}: {
|
|
21
|
-
account: Account;
|
|
22
|
-
deviceId: any;
|
|
23
|
-
transaction: Transaction;
|
|
24
|
-
}): Observable<SignOperationEvent> =>
|
|
25
|
-
Observable.create((o) => {
|
|
26
|
-
async function main() {
|
|
27
|
-
const { currency } = account;
|
|
28
|
-
const transport = await open(deviceId);
|
|
29
|
-
const hwApp = new Btc(transport);
|
|
30
|
-
const walletAccount = await getWalletAccount(account);
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
log("hw", `signTransaction ${currency.id} for account ${account.id}`);
|
|
34
|
-
const txInfo = await buildTransaction(account, transaction);
|
|
35
|
-
let senders: string[] = [];
|
|
36
|
-
let recipients: string[] = [];
|
|
37
|
-
let fee = new BigNumber(0);
|
|
38
|
-
// Maybe better not re-calculate these fields here, instead include them
|
|
39
|
-
// in Transaction type and set them in prepareTransaction?
|
|
40
|
-
await calculateFees({
|
|
41
|
-
account,
|
|
42
|
-
transaction,
|
|
43
|
-
}).then((res) => {
|
|
44
|
-
senders = res.txInputs
|
|
45
|
-
.map((i) => i.address)
|
|
46
|
-
.filter(Boolean) as string[];
|
|
47
|
-
recipients = res.txOutputs
|
|
48
|
-
.map((o) => o.address)
|
|
49
|
-
.filter(Boolean) as string[];
|
|
50
|
-
fee = res.fees;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// FIXME (legacy)
|
|
54
|
-
// should be `transaction.getLockTime()` as soon as lock time is
|
|
55
|
-
// handled by libcore (actually: it always returns a default value
|
|
56
|
-
// and that caused issue with zcash (see #904))
|
|
57
|
-
// cf. https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/transaction_builders/BitcoinLikeUtxoPicker.cpp#L156-L159
|
|
58
|
-
let lockTime;
|
|
59
|
-
|
|
60
|
-
// (legacy) Set lockTime for Komodo to enable reward claiming on UTXOs created by
|
|
61
|
-
// Ledger Live. We should only set this if the currency is Komodo and
|
|
62
|
-
// lockTime isn't already defined.
|
|
63
|
-
if (currency.id === "komodo" && lockTime === undefined) {
|
|
64
|
-
const unixtime = Math.floor(Date.now() / 1000);
|
|
65
|
-
lockTime = unixtime - 777;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const networkParams = getNetworkParameters(currency.id);
|
|
69
|
-
const sigHashType = networkParams.sigHash;
|
|
70
|
-
if (isNaN(sigHashType)) {
|
|
71
|
-
throw new Error("sigHashType should not be NaN");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const segwit = isSegwitDerivationMode(account.derivationMode);
|
|
75
|
-
|
|
76
|
-
// FIXME Call to explorer needed to set timestamp
|
|
77
|
-
// cf. https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/transaction_builders/BitcoinLikeUtxoPicker.cpp#L150-L154
|
|
78
|
-
/*
|
|
79
|
-
const hasTimestamp = networkParams.usesTimestampedTransaction;
|
|
80
|
-
const initialTimestamp = hasTimestamp
|
|
81
|
-
? transaction.timestamp
|
|
82
|
-
: undefined;
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
const perCoin = perCoinLogic[currency.id];
|
|
86
|
-
let additionals = [currency.id];
|
|
87
|
-
|
|
88
|
-
if (account.derivationMode === "native_segwit") {
|
|
89
|
-
additionals.push("bech32");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (perCoin?.getAdditionals) {
|
|
93
|
-
additionals = additionals.concat(
|
|
94
|
-
perCoin.getAdditionals({
|
|
95
|
-
transaction,
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const expiryHeight = perCoin?.hasExpiryHeight
|
|
101
|
-
? Buffer.from([0x00, 0x00, 0x00, 0x00])
|
|
102
|
-
: undefined;
|
|
103
|
-
|
|
104
|
-
const signature = await wallet.signAccountTx({
|
|
105
|
-
btc: hwApp,
|
|
106
|
-
fromAccount: walletAccount,
|
|
107
|
-
txInfo,
|
|
108
|
-
lockTime,
|
|
109
|
-
sigHashType,
|
|
110
|
-
segwit,
|
|
111
|
-
//initialTimestamp,
|
|
112
|
-
additionals,
|
|
113
|
-
expiryHeight,
|
|
114
|
-
onDeviceSignatureGranted: () =>
|
|
115
|
-
o.next({
|
|
116
|
-
type: "device-signature-granted",
|
|
117
|
-
}),
|
|
118
|
-
onDeviceSignatureRequested: () =>
|
|
119
|
-
o.next({
|
|
120
|
-
type: "device-signature-requested",
|
|
121
|
-
}),
|
|
122
|
-
onDeviceStreaming: ({ progress, index, total }) =>
|
|
123
|
-
o.next({
|
|
124
|
-
type: "device-streaming",
|
|
125
|
-
progress,
|
|
126
|
-
index,
|
|
127
|
-
total,
|
|
128
|
-
}),
|
|
129
|
-
});
|
|
130
|
-
// Build the optimistic operation
|
|
131
|
-
const operation: Operation = {
|
|
132
|
-
id: encodeOperationId(account.id, "", "OUT"),
|
|
133
|
-
hash: "", // Will be resolved in broadcast()
|
|
134
|
-
type: "OUT",
|
|
135
|
-
value: new BigNumber(transaction.amount).plus(fee),
|
|
136
|
-
fee,
|
|
137
|
-
blockHash: null,
|
|
138
|
-
blockHeight: null,
|
|
139
|
-
senders,
|
|
140
|
-
recipients,
|
|
141
|
-
accountId: account.id,
|
|
142
|
-
date: new Date(),
|
|
143
|
-
extra: {},
|
|
144
|
-
};
|
|
145
|
-
o.next({
|
|
146
|
-
type: "signed",
|
|
147
|
-
signedOperation: {
|
|
148
|
-
operation,
|
|
149
|
-
signature,
|
|
150
|
-
expirationDate: null,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
} finally {
|
|
154
|
-
close(transport, deviceId);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
main().then(
|
|
159
|
-
() => o.complete(),
|
|
160
|
-
(e) => o.error(e)
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
export default signOperation;
|