@ledgerhq/coin-ton 0.3.12-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +19 -0
  4. package/CHANGELOG.md +15 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +12 -0
  7. package/lib/__tests__/fixtures/api.fixtures.d.ts +4 -0
  8. package/lib/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
  9. package/lib/__tests__/fixtures/api.fixtures.js +33 -0
  10. package/lib/__tests__/fixtures/api.fixtures.js.map +1 -0
  11. package/lib/__tests__/fixtures/common.fixtures.d.ts +29 -0
  12. package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
  13. package/lib/__tests__/fixtures/common.fixtures.js +124 -0
  14. package/lib/__tests__/fixtures/common.fixtures.js.map +1 -0
  15. package/lib/__tests__/integration/bridge.integration.test.d.ts +14 -0
  16. package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
  17. package/lib/__tests__/integration/bridge.integration.test.js +136 -0
  18. package/lib/__tests__/integration/bridge.integration.test.js.map +1 -0
  19. package/lib/__tests__/unit/api.unit.test.d.ts +2 -0
  20. package/lib/__tests__/unit/api.unit.test.d.ts.map +1 -0
  21. package/lib/__tests__/unit/api.unit.test.js +77 -0
  22. package/lib/__tests__/unit/api.unit.test.js.map +1 -0
  23. package/lib/__tests__/unit/broadcast.unit.test.d.ts +2 -0
  24. package/lib/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
  25. package/lib/__tests__/unit/broadcast.unit.test.js +40 -0
  26. package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -0
  27. package/lib/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
  28. package/lib/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
  29. package/lib/__tests__/unit/createTransaction.unit.test.js +34 -0
  30. package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -0
  31. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
  32. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
  33. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +74 -0
  34. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
  35. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
  36. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
  37. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +31 -0
  38. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
  39. package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
  40. package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
  41. package/lib/__tests__/unit/getTransactionStatus.unit.test.js +96 -0
  42. package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
  43. package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
  44. package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
  45. package/lib/__tests__/unit/hw-getAddress.unit.test.js +67 -0
  46. package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
  47. package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
  48. package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
  49. package/lib/__tests__/unit/prepareTransaction.unit.test.js +42 -0
  50. package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
  51. package/lib/__tests__/unit/signOperation.unit.test.d.ts +2 -0
  52. package/lib/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
  53. package/lib/__tests__/unit/signOperation.unit.test.js +83 -0
  54. package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -0
  55. package/lib/__tests__/unit/txn.unit.test.d.ts +2 -0
  56. package/lib/__tests__/unit/txn.unit.test.d.ts.map +1 -0
  57. package/lib/__tests__/unit/txn.unit.test.js +116 -0
  58. package/lib/__tests__/unit/txn.unit.test.js.map +1 -0
  59. package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
  60. package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  61. package/lib/__tests__/unit/utils.unit.test.js +97 -0
  62. package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
  63. package/lib/bridge/bridgeHelpers/api.d.ts +10 -0
  64. package/lib/bridge/bridgeHelpers/api.d.ts.map +1 -0
  65. package/lib/bridge/bridgeHelpers/api.js +104 -0
  66. package/lib/bridge/bridgeHelpers/api.js.map +1 -0
  67. package/lib/bridge/bridgeHelpers/api.types.d.ts +164 -0
  68. package/lib/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
  69. package/lib/bridge/bridgeHelpers/api.types.js +3 -0
  70. package/lib/bridge/bridgeHelpers/api.types.js.map +1 -0
  71. package/lib/bridge/bridgeHelpers/txn.d.ts +5 -0
  72. package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  73. package/lib/bridge/bridgeHelpers/txn.js +166 -0
  74. package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
  75. package/lib/bridge/js.d.ts +12 -0
  76. package/lib/bridge/js.d.ts.map +1 -0
  77. package/lib/bridge/js.js +65 -0
  78. package/lib/bridge/js.js.map +1 -0
  79. package/lib/broadcast.d.ts +5 -0
  80. package/lib/broadcast.d.ts.map +1 -0
  81. package/lib/broadcast.js +19 -0
  82. package/lib/broadcast.js.map +1 -0
  83. package/lib/cli-transaction.d.ts +12 -0
  84. package/lib/cli-transaction.d.ts.map +1 -0
  85. package/lib/cli-transaction.js +21 -0
  86. package/lib/cli-transaction.js.map +1 -0
  87. package/lib/config.d.ts +9 -0
  88. package/lib/config.d.ts.map +1 -0
  89. package/lib/config.js +16 -0
  90. package/lib/config.js.map +1 -0
  91. package/lib/createTransaction.d.ts +5 -0
  92. package/lib/createTransaction.d.ts.map +1 -0
  93. package/lib/createTransaction.js +16 -0
  94. package/lib/createTransaction.js.map +1 -0
  95. package/lib/deviceTransactionConfig.d.ts +11 -0
  96. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  97. package/lib/deviceTransactionConfig.js +37 -0
  98. package/lib/deviceTransactionConfig.js.map +1 -0
  99. package/lib/errors.d.ts +4 -0
  100. package/lib/errors.d.ts.map +1 -0
  101. package/lib/errors.js +9 -0
  102. package/lib/errors.js.map +1 -0
  103. package/lib/estimateMaxSpendable.d.ts +5 -0
  104. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  105. package/lib/estimateMaxSpendable.js +32 -0
  106. package/lib/estimateMaxSpendable.js.map +1 -0
  107. package/lib/getTransactionStatus.d.ts +5 -0
  108. package/lib/getTransactionStatus.d.ts.map +1 -0
  109. package/lib/getTransactionStatus.js +97 -0
  110. package/lib/getTransactionStatus.js.map +1 -0
  111. package/lib/hw-getAddress.d.ts +6 -0
  112. package/lib/hw-getAddress.d.ts.map +1 -0
  113. package/lib/hw-getAddress.js +31 -0
  114. package/lib/hw-getAddress.js.map +1 -0
  115. package/lib/hw-signMessage.d.ts +12 -0
  116. package/lib/hw-signMessage.d.ts.map +1 -0
  117. package/lib/hw-signMessage.js +33 -0
  118. package/lib/hw-signMessage.js.map +1 -0
  119. package/lib/prepareTransaction.d.ts +5 -0
  120. package/lib/prepareTransaction.d.ts.map +1 -0
  121. package/lib/prepareTransaction.js +29 -0
  122. package/lib/prepareTransaction.js.map +1 -0
  123. package/lib/signOperation.d.ts +11 -0
  124. package/lib/signOperation.d.ts.map +1 -0
  125. package/lib/signOperation.js +96 -0
  126. package/lib/signOperation.js.map +1 -0
  127. package/lib/signer.d.ts +27 -0
  128. package/lib/signer.d.ts.map +1 -0
  129. package/lib/signer.js +3 -0
  130. package/lib/signer.js.map +1 -0
  131. package/lib/specs.d.ts +8 -0
  132. package/lib/specs.d.ts.map +1 -0
  133. package/lib/specs.js +106 -0
  134. package/lib/specs.js.map +1 -0
  135. package/lib/speculos-deviceActions.d.ts +4 -0
  136. package/lib/speculos-deviceActions.d.ts.map +1 -0
  137. package/lib/speculos-deviceActions.js +34 -0
  138. package/lib/speculos-deviceActions.js.map +1 -0
  139. package/lib/synchronisation.d.ts +5 -0
  140. package/lib/synchronisation.d.ts.map +1 -0
  141. package/lib/synchronisation.js +95 -0
  142. package/lib/synchronisation.js.map +1 -0
  143. package/lib/transaction.d.ts +14 -0
  144. package/lib/transaction.d.ts.map +1 -0
  145. package/lib/transaction.js +41 -0
  146. package/lib/transaction.js.map +1 -0
  147. package/lib/types.d.ts +65 -0
  148. package/lib/types.d.ts.map +1 -0
  149. package/lib/types.js +3 -0
  150. package/lib/types.js.map +1 -0
  151. package/lib/utils.d.ts +11 -0
  152. package/lib/utils.d.ts.map +1 -0
  153. package/lib/utils.js +125 -0
  154. package/lib/utils.js.map +1 -0
  155. package/lib-es/__tests__/fixtures/api.fixtures.d.ts +4 -0
  156. package/lib-es/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
  157. package/lib-es/__tests__/fixtures/api.fixtures.js +30 -0
  158. package/lib-es/__tests__/fixtures/api.fixtures.js.map +1 -0
  159. package/lib-es/__tests__/fixtures/common.fixtures.d.ts +29 -0
  160. package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
  161. package/lib-es/__tests__/fixtures/common.fixtures.js +118 -0
  162. package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -0
  163. package/lib-es/__tests__/integration/bridge.integration.test.d.ts +14 -0
  164. package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
  165. package/lib-es/__tests__/integration/bridge.integration.test.js +130 -0
  166. package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -0
  167. package/lib-es/__tests__/unit/api.unit.test.d.ts +2 -0
  168. package/lib-es/__tests__/unit/api.unit.test.d.ts.map +1 -0
  169. package/lib-es/__tests__/unit/api.unit.test.js +52 -0
  170. package/lib-es/__tests__/unit/api.unit.test.js.map +1 -0
  171. package/lib-es/__tests__/unit/broadcast.unit.test.d.ts +2 -0
  172. package/lib-es/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
  173. package/lib-es/__tests__/unit/broadcast.unit.test.js +35 -0
  174. package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -0
  175. package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
  176. package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
  177. package/lib-es/__tests__/unit/createTransaction.unit.test.js +29 -0
  178. package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -0
  179. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
  180. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
  181. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +69 -0
  182. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
  183. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
  184. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
  185. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +26 -0
  186. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
  187. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
  188. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
  189. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +91 -0
  190. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
  191. package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
  192. package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
  193. package/lib-es/__tests__/unit/hw-getAddress.unit.test.js +62 -0
  194. package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
  195. package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
  196. package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
  197. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +37 -0
  198. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
  199. package/lib-es/__tests__/unit/signOperation.unit.test.d.ts +2 -0
  200. package/lib-es/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
  201. package/lib-es/__tests__/unit/signOperation.unit.test.js +78 -0
  202. package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -0
  203. package/lib-es/__tests__/unit/txn.unit.test.d.ts +2 -0
  204. package/lib-es/__tests__/unit/txn.unit.test.d.ts.map +1 -0
  205. package/lib-es/__tests__/unit/txn.unit.test.js +111 -0
  206. package/lib-es/__tests__/unit/txn.unit.test.js.map +1 -0
  207. package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
  208. package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  209. package/lib-es/__tests__/unit/utils.unit.test.js +95 -0
  210. package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
  211. package/lib-es/bridge/bridgeHelpers/api.d.ts +10 -0
  212. package/lib-es/bridge/bridgeHelpers/api.d.ts.map +1 -0
  213. package/lib-es/bridge/bridgeHelpers/api.js +93 -0
  214. package/lib-es/bridge/bridgeHelpers/api.js.map +1 -0
  215. package/lib-es/bridge/bridgeHelpers/api.types.d.ts +164 -0
  216. package/lib-es/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
  217. package/lib-es/bridge/bridgeHelpers/api.types.js +2 -0
  218. package/lib-es/bridge/bridgeHelpers/api.types.js.map +1 -0
  219. package/lib-es/bridge/bridgeHelpers/txn.d.ts +5 -0
  220. package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  221. package/lib-es/bridge/bridgeHelpers/txn.js +158 -0
  222. package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
  223. package/lib-es/bridge/js.d.ts +12 -0
  224. package/lib-es/bridge/js.d.ts.map +1 -0
  225. package/lib-es/bridge/js.js +56 -0
  226. package/lib-es/bridge/js.js.map +1 -0
  227. package/lib-es/broadcast.d.ts +5 -0
  228. package/lib-es/broadcast.d.ts.map +1 -0
  229. package/lib-es/broadcast.js +17 -0
  230. package/lib-es/broadcast.js.map +1 -0
  231. package/lib-es/cli-transaction.d.ts +12 -0
  232. package/lib-es/cli-transaction.d.ts.map +1 -0
  233. package/lib-es/cli-transaction.js +15 -0
  234. package/lib-es/cli-transaction.js.map +1 -0
  235. package/lib-es/config.d.ts +9 -0
  236. package/lib-es/config.d.ts.map +1 -0
  237. package/lib-es/config.js +11 -0
  238. package/lib-es/config.js.map +1 -0
  239. package/lib-es/createTransaction.d.ts +5 -0
  240. package/lib-es/createTransaction.d.ts.map +1 -0
  241. package/lib-es/createTransaction.js +14 -0
  242. package/lib-es/createTransaction.js.map +1 -0
  243. package/lib-es/deviceTransactionConfig.d.ts +11 -0
  244. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  245. package/lib-es/deviceTransactionConfig.js +35 -0
  246. package/lib-es/deviceTransactionConfig.js.map +1 -0
  247. package/lib-es/errors.d.ts +4 -0
  248. package/lib-es/errors.d.ts.map +1 -0
  249. package/lib-es/errors.js +6 -0
  250. package/lib-es/errors.js.map +1 -0
  251. package/lib-es/estimateMaxSpendable.d.ts +5 -0
  252. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  253. package/lib-es/estimateMaxSpendable.js +30 -0
  254. package/lib-es/estimateMaxSpendable.js.map +1 -0
  255. package/lib-es/getTransactionStatus.d.ts +5 -0
  256. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  257. package/lib-es/getTransactionStatus.js +93 -0
  258. package/lib-es/getTransactionStatus.js.map +1 -0
  259. package/lib-es/hw-getAddress.d.ts +6 -0
  260. package/lib-es/hw-getAddress.d.ts.map +1 -0
  261. package/lib-es/hw-getAddress.js +29 -0
  262. package/lib-es/hw-getAddress.js.map +1 -0
  263. package/lib-es/hw-signMessage.d.ts +12 -0
  264. package/lib-es/hw-signMessage.d.ts.map +1 -0
  265. package/lib-es/hw-signMessage.js +29 -0
  266. package/lib-es/hw-signMessage.js.map +1 -0
  267. package/lib-es/prepareTransaction.d.ts +5 -0
  268. package/lib-es/prepareTransaction.d.ts.map +1 -0
  269. package/lib-es/prepareTransaction.js +27 -0
  270. package/lib-es/prepareTransaction.js.map +1 -0
  271. package/lib-es/signOperation.d.ts +11 -0
  272. package/lib-es/signOperation.d.ts.map +1 -0
  273. package/lib-es/signOperation.js +91 -0
  274. package/lib-es/signOperation.js.map +1 -0
  275. package/lib-es/signer.d.ts +27 -0
  276. package/lib-es/signer.d.ts.map +1 -0
  277. package/lib-es/signer.js +2 -0
  278. package/lib-es/signer.js.map +1 -0
  279. package/lib-es/specs.d.ts +8 -0
  280. package/lib-es/specs.d.ts.map +1 -0
  281. package/lib-es/specs.js +99 -0
  282. package/lib-es/specs.js.map +1 -0
  283. package/lib-es/speculos-deviceActions.d.ts +4 -0
  284. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  285. package/lib-es/speculos-deviceActions.js +31 -0
  286. package/lib-es/speculos-deviceActions.js.map +1 -0
  287. package/lib-es/synchronisation.d.ts +5 -0
  288. package/lib-es/synchronisation.d.ts.map +1 -0
  289. package/lib-es/synchronisation.js +88 -0
  290. package/lib-es/synchronisation.js.map +1 -0
  291. package/lib-es/transaction.d.ts +14 -0
  292. package/lib-es/transaction.d.ts.map +1 -0
  293. package/lib-es/transaction.js +33 -0
  294. package/lib-es/transaction.js.map +1 -0
  295. package/lib-es/types.d.ts +65 -0
  296. package/lib-es/types.d.ts.map +1 -0
  297. package/lib-es/types.js +2 -0
  298. package/lib-es/types.js.map +1 -0
  299. package/lib-es/utils.d.ts +11 -0
  300. package/lib-es/utils.d.ts.map +1 -0
  301. package/lib-es/utils.js +112 -0
  302. package/lib-es/utils.js.map +1 -0
  303. package/package.json +86 -0
  304. package/src/__tests__/fixtures/api.fixtures.ts +39 -0
  305. package/src/__tests__/fixtures/common.fixtures.ts +139 -0
  306. package/src/__tests__/integration/bridge.integration.test.ts +135 -0
  307. package/src/__tests__/unit/api.unit.test.ts +60 -0
  308. package/src/__tests__/unit/broadcast.unit.test.ts +36 -0
  309. package/src/__tests__/unit/createTransaction.unit.test.ts +20 -0
  310. package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +69 -0
  311. package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +19 -0
  312. package/src/__tests__/unit/getTransactionStatus.unit.test.ts +119 -0
  313. package/src/__tests__/unit/hw-getAddress.unit.test.ts +58 -0
  314. package/src/__tests__/unit/prepareTransaction.unit.test.ts +52 -0
  315. package/src/__tests__/unit/signOperation.unit.test.ts +90 -0
  316. package/src/__tests__/unit/txn.unit.test.ts +121 -0
  317. package/src/__tests__/unit/utils.unit.test.ts +126 -0
  318. package/src/bridge/bridgeHelpers/api.ts +104 -0
  319. package/src/bridge/bridgeHelpers/api.types.ts +178 -0
  320. package/src/bridge/bridgeHelpers/txn.ts +166 -0
  321. package/src/bridge/js.ts +65 -0
  322. package/src/broadcast.ts +13 -0
  323. package/src/cli-transaction.ts +30 -0
  324. package/src/config.ts +21 -0
  325. package/src/createTransaction.ts +17 -0
  326. package/src/deviceTransactionConfig.ts +48 -0
  327. package/src/errors.ts +6 -0
  328. package/src/estimateMaxSpendable.ts +40 -0
  329. package/src/getTransactionStatus.ts +130 -0
  330. package/src/hw-getAddress.ts +28 -0
  331. package/src/hw-signMessage.ts +31 -0
  332. package/src/prepareTransaction.ts +27 -0
  333. package/src/signOperation.ts +115 -0
  334. package/src/signer.ts +32 -0
  335. package/src/specs.ts +122 -0
  336. package/src/speculos-deviceActions.ts +38 -0
  337. package/src/synchronisation.ts +91 -0
  338. package/src/transaction.ts +61 -0
  339. package/src/types.ts +82 -0
  340. package/src/utils.ts +120 -0
  341. package/tsconfig.json +12 -0
@@ -0,0 +1,166 @@
1
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
2
+ import { Operation } from "@ledgerhq/types-live";
3
+ import { Address } from "@ton/ton";
4
+ import BigNumber from "bignumber.js";
5
+ import { TonOperation } from "../../types";
6
+ import { isAddressValid } from "../../utils";
7
+ import { fetchTransactions } from "./api";
8
+ import { TonAddressBook, TonTransaction, TonTransactionsList } from "./api.types";
9
+
10
+ export async function getTransactions(
11
+ addr: string,
12
+ startLt?: string,
13
+ ): Promise<TonTransactionsList> {
14
+ const txs = await fetchTransactions(addr, { startLt });
15
+ if (txs.transactions.length === 0) return txs;
16
+ let tmpTxs: TonTransactionsList;
17
+ let isUncompletedResult = true;
18
+
19
+ while (isUncompletedResult) {
20
+ const { lt, hash } = txs.transactions[txs.transactions.length - 1];
21
+ tmpTxs = await fetchTransactions(addr, { startLt, endLt: lt });
22
+ // we found the last transaction
23
+ if (tmpTxs.transactions.length === 1) {
24
+ isUncompletedResult = false;
25
+ break;
26
+ }
27
+ // it should always match
28
+ if (hash !== tmpTxs.transactions[0].hash) throw Error("[ton] transaction hash does not match");
29
+ tmpTxs.transactions.shift(); // first element is repeated
30
+ txs.transactions.push(...tmpTxs.transactions);
31
+ txs.address_book = { ...txs.address_book, ...tmpTxs.address_book };
32
+ }
33
+ return txs;
34
+ }
35
+
36
+ function getFriendlyAddress(addressBook: TonAddressBook, rawAddr?: string | null): string[] {
37
+ if (!rawAddr) return [];
38
+ if (addressBook[rawAddr]) return [addressBook[rawAddr].user_friendly];
39
+ if (!isAddressValid(rawAddr)) throw new Error("[ton] address is not valid");
40
+ return [Address.parse(rawAddr).toString({ urlSafe: true, bounceable: true })];
41
+ }
42
+
43
+ export function mapTxToOps(
44
+ accountId: string,
45
+ addr: string,
46
+ addressBook: TonAddressBook,
47
+ ): (tx: TonTransaction) => TonOperation[] {
48
+ return (tx: TonTransaction): TonOperation[] => {
49
+ const ops: TonOperation[] = [];
50
+
51
+ if (tx.out_msgs.length > 1) throw Error(`[ton] txn with > 1 output not expected ${tx}`);
52
+
53
+ const accountAddr = Address.parse(tx.account).toString({ urlSafe: true, bounceable: false });
54
+
55
+ if (accountAddr !== addr) throw Error(`[ton] unexpected address ${accountAddr} ${addr}`);
56
+
57
+ const isReceiving =
58
+ tx.in_msg &&
59
+ tx.in_msg.source &&
60
+ tx.in_msg.source !== "" &&
61
+ tx.in_msg.value &&
62
+ tx.in_msg.value !== "0" &&
63
+ tx.account === tx.in_msg.destination;
64
+
65
+ const isSending =
66
+ tx.out_msgs.length !== 0 &&
67
+ tx.out_msgs[0].source &&
68
+ tx.out_msgs[0].source !== "" &&
69
+ tx.out_msgs[0].value &&
70
+ tx.out_msgs[0].value !== "0" &&
71
+ tx.account === tx.out_msgs[0].source;
72
+
73
+ const date = new Date(tx.now * 1000); // now is defined in seconds
74
+ const hash = tx.in_msg?.hash ?? tx.hash; // this is the hash we know in signature time
75
+ const hasFailed =
76
+ tx.description.compute_ph.success === false && tx.description.compute_ph.exit_code !== 0;
77
+
78
+ if (isReceiving) {
79
+ let subOperations: Operation[] | undefined;
80
+ if (tx.total_fees !== "0") {
81
+ // these are small amount of fees payed when receiving
82
+ // we don't want to show them in the charts
83
+ subOperations = [
84
+ {
85
+ id: encodeOperationId(accountId, hash, "NONE"),
86
+ hash,
87
+ type: "NONE",
88
+ value: BigNumber(tx.total_fees),
89
+ fee: BigNumber(0),
90
+ blockHeight: tx.mc_block_seqno ?? 1,
91
+ blockHash: null,
92
+ hasFailed,
93
+ accountId,
94
+ senders: [accountAddr],
95
+ recipients: [],
96
+ date,
97
+ extra: {
98
+ lt: tx.lt,
99
+ explorerHash: tx.hash,
100
+ comment: {
101
+ isEncrypted: false,
102
+ text: "",
103
+ },
104
+ },
105
+ },
106
+ ];
107
+ }
108
+ ops.push({
109
+ id: encodeOperationId(accountId, hash, "IN"),
110
+ hash,
111
+ type: "IN",
112
+ value: BigNumber(tx.in_msg?.value ?? 0),
113
+ fee: BigNumber(tx.total_fees),
114
+ blockHeight: tx.mc_block_seqno ?? 1,
115
+ blockHash: null,
116
+ hasFailed,
117
+ accountId,
118
+ senders: getFriendlyAddress(addressBook, tx.in_msg?.source),
119
+ recipients: [accountAddr],
120
+ date,
121
+ extra: {
122
+ lt: tx.lt,
123
+ explorerHash: tx.hash,
124
+ comment: {
125
+ isEncrypted: tx.in_msg?.message_content?.decoded?.type === "binary_comment",
126
+ text:
127
+ tx.in_msg?.message_content?.decoded?.type === "text_comment"
128
+ ? tx.in_msg.message_content.decoded.comment
129
+ : "",
130
+ },
131
+ },
132
+ subOperations,
133
+ });
134
+ }
135
+
136
+ if (isSending) {
137
+ ops.push({
138
+ id: encodeOperationId(accountId, hash, "OUT"),
139
+ hash: tx.out_msgs[0].hash, // this hash matches with in_msg.hash of IN transaction
140
+ type: "OUT",
141
+ value: BigNumber(tx.out_msgs[0].value ?? 0),
142
+ fee: BigNumber(tx.total_fees),
143
+ blockHeight: tx.mc_block_seqno ?? 1,
144
+ blockHash: null,
145
+ hasFailed,
146
+ accountId,
147
+ senders: [accountAddr],
148
+ recipients: getFriendlyAddress(addressBook, tx.out_msgs[0].destination),
149
+ date,
150
+ extra: {
151
+ lt: tx.lt,
152
+ explorerHash: tx.hash,
153
+ comment: {
154
+ isEncrypted: tx.out_msgs[0].message_content?.decoded?.type === "binary_comment",
155
+ text:
156
+ tx.out_msgs[0].message_content?.decoded?.type === "text_comment"
157
+ ? tx.out_msgs[0].message_content.decoded.comment
158
+ : "",
159
+ },
160
+ },
161
+ });
162
+ }
163
+
164
+ return ops;
165
+ };
166
+ }
@@ -0,0 +1,65 @@
1
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import {
3
+ defaultUpdateTransaction,
4
+ makeAccountBridgeReceive,
5
+ makeScanAccounts,
6
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
7
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
8
+
9
+ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
10
+ import broadcast from "../broadcast";
11
+ import { TonCoinConfig, setCoinConfig } from "../config";
12
+ import createTransaction from "../createTransaction";
13
+ import estimateMaxSpendable from "../estimateMaxSpendable";
14
+ import getTransactionStatus from "../getTransactionStatus";
15
+ import resolver from "../hw-getAddress";
16
+ import prepareTransaction from "../prepareTransaction";
17
+ import { buildSignOperation } from "../signOperation";
18
+ import { TonSigner } from "../signer";
19
+ import { getAccountShape, sync } from "../synchronisation";
20
+ import type { Transaction } from "../types";
21
+
22
+ export function buildCurrencyBridge(signerContext: SignerContext<TonSigner>): CurrencyBridge {
23
+ const getAddress = resolver(signerContext);
24
+
25
+ const scanAccounts = makeScanAccounts({
26
+ getAccountShape,
27
+ getAddressFn: getAddress,
28
+ });
29
+
30
+ return {
31
+ preload: async () => Promise.resolve({}),
32
+ hydrate: () => {},
33
+ scanAccounts,
34
+ };
35
+ }
36
+
37
+ export function buildAccountBridge(
38
+ signerContext: SignerContext<TonSigner>,
39
+ ): AccountBridge<Transaction> {
40
+ const getAddress = resolver(signerContext);
41
+
42
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
43
+ const signOperation = buildSignOperation(signerContext);
44
+
45
+ return {
46
+ estimateMaxSpendable,
47
+ createTransaction,
48
+ updateTransaction: defaultUpdateTransaction,
49
+ getTransactionStatus,
50
+ prepareTransaction,
51
+ sync,
52
+ receive,
53
+ signOperation,
54
+ broadcast,
55
+ };
56
+ }
57
+
58
+ export function createBridges(signerContext: SignerContext<TonSigner>, coinConfig: TonCoinConfig) {
59
+ setCoinConfig(coinConfig);
60
+
61
+ return {
62
+ currencyBridge: buildCurrencyBridge(signerContext),
63
+ accountBridge: buildAccountBridge(signerContext),
64
+ };
65
+ }
@@ -0,0 +1,13 @@
1
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
2
+ import type { AccountBridge } from "@ledgerhq/types-live";
3
+ import { broadcastTx } from "./bridge/bridgeHelpers/api";
4
+ import { Transaction } from "./types";
5
+
6
+ const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
7
+ signedOperation: { signature, operation },
8
+ }) => {
9
+ const hash = await broadcastTx(signature);
10
+ return patchOperationWithHash(operation, hash);
11
+ };
12
+
13
+ export default broadcast;
@@ -0,0 +1,30 @@
1
+ import invariant from "invariant";
2
+ import flatMap from "lodash/flatMap";
3
+
4
+ import type { AccountLike } from "@ledgerhq/types-live";
5
+ import { Transaction } from "./types";
6
+
7
+ function inferTransactions(
8
+ transactions: Array<{
9
+ account: AccountLike;
10
+ transaction: Transaction;
11
+ }>,
12
+ opts: Record<string, string>,
13
+ ): Transaction[] {
14
+ return flatMap(transactions, ({ transaction }) => {
15
+ invariant(transaction.family === "ton", "ton family");
16
+
17
+ return {
18
+ ...transaction,
19
+ family: "ton",
20
+ mode: opts.mode || "send",
21
+ } as Transaction;
22
+ });
23
+ }
24
+
25
+ export default function makeCliTools() {
26
+ return {
27
+ options: [],
28
+ inferTransactions,
29
+ };
30
+ }
package/src/config.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { CurrencyConfig } from "@ledgerhq/coin-framework/config";
2
+
3
+ export type TonCoinConfig = () => CurrencyConfig & {
4
+ infra: {
5
+ API_TON_ENDPOINT: string;
6
+ };
7
+ };
8
+
9
+ let coinConfig: TonCoinConfig | undefined;
10
+
11
+ export const setCoinConfig = (config: TonCoinConfig): void => {
12
+ coinConfig = config;
13
+ };
14
+
15
+ export const getCoinConfig = (): ReturnType<TonCoinConfig> => {
16
+ if (!coinConfig?.()) {
17
+ throw new Error("Ton module config not set");
18
+ }
19
+
20
+ return coinConfig();
21
+ };
@@ -0,0 +1,17 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import { BigNumber } from "bignumber.js";
3
+ import type { Transaction } from "./types";
4
+
5
+ const createTransaction: AccountBridge<Transaction>["createTransaction"] = (): Transaction => ({
6
+ family: "ton",
7
+ amount: new BigNumber(0),
8
+ fees: new BigNumber(0),
9
+ recipient: "",
10
+ useAllAmount: false,
11
+ comment: {
12
+ isEncrypted: false,
13
+ text: "",
14
+ },
15
+ });
16
+
17
+ export default createTransaction;
@@ -0,0 +1,48 @@
1
+ import { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
2
+ import type { Account, AccountLike } from "@ledgerhq/types-live";
3
+ import type { Transaction, TransactionStatus } from "./types";
4
+
5
+ function getDeviceTransactionConfig(input: {
6
+ account: AccountLike;
7
+ parentAccount: Account | null | undefined;
8
+ transaction: Transaction;
9
+ status: TransactionStatus;
10
+ }): Array<DeviceTransactionField> {
11
+ const fields: Array<DeviceTransactionField> = [];
12
+
13
+ fields.push({
14
+ type: "address",
15
+ label: "To",
16
+ address: input.transaction.recipient,
17
+ });
18
+
19
+ if (input.transaction.useAllAmount) {
20
+ fields.push({
21
+ type: "text",
22
+ label: "Amount",
23
+ value: "ALL YOUR TONs",
24
+ });
25
+ } else {
26
+ fields.push({
27
+ type: "amount",
28
+ label: "Amount",
29
+ });
30
+ }
31
+
32
+ fields.push({
33
+ type: "fees",
34
+ label: "Fee",
35
+ });
36
+
37
+ if (!input.transaction.comment.isEncrypted && input.transaction.comment.text) {
38
+ fields.push({
39
+ type: "text",
40
+ label: "Comment",
41
+ value: input.transaction.comment.text,
42
+ });
43
+ }
44
+
45
+ return fields;
46
+ }
47
+
48
+ export default getDeviceTransactionConfig;
package/src/errors.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+
3
+ /*
4
+ * When the comment is invalid.
5
+ */
6
+ export const TonCommentInvalid = createCustomErrorClass("TonCommentInvalid");
@@ -0,0 +1,40 @@
1
+ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
2
+ import type { Account, AccountBridge, AccountLike } from "@ledgerhq/types-live";
3
+ import { BigNumber } from "bignumber.js";
4
+ import { fetchAccountInfo } from "./bridge/bridgeHelpers/api";
5
+ import type { Transaction } from "./types";
6
+ import { buildTonTransaction, getTonEstimatedFees } from "./utils";
7
+
8
+ const estimateMaxSpendable: AccountBridge<Transaction, Account>["estimateMaxSpendable"] = async ({
9
+ account,
10
+ parentAccount,
11
+ transaction,
12
+ }: {
13
+ account: AccountLike;
14
+ parentAccount?: Account | null | undefined;
15
+ transaction?: Transaction | null | undefined;
16
+ }): Promise<BigNumber> => {
17
+ const mainAccount = getMainAccount(account, parentAccount);
18
+ let balance = mainAccount.spendableBalance;
19
+
20
+ if (balance.eq(0)) return balance;
21
+
22
+ const accountInfo = await fetchAccountInfo(mainAccount.freshAddress);
23
+
24
+ const estimatedFees = transaction
25
+ ? transaction.fees ??
26
+ (await getTonEstimatedFees(
27
+ mainAccount,
28
+ accountInfo.status === "uninit",
29
+ buildTonTransaction(transaction, accountInfo.seqno),
30
+ ))
31
+ : BigNumber(0);
32
+
33
+ if (balance.lte(estimatedFees)) return new BigNumber(0);
34
+
35
+ balance = balance.minus(estimatedFees);
36
+
37
+ return balance;
38
+ };
39
+
40
+ export default estimateMaxSpendable;
@@ -0,0 +1,130 @@
1
+ import {
2
+ AmountRequired,
3
+ InvalidAddress,
4
+ InvalidAddressBecauseDestinationIsAlsoSource,
5
+ NotEnoughBalance,
6
+ RecipientRequired,
7
+ } from "@ledgerhq/errors";
8
+ import { Account, AccountBridge, SubAccount } from "@ledgerhq/types-live";
9
+ import BigNumber from "bignumber.js";
10
+ import { TonCommentInvalid } from "./errors";
11
+ import { Transaction, TransactionStatus } from "./types";
12
+ import { addressesAreEqual, commentIsValid, isAddressValid } from "./utils";
13
+
14
+ type ValidatedTransactionFields = "recipient" | "sender" | "amount" | "transaction";
15
+ type ValidationIssues = Partial<Record<ValidatedTransactionFields, Error>>;
16
+
17
+ /**
18
+ * Validate an address for account transaction
19
+ */
20
+ const validateRecipient = (account: Account, tx: Transaction): Array<ValidationIssues> => {
21
+ const errors: ValidationIssues = {};
22
+
23
+ if (tx.recipient) {
24
+ // Check if recipient is matching the format of account valid eth address or not
25
+ const isRecipientValidate = isAddressValid(tx.recipient);
26
+
27
+ if (!isRecipientValidate) {
28
+ errors.recipient = new InvalidAddress("", {
29
+ currencyName: account.currency.name,
30
+ });
31
+ }
32
+ if (addressesAreEqual(account.freshAddress, tx.recipient)) {
33
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource("", {
34
+ currencyName: account.currency.name,
35
+ });
36
+ }
37
+ } else {
38
+ errors.recipient = new RecipientRequired(); // ""
39
+ }
40
+
41
+ return [errors];
42
+ };
43
+
44
+ /**
45
+ * Validate the sender address for account transaction
46
+ */
47
+ const validateSender = (account: Account): Array<ValidationIssues> => {
48
+ const errors: ValidationIssues = {};
49
+
50
+ // Check if sender is matching the format of account valid ton address or not
51
+ const isSenderValidate = isAddressValid(account.freshAddress);
52
+
53
+ if (!isSenderValidate) {
54
+ errors.sender = new InvalidAddress("", {
55
+ currencyName: account.currency.name,
56
+ });
57
+ }
58
+
59
+ return [errors];
60
+ };
61
+
62
+ const validateAmount = (
63
+ account: Account | SubAccount,
64
+ transaction: Transaction,
65
+ totalSpent: BigNumber,
66
+ ): Array<ValidationIssues> => {
67
+ const errors: ValidationIssues = {};
68
+ const warnings: ValidationIssues = {};
69
+
70
+ // if no amount or 0
71
+ if (!transaction.amount || transaction.amount.isZero()) {
72
+ errors.amount = new AmountRequired(); // "Amount required"
73
+ } else if (totalSpent.isGreaterThan(account.balance)) {
74
+ // if not enough to make the transaction
75
+ errors.amount = new NotEnoughBalance(); // "Sorry, insufficient funds"
76
+ }
77
+
78
+ return [errors, warnings];
79
+ };
80
+
81
+ const validateComment = (transaction: Transaction): Array<ValidationIssues> => {
82
+ const errors: ValidationIssues = {};
83
+
84
+ // if the comment isn'transaction encrypted, it should be valid
85
+ if (transaction.comment.isEncrypted || !commentIsValid(transaction.comment)) {
86
+ errors.transaction = new TonCommentInvalid();
87
+ }
88
+ return [errors];
89
+ };
90
+
91
+ export const getTransactionStatus: AccountBridge<
92
+ Transaction,
93
+ Account,
94
+ TransactionStatus
95
+ >["getTransactionStatus"] = async (
96
+ account: Account,
97
+ transaction: Transaction,
98
+ ): Promise<TransactionStatus> => {
99
+ const totalSpent = transaction.amount.plus(transaction.fees);
100
+
101
+ // Recipient related errors and warnings
102
+ const [recipientErr] = validateRecipient(account, transaction);
103
+ // Sender related errors and warnings
104
+ const [senderErr] = validateSender(account);
105
+ // Amount related errors and warnings
106
+ const [amountErr, amountWarn] = validateAmount(account, transaction, totalSpent);
107
+ // Transaction related errors and warnings
108
+ const [transactionErr] = validateComment(transaction);
109
+
110
+ const errors: ValidationIssues = {
111
+ ...recipientErr,
112
+ ...senderErr,
113
+ ...amountErr,
114
+ ...transactionErr,
115
+ };
116
+
117
+ const warnings: ValidationIssues = {
118
+ ...amountWarn,
119
+ };
120
+
121
+ return {
122
+ amount: transaction.amount,
123
+ errors,
124
+ warnings,
125
+ estimatedFees: transaction.fees,
126
+ totalSpent,
127
+ };
128
+ };
129
+
130
+ export default getTransactionStatus;
@@ -0,0 +1,28 @@
1
+ import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
3
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
4
+ import { TonSigner } from "./signer";
5
+ import { getLedgerTonPath } from "./utils";
6
+
7
+ const resolver = (signerContext: SignerContext<TonSigner>): GetAddressFn => {
8
+ return async (deviceId: string, { path, verify }: GetAddressOptions) => {
9
+ const ledgerPath = getLedgerTonPath(path);
10
+
11
+ const sig = await signerContext(deviceId, async signer => {
12
+ return verify
13
+ ? await signer.validateAddress(ledgerPath, { bounceable: false })
14
+ : await signer.getAddress(ledgerPath, { bounceable: false });
15
+ });
16
+
17
+ if (!sig.address || !sig.publicKey.length)
18
+ throw Error(`[ton] Response is empty ${sig.address} ${sig.publicKey}`);
19
+
20
+ return {
21
+ address: sig.address,
22
+ publicKey: sig.publicKey.toString("hex"),
23
+ path,
24
+ };
25
+ };
26
+ };
27
+
28
+ export default resolver;
@@ -0,0 +1,31 @@
1
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
2
+ import { Account, AnyMessage } from "@ledgerhq/types-live";
3
+ import { TonSigner } from "./signer";
4
+ import { TonTransaction } from "./types";
5
+ import { getLedgerTonPath } from "./utils";
6
+
7
+ export const signMessage =
8
+ (signerContext: SignerContext<TonSigner>) =>
9
+ async (deviceId: string, account: Account, { message }: AnyMessage) => {
10
+ if (typeof message !== "string") throw new Error("Invalid message value");
11
+
12
+ const parsedMessage = JSON.parse(message);
13
+ const ledgerPath = getLedgerTonPath(account.freshAddressPath);
14
+
15
+ const sig = await signerContext(deviceId, signer =>
16
+ signer.signTransaction(ledgerPath, parsedMessage as TonTransaction),
17
+ );
18
+
19
+ if (!sig) {
20
+ throw new Error("No signature");
21
+ }
22
+
23
+ return {
24
+ rsv: {
25
+ r: "",
26
+ s: "",
27
+ v: 0,
28
+ },
29
+ signature: sig.toString(),
30
+ };
31
+ };
@@ -0,0 +1,27 @@
1
+ import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
+ import { Account, AccountBridge } from "@ledgerhq/types-live";
3
+ import { fetchAccountInfo } from "./bridge/bridgeHelpers/api";
4
+ import type { Transaction } from "./types";
5
+ import { buildTonTransaction, getTonEstimatedFees } from "./utils";
6
+
7
+ const prepareTransaction: AccountBridge<Transaction, Account>["prepareTransaction"] = async (
8
+ account: Account,
9
+ transaction: Transaction,
10
+ ): Promise<Transaction> => {
11
+ const accountInfo = await fetchAccountInfo(account.freshAddress);
12
+
13
+ const simpleTx = buildTonTransaction(transaction, accountInfo.seqno);
14
+
15
+ const fees = await getTonEstimatedFees(account, accountInfo.status === "uninit", simpleTx);
16
+
17
+ let amount;
18
+ if (transaction.useAllAmount) {
19
+ amount = account.spendableBalance.minus(fees);
20
+ } else {
21
+ amount = transaction.amount;
22
+ }
23
+
24
+ return defaultUpdateTransaction(transaction, { fees, amount });
25
+ };
26
+
27
+ export default prepareTransaction;