@ledgerhq/live-common 21.14.1 → 21.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +85 -0
  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/account/groupOperations.js +1 -1
  19. package/lib/account/groupOperations.js.map +1 -1
  20. package/lib/account/pending.d.ts +1 -0
  21. package/lib/account/pending.d.ts.map +1 -1
  22. package/lib/account/serialization.d.ts +6 -4
  23. package/lib/account/serialization.d.ts.map +1 -1
  24. package/lib/account/serialization.js +47 -9
  25. package/lib/account/serialization.js.map +1 -1
  26. package/lib/api/Ethereum.d.ts +22 -1
  27. package/lib/api/Ethereum.d.ts.map +1 -1
  28. package/lib/api/Ethereum.js +21 -1
  29. package/lib/api/Ethereum.js.map +1 -1
  30. package/lib/apps/polyfill.d.ts.map +1 -1
  31. package/lib/apps/polyfill.js +3 -0
  32. package/lib/apps/polyfill.js.map +1 -1
  33. package/lib/bridge/jsHelpers.d.ts +2 -1
  34. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  35. package/lib/bridge/jsHelpers.js +27 -1
  36. package/lib/bridge/jsHelpers.js.map +1 -1
  37. package/lib/csvExport.d.ts.map +1 -1
  38. package/lib/csvExport.js +3 -1
  39. package/lib/csvExport.js.map +1 -1
  40. package/lib/currencies/sortByMarketcap.d.ts.map +1 -1
  41. package/lib/currencies/sortByMarketcap.js +8 -1
  42. package/lib/currencies/sortByMarketcap.js.map +1 -1
  43. package/lib/currencies/support.d.ts.map +1 -1
  44. package/lib/currencies/support.js.map +1 -1
  45. package/lib/env.d.ts +15 -5
  46. package/lib/env.d.ts.map +1 -1
  47. package/lib/env.js +11 -0
  48. package/lib/env.js.map +1 -1
  49. package/lib/env.react.d.ts +1 -1
  50. package/lib/env.react.d.ts.map +1 -1
  51. package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
  52. package/lib/families/bitcoin/datasets/bitcoin.js +4 -0
  53. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  54. package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
  55. package/lib/families/bitcoin/datasets/bitcoin_cash.js +4 -0
  56. package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
  57. package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
  58. package/lib/families/bitcoin/datasets/bitcoin_gold.js +4 -0
  59. package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
  60. package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
  61. package/lib/families/bitcoin/datasets/dash.js +4 -0
  62. package/lib/families/bitcoin/datasets/dash.js.map +1 -1
  63. package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
  64. package/lib/families/bitcoin/datasets/decred.js +4 -0
  65. package/lib/families/bitcoin/datasets/decred.js.map +1 -1
  66. package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
  67. package/lib/families/bitcoin/datasets/digibyte.js +4 -0
  68. package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
  69. package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
  70. package/lib/families/bitcoin/datasets/dogecoin.js +4 -0
  71. package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
  72. package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
  73. package/lib/families/bitcoin/datasets/komodo.js +4 -0
  74. package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
  75. package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
  76. package/lib/families/bitcoin/datasets/litecoin.js +4 -0
  77. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  78. package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
  79. package/lib/families/bitcoin/datasets/peercoin.js +4 -0
  80. package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
  81. package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
  82. package/lib/families/bitcoin/datasets/pivx.js +4 -0
  83. package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
  84. package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
  85. package/lib/families/bitcoin/datasets/qtum.js +4 -0
  86. package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
  87. package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
  88. package/lib/families/bitcoin/datasets/stakenet.js +4 -0
  89. package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
  90. package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
  91. package/lib/families/bitcoin/datasets/vertcoin.js +4 -0
  92. package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
  93. package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
  94. package/lib/families/bitcoin/datasets/viacoin.js +4 -0
  95. package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
  96. package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
  97. package/lib/families/bitcoin/datasets/zcash.js +4 -0
  98. package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
  99. package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
  100. package/lib/families/bitcoin/datasets/zencash.js +4 -0
  101. package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
  102. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -1
  103. package/lib/families/bitcoin/js-buildTransaction.js +1 -1
  104. package/lib/families/bitcoin/js-buildTransaction.js.map +1 -1
  105. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -1
  106. package/lib/families/bitcoin/js-estimateMaxSpendable.js +1 -1
  107. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -1
  108. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  109. package/lib/families/bitcoin/js-synchronisation.js +26 -14
  110. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  111. package/lib/families/bitcoin/logic.d.ts +1 -1
  112. package/lib/families/bitcoin/logic.d.ts.map +1 -1
  113. package/lib/families/bitcoin/logic.js +6 -0
  114. package/lib/families/bitcoin/logic.js.map +1 -1
  115. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  116. package/lib/families/bitcoin/specs.js +2 -1
  117. package/lib/families/bitcoin/specs.js.map +1 -1
  118. package/lib/families/bitcoin/test-dataset.js +2 -2
  119. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  120. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +2 -1
  121. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
  122. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +16 -12
  123. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
  124. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +2 -1
  125. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
  126. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +12 -7
  127. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
  128. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +2 -1
  129. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
  130. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +12 -7
  131. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
  132. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts +2 -1
  133. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts.map +1 -1
  134. package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.js.map +1 -1
  135. package/lib/families/bitcoin/wallet-btc/utils.d.ts +38 -1
  136. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  137. package/lib/families/bitcoin/wallet-btc/utils.js +104 -32
  138. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  139. package/lib/families/bitcoin/wallet-btc/wallet.d.ts +1 -1
  140. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  141. package/lib/families/bitcoin/wallet-btc/wallet.js +6 -3
  142. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  143. package/lib/families/bitcoin/wallet-btc/xpub.js +2 -2
  144. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  145. package/lib/families/ethereum/signOperation.d.ts.map +1 -1
  146. package/lib/families/ethereum/signOperation.js +7 -0
  147. package/lib/families/ethereum/signOperation.js.map +1 -1
  148. package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
  149. package/lib/families/ethereum/synchronisation.js +175 -15
  150. package/lib/families/ethereum/synchronisation.js.map +1 -1
  151. package/lib/families/ethereum/versions.d.ts +2 -0
  152. package/lib/families/ethereum/versions.d.ts.map +1 -0
  153. package/lib/families/ethereum/versions.js +5 -0
  154. package/lib/families/ethereum/versions.js.map +1 -0
  155. package/lib/nft/NftMetadataProvider/index.d.ts +17 -0
  156. package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -0
  157. package/lib/nft/NftMetadataProvider/index.js +244 -0
  158. package/lib/nft/NftMetadataProvider/index.js.map +1 -0
  159. package/lib/nft/NftMetadataProvider/logic.d.ts +3 -0
  160. package/lib/nft/NftMetadataProvider/logic.d.ts.map +1 -0
  161. package/lib/nft/NftMetadataProvider/logic.js +22 -0
  162. package/lib/nft/NftMetadataProvider/logic.js.map +1 -0
  163. package/lib/nft/NftMetadataProvider/types.d.ts +44 -0
  164. package/lib/nft/NftMetadataProvider/types.d.ts.map +1 -0
  165. package/lib/nft/NftMetadataProvider/types.js +3 -0
  166. package/lib/nft/NftMetadataProvider/types.js.map +1 -0
  167. package/lib/nft/helpers.d.ts +10 -0
  168. package/lib/nft/helpers.d.ts.map +1 -0
  169. package/lib/nft/helpers.js +85 -0
  170. package/lib/nft/helpers.js.map +1 -0
  171. package/lib/nft/index.d.ts +4 -0
  172. package/lib/nft/index.d.ts.map +1 -0
  173. package/lib/nft/index.js +16 -0
  174. package/lib/nft/index.js.map +1 -0
  175. package/lib/nft/nftId.d.ts +3 -0
  176. package/lib/nft/nftId.d.ts.map +1 -0
  177. package/lib/nft/nftId.js +33 -0
  178. package/lib/nft/nftId.js.map +1 -0
  179. package/lib/operation.d.ts +1 -1
  180. package/lib/operation.d.ts.map +1 -1
  181. package/lib/operation.js +19 -5
  182. package/lib/operation.js.map +1 -1
  183. package/lib/reconciliation.d.ts.map +1 -1
  184. package/lib/reconciliation.js +6 -0
  185. package/lib/reconciliation.js.map +1 -1
  186. package/lib/types/account.d.ts +3 -0
  187. package/lib/types/account.d.ts.map +1 -1
  188. package/lib/types/index.d.ts +1 -0
  189. package/lib/types/index.d.ts.map +1 -1
  190. package/lib/types/index.js +1 -0
  191. package/lib/types/index.js.map +1 -1
  192. package/lib/types/nft.d.ts +29 -0
  193. package/lib/types/nft.d.ts.map +1 -0
  194. package/lib/types/nft.js +3 -0
  195. package/lib/types/nft.js.map +1 -0
  196. package/lib/types/operation.d.ts +12 -1
  197. package/lib/types/operation.d.ts.map +1 -1
  198. package/package.json +13 -13
  199. package/src/.DS_Store +0 -0
  200. package/src/__tests__/__snapshots__/all.libcore.ts.snap +11643 -127265
  201. package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +105 -0
  202. package/src/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.ts +3 -2
  203. package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
  204. package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts +35 -31
  205. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.ts +3 -2
  206. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.ts +3 -2
  207. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.ts +6 -4
  208. package/src/account/formatters.ts +43 -0
  209. package/src/account/groupOperations.ts +2 -2
  210. package/src/account/serialization.ts +52 -0
  211. package/src/api/Ethereum.ts +40 -2
  212. package/src/apps/polyfill.ts +3 -0
  213. package/src/bridge/jsHelpers.ts +35 -0
  214. package/src/csvExport.ts +3 -2
  215. package/src/currencies/.DS_Store +0 -0
  216. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +1354 -1
  217. package/src/currencies/sortByMarketcap.ts +9 -1
  218. package/src/currencies/support.ts +1 -0
  219. package/src/env.ts +11 -0
  220. package/src/families/bitcoin/datasets/bitcoin.ts +4 -0
  221. package/src/families/bitcoin/datasets/bitcoin_cash.ts +4 -0
  222. package/src/families/bitcoin/datasets/bitcoin_gold.ts +4 -0
  223. package/src/families/bitcoin/datasets/dash.ts +4 -0
  224. package/src/families/bitcoin/datasets/decred.ts +4 -0
  225. package/src/families/bitcoin/datasets/digibyte.ts +4 -0
  226. package/src/families/bitcoin/datasets/dogecoin.ts +4 -0
  227. package/src/families/bitcoin/datasets/komodo.ts +4 -0
  228. package/src/families/bitcoin/datasets/litecoin.ts +4 -0
  229. package/src/families/bitcoin/datasets/peercoin.ts +4 -0
  230. package/src/families/bitcoin/datasets/pivx.ts +4 -0
  231. package/src/families/bitcoin/datasets/qtum.ts +4 -0
  232. package/src/families/bitcoin/datasets/stakenet.ts +4 -0
  233. package/src/families/bitcoin/datasets/vertcoin.ts +4 -0
  234. package/src/families/bitcoin/datasets/viacoin.ts +4 -0
  235. package/src/families/bitcoin/datasets/zcash.ts +4 -0
  236. package/src/families/bitcoin/datasets/zencash.ts +4 -0
  237. package/src/families/bitcoin/js-buildTransaction.ts +2 -1
  238. package/src/families/bitcoin/js-estimateMaxSpendable.ts +2 -1
  239. package/src/families/bitcoin/js-synchronisation.ts +30 -16
  240. package/src/families/bitcoin/logic.ts +7 -2
  241. package/src/families/bitcoin/specs.ts +6 -1
  242. package/src/families/bitcoin/test-dataset.ts +2 -2
  243. package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +34 -22
  244. package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +30 -9
  245. package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +30 -9
  246. package/src/families/bitcoin/wallet-btc/pickingstrategies/types.ts +3 -3
  247. package/src/families/bitcoin/wallet-btc/utils.ts +118 -35
  248. package/src/families/bitcoin/wallet-btc/wallet.ts +9 -4
  249. package/src/families/bitcoin/wallet-btc/xpub.ts +5 -5
  250. package/src/families/ethereum/modules/__snapshots__/compound.resilience.test.ts.snap +2876 -0
  251. package/src/families/ethereum/signOperation.ts +8 -0
  252. package/src/families/ethereum/synchronisation.ts +185 -6
  253. package/src/families/ethereum/versions.ts +1 -0
  254. package/src/nft/NftMetadataProvider/index.tsx +205 -0
  255. package/src/nft/NftMetadataProvider/logic.ts +20 -0
  256. package/src/nft/NftMetadataProvider/types.ts +60 -0
  257. package/src/nft/helpers.ts +78 -0
  258. package/src/nft/index.ts +3 -0
  259. package/src/nft/nftId.ts +17 -0
  260. package/src/operation.ts +22 -3
  261. package/src/reconciliation.ts +7 -0
  262. package/src/types/account.ts +4 -0
  263. package/src/types/index.ts +1 -0
  264. package/src/types/nft.ts +38 -0
  265. package/src/types/operation.ts +23 -1
@@ -1,6 +1,8 @@
1
1
  import { bech32m, bech32, BechLib } from "bech32";
2
2
  import * as utils from "../../../../families/bitcoin/wallet-btc/utils";
3
3
  import { Currency } from "../../../../families/bitcoin/wallet-btc/crypto/types";
4
+ import cryptoFactory from "../../../../families/bitcoin/wallet-btc/crypto/factory";
5
+ import { DerivationModes } from "../../../../families/bitcoin/wallet-btc";
4
6
 
5
7
  function validateAddrs(
6
8
  addresses: string[],
@@ -208,3 +210,106 @@ describe("Unit tests for various utils functions", () => {
208
210
  validateAddrs(["S6NMcEfYbavHrP3Uo1wbEUvKhAbKeMugaa"], "stealthcoin", false);
209
211
  });
210
212
  });
213
+
214
+ describe("Unit tests for maxTxSize", () => {
215
+ const btc = cryptoFactory("bitcoin_testnet");
216
+ it("Empty tx non-segwit", () => {
217
+ const s = utils.maxTxSizeCeil(0, [], false, btc, DerivationModes.LEGACY);
218
+ expect(s).toEqual(10);
219
+ });
220
+ it("Empty tx segwit", () => {
221
+ const s = utils.maxTxSizeCeil(
222
+ 0,
223
+ [],
224
+ false,
225
+ btc,
226
+ DerivationModes.NATIVE_SEGWIT
227
+ );
228
+ expect(s).toEqual(11);
229
+ });
230
+ it("1 p2wpkh input 1 p2wpkh output", () => {});
231
+
232
+ const tr = "tb1pdedptfps5k6hmzars9ks93ejsujh28kw5dhe06gutt9svap40j8qql2dw2";
233
+ const sh = "2Mv9bnjkBUr1GfCybJc7XmnJ5VG4SAT3shT";
234
+ const pkh = "mkQiYQGCkCC7Wus3vfhfTDjgJzQK554evn";
235
+ const wpkh = "tb1qhff3j7euu6t3lv8s5gsy9t5x82wuhfw5z863gj";
236
+ const p2tr = DerivationModes.TAPROOT;
237
+ const p2sh = DerivationModes.SEGWIT;
238
+ const p2pkh = DerivationModes.LEGACY;
239
+ const p2wpkh = DerivationModes.NATIVE_SEGWIT;
240
+
241
+ test.each([
242
+ // In 148 out 34
243
+ [0, [], false, p2pkh, 10],
244
+ [0, [], true, p2pkh, 44],
245
+ [0, [pkh], false, p2pkh, 44],
246
+ [0, [pkh], true, p2pkh, 78],
247
+ [1, [pkh], true, p2pkh, 226],
248
+ [2, [pkh], true, p2pkh, 374],
249
+ [1, [wpkh], true, p2pkh, 223],
250
+ [1, [sh], true, p2pkh, 224],
251
+ [1, [tr], true, p2pkh, 235],
252
+
253
+ // In 68 out 31
254
+ [0, [], false, p2wpkh, 11],
255
+ [0, [], true, p2wpkh, 42],
256
+ [1, [], false, p2wpkh, 79],
257
+ [1, [], true, p2wpkh, 110],
258
+ [2, [], true, p2wpkh, 178],
259
+
260
+ // In 90 out 32, scriptSig 22
261
+ [0, [], false, p2sh, 11],
262
+ [0, [], true, p2sh, 43],
263
+ [1, [], false, p2sh, 101],
264
+ [1, [sh], false, p2sh, 133],
265
+ [2, [sh], false, p2sh, 223],
266
+
267
+ // Fixed 10.5 In 57.75 out 43
268
+ [0, [], false, p2tr, 11],
269
+ [0, [], true, p2tr, 54],
270
+ [1, [], true, p2tr, Math.ceil(53.5 + 57.75 * 1)],
271
+ [2, [], true, p2tr, Math.ceil(53.5 + 57.75 * 2)],
272
+ [3, [], true, p2tr, Math.ceil(53.5 + 57.75 * 3)],
273
+
274
+ // 0xfc=252 inputs
275
+ [247, [], true, p2tr, Math.ceil(53.5 + 57.75 * 247)],
276
+ [248, [], true, p2tr, Math.ceil(53.5 + 57.75 * 248)],
277
+ [249, [], true, p2tr, Math.ceil(53.5 + 57.75 * 249)],
278
+ [250, [], true, p2tr, Math.ceil(53.5 + 57.75 * 250)],
279
+ [251, [], true, p2tr, Math.ceil(53.5 + 57.75 * 251)],
280
+ [252, [], true, p2tr, Math.ceil(53.5 + 57.75 * 252)],
281
+ // 0xfd=253 inputs will add 2 bytes for >= 0xfd
282
+ [253, [], true, p2tr, Math.ceil(53.5 + 57.75 * 253 + 2)],
283
+ [
284
+ 256 * 256 - 1,
285
+ [],
286
+ true,
287
+ p2tr,
288
+ Math.ceil(53.5 + 57.75 * (256 * 256 - 1) + 2),
289
+ ],
290
+ // 0xffff inputs will add 4 bytes
291
+ [256 * 256, [], true, p2tr, Math.ceil(53.5 + 57.75 * (256 * 256) + 4)],
292
+
293
+ // test address with witness version 16 and witness program [0x01, 0x02] => tb1sqypqyuzpgh
294
+ [
295
+ 2,
296
+ [tr, sh, pkh, wpkh, "tb1sqypqyuzpgh"],
297
+ false,
298
+ p2wpkh,
299
+ Math.ceil(10.5 + 68 * 2 + 43 + 32 + 34 + 31 + 13),
300
+ ],
301
+ ])(
302
+ "%i, %s, %s, %s => %i",
303
+ (inputCount, outputAddrs, useChange, derivationMode, exp) => {
304
+ const s = utils.maxTxSizeCeil(
305
+ inputCount,
306
+ outputAddrs,
307
+ useChange,
308
+ btc,
309
+ derivationMode
310
+ );
311
+ //const s = utils.estimateTxSize(inputCount, outputAddrs.length + (useChange ? 1 : 0), btc, derivationMode);
312
+ expect(s).toEqual(exp);
313
+ }
314
+ );
315
+ });
@@ -57,9 +57,10 @@ describe("testing estimateMaxSpendable", () => {
57
57
  expect(maxSpendable.toNumber()).toEqual(
58
58
  balance -
59
59
  feesPerByte *
60
- utils.estimateTxSize(
60
+ utils.maxTxSizeCeil(
61
61
  2,
62
- 1,
62
+ [],
63
+ true,
63
64
  account.xpub.crypto,
64
65
  account.xpub.derivationMode
65
66
  )
@@ -63,7 +63,7 @@ describe("testing wallet", () => {
63
63
  fromAccount: account,
64
64
  txInfo,
65
65
  });
66
- expect(tx).toEqual("d6154bba4915d07453bb09d4fa02d62e975b4475");
66
+ expect(Buffer.from(tx, "hex")).toHaveLength(20);
67
67
  });
68
68
 
69
69
  it("should allow to build a transaction splitting outputs", async () => {
@@ -87,7 +87,7 @@ describe("testing wallet", () => {
87
87
  fromAccount: account,
88
88
  txInfo,
89
89
  });
90
- expect(tx).toEqual("d922a70d6a66b96cdaba4565270a21f97eb23a6d");
90
+ expect(Buffer.from(tx, "hex")).toHaveLength(20);
91
91
  });
92
92
 
93
93
  it("should throw during sync if there is an error in explorer", async () => {
@@ -3,7 +3,10 @@ import * as bip39 from "bip39";
3
3
  import * as bitcoin from "bitcoinjs-lib";
4
4
  import coininfo from "coininfo";
5
5
  import BigNumber from "bignumber.js";
6
- import { DerivationModes } from "../../../../families/bitcoin/wallet-btc/types";
6
+ import {
7
+ DerivationModes,
8
+ OutputInfo,
9
+ } from "../../../../families/bitcoin/wallet-btc/types";
7
10
  import Xpub from "../../../../families/bitcoin/wallet-btc/xpub";
8
11
  import BitcoinLikeExplorer from "../../../../families/bitcoin/wallet-btc/explorer";
9
12
  import Crypto from "../../../../families/bitcoin/wallet-btc/crypto/bitcoin";
@@ -42,6 +45,17 @@ describe("testing xpub legacy transactions", () => {
42
45
  xpub,
43
46
  };
44
47
 
48
+ function outputs(amount: number): OutputInfo[] {
49
+ return [
50
+ {
51
+ address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
52
+ isChange: false,
53
+ script: Buffer.from([]),
54
+ value: new BigNumber(amount),
55
+ },
56
+ ];
57
+ }
58
+
45
59
  it("merge output strategy should be correct", async () => {
46
60
  // Initialize the xpub with 2 txs. So that it has 2 utxo
47
61
  dataset.xpub.storage.appendTxs([
@@ -134,17 +148,15 @@ describe("testing xpub legacy transactions", () => {
134
148
  );
135
149
  let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
136
150
  dataset.xpub,
137
- new BigNumber(10000),
138
- 0,
139
- 1
151
+ outputs(10000),
152
+ 0
140
153
  );
141
154
  expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
142
155
  expect(Number(res.unspentUtxos[0].value)).toEqual(300000000); // use cheaper utxo first
143
156
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
144
157
  dataset.xpub,
145
- new BigNumber(500000000),
146
- 0,
147
- 1
158
+ outputs(500000000),
159
+ 0
148
160
  );
149
161
  expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
150
162
  expect(
@@ -161,17 +173,15 @@ describe("testing xpub legacy transactions", () => {
161
173
  );
162
174
  let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
163
175
  dataset.xpub,
164
- new BigNumber(10000),
165
- 0,
166
- 1
176
+ outputs(10000),
177
+ 0
167
178
  );
168
179
  expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
169
180
  expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000); // use old utxo first
170
181
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
171
182
  dataset.xpub,
172
- new BigNumber(5200000000),
173
- 0,
174
- 1
183
+ outputs(5200000000),
184
+ 0
175
185
  );
176
186
  expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
177
187
  expect(
@@ -323,45 +333,40 @@ describe("testing xpub legacy transactions", () => {
323
333
  );
324
334
  let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
325
335
  dataset.xpub,
326
- new BigNumber(10000),
327
- 10,
328
- 1
336
+ outputs(10000),
337
+ 10
329
338
  );
330
339
  expect(res.unspentUtxos.length).toEqual(1);
331
340
  expect(Number(res.unspentUtxos[0].value)).toEqual(100000000);
332
341
 
333
342
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
334
343
  dataset.xpub,
335
- new BigNumber(290000000),
336
- 10,
337
- 1
344
+ outputs(290000000),
345
+ 10
338
346
  );
339
347
  expect(res.unspentUtxos.length).toEqual(1);
340
348
  expect(Number(res.unspentUtxos[0].value)).toEqual(300000000);
341
349
 
342
350
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
343
351
  dataset.xpub,
344
- new BigNumber(500000000),
345
- 10,
346
- 1
352
+ outputs(500000000),
353
+ 10
347
354
  );
348
355
  expect(res.unspentUtxos.length).toEqual(1);
349
356
  expect(Number(res.unspentUtxos[0].value)).toEqual(600000000);
350
357
 
351
358
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
352
359
  dataset.xpub,
353
- new BigNumber(800000000),
354
- 10,
355
- 1
360
+ outputs(800000000),
361
+ 10
356
362
  );
357
363
  expect(res.unspentUtxos.length).toEqual(1);
358
364
  expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000);
359
365
 
360
366
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
361
367
  dataset.xpub,
362
- new BigNumber(5000000000),
363
- 10,
364
- 1
368
+ outputs(5000000000),
369
+ 10
365
370
  );
366
371
  expect(res.unspentUtxos.length).toEqual(2);
367
372
  expect(
@@ -370,9 +375,8 @@ describe("testing xpub legacy transactions", () => {
370
375
 
371
376
  res = await utxoPickingStrategy.selectUnspentUtxosToUse(
372
377
  dataset.xpub,
373
- new BigNumber(5600000000),
374
- 10,
375
- 1
378
+ outputs(5600000000),
379
+ 10
376
380
  );
377
381
  expect(res.unspentUtxos.length).toEqual(3);
378
382
  expect(
@@ -178,9 +178,10 @@ describe.skip("testing xpub segwit transactions", () => {
178
178
  await xpubs[1].xpub.sync();
179
179
 
180
180
  expectedFee1 =
181
- utils.estimateTxSize(
181
+ utils.maxTxSizeCeil(
182
182
  inputs.length,
183
- outputs.length,
183
+ outputs.map((o) => o.address),
184
+ false,
184
185
  crypto,
185
186
  DerivationModes.SEGWIT
186
187
  ) * 100;
@@ -167,9 +167,10 @@ describe.skip("testing xpub native segwit transactions", () => {
167
167
  await xpubs[1].xpub.sync();
168
168
 
169
169
  expectedFee1 =
170
- utils.estimateTxSize(
170
+ utils.maxTxSizeCeil(
171
171
  inputs.length,
172
- outputs.length,
172
+ outputs.map((o) => o.address),
173
+ false,
173
174
  crypto,
174
175
  DerivationModes.NATIVE_SEGWIT
175
176
  ) * 100;
@@ -148,9 +148,10 @@ describe.skip("testing xpub legacy transactions", () => {
148
148
  }
149
149
 
150
150
  expectedFee1 =
151
- utils.estimateTxSize(
151
+ utils.maxTxSizeCeil(
152
152
  inputs.length,
153
- outputs.length,
153
+ outputs.map((o) => o.address),
154
+ false,
154
155
  crypto,
155
156
  DerivationModes.LEGACY
156
157
  ) * 100;
@@ -280,9 +281,10 @@ describe.skip("testing xpub legacy transactions", () => {
280
281
  await xpubs[1].xpub.sync();
281
282
 
282
283
  expectedFee2 =
283
- utils.estimateTxSize(
284
+ utils.maxTxSizeCeil(
284
285
  inputs.length,
285
- outputs.length,
286
+ outputs.map((o) => o.address),
287
+ false,
286
288
  crypto,
287
289
  DerivationModes.LEGACY
288
290
  ) * 100;
@@ -12,6 +12,15 @@ import { formatCurrencyUnit } from "../currencies";
12
12
  import { getOperationAmountNumber } from "../operation";
13
13
  import { getTagDerivationMode } from "../derivation";
14
14
  import byFamily from "../generated/account";
15
+ import { nftsByCollections } from "../nft";
16
+
17
+ const styling = {
18
+ bold: (str: string) => `\x1b[1m${str}\x1b[22m`,
19
+ underline: (str: string) => `\x1b[4m${str}\x1b[24m`,
20
+ cyan: (str: string) => `\x1b[36m${str}\x1b[37m`,
21
+ magenta: (str: string) => `\x1b[35m${str}\x1b[37m`,
22
+ reverse: (str: string) => `\x1b[7m${str}\x1b[27m`,
23
+ };
15
24
 
16
25
  const isSignificantAccount = (acc) =>
17
26
  acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6));
@@ -80,6 +89,7 @@ const cliFormat = (account, level?: string) => {
80
89
  derivationMode,
81
90
  index,
82
91
  operations,
92
+ nfts,
83
93
  } = account;
84
94
  const tag = getTagDerivationMode(account.currency, derivationMode);
85
95
  const balance = formatCurrencyUnit(account.unit, account.balance, {
@@ -122,6 +132,39 @@ const cliFormat = (account, level?: string) => {
122
132
  maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountUnit(ta))
123
133
  )
124
134
  .join("\n");
135
+
136
+ if (nfts?.length) {
137
+ const NFTCollections = nftsByCollections(nfts);
138
+
139
+ str += "\n";
140
+ str += `NFT Collections (${NFTCollections.length}) `;
141
+ str += "\n";
142
+
143
+ str += NFTCollections.map(
144
+ // nfts are set to any because there not just NFT, we added a metadata prop on the fly
145
+ // in the first step of the Rxjs flow to avoid having some async code here
146
+ ({ contract, nfts }: { contract: string; nfts: any[] }) => {
147
+ const tokenName = nfts?.[0]?.metadata?.tokenName;
148
+ const { bold, magenta, cyan, reverse } = styling;
149
+
150
+ return (
151
+ `${bold(tokenName ?? "Unknown Collection Name")} (${magenta(
152
+ contract
153
+ )}): ` +
154
+ nfts
155
+ .map((t) =>
156
+ t?.metadata?.nftName
157
+ ? `\n ${t.amount}x ${reverse(
158
+ ` ${t?.metadata?.nftName} `
159
+ )} ${cyan("#" + t.tokenId)}`
160
+ : `\n ${t.amount}x ${cyan("#" + t.tokenId)}`
161
+ )
162
+ .join()
163
+ );
164
+ }
165
+ ).join("\n");
166
+ }
167
+
125
168
  if (level === "basic") return str;
126
169
  str += "\nOPERATIONS (" + operations.length + ")";
127
170
  str += operations
@@ -1,6 +1,6 @@
1
1
  import type { AccountLikeArray, AccountLike, Operation } from "../types";
2
2
  import { flattenAccounts } from "./helpers";
3
- import { flattenOperationWithInternals } from "../operation";
3
+ import { flattenOperationWithInternalsAndNfts } from "../operation";
4
4
  export type DailyOperationsSection = {
5
5
  day: Date;
6
6
  data: Operation[];
@@ -105,7 +105,7 @@ export function groupAccountsOperationsByDay(
105
105
  indexes[bestOpInfo.accountI]++;
106
106
  }
107
107
 
108
- const ops = flattenOperationWithInternals(bestOp);
108
+ const ops = flattenOperationWithInternalsAndNfts(bestOp);
109
109
  return {
110
110
  ops,
111
111
  date: bestOp.date,
@@ -16,6 +16,8 @@ import type {
16
16
  OperationRaw,
17
17
  SubAccount,
18
18
  SubAccountRaw,
19
+ NFT,
20
+ NFTRaw,
19
21
  } from "../types";
20
22
  import type { TronResources, TronResourcesRaw } from "../families/tron/types";
21
23
  import {
@@ -101,6 +103,7 @@ export const toOperationRaw = (
101
103
  fee,
102
104
  subOperations,
103
105
  internalOperations,
106
+ nftOperations,
104
107
  extra,
105
108
  id,
106
109
  hash,
@@ -112,6 +115,10 @@ export const toOperationRaw = (
112
115
  transactionSequenceNumber,
113
116
  accountId,
114
117
  hasFailed,
118
+ contract,
119
+ operator,
120
+ standard,
121
+ tokenId,
115
122
  }: Operation,
116
123
  preserveSubOperation?: boolean
117
124
  ): OperationRaw => {
@@ -142,6 +149,10 @@ export const toOperationRaw = (
142
149
  date: date.toISOString(),
143
150
  value: value.toFixed(),
144
151
  fee: fee.toString(),
152
+ contract,
153
+ operator,
154
+ standard,
155
+ tokenId,
145
156
  };
146
157
 
147
158
  if (transactionSequenceNumber !== undefined) {
@@ -160,6 +171,10 @@ export const toOperationRaw = (
160
171
  copy.internalOperations = internalOperations.map((o) => toOperationRaw(o));
161
172
  }
162
173
 
174
+ if (nftOperations) {
175
+ copy.nftOperations = nftOperations.map((o) => toOperationRaw(o));
176
+ }
177
+
163
178
  return copy;
164
179
  };
165
180
  export const inferSubOperations = (
@@ -198,6 +213,7 @@ export const fromOperationRaw = (
198
213
  extra,
199
214
  subOperations,
200
215
  internalOperations,
216
+ nftOperations,
201
217
  id,
202
218
  hash,
203
219
  type,
@@ -207,6 +223,10 @@ export const fromOperationRaw = (
207
223
  blockHash,
208
224
  transactionSequenceNumber,
209
225
  hasFailed,
226
+ contract,
227
+ operator,
228
+ standard,
229
+ tokenId,
210
230
  }: OperationRaw,
211
231
  accountId: string,
212
232
  subAccounts?: SubAccount[] | null | undefined
@@ -238,6 +258,10 @@ export const fromOperationRaw = (
238
258
  value: new BigNumber(value),
239
259
  fee: new BigNumber(fee),
240
260
  extra: e || {},
261
+ contract,
262
+ operator,
263
+ standard,
264
+ tokenId,
241
265
  };
242
266
 
243
267
  if (transactionSequenceNumber !== undefined) {
@@ -262,6 +286,12 @@ export const fromOperationRaw = (
262
286
  );
263
287
  }
264
288
 
289
+ if (nftOperations) {
290
+ res.nftOperations = nftOperations.map((o) =>
291
+ fromOperationRaw(o, o.accountId)
292
+ );
293
+ }
294
+
265
295
  return res;
266
296
  };
267
297
  export const toTronResourcesRaw = ({
@@ -677,6 +707,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
677
707
  polkadotResources,
678
708
  elrondResources,
679
709
  cryptoOrgResources,
710
+ nfts,
680
711
  } = rawAccount;
681
712
  const subAccounts =
682
713
  subAccountsRaw &&
@@ -734,6 +765,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
734
765
  swapHistory: [],
735
766
  syncHash,
736
767
  balanceHistoryCache: balanceHistoryCache || emptyHistoryCache,
768
+ nfts: nfts?.map((n) => fromNFTRaw(n)),
737
769
  };
738
770
  res.balanceHistoryCache = generateHistoryFromOperations(res);
739
771
 
@@ -834,6 +866,7 @@ export function toAccountRaw({
834
866
  polkadotResources,
835
867
  elrondResources,
836
868
  cryptoOrgResources,
869
+ nfts,
837
870
  }: Account): AccountRaw {
838
871
  const res: AccountRaw = {
839
872
  id,
@@ -857,6 +890,7 @@ export function toAccountRaw({
857
890
  lastSyncDate: lastSyncDate.toISOString(),
858
891
  balance: balance.toFixed(),
859
892
  spendableBalance: spendableBalance.toFixed(),
893
+ nfts: nfts?.map((n) => toNFTRaw(n)),
860
894
  };
861
895
 
862
896
  if (balanceHistory) {
@@ -914,3 +948,21 @@ export function toAccountRaw({
914
948
  }
915
949
  return res;
916
950
  }
951
+
952
+ export function toNFTRaw({ id, tokenId, amount, collection }: NFT): NFTRaw {
953
+ return {
954
+ id,
955
+ tokenId,
956
+ amount: amount.toFixed(),
957
+ collection,
958
+ };
959
+ }
960
+
961
+ export function fromNFTRaw({ id, tokenId, amount, collection }: NFTRaw): NFT {
962
+ return {
963
+ id,
964
+ tokenId,
965
+ amount: new BigNumber(amount),
966
+ collection,
967
+ };
968
+ }
@@ -3,12 +3,14 @@ import invariant from "invariant";
3
3
  import { BigNumber } from "bignumber.js";
4
4
  import { LedgerAPINotAvailable } from "@ledgerhq/errors";
5
5
  import JSONBigNumber from "@ledgerhq/json-bignumber";
6
- import type { CryptoCurrency } from "../types";
6
+ import type { CryptoCurrency, NFTMetadataResponse } from "../types";
7
7
  import type { EthereumGasLimitRequest } from "../families/ethereum/types";
8
8
  import network from "../network";
9
9
  import { blockchainBaseURL } from "./Ledger";
10
10
  import { FeeEstimationFailed } from "../errors";
11
11
  import { makeLRUCache } from "../cache";
12
+ import { getEnv } from "../env";
13
+
12
14
  export type Block = {
13
15
  height: BigNumber;
14
16
  }; // TODO more fields actually
@@ -37,6 +39,22 @@ export type Tx = {
37
39
  }>;
38
40
  truncated: boolean;
39
41
  };
42
+ erc721_transfer_events?: Array<{
43
+ contract: string;
44
+ sender: string;
45
+ receiver: string;
46
+ token_id: string;
47
+ }>;
48
+ erc1155_transfer_events?: Array<{
49
+ contract: string;
50
+ sender: string;
51
+ operator: string;
52
+ receiver: string;
53
+ transfers: Array<{
54
+ id: string;
55
+ value: string;
56
+ }>;
57
+ }>;
40
58
  actions?: Array<{
41
59
  from: string;
42
60
  to: string;
@@ -59,6 +77,12 @@ export type ERC20BalanceOutput = Array<{
59
77
  contract: string;
60
78
  balance: BigNumber;
61
79
  }>;
80
+ export type NFTMetadataInput = Readonly<
81
+ Array<{
82
+ contract: string;
83
+ tokenId: string;
84
+ }>
85
+ >;
62
86
  export type API = {
63
87
  getTransactions: (
64
88
  address: string,
@@ -72,6 +96,7 @@ export type API = {
72
96
  getAccountNonce: (address: string) => Promise<number>;
73
97
  broadcastTransaction: (signedTransaction: string) => Promise<string>;
74
98
  getERC20Balances: (input: ERC20BalancesInput) => Promise<ERC20BalanceOutput>;
99
+ getNFTMetadata: (input: NFTMetadataInput) => Promise<NFTMetadataResponse[]>;
75
100
  getAccountBalance: (address: string) => Promise<BigNumber>;
76
101
  roughlyEstimateGasLimit: (address: string) => Promise<BigNumber>;
77
102
  getERC20ApprovalsPerContract: (
@@ -107,7 +132,10 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
107
132
  let { data } = await network({
108
133
  method: "GET",
109
134
  url: URL.format({
110
- pathname: `${baseURL}/addresses/${address}/transactions`,
135
+ pathname:
136
+ getEnv("NFT") && currency.ticker === "ETH"
137
+ ? `https://explorers.api-01.live.ledger-stg.com/blockchain/v3/eth/addresses/${address}/transactions`
138
+ : `${baseURL}/addresses/${address}/transactions`,
111
139
  query: {
112
140
  batch_size,
113
141
  noinput: true,
@@ -178,6 +206,16 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
178
206
  return data;
179
207
  },
180
208
 
209
+ async getNFTMetadata(input) {
210
+ const { data }: { data: NFTMetadataResponse[] } = await network({
211
+ method: "POST",
212
+ url: getEnv("NFT_ETH_METADATA_SERVICE"),
213
+ data: input,
214
+ });
215
+
216
+ return data;
217
+ },
218
+
181
219
  async getERC20ApprovalsPerContract(owner, contract) {
182
220
  try {
183
221
  const { data } = await network({
@@ -49,6 +49,9 @@ export const whitelistDependencies = ["Decred", "Decred Testnet"];
49
49
  ["Opensea", "Ethereum"],
50
50
  ["StakeDAO", "Ethereum"],
51
51
  ["Yearn", "Ethereum"],
52
+ ["RocketPool", "Ethereum"],
53
+ ["POAP", "Ethereum"],
54
+ ["OlympusDAO", "Ethereum"],
52
55
  ].forEach(([name, dep]) => declareDep(name, dep));
53
56
  export const getDependencies = (appName: string): string[] =>
54
57
  directDep[appName] || [];