@ledgerhq/live-common 21.20.0 → 21.21.0-rc.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 (428) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +4 -0
  2. package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
  3. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +12 -0
  4. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
  5. package/lib/__tests__/test-helpers/setup.js +1 -0
  6. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  7. package/lib/account/pending.d.ts +1 -1
  8. package/lib/api/Ledger.d.ts.map +1 -1
  9. package/lib/api/Ledger.js +12 -2
  10. package/lib/api/Ledger.js.map +1 -1
  11. package/lib/api/explorerConfig/index.d.ts.map +1 -1
  12. package/lib/api/explorerConfig/index.js +5 -1
  13. package/lib/api/explorerConfig/index.js.map +1 -1
  14. package/lib/data/icons/react/cro.d.ts +8 -0
  15. package/lib/data/icons/react/cro.d.ts.map +1 -0
  16. package/lib/data/icons/react/cro.js +33 -0
  17. package/lib/data/icons/react/cro.js.map +1 -0
  18. package/lib/data/icons/react/index.d.ts +2 -0
  19. package/lib/data/icons/react/index.d.ts.map +1 -1
  20. package/lib/data/icons/react/index.js +12 -8
  21. package/lib/data/icons/react/index.js.map +1 -1
  22. package/lib/data/icons/react/sol.d.ts +8 -0
  23. package/lib/data/icons/react/sol.d.ts.map +1 -0
  24. package/lib/data/icons/react/sol.js +30 -0
  25. package/lib/data/icons/react/sol.js.map +1 -0
  26. package/lib/data/icons/reactNative/cro.d.ts +8 -0
  27. package/lib/data/icons/reactNative/cro.d.ts.map +1 -0
  28. package/lib/data/icons/reactNative/cro.js +34 -0
  29. package/lib/data/icons/reactNative/cro.js.map +1 -0
  30. package/lib/data/icons/reactNative/index.d.ts +2 -0
  31. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  32. package/lib/data/icons/reactNative/index.js +12 -8
  33. package/lib/data/icons/reactNative/index.js.map +1 -1
  34. package/lib/data/icons/reactNative/sol.d.ts +8 -0
  35. package/lib/data/icons/reactNative/sol.d.ts.map +1 -0
  36. package/lib/data/icons/reactNative/sol.js +31 -0
  37. package/lib/data/icons/reactNative/sol.js.map +1 -0
  38. package/lib/derivation.d.ts +7 -0
  39. package/lib/derivation.d.ts.map +1 -1
  40. package/lib/derivation.js +16 -1
  41. package/lib/derivation.js.map +1 -1
  42. package/lib/errors.d.ts +1 -0
  43. package/lib/errors.d.ts.map +1 -1
  44. package/lib/errors.js +1 -0
  45. package/lib/errors.js.map +1 -1
  46. package/lib/families/bitcoin/exchange.d.ts +1 -1
  47. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -1
  48. package/lib/families/bitcoin/getAccountNetworkInfo.js +3 -2
  49. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -1
  50. package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
  51. package/lib/families/bitcoin/js-signOperation.js +7 -2
  52. package/lib/families/bitcoin/js-signOperation.js.map +1 -1
  53. package/lib/families/bitcoin/js-synchronisation.d.ts +2 -2
  54. package/lib/families/bitcoin/specs.d.ts +1 -0
  55. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  56. package/lib/families/bitcoin/specs.js +14 -1
  57. package/lib/families/bitcoin/specs.js.map +1 -1
  58. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +1 -1
  59. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  60. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  61. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  62. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +8 -1
  63. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  64. package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts +16 -0
  65. package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -0
  66. package/lib/families/bitcoin/wallet-btc/crypto/decred.js +248 -0
  67. package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -0
  68. package/lib/families/bitcoin/wallet-btc/crypto/factory.d.ts.map +1 -1
  69. package/lib/families/bitcoin/wallet-btc/crypto/factory.js +5 -0
  70. package/lib/families/bitcoin/wallet-btc/crypto/factory.js.map +1 -1
  71. package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts +1 -0
  72. package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts.map +1 -1
  73. package/lib/families/bitcoin/wallet-btc/crypto/index.js +3 -1
  74. package/lib/families/bitcoin/wallet-btc/crypto/index.js.map +1 -1
  75. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
  76. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +13 -3
  77. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  78. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +1 -1
  79. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
  80. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  81. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +8 -1
  82. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  83. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  84. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +8 -1
  85. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  86. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  87. package/lib/families/bitcoin/wallet-btc/utils.js +6 -1
  88. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  89. package/lib/families/bitcoin/wallet-btc/wallet.d.ts +2 -0
  90. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  91. package/lib/families/bitcoin/wallet-btc/wallet.js +15 -7
  92. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  93. package/lib/families/crypto_org/js-synchronisation.d.ts +2 -2
  94. package/lib/families/elrond/js-synchronisation.d.ts +2 -2
  95. package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
  96. package/lib/families/ethereum/synchronisation.js +2 -2
  97. package/lib/families/ethereum/synchronisation.js.map +1 -1
  98. package/lib/families/polkadot/api/sidecar.js +4 -2
  99. package/lib/families/polkadot/api/sidecar.js.map +1 -1
  100. package/lib/families/polkadot/js-synchronisation.d.ts +2 -2
  101. package/lib/families/solana/api/cached.d.ts +5 -0
  102. package/lib/families/solana/api/cached.d.ts.map +1 -0
  103. package/lib/families/solana/api/cached.js +80 -0
  104. package/lib/families/solana/api/cached.js.map +1 -0
  105. package/lib/families/solana/api/chain/account/index.d.ts +2 -0
  106. package/lib/families/solana/api/chain/account/index.d.ts.map +1 -0
  107. package/lib/families/solana/api/chain/account/index.js +14 -0
  108. package/lib/families/solana/api/chain/account/index.js.map +1 -0
  109. package/lib/families/solana/api/chain/account/parser.d.ts +5 -0
  110. package/lib/families/solana/api/chain/account/parser.d.ts.map +1 -0
  111. package/lib/families/solana/api/chain/account/parser.js +33 -0
  112. package/lib/families/solana/api/chain/account/parser.js.map +1 -0
  113. package/lib/families/solana/api/chain/account/stake.d.ts +237 -0
  114. package/lib/families/solana/api/chain/account/stake.d.ts.map +1 -0
  115. package/lib/families/solana/api/chain/account/stake.js +43 -0
  116. package/lib/families/solana/api/chain/account/stake.js.map +1 -0
  117. package/lib/families/solana/api/chain/account/token.d.ts +116 -0
  118. package/lib/families/solana/api/chain/account/token.d.ts.map +1 -0
  119. package/lib/families/solana/api/chain/account/token.js +42 -0
  120. package/lib/families/solana/api/chain/account/token.js.map +1 -0
  121. package/lib/families/solana/api/chain/index.d.ts +22 -0
  122. package/lib/families/solana/api/chain/index.d.ts.map +1 -0
  123. package/lib/families/solana/api/chain/index.js +54 -0
  124. package/lib/families/solana/api/chain/index.js.map +1 -0
  125. package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts +15 -0
  126. package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
  127. package/lib/families/solana/api/chain/instruction/associated-token-account/index.js +21 -0
  128. package/lib/families/solana/api/chain/instruction/associated-token-account/index.js.map +1 -0
  129. package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts +30 -0
  130. package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
  131. package/lib/families/solana/api/chain/instruction/associated-token-account/types.js +19 -0
  132. package/lib/families/solana/api/chain/instruction/associated-token-account/types.js.map +1 -0
  133. package/lib/families/solana/api/chain/instruction/memo/index.d.ts +15 -0
  134. package/lib/families/solana/api/chain/instruction/memo/index.d.ts.map +1 -0
  135. package/lib/families/solana/api/chain/instruction/memo/index.js +14 -0
  136. package/lib/families/solana/api/chain/instruction/memo/index.js.map +1 -0
  137. package/lib/families/solana/api/chain/instruction/memo/types.d.ts +21 -0
  138. package/lib/families/solana/api/chain/instruction/memo/types.d.ts.map +1 -0
  139. package/lib/families/solana/api/chain/instruction/memo/types.js +16 -0
  140. package/lib/families/solana/api/chain/instruction/memo/types.js.map +1 -0
  141. package/lib/families/solana/api/chain/instruction/stake/index.d.ts +15 -0
  142. package/lib/families/solana/api/chain/instruction/stake/index.d.ts.map +1 -0
  143. package/lib/families/solana/api/chain/instruction/stake/index.js +20 -0
  144. package/lib/families/solana/api/chain/instruction/stake/index.js.map +1 -0
  145. package/lib/families/solana/api/chain/instruction/stake/types.d.ts +215 -0
  146. package/lib/families/solana/api/chain/instruction/stake/types.d.ts.map +1 -0
  147. package/lib/families/solana/api/chain/instruction/stake/types.js +80 -0
  148. package/lib/families/solana/api/chain/instruction/stake/types.js.map +1 -0
  149. package/lib/families/solana/api/chain/instruction/token/index.d.ts +15 -0
  150. package/lib/families/solana/api/chain/instruction/token/index.d.ts.map +1 -0
  151. package/lib/families/solana/api/chain/instruction/token/index.js +20 -0
  152. package/lib/families/solana/api/chain/instruction/token/index.js.map +1 -0
  153. package/lib/families/solana/api/chain/instruction/token/types.d.ts +497 -0
  154. package/lib/families/solana/api/chain/instruction/token/types.d.ts.map +1 -0
  155. package/lib/families/solana/api/chain/instruction/token/types.js +205 -0
  156. package/lib/families/solana/api/chain/instruction/token/types.js.map +1 -0
  157. package/lib/families/solana/api/chain/program/constants.d.ts +11 -0
  158. package/lib/families/solana/api/chain/program/constants.d.ts.map +1 -0
  159. package/lib/families/solana/api/chain/program/constants.js +14 -0
  160. package/lib/families/solana/api/chain/program/constants.js.map +1 -0
  161. package/lib/families/solana/api/chain/program/index.d.ts +2 -0
  162. package/lib/families/solana/api/chain/program/index.d.ts.map +1 -0
  163. package/lib/families/solana/api/chain/program/index.js +14 -0
  164. package/lib/families/solana/api/chain/program/index.js.map +1 -0
  165. package/lib/families/solana/api/chain/program/parser.d.ts +30 -0
  166. package/lib/families/solana/api/chain/program/parser.d.ts.map +1 -0
  167. package/lib/families/solana/api/chain/program/parser.js +70 -0
  168. package/lib/families/solana/api/chain/program/parser.js.map +1 -0
  169. package/lib/families/solana/api/chain/validators/bignum.d.ts +3 -0
  170. package/lib/families/solana/api/chain/validators/bignum.d.ts.map +1 -0
  171. package/lib/families/solana/api/chain/validators/bignum.js +11 -0
  172. package/lib/families/solana/api/chain/validators/bignum.js.map +1 -0
  173. package/lib/families/solana/api/chain/validators/index.d.ts +10 -0
  174. package/lib/families/solana/api/chain/validators/index.d.ts.map +1 -0
  175. package/lib/families/solana/api/chain/validators/index.js +10 -0
  176. package/lib/families/solana/api/chain/validators/index.js.map +1 -0
  177. package/lib/families/solana/api/chain/validators/pubkey.d.ts +3 -0
  178. package/lib/families/solana/api/chain/validators/pubkey.d.ts.map +1 -0
  179. package/lib/families/solana/api/chain/validators/pubkey.js +7 -0
  180. package/lib/families/solana/api/chain/validators/pubkey.js.map +1 -0
  181. package/lib/families/solana/api/chain/web3.d.ts +29 -0
  182. package/lib/families/solana/api/chain/web3.d.ts.map +1 -0
  183. package/lib/families/solana/api/chain/web3.js +287 -0
  184. package/lib/families/solana/api/chain/web3.js.map +1 -0
  185. package/lib/families/solana/api/index.d.ts +5 -0
  186. package/lib/families/solana/api/index.d.ts.map +1 -0
  187. package/lib/families/solana/api/index.js +21 -0
  188. package/lib/families/solana/api/index.js.map +1 -0
  189. package/lib/families/solana/api/logged.d.ts +3 -0
  190. package/lib/families/solana/api/logged.d.ts.map +1 -0
  191. package/lib/families/solana/api/logged.js +53 -0
  192. package/lib/families/solana/api/logged.js.map +1 -0
  193. package/lib/families/solana/api/queued.d.ts +3 -0
  194. package/lib/families/solana/api/queued.d.ts.map +1 -0
  195. package/lib/families/solana/api/queued.js +31 -0
  196. package/lib/families/solana/api/queued.js.map +1 -0
  197. package/lib/families/solana/bridge/bridge.d.ts +12 -0
  198. package/lib/families/solana/bridge/bridge.d.ts.map +1 -0
  199. package/lib/families/solana/bridge/bridge.js +218 -0
  200. package/lib/families/solana/bridge/bridge.js.map +1 -0
  201. package/lib/families/solana/bridge/js.d.ts +6 -0
  202. package/lib/families/solana/bridge/js.d.ts.map +1 -0
  203. package/lib/families/solana/bridge/js.js +15 -0
  204. package/lib/families/solana/bridge/js.js.map +1 -0
  205. package/lib/families/solana/bridge/mock-data.d.ts +186 -0
  206. package/lib/families/solana/bridge/mock-data.d.ts.map +1 -0
  207. package/lib/families/solana/bridge/mock-data.js +23 -0
  208. package/lib/families/solana/bridge/mock-data.js.map +1 -0
  209. package/lib/families/solana/bridge/mock.d.ts +6 -0
  210. package/lib/families/solana/bridge/mock.d.ts.map +1 -0
  211. package/lib/families/solana/bridge/mock.js +75 -0
  212. package/lib/families/solana/bridge/mock.js.map +1 -0
  213. package/lib/families/solana/cli-transaction.d.ts +14 -0
  214. package/lib/families/solana/cli-transaction.d.ts.map +1 -0
  215. package/lib/families/solana/cli-transaction.js +137 -0
  216. package/lib/families/solana/cli-transaction.js.map +1 -0
  217. package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts +6 -0
  218. package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts.map +1 -0
  219. package/lib/families/solana/datasets/solana.scanAccounts.1.js +7 -0
  220. package/lib/families/solana/datasets/solana.scanAccounts.1.js.map +1 -0
  221. package/lib/families/solana/deviceTransactionConfig.d.ts +10 -0
  222. package/lib/families/solana/deviceTransactionConfig.d.ts.map +1 -0
  223. package/lib/families/solana/deviceTransactionConfig.js +121 -0
  224. package/lib/families/solana/deviceTransactionConfig.js.map +1 -0
  225. package/lib/families/solana/errors.d.ts +25 -0
  226. package/lib/families/solana/errors.d.ts.map +1 -0
  227. package/lib/families/solana/errors.js +13 -0
  228. package/lib/families/solana/errors.js.map +1 -0
  229. package/lib/families/solana/hw-getAddress.d.ts +4 -0
  230. package/lib/families/solana/hw-getAddress.d.ts.map +1 -0
  231. package/lib/families/solana/hw-getAddress.js +66 -0
  232. package/lib/families/solana/hw-getAddress.js.map +1 -0
  233. package/lib/families/solana/js-broadcast.d.ts +7 -0
  234. package/lib/families/solana/js-broadcast.d.ts.map +1 -0
  235. package/lib/families/solana/js-broadcast.js +59 -0
  236. package/lib/families/solana/js-broadcast.js.map +1 -0
  237. package/lib/families/solana/js-buildTransaction.d.ts +6 -0
  238. package/lib/families/solana/js-buildTransaction.d.ts.map +1 -0
  239. package/lib/families/solana/js-buildTransaction.js +123 -0
  240. package/lib/families/solana/js-buildTransaction.js.map +1 -0
  241. package/lib/families/solana/js-createTransaction.d.ts +6 -0
  242. package/lib/families/solana/js-createTransaction.d.ts.map +1 -0
  243. package/lib/families/solana/js-createTransaction.js +35 -0
  244. package/lib/families/solana/js-createTransaction.js.map +1 -0
  245. package/lib/families/solana/js-estimateMaxSpendable.d.ts +7 -0
  246. package/lib/families/solana/js-estimateMaxSpendable.d.ts.map +1 -0
  247. package/lib/families/solana/js-estimateMaxSpendable.js +72 -0
  248. package/lib/families/solana/js-estimateMaxSpendable.js.map +1 -0
  249. package/lib/families/solana/js-getTransactionStatus.d.ts +5 -0
  250. package/lib/families/solana/js-getTransactionStatus.d.ts.map +1 -0
  251. package/lib/families/solana/js-getTransactionStatus.js +106 -0
  252. package/lib/families/solana/js-getTransactionStatus.js.map +1 -0
  253. package/lib/families/solana/js-prepareTransaction.d.ts +6 -0
  254. package/lib/families/solana/js-prepareTransaction.d.ts.map +1 -0
  255. package/lib/families/solana/js-prepareTransaction.js +380 -0
  256. package/lib/families/solana/js-prepareTransaction.js.map +1 -0
  257. package/lib/families/solana/js-signOperation.d.ts +10 -0
  258. package/lib/families/solana/js-signOperation.d.ts.map +1 -0
  259. package/lib/families/solana/js-signOperation.js +193 -0
  260. package/lib/families/solana/js-signOperation.js.map +1 -0
  261. package/lib/families/solana/js-synchronization.d.ts +5 -0
  262. package/lib/families/solana/js-synchronization.d.ts.map +1 -0
  263. package/lib/families/solana/js-synchronization.js +464 -0
  264. package/lib/families/solana/js-synchronization.js.map +1 -0
  265. package/lib/families/solana/logic.d.ts +15 -0
  266. package/lib/families/solana/logic.d.ts.map +1 -0
  267. package/lib/families/solana/logic.js +49 -0
  268. package/lib/families/solana/logic.js.map +1 -0
  269. package/lib/families/solana/specs.d.ts +7 -0
  270. package/lib/families/solana/specs.d.ts.map +1 -0
  271. package/lib/families/solana/specs.js +100 -0
  272. package/lib/families/solana/specs.js.map +1 -0
  273. package/lib/families/solana/speculos-deviceActions.d.ts +8 -0
  274. package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -0
  275. package/lib/families/solana/speculos-deviceActions.js +60 -0
  276. package/lib/families/solana/speculos-deviceActions.js.map +1 -0
  277. package/lib/families/solana/test-dataset.d.ts +5 -0
  278. package/lib/families/solana/test-dataset.d.ts.map +1 -0
  279. package/lib/families/solana/test-dataset.js +396 -0
  280. package/lib/families/solana/test-dataset.js.map +1 -0
  281. package/lib/families/solana/transaction.d.ts +12 -0
  282. package/lib/families/solana/transaction.d.ts.map +1 -0
  283. package/lib/families/solana/transaction.js +109 -0
  284. package/lib/families/solana/transaction.js.map +1 -0
  285. package/lib/families/solana/types.d.ts +84 -0
  286. package/lib/families/solana/types.d.ts.map +1 -0
  287. package/lib/families/solana/types.js +6 -0
  288. package/lib/families/solana/types.js.map +1 -0
  289. package/lib/families/solana/utils.d.ts +10 -0
  290. package/lib/families/solana/utils.d.ts.map +1 -0
  291. package/lib/families/solana/utils.js +194 -0
  292. package/lib/families/solana/utils.js.map +1 -0
  293. package/lib/families/stellar/js-synchronization.d.ts +2 -2
  294. package/lib/generated/bridge/js.d.ts +4 -0
  295. package/lib/generated/bridge/js.d.ts.map +1 -1
  296. package/lib/generated/bridge/js.js +8 -6
  297. package/lib/generated/bridge/js.js.map +1 -1
  298. package/lib/generated/bridge/mock.d.ts +4 -0
  299. package/lib/generated/bridge/mock.d.ts.map +1 -1
  300. package/lib/generated/bridge/mock.js +6 -4
  301. package/lib/generated/bridge/mock.js.map +1 -1
  302. package/lib/generated/cli-transaction.d.ts +9 -0
  303. package/lib/generated/cli-transaction.d.ts.map +1 -1
  304. package/lib/generated/cli-transaction.js +8 -6
  305. package/lib/generated/cli-transaction.js.map +1 -1
  306. package/lib/generated/deviceTransactionConfig.d.ts +2 -0
  307. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  308. package/lib/generated/deviceTransactionConfig.js +8 -6
  309. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  310. package/lib/generated/exchange.d.ts +1 -1
  311. package/lib/generated/hw-getAddress.d.ts +1 -0
  312. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  313. package/lib/generated/hw-getAddress.js +8 -6
  314. package/lib/generated/hw-getAddress.js.map +1 -1
  315. package/lib/generated/specs.d.ts +4 -0
  316. package/lib/generated/specs.d.ts.map +1 -1
  317. package/lib/generated/specs.js +8 -6
  318. package/lib/generated/specs.js.map +1 -1
  319. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  320. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  321. package/lib/generated/speculos-deviceActions.js +8 -6
  322. package/lib/generated/speculos-deviceActions.js.map +1 -1
  323. package/lib/generated/test-dataset.d.ts +1 -0
  324. package/lib/generated/test-dataset.d.ts.map +1 -1
  325. package/lib/generated/test-dataset.js +8 -6
  326. package/lib/generated/test-dataset.js.map +1 -1
  327. package/lib/generated/transaction.d.ts +5 -0
  328. package/lib/generated/transaction.d.ts.map +1 -1
  329. package/lib/generated/transaction.js +8 -6
  330. package/lib/generated/transaction.js.map +1 -1
  331. package/lib/generated/types.d.ts +12 -6
  332. package/lib/generated/types.d.ts.map +1 -1
  333. package/lib/generated/types.js +5 -3
  334. package/lib/generated/types.js.map +1 -1
  335. package/lib/nft/helpers.js +1 -1
  336. package/lib/nft/helpers.js.map +1 -1
  337. package/package.json +8 -4
  338. package/src/__tests__/__snapshots__/all.libcore.ts.snap +113 -0
  339. package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +4 -0
  340. package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +12 -0
  341. package/src/__tests__/test-helpers/setup.ts +1 -0
  342. package/src/api/Ledger.ts +11 -1
  343. package/src/api/explorerConfig/index.ts +1 -3
  344. package/src/data/icons/react/cro.tsx +12 -0
  345. package/src/data/icons/react/index.tsx +2 -0
  346. package/src/data/icons/react/sol.tsx +12 -0
  347. package/src/data/icons/reactNative/cro.tsx +13 -0
  348. package/src/data/icons/reactNative/index.tsx +2 -0
  349. package/src/data/icons/reactNative/sol.tsx +13 -0
  350. package/src/data/icons/svg/CRO.svg +6 -0
  351. package/src/data/icons/svg/SOL.svg +3 -0
  352. package/src/derivation.ts +13 -0
  353. package/src/errors.ts +1 -0
  354. package/src/families/bitcoin/getAccountNetworkInfo.ts +5 -2
  355. package/src/families/bitcoin/js-signOperation.ts +4 -7
  356. package/src/families/bitcoin/specs.ts +16 -0
  357. package/src/families/bitcoin/wallet-btc/crypto/base.ts +1 -1
  358. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +8 -1
  359. package/src/families/bitcoin/wallet-btc/crypto/decred.ts +251 -0
  360. package/src/families/bitcoin/wallet-btc/crypto/factory.ts +5 -0
  361. package/src/families/bitcoin/wallet-btc/crypto/index.ts +1 -0
  362. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +13 -3
  363. package/src/families/bitcoin/wallet-btc/crypto/types.ts +1 -0
  364. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +8 -1
  365. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +8 -1
  366. package/src/families/bitcoin/wallet-btc/utils.ts +6 -1
  367. package/src/families/bitcoin/wallet-btc/wallet.ts +18 -5
  368. package/src/families/ethereum/synchronisation.ts +5 -2
  369. package/src/families/polkadot/api/sidecar.ts +2 -2
  370. package/src/families/solana/api/cached.ts +89 -0
  371. package/src/families/solana/api/chain/account/index.ts +1 -0
  372. package/src/families/solana/api/chain/account/parser.ts +35 -0
  373. package/src/families/solana/api/chain/account/stake.ts +50 -0
  374. package/src/families/solana/api/chain/account/token.ts +63 -0
  375. package/src/families/solana/api/chain/index.ts +115 -0
  376. package/src/families/solana/api/chain/instruction/associated-token-account/index.ts +37 -0
  377. package/src/families/solana/api/chain/instruction/associated-token-account/types.ts +23 -0
  378. package/src/families/solana/api/chain/instruction/memo/index.ts +24 -0
  379. package/src/families/solana/api/chain/instruction/memo/types.ts +18 -0
  380. package/src/families/solana/api/chain/instruction/stake/index.ts +29 -0
  381. package/src/families/solana/api/chain/instruction/stake/types.ts +95 -0
  382. package/src/families/solana/api/chain/instruction/token/index.ts +30 -0
  383. package/src/families/solana/api/chain/instruction/token/types.ts +237 -0
  384. package/src/families/solana/api/chain/program/constants.ts +10 -0
  385. package/src/families/solana/api/chain/program/index.ts +1 -0
  386. package/src/families/solana/api/chain/program/parser.ts +122 -0
  387. package/src/families/solana/api/chain/validators/bignum.ts +11 -0
  388. package/src/families/solana/api/chain/validators/index.ts +9 -0
  389. package/src/families/solana/api/chain/validators/pubkey.ts +8 -0
  390. package/src/families/solana/api/chain/web3.ts +258 -0
  391. package/src/families/solana/api/index.ts +4 -0
  392. package/src/families/solana/api/logged.ts +50 -0
  393. package/src/families/solana/api/queued.ts +23 -0
  394. package/src/families/solana/bridge/bridge.ts +169 -0
  395. package/src/families/solana/bridge/js.ts +28 -0
  396. package/src/families/solana/bridge/mock-data.ts +22 -0
  397. package/src/families/solana/bridge/mock.ts +80 -0
  398. package/src/families/solana/cli-transaction.ts +175 -0
  399. package/src/families/solana/datasets/solana.scanAccounts.1.ts +9 -0
  400. package/src/families/solana/deviceTransactionConfig.ts +160 -0
  401. package/src/families/solana/errors.ts +32 -0
  402. package/src/families/solana/hw-getAddress.ts +20 -0
  403. package/src/families/solana/js-broadcast.ts +20 -0
  404. package/src/families/solana/js-buildTransaction.ts +75 -0
  405. package/src/families/solana/js-createTransaction.ts +27 -0
  406. package/src/families/solana/js-estimateMaxSpendable.ts +29 -0
  407. package/src/families/solana/js-getTransactionStatus.ts +78 -0
  408. package/src/families/solana/js-prepareTransaction.ts +423 -0
  409. package/src/families/solana/js-signOperation.ts +230 -0
  410. package/src/families/solana/js-synchronization.ts +544 -0
  411. package/src/families/solana/logic.ts +52 -0
  412. package/src/families/solana/specs.ts +100 -0
  413. package/src/families/solana/speculos-deviceActions.ts +59 -0
  414. package/src/families/solana/test-dataset.ts +572 -0
  415. package/src/families/solana/transaction.ts +146 -0
  416. package/src/families/solana/types.ts +110 -0
  417. package/src/families/solana/utils.ts +80 -0
  418. package/src/generated/bridge/js.ts +3 -0
  419. package/src/generated/bridge/mock.ts +3 -0
  420. package/src/generated/cli-transaction.ts +3 -0
  421. package/src/generated/deviceTransactionConfig.ts +3 -0
  422. package/src/generated/hw-getAddress.ts +3 -0
  423. package/src/generated/specs.ts +3 -0
  424. package/src/generated/speculos-deviceActions.ts +3 -0
  425. package/src/generated/test-dataset.ts +3 -0
  426. package/src/generated/transaction.ts +3 -0
  427. package/src/generated/types.ts +14 -0
  428. package/src/nft/helpers.ts +1 -1
@@ -0,0 +1,122 @@
1
+ import {
2
+ ParsedInstruction,
3
+ PartiallyDecodedInstruction,
4
+ } from "@solana/web3.js";
5
+ import {
6
+ parseSplTokenInstruction,
7
+ TokenInstructionDescriptor,
8
+ } from "../instruction/token";
9
+ import { PARSED_PROGRAMS } from "./constants";
10
+ import {
11
+ AssociatedTokenAccountInstructionDescriptor,
12
+ parseAssociatedTokenAccountInstruction,
13
+ } from "../instruction/associated-token-account";
14
+ import {
15
+ MemoInstructionDescriptor,
16
+ parseSplMemoInstruction,
17
+ } from "../instruction/memo";
18
+ import {
19
+ parseStakeInstruction,
20
+ StakeInstructionDescriptor,
21
+ } from "../instruction/stake";
22
+
23
+ type ParsedProgram =
24
+ | {
25
+ program: "spl-associated-token-account";
26
+ title: string;
27
+ instruction: AssociatedTokenAccountInstructionDescriptor;
28
+ }
29
+ | {
30
+ program: "spl-memo";
31
+ title: string;
32
+ instruction: MemoInstructionDescriptor;
33
+ }
34
+ | {
35
+ program: "stake";
36
+ title: string;
37
+ instruction: StakeInstructionDescriptor;
38
+ }
39
+ | {
40
+ program: "spl-token";
41
+ title: string;
42
+ instruction: TokenInstructionDescriptor;
43
+ }
44
+ | {
45
+ program: "unknown";
46
+ title: "Unknown";
47
+ instruction: undefined;
48
+ };
49
+
50
+ export const parse = (
51
+ ix: ParsedInstruction | PartiallyDecodedInstruction
52
+ ): ParsedProgram => {
53
+ if ("parsed" in ix) {
54
+ const program: typeof PARSED_PROGRAMS[keyof typeof PARSED_PROGRAMS] =
55
+ ix.program as any;
56
+
57
+ switch (program) {
58
+ case "spl-associated-token-account":
59
+ return {
60
+ program,
61
+ title: "Associated Token Account",
62
+ instruction: parseAssociatedTokenAccountInstruction({
63
+ ...ix,
64
+ program,
65
+ }),
66
+ };
67
+ case "spl-memo":
68
+ return {
69
+ program,
70
+ title: "Memo",
71
+ instruction: parseSplMemoInstruction({
72
+ ...ix,
73
+ program,
74
+ }),
75
+ };
76
+ case "stake":
77
+ return {
78
+ program,
79
+ title: "Stake",
80
+ instruction: parseStakeInstruction({
81
+ ...ix,
82
+ program,
83
+ }),
84
+ };
85
+ case "spl-token":
86
+ return {
87
+ program,
88
+ title: "Token",
89
+ instruction: parseSplTokenInstruction({
90
+ ...ix,
91
+ program,
92
+ }),
93
+ };
94
+ default:
95
+ return unknown();
96
+ }
97
+ }
98
+
99
+ return unknown();
100
+ };
101
+
102
+ export const parseQuiet = (
103
+ ix: ParsedInstruction | PartiallyDecodedInstruction
104
+ ): ParsedProgram => {
105
+ try {
106
+ return parse(ix);
107
+ } catch (_) {
108
+ return unknown();
109
+ }
110
+ };
111
+
112
+ function unknown(): {
113
+ program: "unknown";
114
+ title: "Unknown";
115
+ instruction: undefined;
116
+ } {
117
+ return {
118
+ program: "unknown",
119
+ title: "Unknown",
120
+ instruction: undefined,
121
+ } as const;
122
+ }
@@ -0,0 +1,11 @@
1
+ import { coerce, instance, string } from "superstruct";
2
+ import { BigNumber } from "bignumber.js";
3
+
4
+ export const BigNumFromString = coerce(
5
+ instance(BigNumber),
6
+ string(),
7
+ (value) => {
8
+ if (typeof value === "string") return new BigNumber(value, 10);
9
+ throw new Error("invalid big num");
10
+ }
11
+ );
@@ -0,0 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/no-redeclare */
2
+
3
+ import { type, any, Infer, string } from "superstruct";
4
+
5
+ export type ParsedInfo = Infer<typeof ParsedInfo>;
6
+ export const ParsedInfo = type({
7
+ type: string(),
8
+ info: any(),
9
+ });
@@ -0,0 +1,8 @@
1
+ import { coerce, instance, string } from "superstruct";
2
+ import { PublicKey } from "@solana/web3.js";
3
+
4
+ export const PublicKeyFromString = coerce(
5
+ instance(PublicKey),
6
+ string(),
7
+ (value) => new PublicKey(value)
8
+ );
@@ -0,0 +1,258 @@
1
+ import {
2
+ Connection,
3
+ PublicKey,
4
+ SystemProgram,
5
+ Transaction,
6
+ ConfirmedSignatureInfo,
7
+ ParsedConfirmedTransaction,
8
+ TransactionInstruction,
9
+ } from "@solana/web3.js";
10
+ import { chunk } from "lodash";
11
+ import {
12
+ TokenCreateATACommand,
13
+ TokenTransferCommand,
14
+ TransferCommand,
15
+ } from "../../types";
16
+ import {
17
+ TOKEN_PROGRAM_ID,
18
+ ASSOCIATED_TOKEN_PROGRAM_ID,
19
+ Token,
20
+ } from "@solana/spl-token";
21
+ import { tryParseAsTokenAccount, parseTokenAccountInfo } from "./account";
22
+ import { TokenAccountInfo } from "./account/token";
23
+ import { drainSeqAsyncGen } from "../../utils";
24
+ import { Awaited } from "../../logic";
25
+ import { ChainAPI } from ".";
26
+
27
+ const MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
28
+
29
+ type ParsedOnChainTokenAccount = Awaited<
30
+ ReturnType<Connection["getParsedTokenAccountsByOwner"]>
31
+ >["value"][number];
32
+
33
+ export type ParsedOnChainTokenAccountWithInfo = {
34
+ onChainAcc: ParsedOnChainTokenAccount;
35
+ info: TokenAccountInfo;
36
+ };
37
+
38
+ export function toTokenAccountWithInfo(
39
+ onChainAcc: ParsedOnChainTokenAccount
40
+ ): ParsedOnChainTokenAccountWithInfo {
41
+ const parsedInfo = onChainAcc.account.data.parsed.info;
42
+ const info = parseTokenAccountInfo(parsedInfo);
43
+ return { onChainAcc, info };
44
+ }
45
+
46
+ export type TransactionDescriptor = {
47
+ parsed: ParsedConfirmedTransaction;
48
+ info: ConfirmedSignatureInfo;
49
+ };
50
+
51
+ async function* getTransactionsBatched(
52
+ address: string,
53
+ untilTxSignature: string | undefined,
54
+ api: ChainAPI
55
+ ): AsyncGenerator<TransactionDescriptor[], void, unknown> {
56
+ // as per Ledger team - last 100 operations is a sane limit to begin with
57
+ const signatures = await api.getSignaturesForAddress(address, {
58
+ until: untilTxSignature,
59
+ limit: 100,
60
+ });
61
+
62
+ // max req payload is 50K, around 200 transactions atm
63
+ // requesting 100 at a time to give some space for payload to change in future
64
+ const batchSize = 100;
65
+
66
+ for (const signaturesInfoBatch of chunk(signatures, batchSize)) {
67
+ const transactions = await api.getParsedConfirmedTransactions(
68
+ signaturesInfoBatch.map((tx) => tx.signature)
69
+ );
70
+ const txsDetails = transactions.reduce((acc, tx, index) => {
71
+ if (tx && !tx.meta?.err && tx.blockTime) {
72
+ acc.push({
73
+ info: signaturesInfoBatch[index],
74
+ parsed: tx,
75
+ });
76
+ }
77
+ return acc;
78
+ }, [] as TransactionDescriptor[]);
79
+
80
+ yield txsDetails;
81
+ }
82
+ }
83
+
84
+ async function* getTransactionsGen(
85
+ address: string,
86
+ untilTxSignature: string | undefined,
87
+ api: ChainAPI
88
+ ): AsyncGenerator<TransactionDescriptor, void, undefined> {
89
+ for await (const txDetailsBatch of getTransactionsBatched(
90
+ address,
91
+ untilTxSignature,
92
+ api
93
+ )) {
94
+ yield* txDetailsBatch;
95
+ }
96
+ }
97
+
98
+ export function getTransactions(
99
+ address: string,
100
+ untilTxSignature: string | undefined,
101
+ api: ChainAPI
102
+ ): Promise<TransactionDescriptor[]> {
103
+ return drainSeqAsyncGen(getTransactionsGen(address, untilTxSignature, api));
104
+ }
105
+
106
+ export const buildTransferInstructions = ({
107
+ sender,
108
+ recipient,
109
+ amount,
110
+ memo,
111
+ }: TransferCommand): TransactionInstruction[] => {
112
+ const fromPublicKey = new PublicKey(sender);
113
+ const toPublicKey = new PublicKey(recipient);
114
+
115
+ const instructions: TransactionInstruction[] = [
116
+ SystemProgram.transfer({
117
+ fromPubkey: fromPublicKey,
118
+ toPubkey: toPublicKey,
119
+ lamports: amount,
120
+ }),
121
+ ];
122
+
123
+ if (memo) {
124
+ const memoIx = new TransactionInstruction({
125
+ keys: [],
126
+ programId: new PublicKey(MEMO_PROGRAM_ID),
127
+ data: Buffer.from(memo),
128
+ });
129
+ instructions.push(memoIx);
130
+ }
131
+
132
+ return instructions;
133
+ };
134
+
135
+ export const buildTokenTransferInstructions = (
136
+ command: TokenTransferCommand
137
+ ): TransactionInstruction[] => {
138
+ const {
139
+ ownerAddress,
140
+ ownerAssociatedTokenAccountAddress,
141
+ amount,
142
+ recipientDescriptor,
143
+ mintAddress,
144
+ mintDecimals,
145
+ memo,
146
+ } = command;
147
+ const ownerPubkey = new PublicKey(ownerAddress);
148
+
149
+ const destinationPubkey = new PublicKey(recipientDescriptor.tokenAccAddress);
150
+
151
+ const instructions: TransactionInstruction[] = [];
152
+
153
+ const mintPubkey = new PublicKey(mintAddress);
154
+
155
+ if (recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
156
+ instructions.push(
157
+ Token.createAssociatedTokenAccountInstruction(
158
+ ASSOCIATED_TOKEN_PROGRAM_ID,
159
+ TOKEN_PROGRAM_ID,
160
+ mintPubkey,
161
+ destinationPubkey,
162
+ new PublicKey(recipientDescriptor.walletAddress),
163
+ ownerPubkey
164
+ )
165
+ );
166
+ }
167
+
168
+ instructions.push(
169
+ Token.createTransferCheckedInstruction(
170
+ TOKEN_PROGRAM_ID,
171
+ new PublicKey(ownerAssociatedTokenAccountAddress),
172
+ mintPubkey,
173
+ destinationPubkey,
174
+ ownerPubkey,
175
+ [],
176
+ amount,
177
+ mintDecimals
178
+ )
179
+ );
180
+
181
+ if (memo) {
182
+ instructions.push(
183
+ new TransactionInstruction({
184
+ keys: [],
185
+ programId: new PublicKey(MEMO_PROGRAM_ID),
186
+ data: Buffer.from(memo),
187
+ })
188
+ );
189
+ }
190
+
191
+ return instructions;
192
+ };
193
+
194
+ export const addSignatureToTransaction = ({
195
+ tx,
196
+ address,
197
+ signature,
198
+ }: {
199
+ tx: Transaction;
200
+ address: string;
201
+ signature: Buffer;
202
+ }): Transaction => {
203
+ tx.addSignature(new PublicKey(address), signature);
204
+
205
+ return tx;
206
+ };
207
+
208
+ export async function findAssociatedTokenAccountPubkey(
209
+ ownerAddress: string,
210
+ mintAddress: string
211
+ ): Promise<PublicKey> {
212
+ const ownerPubKey = new PublicKey(ownerAddress);
213
+ const mintPubkey = new PublicKey(mintAddress);
214
+
215
+ return Token.getAssociatedTokenAddress(
216
+ ASSOCIATED_TOKEN_PROGRAM_ID,
217
+ TOKEN_PROGRAM_ID,
218
+ mintPubkey,
219
+ ownerPubKey
220
+ );
221
+ }
222
+
223
+ export const getMaybeTokenAccount = async (
224
+ address: string,
225
+ api: ChainAPI
226
+ ): Promise<TokenAccountInfo | undefined | Error> => {
227
+ const accInfo = await api.getAccountInfo(address);
228
+
229
+ const tokenAccount =
230
+ accInfo !== null && "parsed" in accInfo.data
231
+ ? tryParseAsTokenAccount(accInfo.data)
232
+ : undefined;
233
+
234
+ return tokenAccount;
235
+ };
236
+
237
+ export function buildCreateAssociatedTokenAccountInstruction({
238
+ mint,
239
+ owner,
240
+ associatedTokenAccountAddress,
241
+ }: TokenCreateATACommand): TransactionInstruction[] {
242
+ const ownerPubKey = new PublicKey(owner);
243
+ const mintPubkey = new PublicKey(mint);
244
+ const associatedTokenAccPubkey = new PublicKey(associatedTokenAccountAddress);
245
+
246
+ const instructions: TransactionInstruction[] = [
247
+ Token.createAssociatedTokenAccountInstruction(
248
+ ASSOCIATED_TOKEN_PROGRAM_ID,
249
+ TOKEN_PROGRAM_ID,
250
+ mintPubkey,
251
+ associatedTokenAccPubkey,
252
+ ownerPubKey,
253
+ ownerPubKey
254
+ ),
255
+ ];
256
+
257
+ return instructions;
258
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./chain/index";
2
+ export { cached } from "./cached";
3
+ export { queued } from "./queued";
4
+ export { logged } from "./logged";
@@ -0,0 +1,50 @@
1
+ import { ChainAPI } from "./chain";
2
+
3
+ //import fs from "fs";
4
+
5
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
6
+ function write(file: string, str: string) {
7
+ // fs is not available on mobile
8
+ //fs.appendFileSync(file, str);
9
+ }
10
+
11
+ export function logged(api: ChainAPI, file: string): ChainAPI {
12
+ const proxy: ChainAPI = new Proxy(api, {
13
+ get(target, propKey, receiver) {
14
+ if (typeof propKey === "symbol") {
15
+ throw new Error("symbols not supported");
16
+ }
17
+ const targetValue = Reflect.get(target, propKey, receiver);
18
+ if (typeof targetValue === "function") {
19
+ return function (...args: unknown[]) {
20
+ const result = targetValue.apply(this, args);
21
+ const log = (answer: unknown) => {
22
+ const summary = {
23
+ method: propKey,
24
+ params: args,
25
+ answer,
26
+ };
27
+ const summaryJson = JSON.stringify(summary).replace(
28
+ /{"_bn":(".*?")}/g,
29
+ "new PublicKey(Buffer.from($1, 'hex'))"
30
+ );
31
+ write(file, summaryJson + ",\n");
32
+ };
33
+ if (result instanceof Promise) {
34
+ return result.then((answer) => {
35
+ log(answer);
36
+ return answer;
37
+ });
38
+ } else {
39
+ log(result);
40
+ return result;
41
+ }
42
+ };
43
+ } else {
44
+ return targetValue;
45
+ }
46
+ },
47
+ });
48
+
49
+ return proxy;
50
+ }
@@ -0,0 +1,23 @@
1
+ import { asyncQueue } from "../utils";
2
+ import { ChainAPI } from "./chain";
3
+
4
+ export function queued(api: ChainAPI, delayBetweenRuns = 100): ChainAPI {
5
+ const q = asyncQueue({
6
+ delayBetweenRuns,
7
+ });
8
+
9
+ const proxy: ChainAPI = new Proxy(api, {
10
+ get(target, propKey, receiver) {
11
+ const targetValue = Reflect.get(target, propKey, receiver);
12
+ if (typeof targetValue === "function") {
13
+ return function (...args: unknown[]) {
14
+ return q.submit(() => targetValue.apply(this, args));
15
+ };
16
+ } else {
17
+ return targetValue;
18
+ }
19
+ },
20
+ });
21
+
22
+ return proxy;
23
+ }
@@ -0,0 +1,169 @@
1
+ import {
2
+ GetAccountShape,
3
+ makeAccountBridgeReceive,
4
+ makeSync as makeSyncHelper,
5
+ makeScanAccounts as makeScanHelper,
6
+ } from "../../../bridge/jsHelpers";
7
+ import type {
8
+ Account,
9
+ AccountBridge,
10
+ AccountLike,
11
+ BroadcastFnSignature,
12
+ CurrencyBridge,
13
+ SignOperationFnSignature,
14
+ } from "../../../types";
15
+ import type { Transaction } from "../types";
16
+ import { getAccountShapeWithAPI } from "../js-synchronization";
17
+ import getTransactionStatus from "../js-getTransactionStatus";
18
+ import estimateMaxSpendableWithAPI from "../js-estimateMaxSpendable";
19
+ import createTransaction, { updateTransaction } from "../js-createTransaction";
20
+ import { signOperationWithAPI } from "../js-signOperation";
21
+ import { broadcastWithAPI } from "../js-broadcast";
22
+ import { prepareTransaction as prepareTransactionWithAPI } from "../js-prepareTransaction";
23
+ import { ChainAPI, Config } from "../api";
24
+ import { makeLRUCache } from "../../../cache";
25
+ import { clusterByCurrencyId } from "../utils";
26
+ import { minutes, seconds } from "../api/cached";
27
+ import hash from "object-hash";
28
+ import BigNumber from "bignumber.js";
29
+
30
+ function makePrepare(getChainAPI: (config: Config) => Promise<ChainAPI>) {
31
+ async function prepareTransaction(
32
+ mainAccount: Account,
33
+ transaction: Transaction
34
+ ) {
35
+ const config = {
36
+ cluster: clusterByCurrencyId(mainAccount.currency.id),
37
+ };
38
+
39
+ const chainAPI = await getChainAPI(config);
40
+ return prepareTransactionWithAPI(mainAccount, transaction, chainAPI);
41
+ }
42
+
43
+ const cacheKeyByAccTx = (account: Account, tx: Transaction) =>
44
+ hash({
45
+ account: {
46
+ id: account.id,
47
+ address: account.freshAddress,
48
+ syncDate: account.lastSyncDate.toISOString(),
49
+ },
50
+ tx: {
51
+ recipient: tx.recipient,
52
+ amount: tx.amount.toNumber(),
53
+ useAllAmount: tx.useAllAmount,
54
+ subAccountId: tx.subAccountId,
55
+ model: tx.model,
56
+ },
57
+ });
58
+
59
+ return makeLRUCache(prepareTransaction, cacheKeyByAccTx, seconds(30));
60
+ }
61
+
62
+ function makeSyncAndScan(getChainAPI: (config: Config) => Promise<ChainAPI>) {
63
+ const getAccountShape: GetAccountShape = async (info) => {
64
+ const config = {
65
+ cluster: clusterByCurrencyId(info.currency.id),
66
+ };
67
+
68
+ const chainAPI = await getChainAPI(config);
69
+ return getAccountShapeWithAPI(info, chainAPI);
70
+ };
71
+ return {
72
+ sync: makeSyncHelper(getAccountShape),
73
+ scan: makeScanHelper(getAccountShape),
74
+ };
75
+ }
76
+
77
+ function makeEstimateMaxSpendable(
78
+ getChainAPI: (config: Config) => Promise<ChainAPI>
79
+ ) {
80
+ async function estimateMaxSpendable(
81
+ arg: Parameters<AccountBridge<Transaction>["estimateMaxSpendable"]>[0]
82
+ ): Promise<BigNumber> {
83
+ const { account, parentAccount } = arg;
84
+
85
+ const currencyId =
86
+ account.type === "Account"
87
+ ? account.currency.id
88
+ : parentAccount?.currency.id;
89
+
90
+ if (currencyId === undefined) {
91
+ throw new Error("currency not found");
92
+ }
93
+
94
+ const config = {
95
+ cluster: clusterByCurrencyId(currencyId),
96
+ };
97
+
98
+ const api = await getChainAPI(config);
99
+
100
+ return estimateMaxSpendableWithAPI(arg, api);
101
+ }
102
+
103
+ const cacheKeyByAccBalance = ({ account }: { account: AccountLike }) =>
104
+ `${account.id}:${account.balance.toString()}`;
105
+
106
+ return makeLRUCache(estimateMaxSpendable, cacheKeyByAccBalance, minutes(5));
107
+ }
108
+
109
+ function makeBroadcast(
110
+ getChainAPI: (config: Config) => Promise<ChainAPI>
111
+ ): BroadcastFnSignature {
112
+ return async (info) => {
113
+ const config = {
114
+ cluster: clusterByCurrencyId(info.account.currency.id),
115
+ };
116
+ const api = await getChainAPI(config);
117
+ return broadcastWithAPI(info, api);
118
+ };
119
+ }
120
+
121
+ function makeSign(
122
+ getChainAPI: (config: Config) => Promise<ChainAPI>
123
+ ): SignOperationFnSignature<Transaction> {
124
+ return (info) => {
125
+ const config = {
126
+ cluster: clusterByCurrencyId(info.account.currency.id),
127
+ };
128
+ const api = () => getChainAPI(config);
129
+ return signOperationWithAPI(info, api);
130
+ };
131
+ }
132
+
133
+ export function makeBridges({
134
+ getAPI,
135
+ getQueuedAPI,
136
+ getQueuedAndCachedAPI,
137
+ }: {
138
+ getAPI: (config: Config) => Promise<ChainAPI>;
139
+ getQueuedAPI: (config: Config) => Promise<ChainAPI>;
140
+ getQueuedAndCachedAPI: (config: Config) => Promise<ChainAPI>;
141
+ }): {
142
+ currencyBridge: CurrencyBridge;
143
+ accountBridge: AccountBridge<Transaction>;
144
+ } {
145
+ const { sync, scan } = makeSyncAndScan(getQueuedAPI);
146
+
147
+ const accountBridge: AccountBridge<Transaction> = {
148
+ createTransaction,
149
+ updateTransaction,
150
+ estimateMaxSpendable: makeEstimateMaxSpendable(getQueuedAndCachedAPI),
151
+ getTransactionStatus,
152
+ sync,
153
+ receive: makeAccountBridgeReceive(),
154
+ prepareTransaction: makePrepare(getQueuedAndCachedAPI),
155
+ broadcast: makeBroadcast(getAPI),
156
+ signOperation: makeSign(getAPI),
157
+ };
158
+
159
+ const currencyBridge: CurrencyBridge = {
160
+ preload: async (): Promise<any> => {},
161
+ hydrate: (): void => {},
162
+ scanAccounts: scan,
163
+ };
164
+
165
+ return {
166
+ currencyBridge,
167
+ accountBridge,
168
+ };
169
+ }
@@ -0,0 +1,28 @@
1
+ import { cached, Config, getChainAPI, queued } from "../api";
2
+ import { makeLRUCache } from "../../../cache";
3
+ import { makeBridges } from "./bridge";
4
+ import { minutes } from "../api/cached";
5
+
6
+ const getAPI = makeLRUCache(
7
+ (config: Config) => Promise.resolve(getChainAPI(config)),
8
+ (config) => config.cluster,
9
+ minutes(1000)
10
+ );
11
+
12
+ const getQueuedAPI = makeLRUCache(
13
+ (config: Config) => getAPI(config).then((api) => queued(api, 100)),
14
+ (config) => config.cluster,
15
+ minutes(1000)
16
+ );
17
+
18
+ const getQueuedAndCachedAPI = makeLRUCache(
19
+ (config: Config) => getQueuedAPI(config).then(cached),
20
+ (config) => config.cluster,
21
+ minutes(1000)
22
+ );
23
+
24
+ export default makeBridges({
25
+ getAPI,
26
+ getQueuedAPI,
27
+ getQueuedAndCachedAPI,
28
+ });