@ledgerhq/live-common 21.16.0 → 21.16.4

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.
Files changed (187) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +95 -7
  2. package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
  3. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js +1 -1
  4. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js.map +1 -1
  5. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +2 -2
  6. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
  7. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js +20 -10
  8. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js.map +1 -1
  9. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js +1 -1
  10. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js.map +1 -1
  11. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js +1 -1
  12. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js.map +1 -1
  13. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js +2 -2
  14. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js.map +1 -1
  15. package/lib/account/formatters.d.ts.map +1 -1
  16. package/lib/account/formatters.js +33 -1
  17. package/lib/account/formatters.js.map +1 -1
  18. package/lib/apps/polyfill.d.ts.map +1 -1
  19. package/lib/apps/polyfill.js +3 -0
  20. package/lib/apps/polyfill.js.map +1 -1
  21. package/lib/currencies/support.d.ts.map +1 -1
  22. package/lib/currencies/support.js.map +1 -1
  23. package/lib/families/bitcoin/bech32m.d.ts +22 -0
  24. package/lib/families/bitcoin/bech32m.d.ts.map +1 -0
  25. package/lib/families/bitcoin/bech32m.js +166 -0
  26. package/lib/families/bitcoin/bech32m.js.map +1 -0
  27. package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
  28. package/lib/families/bitcoin/datasets/bitcoin.js +4 -0
  29. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  30. package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
  31. package/lib/families/bitcoin/datasets/bitcoin_cash.js +4 -0
  32. package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
  33. package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
  34. package/lib/families/bitcoin/datasets/bitcoin_gold.js +4 -0
  35. package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
  36. package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
  37. package/lib/families/bitcoin/datasets/dash.js +4 -0
  38. package/lib/families/bitcoin/datasets/dash.js.map +1 -1
  39. package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
  40. package/lib/families/bitcoin/datasets/decred.js +4 -0
  41. package/lib/families/bitcoin/datasets/decred.js.map +1 -1
  42. package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
  43. package/lib/families/bitcoin/datasets/digibyte.js +4 -0
  44. package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
  45. package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
  46. package/lib/families/bitcoin/datasets/dogecoin.js +4 -0
  47. package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
  48. package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
  49. package/lib/families/bitcoin/datasets/komodo.js +4 -0
  50. package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
  51. package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
  52. package/lib/families/bitcoin/datasets/litecoin.js +4 -0
  53. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  54. package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
  55. package/lib/families/bitcoin/datasets/peercoin.js +4 -0
  56. package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
  57. package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
  58. package/lib/families/bitcoin/datasets/pivx.js +4 -0
  59. package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
  60. package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
  61. package/lib/families/bitcoin/datasets/qtum.js +4 -0
  62. package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
  63. package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
  64. package/lib/families/bitcoin/datasets/stakenet.js +4 -0
  65. package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
  66. package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
  67. package/lib/families/bitcoin/datasets/vertcoin.js +4 -0
  68. package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
  69. package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
  70. package/lib/families/bitcoin/datasets/viacoin.js +4 -0
  71. package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
  72. package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
  73. package/lib/families/bitcoin/datasets/zcash.js +4 -0
  74. package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
  75. package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
  76. package/lib/families/bitcoin/datasets/zencash.js +4 -0
  77. package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
  78. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -1
  79. package/lib/families/bitcoin/js-buildTransaction.js +1 -1
  80. package/lib/families/bitcoin/js-buildTransaction.js.map +1 -1
  81. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -1
  82. package/lib/families/bitcoin/js-estimateMaxSpendable.js +1 -1
  83. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -1
  84. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  85. package/lib/families/bitcoin/js-synchronisation.js +31 -8
  86. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  87. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
  88. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +11 -11
  89. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
  90. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  91. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +2 -1
  92. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  93. package/lib/families/bitcoin/wallet-btc/crypto/digibyte.js +21 -2
  94. package/lib/families/bitcoin/wallet-btc/crypto/digibyte.js.map +1 -1
  95. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +2 -2
  96. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  97. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  98. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +3 -2
  99. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  100. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  101. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +3 -2
  102. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  103. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +2 -1
  104. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
  105. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +16 -12
  106. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
  107. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +2 -1
  108. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
  109. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +12 -7
  110. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
  111. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +2 -1
  112. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
  113. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +12 -7
  114. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
  115. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts +2 -1
  116. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts.map +1 -1
  117. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.js.map +1 -1
  118. package/lib/families/bitcoin/wallet-btc/utils.d.ts +38 -2
  119. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  120. package/lib/families/bitcoin/wallet-btc/utils.js +103 -35
  121. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  122. package/lib/families/bitcoin/wallet-btc/wallet.d.ts +1 -1
  123. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  124. package/lib/families/bitcoin/wallet-btc/wallet.js +9 -8
  125. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  126. package/lib/families/bitcoin/wallet-btc/xpub.js +2 -2
  127. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  128. package/lib/families/elrond/logic.js +22 -3
  129. package/lib/families/elrond/logic.js.map +1 -1
  130. package/lib/nft/NftMetadataProvider/index.d.ts +7 -0
  131. package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -1
  132. package/lib/nft/NftMetadataProvider/index.js +3 -3
  133. package/lib/nft/NftMetadataProvider/index.js.map +1 -1
  134. package/lib/operation.js +1 -1
  135. package/lib/operation.js.map +1 -1
  136. package/package.json +10 -10
  137. package/src/.DS_Store +0 -0
  138. package/src/__tests__/__snapshots__/all.libcore.ts.snap +1243 -123478
  139. package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +109 -2
  140. package/src/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.ts +3 -2
  141. package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
  142. package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts +35 -31
  143. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.ts +3 -2
  144. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.ts +3 -2
  145. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.ts +6 -4
  146. package/src/account/formatters.ts +43 -0
  147. package/src/apps/polyfill.ts +3 -0
  148. package/src/currencies/.DS_Store +0 -0
  149. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +3 -1
  150. package/src/currencies/support.ts +1 -0
  151. package/src/families/bitcoin/bech32m.ts +197 -0
  152. package/src/families/bitcoin/datasets/bitcoin.ts +4 -0
  153. package/src/families/bitcoin/datasets/bitcoin_cash.ts +4 -0
  154. package/src/families/bitcoin/datasets/bitcoin_gold.ts +4 -0
  155. package/src/families/bitcoin/datasets/dash.ts +4 -0
  156. package/src/families/bitcoin/datasets/decred.ts +4 -0
  157. package/src/families/bitcoin/datasets/digibyte.ts +4 -0
  158. package/src/families/bitcoin/datasets/dogecoin.ts +4 -0
  159. package/src/families/bitcoin/datasets/komodo.ts +4 -0
  160. package/src/families/bitcoin/datasets/litecoin.ts +4 -0
  161. package/src/families/bitcoin/datasets/peercoin.ts +4 -0
  162. package/src/families/bitcoin/datasets/pivx.ts +4 -0
  163. package/src/families/bitcoin/datasets/qtum.ts +4 -0
  164. package/src/families/bitcoin/datasets/stakenet.ts +4 -0
  165. package/src/families/bitcoin/datasets/vertcoin.ts +4 -0
  166. package/src/families/bitcoin/datasets/viacoin.ts +4 -0
  167. package/src/families/bitcoin/datasets/zcash.ts +4 -0
  168. package/src/families/bitcoin/datasets/zencash.ts +4 -0
  169. package/src/families/bitcoin/js-buildTransaction.ts +2 -1
  170. package/src/families/bitcoin/js-estimateMaxSpendable.ts +2 -1
  171. package/src/families/bitcoin/js-synchronisation.ts +39 -11
  172. package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +5 -4
  173. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +2 -1
  174. package/src/families/bitcoin/wallet-btc/crypto/digibyte.ts +1 -1
  175. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +1 -1
  176. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +3 -2
  177. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +3 -2
  178. package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +34 -22
  179. package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +30 -9
  180. package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +30 -9
  181. package/src/families/bitcoin/wallet-btc/pickingstrategies/types.ts +3 -3
  182. package/src/families/bitcoin/wallet-btc/utils.ts +113 -41
  183. package/src/families/bitcoin/wallet-btc/wallet.ts +10 -8
  184. package/src/families/bitcoin/wallet-btc/xpub.ts +5 -5
  185. package/src/families/elrond/logic.ts +1 -1
  186. package/src/nft/NftMetadataProvider/index.tsx +1 -1
  187. package/src/operation.ts +1 -1
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "bitcoin_cash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "bitcoin_gold seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "dash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "decred seed 1",
@@ -27,6 +27,10 @@ const networkInfo: NetworkInfoRaw = {
27
27
  },
28
28
  };
29
29
  const dataset: CurrenciesData<Transaction> = {
30
+ FIXME_ignoreAccountFields: [
31
+ "bitcoinResources.walletAccount", // it is not "stable"
32
+ "bitcoinResources.utxos", // TODO: fix ordering
33
+ ],
30
34
  scanAccounts: [scanAccounts1],
31
35
  accounts: [
32
36
  {
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "dogecoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "komodo seed 1",
@@ -27,6 +27,10 @@ const networkInfo: NetworkInfoRaw = {
27
27
  },
28
28
  };
29
29
  const dataset: CurrenciesData<Transaction> = {
30
+ FIXME_ignoreAccountFields: [
31
+ "bitcoinResources.walletAccount", // it is not "stable"
32
+ "bitcoinResources.utxos", // TODO: fix ordering
33
+ ],
30
34
  scanAccounts: [scanAccounts1],
31
35
  accounts: [
32
36
  {
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "peercoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "pivx seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "qtum seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "stakenet seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "vertcoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "viacoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "zcash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "zencash seed 1",
@@ -44,7 +44,8 @@ export const buildTransaction = async (
44
44
  walletAccount,
45
45
  transaction.feePerByte.toNumber(), //!\ wallet-btc handles fees as JS number
46
46
  transaction.utxoStrategy.excludeUTXOs,
47
- transaction.utxoStrategy.pickUnconfirmedRBF
47
+ transaction.utxoStrategy.pickUnconfirmedRBF,
48
+ [transaction.recipient]
48
49
  );
49
50
  log("btcwallet", "building transaction", transaction);
50
51
  const txInfo = await wallet.buildAccountTx({
@@ -30,7 +30,8 @@ const estimateMaxSpendable = async ({
30
30
  walletAccount,
31
31
  feePerByte.toNumber(), //!\ wallet-btc handles fees as JS number
32
32
  transaction?.utxoStrategy?.excludeUTXOs || [],
33
- transaction?.utxoStrategy?.pickUnconfirmedRBF || false
33
+ transaction?.utxoStrategy?.pickUnconfirmedRBF || false,
34
+ transaction ? [transaction.recipient] : []
34
35
  );
35
36
  return maxSpendable.lt(0) ? new BigNumber(0) : maxSpendable;
36
37
  };
@@ -129,24 +129,52 @@ const mapTxToOperations = (
129
129
  const transactionSequenceNumber =
130
130
  (accountInputs.length > 0 && accountInputs[0].sequence) || undefined;
131
131
 
132
- // Change output is the last one
132
+ const hasSpentNothing = value.eq(0);
133
+ // Change output is always the last one
133
134
  const changeOutputIndex = tx.outputs
134
135
  .map((o) => o.output_index)
135
136
  .reduce((p, c) => (p > c ? p : c));
136
137
 
137
138
  for (const output of tx.outputs) {
138
139
  if (output.address) {
139
- if (accountAddresses.includes(output.address)) {
140
+ if (!accountAddresses.includes(output.address)) {
141
+ // The output doesn't belong to this account
142
+ if (
143
+ tx.outputs.length === 1 || // The transaction has only 1 output
144
+ output.output_index < changeOutputIndex // The output isn't the change output
145
+ ) {
146
+ recipients.push(
147
+ syncReplaceAddress
148
+ ? syncReplaceAddress(output.address)
149
+ : output.address
150
+ );
151
+ }
152
+ } else {
153
+ // The output belongs to this account
140
154
  accountOutputs.push(output);
141
- } else if (
142
- !changeAddresses.includes(output.address) ||
143
- output.output_index !== changeOutputIndex
144
- ) {
145
- recipients.push(
146
- syncReplaceAddress
147
- ? syncReplaceAddress(output.address)
148
- : output.address
149
- );
155
+
156
+ if (!changeAddresses.includes(output.address)) {
157
+ // The output isn't a change output of this account
158
+ recipients.push(
159
+ syncReplaceAddress
160
+ ? syncReplaceAddress(output.address)
161
+ : output.address
162
+ );
163
+ } else {
164
+ // The output is a change output of this account,
165
+ // we count it as a recipient only in some special cases
166
+ if (
167
+ (recipients.length === 0 &&
168
+ output.output_index >= changeOutputIndex) ||
169
+ hasSpentNothing
170
+ ) {
171
+ recipients.push(
172
+ syncReplaceAddress
173
+ ? syncReplaceAddress(output.address)
174
+ : output.address
175
+ );
176
+ }
177
+ }
150
178
  }
151
179
  }
152
180
  }
@@ -1,9 +1,10 @@
1
1
  // from https://github.com/LedgerHQ/xpub-scan/blob/master/src/actions/deriveAddresses.ts
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-ignore
4
- import { bech32, bech32m } from "bech32";
2
+
3
+ import * as bech32 from "bech32";
4
+ import { bech32m } from "../../bech32m";
5
5
  import * as bjs from "bitcoinjs-lib";
6
6
  import { publicKeyTweakAdd } from "secp256k1";
7
+ import { InvalidAddress } from "@ledgerhq/errors";
7
8
  import { DerivationModes } from "../types";
8
9
  import Base from "./base";
9
10
 
@@ -87,7 +88,7 @@ class Bitcoin extends Base {
87
88
  // Make sure the address is valid on this network
88
89
  // otherwise we can't call toOutputScriptTemporary.
89
90
  if (!this.validateAddress(address)) {
90
- throw new Error("Invalid address");
91
+ throw new InvalidAddress();
91
92
  }
92
93
  // bitcoinjs-lib/src/address doesn't yet have released support for bech32m,
93
94
  // so we'll implement our own version of toOutputScript while waiting.
@@ -5,6 +5,7 @@ import bchaddr from "bchaddrjs";
5
5
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
6
  // @ts-ignore
7
7
  import { toOutputScript } from "bitcoinjs-lib/src/address";
8
+ import { InvalidAddress } from "@ledgerhq/errors";
8
9
  import { DerivationModes } from "../types";
9
10
  import { ICrypto } from "./types";
10
11
 
@@ -60,7 +61,7 @@ class BitcoinCash implements ICrypto {
60
61
 
61
62
  toOutputScript(address: string) {
62
63
  if (!this.validateAddress(address)) {
63
- throw new Error("Invalid address");
64
+ throw new InvalidAddress();
64
65
  }
65
66
  // TODO find a better way to calculate the script from bch address instead of converting to bitcoin address
66
67
  return toOutputScript(bchaddr.toLegacyAddress(address), this.network);
@@ -1,4 +1,4 @@
1
- import { bech32 } from "bech32";
1
+ import * as bech32 from "bech32";
2
2
  import bs58check from "bs58check";
3
3
  import Base from "./base";
4
4
 
@@ -3,7 +3,7 @@ import * as bip32 from "bip32";
3
3
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
4
  // @ts-ignore
5
5
  import { toOutputScript } from "bitcoinjs-lib/src/address";
6
- import { bech32 } from "bech32";
6
+ import * as bech32 from "bech32";
7
7
  import { DerivationModes } from "../types";
8
8
  import { ICrypto } from "./types";
9
9
  import Base from "./base";
@@ -5,9 +5,10 @@ import { toOutputScript } from "bitcoinjs-lib/src/address";
5
5
  // @ts-ignore
6
6
  import zec from "zcash-bitcore-lib";
7
7
  import bs58check from "bs58check";
8
+ import coininfo from "coininfo";
9
+ import { InvalidAddress } from "@ledgerhq/errors";
8
10
  import { DerivationModes } from "../types";
9
11
  import { ICrypto } from "./types";
10
- import coininfo from "coininfo";
11
12
 
12
13
  class ZCash implements ICrypto {
13
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -61,7 +62,7 @@ class ZCash implements ICrypto {
61
62
 
62
63
  toOutputScript(address: string) {
63
64
  if (!this.validateAddress(address)) {
64
- throw new Error("Invalid address");
65
+ throw new InvalidAddress();
65
66
  }
66
67
  // TODO find a better way to calculate the script from zec address instead of converting to bitcoin address
67
68
  return toOutputScript(
@@ -5,9 +5,10 @@ import { toOutputScript } from "bitcoinjs-lib/src/address";
5
5
  // @ts-ignore
6
6
  import zec from "zcash-bitcore-lib";
7
7
  import bs58check from "bs58check";
8
+ import coininfo from "coininfo";
9
+ import { InvalidAddress } from "@ledgerhq/errors";
8
10
  import { DerivationModes } from "../types";
9
11
  import { ICrypto } from "./types";
10
- import coininfo from "coininfo";
11
12
 
12
13
  class Zen implements ICrypto {
13
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -81,7 +82,7 @@ class Zen implements ICrypto {
81
82
 
82
83
  toOutputScript(address: string) {
83
84
  if (!this.validateAddress(address)) {
84
- throw new Error("Invalid address");
85
+ throw new InvalidAddress();
85
86
  }
86
87
  // TODO find a better way to calculate the script from zen address instead of converting to bitcoin address
87
88
  return toOutputScript(
@@ -7,14 +7,14 @@ import { PickingStrategy } from "./types";
7
7
  import * as utils from "../utils";
8
8
  import { DeepFirst } from "./DeepFirst";
9
9
  import { log } from "@ledgerhq/logs";
10
+ import { OutputInfo } from "..";
10
11
 
11
12
  export class CoinSelect extends PickingStrategy {
12
13
  // eslint-disable-next-line class-methods-use-this
13
14
  async selectUnspentUtxosToUse(
14
15
  xpub: Xpub,
15
- amount: BigNumber,
16
- feePerByte: number,
17
- nbOutputsWithoutChange: number
16
+ outputs: OutputInfo[],
17
+ feePerByte: number
18
18
  ) {
19
19
  // get the utxos to use as input
20
20
  // from all addresses of the account
@@ -34,18 +34,30 @@ export class CoinSelect extends PickingStrategy {
34
34
  const TOTAL_TRIES = 100000;
35
35
  log("picking strategy", "utxos", unspentUtxos);
36
36
  // Compute cost of change
37
- const fixedSize = utils.accurateTxSize(
38
- 0,
37
+ const fixedSize = utils.maxTxSize(
39
38
  0,
39
+ [],
40
+ false,
40
41
  this.crypto,
41
42
  this.derivationMode
42
43
  );
44
+ const outputAddresses = outputs.map((o) => o.address);
43
45
  // Size of only 1 output (without fixed size)
44
46
  const oneOutputSize =
45
- utils.accurateTxSize(0, 1, this.crypto, this.derivationMode) - fixedSize;
47
+ outputAddresses.length > 0
48
+ ? utils.maxTxSize(
49
+ 0,
50
+ [outputAddresses[0]],
51
+ false,
52
+ this.crypto,
53
+ this.derivationMode
54
+ ) - fixedSize
55
+ : utils.maxTxSize(0, [], true, this.crypto, this.derivationMode) -
56
+ fixedSize;
46
57
  // Size 1 signed UTXO (signed input)
47
58
  const oneInputSize =
48
- utils.accurateTxSize(1, 0, this.crypto, this.derivationMode) - fixedSize;
59
+ utils.maxTxSize(1, [], false, this.crypto, this.derivationMode) -
60
+ fixedSize;
49
61
 
50
62
  // Calculate effective value of outputs
51
63
  let currentAvailableValue = 0;
@@ -70,12 +82,16 @@ export class CoinSelect extends PickingStrategy {
70
82
  // Get no inputs fees
71
83
  // At beginning, there are no outputs in tx, so noInputFees are fixed fees
72
84
  const notInputFees =
73
- feePerByte * (fixedSize + oneOutputSize * nbOutputsWithoutChange);
85
+ feePerByte * (fixedSize + oneOutputSize * outputs.length);
74
86
 
75
87
  // Start coin selection algorithm (according to SelectCoinBnb from Bitcoin Core)
76
88
  let currentValue = 0;
77
89
  const currentSelection: boolean[] = [];
78
90
 
91
+ const amount = outputs.reduce(
92
+ (sum, output) => sum.plus(output.value),
93
+ new BigNumber(0)
94
+ );
79
95
  // Actual amount we are targetting
80
96
  const actualTarget = notInputFees + amount.toNumber();
81
97
 
@@ -102,9 +118,10 @@ export class CoinSelect extends PickingStrategy {
102
118
  currentSelectionNeedChangeoutput = true;
103
119
  currentWaste =
104
120
  feePerByte *
105
- utils.estimateTxSize(
121
+ utils.maxTxSizeCeil(
106
122
  nbInput,
107
- nbOutputsWithoutChange + 1,
123
+ outputAddresses,
124
+ true,
108
125
  this.crypto,
109
126
  this.derivationMode
110
127
  );
@@ -113,9 +130,10 @@ export class CoinSelect extends PickingStrategy {
113
130
  currentSelectionNeedChangeoutput = false;
114
131
  currentWaste =
115
132
  feePerByte *
116
- utils.estimateTxSize(
133
+ utils.maxTxSizeCeil(
117
134
  nbInput,
118
- nbOutputsWithoutChange,
135
+ outputAddresses,
136
+ false,
119
137
  this.crypto,
120
138
  this.derivationMode
121
139
  ) +
@@ -170,11 +188,10 @@ export class CoinSelect extends PickingStrategy {
170
188
  }
171
189
  const fee =
172
190
  feePerByte *
173
- utils.estimateTxSize(
191
+ utils.maxTxSizeCeil(
174
192
  unspentUtxoSelected.length,
175
- bestSelectionNeedChangeoutput
176
- ? nbOutputsWithoutChange + 1
177
- : nbOutputsWithoutChange,
193
+ outputAddresses,
194
+ bestSelectionNeedChangeoutput,
178
195
  this.crypto,
179
196
  this.derivationMode
180
197
  );
@@ -191,11 +208,6 @@ export class CoinSelect extends PickingStrategy {
191
208
  this.derivationMode,
192
209
  this.excludedUTXOs
193
210
  );
194
- return pickingStrategy.selectUnspentUtxosToUse(
195
- xpub,
196
- amount,
197
- feePerByte,
198
- nbOutputsWithoutChange
199
- );
211
+ return pickingStrategy.selectUnspentUtxosToUse(xpub, outputs, feePerByte);
200
212
  }
201
213
  }
@@ -6,14 +6,14 @@ import Xpub from "../xpub";
6
6
  import { PickingStrategy } from "./types";
7
7
  import * as utils from "../utils";
8
8
  import { log } from "@ledgerhq/logs";
9
+ import { OutputInfo } from "..";
9
10
 
10
11
  export class DeepFirst extends PickingStrategy {
11
12
  // eslint-disable-next-line class-methods-use-this
12
13
  async selectUnspentUtxosToUse(
13
14
  xpub: Xpub,
14
- amount: BigNumber,
15
- feePerByte: number,
16
- nbOutputsWithoutChange: number
15
+ outputs: OutputInfo[],
16
+ feePerByte: number
17
17
  ) {
18
18
  // get the utxos to use as input
19
19
  // from all addresses of the account
@@ -31,26 +31,47 @@ export class DeepFirst extends PickingStrategy {
31
31
  ).length
32
32
  );
33
33
 
34
+ const outputAddresses = outputs.map((o) => o.address);
34
35
  unspentUtxos = sortBy(unspentUtxos, "block_height");
35
36
  // https://metamug.com/article/security/bitcoin-transaction-fee-satoshi-per-byte.html
36
- const txSizeNoInput = utils.accurateTxSize(
37
+ const txSizeNoInput = utils.maxTxSize(
37
38
  0,
38
- nbOutputsWithoutChange,
39
+ outputAddresses,
40
+ false,
39
41
  this.crypto,
40
42
  this.derivationMode
41
43
  );
42
44
  let fee = txSizeNoInput * feePerByte;
45
+ const emptyTxSize = utils.maxTxSizeCeil(
46
+ 0,
47
+ [],
48
+ false,
49
+ this.crypto,
50
+ this.derivationMode
51
+ );
43
52
  const sizePerInput =
44
- utils.accurateTxSize(1, 0, this.crypto, this.derivationMode) -
45
- utils.accurateTxSize(0, 0, this.crypto, this.derivationMode);
53
+ utils.maxTxSize(1, [], false, this.crypto, this.derivationMode) -
54
+ emptyTxSize;
46
55
 
47
56
  const sizePerOutput =
48
- utils.accurateTxSize(0, 1, this.crypto, this.derivationMode) -
49
- utils.accurateTxSize(0, 0, this.crypto, this.derivationMode);
57
+ (outputAddresses[0]
58
+ ? utils.maxTxSize(
59
+ 0,
60
+ [outputAddresses[0]],
61
+ false,
62
+ this.crypto,
63
+ this.derivationMode
64
+ )
65
+ : utils.maxTxSize(0, [], true, this.crypto, this.derivationMode)) -
66
+ emptyTxSize;
50
67
 
51
68
  let total = new BigNumber(0);
52
69
  const unspentUtxoSelected: Output[] = [];
53
70
 
71
+ const amount = outputs.reduce(
72
+ (sum, output) => sum.plus(output.value),
73
+ new BigNumber(0)
74
+ );
54
75
  let i = 0;
55
76
  while (total.lt(amount.plus(fee))) {
56
77
  if (!unspentUtxos[i]) {
@@ -6,14 +6,14 @@ import Xpub from "../xpub";
6
6
  import { PickingStrategy } from "./types";
7
7
  import * as utils from "../utils";
8
8
  import { log } from "@ledgerhq/logs";
9
+ import { OutputInfo } from "..";
9
10
 
10
11
  export class Merge extends PickingStrategy {
11
12
  // eslint-disable-next-line class-methods-use-this
12
13
  async selectUnspentUtxosToUse(
13
14
  xpub: Xpub,
14
- amount: BigNumber,
15
- feePerByte: number,
16
- nbOutputsWithoutChange: number
15
+ outputs: OutputInfo[],
16
+ feePerByte: number
17
17
  ) {
18
18
  // get the utxos to use as input
19
19
  // from all addresses of the account
@@ -31,19 +31,36 @@ export class Merge extends PickingStrategy {
31
31
  ).length
32
32
  );
33
33
 
34
+ const outputAddresses = outputs.map((o) => o.address);
35
+ const emptyTxSize = utils.maxTxSizeCeil(
36
+ 0,
37
+ [],
38
+ false,
39
+ this.crypto,
40
+ this.derivationMode
41
+ );
34
42
  const sizePerInput =
35
- utils.accurateTxSize(1, 0, this.crypto, this.derivationMode) -
36
- utils.accurateTxSize(0, 0, this.crypto, this.derivationMode);
43
+ utils.maxTxSize(1, [], false, this.crypto, this.derivationMode) -
44
+ emptyTxSize;
37
45
 
38
46
  const sizePerOutput =
39
- utils.accurateTxSize(0, 1, this.crypto, this.derivationMode) -
40
- utils.accurateTxSize(0, 0, this.crypto, this.derivationMode);
47
+ (outputAddresses[0]
48
+ ? utils.maxTxSize(
49
+ 0,
50
+ [outputAddresses[0]],
51
+ false,
52
+ this.crypto,
53
+ this.derivationMode
54
+ )
55
+ : utils.maxTxSize(0, [], true, this.crypto, this.derivationMode)) -
56
+ emptyTxSize;
41
57
 
42
58
  unspentUtxos = sortBy(unspentUtxos, (utxo) => parseInt(utxo.value, 10));
43
59
  // https://metamug.com/article/security/bitcoin-transaction-fee-satoshi-per-byte.html
44
- const txSizeNoInput = utils.accurateTxSize(
60
+ const txSizeNoInput = utils.maxTxSize(
45
61
  0,
46
- nbOutputsWithoutChange,
62
+ outputAddresses,
63
+ false,
47
64
  this.crypto,
48
65
  this.derivationMode
49
66
  );
@@ -53,6 +70,10 @@ export class Merge extends PickingStrategy {
53
70
  const unspentUtxoSelected: Output[] = [];
54
71
 
55
72
  let i = 0;
73
+ const amount = outputs.reduce(
74
+ (sum, output) => sum.plus(output.value),
75
+ new BigNumber(0)
76
+ );
56
77
  while (total.lt(amount.plus(fee))) {
57
78
  if (!unspentUtxos[i]) {
58
79
  throw new NotEnoughBalance();