@ledgerhq/live-common 27.3.2 → 27.4.0-next.1

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 (258) hide show
  1. package/lib/__tests__/environment.test.d.ts +2 -0
  2. package/lib/__tests__/environment.test.d.ts.map +1 -0
  3. package/lib/__tests__/environment.test.js +13 -0
  4. package/lib/__tests__/environment.test.js.map +1 -0
  5. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +0 -31
  6. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
  7. package/lib/account/support.d.ts.map +1 -1
  8. package/lib/account/support.js +3 -2
  9. package/lib/account/support.js.map +1 -1
  10. package/lib/apps/hw.d.ts +4 -1
  11. package/lib/apps/hw.d.ts.map +1 -1
  12. package/lib/apps/hw.js +10 -4
  13. package/lib/apps/hw.js.map +1 -1
  14. package/lib/apps/mock.d.ts +1 -0
  15. package/lib/apps/mock.d.ts.map +1 -1
  16. package/lib/apps/mock.js +24 -2
  17. package/lib/apps/mock.js.map +1 -1
  18. package/lib/apps/runner.d.ts +8 -1
  19. package/lib/apps/runner.d.ts.map +1 -1
  20. package/lib/apps/runner.js +15 -3
  21. package/lib/apps/runner.js.map +1 -1
  22. package/lib/apps/support.js +1 -1
  23. package/lib/bot/engine.d.ts.map +1 -1
  24. package/lib/bot/engine.js +5 -2
  25. package/lib/bot/engine.js.map +1 -1
  26. package/lib/bot/index.d.ts.map +1 -1
  27. package/lib/bot/index.js +5 -3
  28. package/lib/bot/index.js.map +1 -1
  29. package/lib/bot/types.d.ts +2 -0
  30. package/lib/bot/types.d.ts.map +1 -1
  31. package/lib/data/icons/react/index.d.ts +1 -0
  32. package/lib/data/icons/react/index.d.ts.map +1 -1
  33. package/lib/data/icons/react/index.js +3 -1
  34. package/lib/data/icons/react/index.js.map +1 -1
  35. package/lib/data/icons/react/yae.d.ts +8 -0
  36. package/lib/data/icons/react/yae.d.ts.map +1 -0
  37. package/lib/data/icons/react/yae.js +36 -0
  38. package/lib/data/icons/react/yae.js.map +1 -0
  39. package/lib/data/icons/reactNative/index.d.ts +1 -0
  40. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  41. package/lib/data/icons/reactNative/index.js +3 -1
  42. package/lib/data/icons/reactNative/index.js.map +1 -1
  43. package/lib/data/icons/reactNative/yae.d.ts +8 -0
  44. package/lib/data/icons/reactNative/yae.d.ts.map +1 -0
  45. package/lib/data/icons/reactNative/yae.js +37 -0
  46. package/lib/data/icons/reactNative/yae.js.map +1 -0
  47. package/lib/exchange/hw-app-exchange/Exchange.js +4 -4
  48. package/lib/families/bitcoin/account.d.ts.map +1 -1
  49. package/lib/families/bitcoin/bech32m.d.ts +2 -8
  50. package/lib/families/bitcoin/bech32m.d.ts.map +1 -1
  51. package/lib/families/bitcoin/bridge/js.d.ts.map +1 -1
  52. package/lib/families/bitcoin/bridge/js.js.map +1 -1
  53. package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
  54. package/lib/families/bitcoin/bridge/mock.js.map +1 -1
  55. package/lib/families/bitcoin/cache.d.ts +2 -15
  56. package/lib/families/bitcoin/cache.d.ts.map +1 -1
  57. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +2 -15
  58. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +1 -1
  59. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  60. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  61. package/lib/families/bitcoin/logic.d.ts +1 -1
  62. package/lib/families/bitcoin/logic.d.ts.map +1 -1
  63. package/lib/families/bitcoin/logic.js.map +1 -1
  64. package/lib/families/bitcoin/presync.d.ts.map +1 -1
  65. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +0 -2
  66. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  67. package/lib/families/bitcoin/wallet-btc/crypto/base.js +0 -16
  68. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  69. package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts +4 -3
  70. package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts.map +1 -1
  71. package/lib/families/bitcoin/wallet-btc/crypto/bip32.js +3 -1
  72. package/lib/families/bitcoin/wallet-btc/crypto/bip32.js.map +1 -1
  73. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts +2 -3
  74. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  75. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +0 -7
  76. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  77. package/lib/families/bitcoin/wallet-btc/crypto/factory.d.ts.map +1 -1
  78. package/lib/families/bitcoin/wallet-btc/crypto/factory.js +0 -3
  79. package/lib/families/bitcoin/wallet-btc/crypto/factory.js.map +1 -1
  80. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts +2 -3
  81. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
  82. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +0 -16
  83. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  84. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +0 -1
  85. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
  86. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +0 -2
  87. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  88. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +0 -5
  89. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  90. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +0 -2
  91. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  92. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +0 -5
  93. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  94. package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts +11 -5
  95. package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts.map +1 -1
  96. package/lib/families/bitcoin/wallet-btc/explorer/index.js +8 -40
  97. package/lib/families/bitcoin/wallet-btc/explorer/index.js.map +1 -1
  98. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +1 -1
  99. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
  100. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
  101. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +1 -1
  102. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
  103. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
  104. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +1 -1
  105. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
  106. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
  107. package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +1 -5
  108. package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
  109. package/lib/families/bitcoin/wallet-btc/storage/index.js +7 -9
  110. package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
  111. package/lib/families/bitcoin/wallet-btc/utils.d.ts +3 -3
  112. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  113. package/lib/families/bitcoin/wallet-btc/utils.js +2 -11
  114. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  115. package/lib/families/bitcoin/wallet-btc/wallet.d.ts +10 -7
  116. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  117. package/lib/families/bitcoin/wallet-btc/wallet.js +1 -18
  118. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  119. package/lib/families/bitcoin/wallet-btc/xpub.d.ts +1 -9
  120. package/lib/families/bitcoin/wallet-btc/xpub.d.ts.map +1 -1
  121. package/lib/families/bitcoin/wallet-btc/xpub.js +60 -208
  122. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  123. package/lib/families/cardano/js-synchronisation.js +1 -1
  124. package/lib/families/cardano/js-synchronisation.js.map +1 -1
  125. package/lib/families/cardano/specs.js +1 -1
  126. package/lib/families/celo/specs/createSendMutation.d.ts.map +1 -1
  127. package/lib/families/celo/specs/createSendMutation.js +0 -2
  128. package/lib/families/celo/specs/createSendMutation.js.map +1 -1
  129. package/lib/families/celo/specs.js +1 -1
  130. package/lib/families/crypto_org/specs.d.ts.map +1 -1
  131. package/lib/families/crypto_org/specs.js +3 -2
  132. package/lib/families/crypto_org/specs.js.map +1 -1
  133. package/lib/families/ethereum/specs.js +3 -3
  134. package/lib/families/ethereum/specs.js.map +1 -1
  135. package/lib/families/evm/specs.js +6 -6
  136. package/lib/families/evm/specs.js.map +1 -1
  137. package/lib/families/filecoin/specs.d.ts.map +1 -1
  138. package/lib/families/filecoin/specs.js +1 -2
  139. package/lib/families/filecoin/specs.js.map +1 -1
  140. package/lib/families/hedera/api/network.d.ts.map +1 -1
  141. package/lib/families/hedera/api/network.js +16 -8
  142. package/lib/families/hedera/api/network.js.map +1 -1
  143. package/lib/families/hedera/errors.d.ts +4 -0
  144. package/lib/families/hedera/errors.d.ts.map +1 -0
  145. package/lib/families/hedera/errors.js +6 -0
  146. package/lib/families/hedera/errors.js.map +1 -0
  147. package/lib/families/hedera/specs.d.ts.map +1 -1
  148. package/lib/families/hedera/specs.js +0 -11
  149. package/lib/families/hedera/specs.js.map +1 -1
  150. package/lib/families/osmosis/specs.js +1 -1
  151. package/lib/families/polkadot/specs.d.ts.map +1 -1
  152. package/lib/families/polkadot/specs.js +1 -0
  153. package/lib/families/polkadot/specs.js.map +1 -1
  154. package/lib/families/solana/specs.d.ts.map +1 -1
  155. package/lib/families/solana/specs.js +1 -0
  156. package/lib/families/solana/specs.js.map +1 -1
  157. package/lib/families/tezos/bakers.whitelist-default.d.ts.map +1 -1
  158. package/lib/families/tezos/bakers.whitelist-default.js +1 -1
  159. package/lib/families/tezos/bakers.whitelist-default.js.map +1 -1
  160. package/lib/families/tezos/bridge/js.d.ts.map +1 -1
  161. package/lib/families/tezos/bridge/js.js +2 -1
  162. package/lib/families/tezos/bridge/js.js.map +1 -1
  163. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  164. package/lib/featureFlags/defaultFeatures.js +6 -0
  165. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  166. package/lib/hw/actions/app.d.ts +7 -0
  167. package/lib/hw/actions/app.d.ts.map +1 -1
  168. package/lib/hw/actions/app.js +25 -11
  169. package/lib/hw/actions/app.js.map +1 -1
  170. package/lib/hw/connectApp.d.ts +4 -0
  171. package/lib/hw/connectApp.d.ts.map +1 -1
  172. package/lib/hw/connectApp.js +10 -1
  173. package/lib/hw/connectApp.js.map +1 -1
  174. package/lib/manager/localization.d.ts +1 -1
  175. package/lib/manager/localization.d.ts.map +1 -1
  176. package/lib/manager/localization.js +1 -1
  177. package/lib/manager/localization.js.map +1 -1
  178. package/lib/rxjs/operators/retryWithDelay.d.ts +12 -0
  179. package/lib/rxjs/operators/retryWithDelay.d.ts.map +1 -0
  180. package/lib/rxjs/operators/retryWithDelay.js +28 -0
  181. package/lib/rxjs/operators/retryWithDelay.js.map +1 -0
  182. package/lib/rxjs/operators/throwIf.d.ts +23 -0
  183. package/lib/rxjs/operators/throwIf.d.ts.map +1 -0
  184. package/lib/rxjs/operators/throwIf.js +37 -0
  185. package/lib/rxjs/operators/throwIf.js.map +1 -0
  186. package/package.json +5 -5
  187. package/src/__tests__/environment.test.ts +12 -0
  188. package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +0 -33
  189. package/src/account/support.ts +3 -2
  190. package/src/apps/hw.ts +17 -4
  191. package/src/apps/mock.ts +24 -2
  192. package/src/apps/runner.ts +28 -4
  193. package/src/apps/support.ts +1 -1
  194. package/src/bot/engine.ts +9 -1
  195. package/src/bot/index.ts +7 -2
  196. package/src/bot/types.ts +3 -0
  197. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +33 -0
  198. package/src/data/icons/react/index.tsx +1 -0
  199. package/src/data/icons/react/yae.tsx +14 -0
  200. package/src/data/icons/reactNative/index.tsx +1 -0
  201. package/src/data/icons/reactNative/yae.tsx +15 -0
  202. package/src/data/icons/svg/YAE.svg +4 -0
  203. package/src/exchange/hw-app-exchange/Exchange.ts +4 -4
  204. package/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap +807 -27
  205. package/src/families/bitcoin/account.ts +1 -1
  206. package/src/families/bitcoin/bech32m.ts +2 -2
  207. package/src/families/bitcoin/bridge/js.ts +6 -3
  208. package/src/families/bitcoin/bridge/mock.ts +6 -2
  209. package/src/families/bitcoin/js-getFeesForTransaction.ts +1 -1
  210. package/src/families/bitcoin/js-synchronisation.ts +0 -1
  211. package/src/families/bitcoin/logic.ts +5 -2
  212. package/src/families/bitcoin/presync.ts +1 -1
  213. package/src/families/bitcoin/specs.ts +1 -1
  214. package/src/families/bitcoin/wallet-btc/crypto/base.ts +0 -20
  215. package/src/families/bitcoin/wallet-btc/crypto/bip32.ts +6 -5
  216. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +1 -9
  217. package/src/families/bitcoin/wallet-btc/crypto/factory.ts +1 -4
  218. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +1 -20
  219. package/src/families/bitcoin/wallet-btc/crypto/types.ts +0 -3
  220. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +1 -7
  221. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +1 -7
  222. package/src/families/bitcoin/wallet-btc/explorer/index.ts +24 -49
  223. package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +6 -1
  224. package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +6 -1
  225. package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +6 -1
  226. package/src/families/bitcoin/wallet-btc/storage/index.ts +34 -20
  227. package/src/families/bitcoin/wallet-btc/utils.ts +16 -21
  228. package/src/families/bitcoin/wallet-btc/wallet.ts +17 -31
  229. package/src/families/bitcoin/wallet-btc/xpub.ts +41 -150
  230. package/src/families/cardano/js-synchronisation.ts +1 -1
  231. package/src/families/cardano/specs.ts +1 -1
  232. package/src/families/celo/specs/createSendMutation.ts +1 -3
  233. package/src/families/celo/specs.ts +1 -1
  234. package/src/families/crypto_org/specs.ts +3 -2
  235. package/src/families/ethereum/specs.ts +3 -3
  236. package/src/families/evm/specs.ts +6 -6
  237. package/src/families/filecoin/__snapshots__/bridge.integration.test.ts.snap +24 -2
  238. package/src/families/filecoin/specs.ts +1 -2
  239. package/src/families/hedera/api/network.ts +10 -3
  240. package/src/families/hedera/errors.ts +5 -0
  241. package/src/families/hedera/specs.ts +0 -17
  242. package/src/families/osmosis/__snapshots__/bridge.integration.test.ts.snap +101 -3
  243. package/src/families/osmosis/specs.ts +1 -1
  244. package/src/families/polkadot/specs.ts +1 -0
  245. package/src/families/solana/specs.ts +1 -0
  246. package/src/families/tezos/bakers.whitelist-default.ts +0 -2
  247. package/src/families/tezos/bridge/js.ts +4 -1
  248. package/src/featureFlags/defaultFeatures.ts +6 -0
  249. package/src/hw/actions/app.ts +35 -4
  250. package/src/hw/connectApp.ts +18 -1
  251. package/src/manager/localization.ts +2 -2
  252. package/src/rxjs/operators/retryWithDelay.ts +36 -0
  253. package/src/rxjs/operators/throwIf.ts +40 -0
  254. package/lib/families/bitcoin/wallet-btc/utils/eventemitter.d.ts +0 -6
  255. package/lib/families/bitcoin/wallet-btc/utils/eventemitter.d.ts.map +0 -1
  256. package/lib/families/bitcoin/wallet-btc/utils/eventemitter.js +0 -64
  257. package/lib/families/bitcoin/wallet-btc/utils/eventemitter.js.map +0 -1
  258. package/src/families/bitcoin/wallet-btc/utils/eventemitter.ts +0 -9
@@ -23,15 +23,17 @@ class BitcoinLikeStorage implements IStorage {
23
23
  // returning unordered tx within the same block)
24
24
  spentUtxos: { [key: string]: Input[] } = {};
25
25
 
26
- getLastTx(txFilter: { account: number; index: number; confirmed?: boolean }) {
26
+ getLastTx(txFilter: {
27
+ account: number;
28
+ index: number;
29
+ confirmed?: boolean;
30
+ }): TX | undefined {
27
31
  if (
28
32
  typeof this.accountIndex[`${txFilter.account}-${txFilter.index}`] ===
29
33
  "undefined"
30
34
  ) {
31
35
  return undefined;
32
36
  }
33
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34
- // @ts-ignore
35
37
  const tx: TX | undefined = findLast(
36
38
  this.accountIndex[`${txFilter.account}-${txFilter.index}`].map(
37
39
  (i) => this.txs[i]
@@ -39,7 +41,7 @@ class BitcoinLikeStorage implements IStorage {
39
41
  (t) => {
40
42
  return (
41
43
  typeof txFilter.confirmed === "undefined" ||
42
- (txFilter.confirmed && t.block) ||
44
+ (txFilter.confirmed && !!t.block) ||
43
45
  (!txFilter.confirmed && !t.block)
44
46
  );
45
47
  }
@@ -47,27 +49,25 @@ class BitcoinLikeStorage implements IStorage {
47
49
  return tx;
48
50
  }
49
51
 
50
- getLastUnconfirmedTx() {
51
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
52
- // @ts-ignore
52
+ getLastUnconfirmedTx(): TX | undefined {
53
53
  const tx: TX | undefined = findLast(this.txs, (t) => {
54
54
  return !t.block;
55
55
  });
56
56
  return tx;
57
57
  }
58
58
 
59
- getTx(address: string, txId: string) {
59
+ getTx(address: string, txId: string): TX {
60
60
  const index = `${address}-${txId}`;
61
61
  return this.txs[this.primaryIndex[index]];
62
62
  }
63
63
 
64
64
  // TODO: only expose unspentUtxos
65
- getAddressUnspentUtxos(address: Address) {
65
+ getAddressUnspentUtxos(address: Address): Output[] {
66
66
  const indexAddress = address.address;
67
67
  return this.unspentUtxos[indexAddress];
68
68
  }
69
69
 
70
- appendTxs(txs: TX[]) {
70
+ appendTxs(txs: TX[]): number {
71
71
  const lastLength = this.txs.length;
72
72
 
73
73
  txs.forEach((tx) => {
@@ -118,12 +118,20 @@ class BitcoinLikeStorage implements IStorage {
118
118
  return this.txs.length - lastLength;
119
119
  }
120
120
 
121
- getUniquesAddresses(addressesFilter: { account?: number; index?: number }) {
121
+ getUniquesAddresses(addressesFilter: {
122
+ account?: number;
123
+ index?: number;
124
+ }): Address[] {
122
125
  // TODO: to speed up, create more useful indexes in appendTxs
123
126
  return uniqBy(
124
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
125
- // @ts-ignore
126
- filter(this.txs, addressesFilter).map((tx: TX) => ({
127
+ filter(
128
+ this.txs,
129
+ (t) =>
130
+ (typeof addressesFilter.account === "undefined" ||
131
+ addressesFilter.account === t.account) &&
132
+ (typeof addressesFilter.index === "undefined" ||
133
+ addressesFilter.index === t.index)
134
+ ).map((tx: TX) => ({
127
135
  address: tx.address,
128
136
  account: tx.account,
129
137
  index: tx.index,
@@ -132,7 +140,7 @@ class BitcoinLikeStorage implements IStorage {
132
140
  );
133
141
  }
134
142
 
135
- removeTxs(txsFilter: { account: number; index: number }) {
143
+ removeTxs(txsFilter: { account: number; index: number }): void {
136
144
  const newTxs: TX[] = [];
137
145
  this.primaryIndex = {};
138
146
  this.accountIndex = {};
@@ -155,7 +163,7 @@ class BitcoinLikeStorage implements IStorage {
155
163
 
156
164
  // We are a bit ugly because we can't rely undo unspentUTXO
157
165
  // So we clean the address and rebuild without the pendings
158
- removePendingTxs(txsFilter: { account: number; index: number }) {
166
+ removePendingTxs(txsFilter: { account: number; index: number }): void {
159
167
  const newTxs: TX[] = [];
160
168
  const txsToReAdd: TX[] = [];
161
169
  this.primaryIndex = {};
@@ -190,14 +198,14 @@ class BitcoinLikeStorage implements IStorage {
190
198
  this.addressCache[key] = address;
191
199
  }
192
200
 
193
- exportSync() {
201
+ exportSync(): { txs: TX[]; addressCache: { [key: string]: string } } {
194
202
  return {
195
203
  txs: this.txs,
196
204
  addressCache: this.addressCache,
197
205
  };
198
206
  }
199
207
 
200
- loadSync(data: { txs: TX[]; addressCache: { [key: string]: string } }) {
208
+ loadSync(data: { txs: TX[]; addressCache: { [key: string]: string } }): void {
201
209
  this.txs = [];
202
210
  this.primaryIndex = {};
203
211
  this.accountIndex = {};
@@ -214,11 +222,17 @@ class BitcoinLikeStorage implements IStorage {
214
222
  Base.addressCache = { ...Base.addressCache, ...this.addressCache };
215
223
  }
216
224
 
217
- async export() {
225
+ async export(): Promise<{
226
+ txs: TX[];
227
+ addressCache: { [key: string]: string };
228
+ }> {
218
229
  return this.exportSync();
219
230
  }
220
231
 
221
- async load(data: { txs: TX[]; addressCache: { [key: string]: string } }) {
232
+ async load(data: {
233
+ txs: TX[];
234
+ addressCache: { [key: string]: string };
235
+ }): Promise<void> {
222
236
  return this.loadSync(data);
223
237
  }
224
238
 
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
2
  import * as bitcoin from "bitcoinjs-lib";
3
3
  import bs58 from "bs58";
4
4
  import { padStart } from "lodash";
@@ -9,18 +9,16 @@ import { fallbackValidateAddress } from "./crypto/base";
9
9
  import { UnsupportedDerivation } from "../../../errors";
10
10
  import varuint from "varuint-bitcoin";
11
11
 
12
- export function parseHexString(str: any) {
12
+ export function parseHexString(str: any): number[] {
13
13
  const result: Array<number> = [];
14
14
  while (str.length >= 2) {
15
15
  result.push(parseInt(str.substring(0, 2), 16));
16
- // eslint-disable-next-line no-param-reassign
17
16
  str = str.substring(2, str.length);
18
17
  }
19
18
  return result;
20
19
  }
21
20
 
22
- export function encodeBase58Check(vchIn: any) {
23
- // eslint-disable-next-line no-param-reassign
21
+ export function encodeBase58Check(vchIn: any): string {
24
22
  vchIn = parseHexString(vchIn);
25
23
  let chksum = bitcoin.crypto.sha256(Buffer.from(vchIn));
26
24
  chksum = bitcoin.crypto.sha256(chksum);
@@ -29,29 +27,23 @@ export function encodeBase58Check(vchIn: any) {
29
27
  return bs58.encode(hash);
30
28
  }
31
29
 
32
- export function toHexDigit(number: any) {
30
+ export function toHexDigit(number: any): string {
33
31
  const digits = "0123456789abcdef";
34
- // eslint-disable-next-line no-bitwise
35
32
  return digits.charAt(number >> 4) + digits.charAt(number & 0x0f);
36
33
  }
37
34
 
38
- export function toHexInt(number: any) {
35
+ export function toHexInt(number: any): string {
39
36
  return (
40
- // eslint-disable-next-line no-bitwise
41
37
  toHexDigit((number >> 24) & 0xff) +
42
- // eslint-disable-next-line no-bitwise
43
38
  toHexDigit((number >> 16) & 0xff) +
44
- // eslint-disable-next-line no-bitwise
45
39
  toHexDigit((number >> 8) & 0xff) +
46
- // eslint-disable-next-line no-bitwise
47
40
  toHexDigit(number & 0xff)
48
41
  );
49
42
  }
50
43
 
51
- export function compressPublicKey(publicKey: any) {
52
- let compressedKeyIndex;
44
+ export function compressPublicKey(publicKey: any): string {
45
+ let compressedKeyIndex: string;
53
46
  if (publicKey.substring(0, 2) !== "04") {
54
- // eslint-disable-next-line no-throw-literal
55
47
  throw new Error("Invalid public key format");
56
48
  }
57
49
  if (parseInt(publicKey.substring(128, 130), 16) % 2 !== 0) {
@@ -70,7 +62,7 @@ export function createXPUB(
70
62
  chaincode: any,
71
63
  publicKey: any,
72
64
  network: any
73
- ) {
65
+ ): string {
74
66
  let xpub = toHexInt(network);
75
67
  xpub += padStart(depth.toString(16), 2, "0");
76
68
  xpub += padStart(fingerprint.toString(16), 8, "0");
@@ -80,7 +72,7 @@ export function createXPUB(
80
72
  return xpub;
81
73
  }
82
74
 
83
- export function byteSize(count: number) {
75
+ export function byteSize(count: number): number {
84
76
  if (count < 0xfd) {
85
77
  return 1;
86
78
  }
@@ -227,7 +219,7 @@ export function maxTxSizeCeil(
227
219
  }
228
220
 
229
221
  // refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/api_impl/BitcoinLikeTransactionApi.cpp#L253
230
- export function computeDustAmount(currency: ICrypto, txSize: number) {
222
+ export function computeDustAmount(currency: ICrypto, txSize: number): number {
231
223
  let dustAmount = currency.network.dustThreshold;
232
224
  switch (currency.network.dustPolicy) {
233
225
  case "PER_KBYTE":
@@ -242,7 +234,7 @@ export function computeDustAmount(currency: ICrypto, txSize: number) {
242
234
  return dustAmount;
243
235
  }
244
236
 
245
- export function isValidAddress(address: string, currency?: Currency) {
237
+ export function isValidAddress(address: string, currency?: Currency): boolean {
246
238
  if (!currency) {
247
239
  // If the caller doesn't provide the currency, we'll
248
240
  // fallback to a pre-taproot basic validation that doesn't
@@ -253,7 +245,10 @@ export function isValidAddress(address: string, currency?: Currency) {
253
245
  return crypto.validateAddress(address);
254
246
  }
255
247
 
256
- export function isTaprootAddress(address: string, currency?: Currency) {
248
+ export function isTaprootAddress(
249
+ address: string,
250
+ currency?: Currency
251
+ ): boolean {
257
252
  if (currency === "bitcoin") {
258
253
  return cryptoFactory("bitcoin").isTaprootAddress(address);
259
254
  } else if (currency === "bitcoin_testnet") {
@@ -263,7 +258,7 @@ export function isTaprootAddress(address: string, currency?: Currency) {
263
258
  }
264
259
  }
265
260
 
266
- export function writeVarInt(buffer: Buffer, i: number, offset: number) {
261
+ export function writeVarInt(buffer: Buffer, i: number, offset: number): number {
267
262
  // refer to https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f44f722d30cd14a1861c8546e6b455f73862c1e/src/bufferutils.js#L78
268
263
  varuint.encode(i, buffer, offset);
269
264
  offset += varuint.encode.bytes;
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-ignore
3
1
  import { flatten } from "lodash";
4
2
  import BigNumber from "bignumber.js";
5
3
  import Btc from "@ledgerhq/hw-app-btc";
@@ -11,16 +9,16 @@ import { Account, SerializedAccount } from "./account";
11
9
  import Xpub from "./xpub";
12
10
  import { IExplorer } from "./explorer/types";
13
11
  import BitcoinLikeExplorer from "./explorer";
14
- import { IStorage } from "./storage/types";
12
+ import { IStorage, Output } from "./storage/types";
15
13
  import BitcoinLikeStorage from "./storage";
16
14
  import { PickingStrategy } from "./pickingstrategies/types";
17
15
  import * as utils from "./utils";
18
16
  import cryptoFactory from "./crypto/factory";
17
+ import { TX, Address } from "./storage/types";
19
18
 
20
19
  class BitcoinLikeWallet {
21
20
  explorerInstances: { [key: string]: IExplorer } = {};
22
21
 
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
22
  explorers: { [key: string]: (explorerURI: string) => IExplorer } = {
25
23
  ledgerv3: (explorerURI) =>
26
24
  new BitcoinLikeExplorer({
@@ -34,12 +32,14 @@ class BitcoinLikeWallet {
34
32
  }),
35
33
  };
36
34
 
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
35
  accountStorages: { [key: string]: (...args: any[]) => IStorage } = {
39
36
  mock: () => new BitcoinLikeStorage(),
40
37
  };
41
38
 
42
- getExplorer(explorer: "ledgerv3" | "ledgerv2", explorerURI: string) {
39
+ getExplorer(
40
+ explorer: "ledgerv3" | "ledgerv2",
41
+ explorerURI: string
42
+ ): IExplorer {
43
43
  const id = `explorer-${explorer}-uri-${explorerURI}`;
44
44
  this.explorerInstances[id] =
45
45
  this.explorerInstances[id] || this.explorers[explorer](explorerURI);
@@ -56,7 +56,6 @@ class BitcoinLikeWallet {
56
56
  explorer: "ledgerv3" | "ledgerv2";
57
57
  explorerURI: string;
58
58
  storage: "mock";
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
59
  storageParams: any[];
61
60
  }): Promise<Account> {
62
61
  const crypto = cryptoFactory(params.currency);
@@ -77,31 +76,26 @@ class BitcoinLikeWallet {
77
76
  };
78
77
  }
79
78
 
80
- // eslint-disable-next-line class-methods-use-this
81
- async syncAccount(account: Account) {
79
+ async syncAccount(account: Account): Promise<number> {
82
80
  return account.xpub.sync();
83
81
  }
84
82
 
85
- // eslint-disable-next-line class-methods-use-this
86
- async getAccountNewReceiveAddress(account: Account) {
83
+ async getAccountNewReceiveAddress(account: Account): Promise<Address> {
87
84
  const address = await account.xpub.getNewAddress(0, 1);
88
85
  return address;
89
86
  }
90
87
 
91
- // eslint-disable-next-line class-methods-use-this
92
- async getAccountNewChangeAddress(account: Account) {
88
+ async getAccountNewChangeAddress(account: Account): Promise<Address> {
93
89
  const address = await account.xpub.getNewAddress(1, 1);
94
90
  return address;
95
91
  }
96
92
 
97
- // eslint-disable-next-line class-methods-use-this
98
- async getAccountTransactions(account: Account) {
99
- const txs = await account.xpub.storage.export();
93
+ async getAccountTransactions(account: Account): Promise<{ txs: TX[] }> {
94
+ const txs = (await account.xpub.storage.export()) as { txs: TX[] };
100
95
  return txs;
101
96
  }
102
97
 
103
- // eslint-disable-next-line class-methods-use-this
104
- async getAccountUnspentUtxos(account: Account) {
98
+ async getAccountUnspentUtxos(account: Account): Promise<Output[]> {
105
99
  const addresses = await account.xpub.getXpubAddresses();
106
100
  return flatten(
107
101
  await Promise.all(
@@ -112,13 +106,12 @@ class BitcoinLikeWallet {
112
106
  );
113
107
  }
114
108
 
115
- // eslint-disable-next-line class-methods-use-this
116
109
  async estimateAccountMaxSpendable(
117
110
  account: Account,
118
111
  feePerByte: number,
119
112
  excludeUTXOs: Array<{ hash: string; outputIndex: number }>,
120
113
  outputAddresses: string[] = []
121
- ) {
114
+ ): Promise<BigNumber> {
122
115
  const addresses = await account.xpub.getXpubAddresses();
123
116
  const changeAddresses = (await account.xpub.getAccountAddresses(1)).map(
124
117
  (item) => item.address
@@ -168,14 +161,12 @@ class BitcoinLikeWallet {
168
161
  return maxSpendable.lt(0) ? new BigNumber(0) : maxSpendable;
169
162
  }
170
163
 
171
- // eslint-disable-next-line class-methods-use-this
172
- async getAccountBalance(account: Account) {
164
+ async getAccountBalance(account: Account): Promise<BigNumber> {
173
165
  const balance = await account.xpub.getXpubBalance();
174
166
  return balance;
175
167
  }
176
168
 
177
- // eslint-disable-next-line class-methods-use-this
178
- async getAccountPendings(account: Account) {
169
+ async getAccountPendings(account: Account): Promise<TX[]> {
179
170
  const addresses = await account.xpub.getXpubAddresses();
180
171
  return flatten(
181
172
  await Promise.all(
@@ -184,7 +175,6 @@ class BitcoinLikeWallet {
184
175
  );
185
176
  }
186
177
 
187
- // eslint-disable-next-line class-methods-use-this
188
178
  async buildAccountTx(params: {
189
179
  fromAccount: Account;
190
180
  dest: string;
@@ -205,7 +195,6 @@ class BitcoinLikeWallet {
205
195
  return txInfo;
206
196
  }
207
197
 
208
- // eslint-disable-next-line class-methods-use-this
209
198
  async signAccountTx(params: {
210
199
  btc: Btc;
211
200
  fromAccount: Account;
@@ -225,7 +214,7 @@ class BitcoinLikeWallet {
225
214
  total: number;
226
215
  index: number;
227
216
  }) => void;
228
- }) {
217
+ }): Promise<string> {
229
218
  const {
230
219
  btc,
231
220
  fromAccount,
@@ -351,8 +340,7 @@ class BitcoinLikeWallet {
351
340
  return tx;
352
341
  }
353
342
 
354
- // eslint-disable-next-line class-methods-use-this
355
- async broadcastTx(fromAccount: Account, tx: string) {
343
+ async broadcastTx(fromAccount: Account, tx: string): Promise<string> {
356
344
  const res = await fromAccount.xpub.broadcastTx(tx);
357
345
  return res.data.result;
358
346
  }
@@ -400,7 +388,6 @@ class BitcoinLikeWallet {
400
388
  };
401
389
  }
402
390
 
403
- // eslint-disable-next-line class-methods-use-this
404
391
  async exportToSerializedAccount(
405
392
  account: Account
406
393
  ): Promise<SerializedAccount> {
@@ -415,7 +402,6 @@ class BitcoinLikeWallet {
415
402
  };
416
403
  }
417
404
 
418
- // eslint-disable-next-line class-methods-use-this
419
405
  exportToSerializedAccountSync(account: Account): SerializedAccount {
420
406
  const data = account.xpub.storage.exportSync();
421
407