@ledgerhq/coin-canton 0.2.0-nightly.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 (424) hide show
  1. package/.env.integ.test.example +2 -0
  2. package/.eslintrc.js +22 -0
  3. package/.turbo/turbo-build.log +4 -0
  4. package/.unimportedrc.json +29 -0
  5. package/CHANGELOG.md +14 -0
  6. package/LICENSE.txt +21 -0
  7. package/jest.config.js +21 -0
  8. package/jest.integ.config.js +8 -0
  9. package/lib/api/index.d.ts +4 -0
  10. package/lib/api/index.d.ts.map +1 -0
  11. package/lib/api/index.js +44 -0
  12. package/lib/api/index.js.map +1 -0
  13. package/lib/api/index.test.d.ts +2 -0
  14. package/lib/api/index.test.d.ts.map +1 -0
  15. package/lib/api/index.test.js +16 -0
  16. package/lib/api/index.test.js.map +1 -0
  17. package/lib/bridge/broadcast.d.ts +4 -0
  18. package/lib/bridge/broadcast.d.ts.map +1 -0
  19. package/lib/bridge/broadcast.js +11 -0
  20. package/lib/bridge/broadcast.js.map +1 -0
  21. package/lib/bridge/broadcast.test.d.ts +2 -0
  22. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  23. package/lib/bridge/broadcast.test.js +35 -0
  24. package/lib/bridge/broadcast.test.js.map +1 -0
  25. package/lib/bridge/createTransaction.d.ts +4 -0
  26. package/lib/bridge/createTransaction.d.ts.map +1 -0
  27. package/lib/bridge/createTransaction.js +19 -0
  28. package/lib/bridge/createTransaction.js.map +1 -0
  29. package/lib/bridge/createTransaction.test.d.ts +2 -0
  30. package/lib/bridge/createTransaction.test.d.ts.map +1 -0
  31. package/lib/bridge/createTransaction.test.js +12 -0
  32. package/lib/bridge/createTransaction.test.js.map +1 -0
  33. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  34. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  35. package/lib/bridge/deviceTransactionConfig.js +21 -0
  36. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  37. package/lib/bridge/deviceTransactionConfig.test.d.ts +2 -0
  38. package/lib/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  39. package/lib/bridge/deviceTransactionConfig.test.js +22 -0
  40. package/lib/bridge/deviceTransactionConfig.test.js.map +1 -0
  41. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  42. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  43. package/lib/bridge/estimateMaxSpendable.js +26 -0
  44. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  45. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  46. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  47. package/lib/bridge/getTransactionStatus.js +78 -0
  48. package/lib/bridge/getTransactionStatus.js.map +1 -0
  49. package/lib/bridge/index.d.ts +11 -0
  50. package/lib/bridge/index.d.ts.map +1 -0
  51. package/lib/bridge/index.js +51 -0
  52. package/lib/bridge/index.js.map +1 -0
  53. package/lib/bridge/index.test.d.ts +2 -0
  54. package/lib/bridge/index.test.d.ts.map +1 -0
  55. package/lib/bridge/index.test.js +31 -0
  56. package/lib/bridge/index.test.js.map +1 -0
  57. package/lib/bridge/prepareTransaction.d.ts +4 -0
  58. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  59. package/lib/bridge/prepareTransaction.js +20 -0
  60. package/lib/bridge/prepareTransaction.js.map +1 -0
  61. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  62. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  63. package/lib/bridge/prepareTransaction.test.js +30 -0
  64. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  65. package/lib/bridge/signOperation.d.ts +5 -0
  66. package/lib/bridge/signOperation.d.ts.map +1 -0
  67. package/lib/bridge/signOperation.js +71 -0
  68. package/lib/bridge/signOperation.js.map +1 -0
  69. package/lib/bridge/sync.d.ts +3 -0
  70. package/lib/bridge/sync.d.ts.map +1 -0
  71. package/lib/bridge/sync.js +86 -0
  72. package/lib/bridge/sync.js.map +1 -0
  73. package/lib/bridge/transaction.d.ts +15 -0
  74. package/lib/bridge/transaction.d.ts.map +1 -0
  75. package/lib/bridge/transaction.js +50 -0
  76. package/lib/bridge/transaction.js.map +1 -0
  77. package/lib/bridge/updateTransaction.d.ts +4 -0
  78. package/lib/bridge/updateTransaction.d.ts.map +1 -0
  79. package/lib/bridge/updateTransaction.js +17 -0
  80. package/lib/bridge/updateTransaction.js.map +1 -0
  81. package/lib/common-logic/account/getBalance.d.ts +3 -0
  82. package/lib/common-logic/account/getBalance.d.ts.map +1 -0
  83. package/lib/common-logic/account/getBalance.js +10 -0
  84. package/lib/common-logic/account/getBalance.js.map +1 -0
  85. package/lib/common-logic/account/getNextSequence.d.ts +2 -0
  86. package/lib/common-logic/account/getNextSequence.d.ts.map +1 -0
  87. package/lib/common-logic/account/getNextSequence.js +9 -0
  88. package/lib/common-logic/account/getNextSequence.js.map +1 -0
  89. package/lib/common-logic/common.d.ts +3 -0
  90. package/lib/common-logic/common.d.ts.map +1 -0
  91. package/lib/common-logic/common.js +11 -0
  92. package/lib/common-logic/common.js.map +1 -0
  93. package/lib/common-logic/history/lastBlock.d.ts +3 -0
  94. package/lib/common-logic/history/lastBlock.d.ts.map +1 -0
  95. package/lib/common-logic/history/lastBlock.js +13 -0
  96. package/lib/common-logic/history/lastBlock.js.map +1 -0
  97. package/lib/common-logic/history/listOperations.d.ts +11 -0
  98. package/lib/common-logic/history/listOperations.d.ts.map +1 -0
  99. package/lib/common-logic/history/listOperations.js +52 -0
  100. package/lib/common-logic/history/listOperations.js.map +1 -0
  101. package/lib/common-logic/index.d.ts +11 -0
  102. package/lib/common-logic/index.d.ts.map +1 -0
  103. package/lib/common-logic/index.js +24 -0
  104. package/lib/common-logic/index.js.map +1 -0
  105. package/lib/common-logic/transaction/broadcast.d.ts +2 -0
  106. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -0
  107. package/lib/common-logic/transaction/broadcast.js +9 -0
  108. package/lib/common-logic/transaction/broadcast.js.map +1 -0
  109. package/lib/common-logic/transaction/combine.d.ts +2 -0
  110. package/lib/common-logic/transaction/combine.d.ts.map +1 -0
  111. package/lib/common-logic/transaction/combine.js +9 -0
  112. package/lib/common-logic/transaction/combine.js.map +1 -0
  113. package/lib/common-logic/transaction/craftTransaction.d.ts +15 -0
  114. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -0
  115. package/lib/common-logic/transaction/craftTransaction.js +20 -0
  116. package/lib/common-logic/transaction/craftTransaction.js.map +1 -0
  117. package/lib/common-logic/transaction/estimateFees.d.ts +2 -0
  118. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -0
  119. package/lib/common-logic/transaction/estimateFees.js +21 -0
  120. package/lib/common-logic/transaction/estimateFees.js.map +1 -0
  121. package/lib/common-logic/utils.d.ts +6 -0
  122. package/lib/common-logic/utils.d.ts.map +1 -0
  123. package/lib/common-logic/utils.js +22 -0
  124. package/lib/common-logic/utils.js.map +1 -0
  125. package/lib/config.d.ts +12 -0
  126. package/lib/config.d.ts.map +1 -0
  127. package/lib/config.js +9 -0
  128. package/lib/config.js.map +1 -0
  129. package/lib/index.d.ts +4 -0
  130. package/lib/index.d.ts.map +1 -0
  131. package/lib/index.js +21 -0
  132. package/lib/index.js.map +1 -0
  133. package/lib/network/indexer.d.ts +6 -0
  134. package/lib/network/indexer.d.ts.map +1 -0
  135. package/lib/network/indexer.js +19 -0
  136. package/lib/network/indexer.js.map +1 -0
  137. package/lib/network/mock-network.d.ts +5 -0
  138. package/lib/network/mock-network.d.ts.map +1 -0
  139. package/lib/network/mock-network.js +29 -0
  140. package/lib/network/mock-network.js.map +1 -0
  141. package/lib/network/node.d.ts +12 -0
  142. package/lib/network/node.d.ts.map +1 -0
  143. package/lib/network/node.js +92 -0
  144. package/lib/network/node.js.map +1 -0
  145. package/lib/network/types.d.ts +47 -0
  146. package/lib/network/types.d.ts.map +1 -0
  147. package/lib/network/types.js +7 -0
  148. package/lib/network/types.js.map +1 -0
  149. package/lib/signer/getAddress.d.ts +6 -0
  150. package/lib/signer/getAddress.d.ts.map +1 -0
  151. package/lib/signer/getAddress.js +14 -0
  152. package/lib/signer/getAddress.js.map +1 -0
  153. package/lib/signer/index.d.ts +6 -0
  154. package/lib/signer/index.d.ts.map +1 -0
  155. package/lib/signer/index.js +11 -0
  156. package/lib/signer/index.js.map +1 -0
  157. package/lib/test/bot-deviceActions.d.ts +4 -0
  158. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  159. package/lib/test/bot-deviceActions.js +44 -0
  160. package/lib/test/bot-deviceActions.js.map +1 -0
  161. package/lib/test/bot-specs.d.ts +2 -0
  162. package/lib/test/bot-specs.d.ts.map +1 -0
  163. package/lib/test/bot-specs.js +79 -0
  164. package/lib/test/bot-specs.js.map +1 -0
  165. package/lib/test/bridgeDatasetTest.d.ts +5 -0
  166. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  167. package/lib/test/bridgeDatasetTest.js +148 -0
  168. package/lib/test/bridgeDatasetTest.js.map +1 -0
  169. package/lib/test/cli.d.ts +26 -0
  170. package/lib/test/cli.d.ts.map +1 -0
  171. package/lib/test/cli.js +36 -0
  172. package/lib/test/cli.js.map +1 -0
  173. package/lib/test/index.d.ts +5 -0
  174. package/lib/test/index.d.ts.map +1 -0
  175. package/lib/test/index.js +26 -0
  176. package/lib/test/index.js.map +1 -0
  177. package/lib/types/bridge.d.ts +23 -0
  178. package/lib/types/bridge.d.ts.map +1 -0
  179. package/lib/types/bridge.js +3 -0
  180. package/lib/types/bridge.js.map +1 -0
  181. package/lib/types/errors.d.ts +4 -0
  182. package/lib/types/errors.d.ts.map +1 -0
  183. package/lib/types/errors.js +6 -0
  184. package/lib/types/errors.js.map +1 -0
  185. package/lib/types/index.d.ts +13 -0
  186. package/lib/types/index.d.ts.map +1 -0
  187. package/lib/types/index.js +19 -0
  188. package/lib/types/index.js.map +1 -0
  189. package/lib/types/signer.d.ts +10 -0
  190. package/lib/types/signer.d.ts.map +1 -0
  191. package/lib/types/signer.js +3 -0
  192. package/lib/types/signer.js.map +1 -0
  193. package/lib-es/api/index.d.ts +4 -0
  194. package/lib-es/api/index.d.ts.map +1 -0
  195. package/lib-es/api/index.js +38 -0
  196. package/lib-es/api/index.js.map +1 -0
  197. package/lib-es/api/index.test.d.ts +2 -0
  198. package/lib-es/api/index.test.d.ts.map +1 -0
  199. package/lib-es/api/index.test.js +14 -0
  200. package/lib-es/api/index.test.js.map +1 -0
  201. package/lib-es/bridge/broadcast.d.ts +4 -0
  202. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  203. package/lib-es/bridge/broadcast.js +7 -0
  204. package/lib-es/bridge/broadcast.js.map +1 -0
  205. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  206. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  207. package/lib-es/bridge/broadcast.test.js +33 -0
  208. package/lib-es/bridge/broadcast.test.js.map +1 -0
  209. package/lib-es/bridge/createTransaction.d.ts +4 -0
  210. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  211. package/lib-es/bridge/createTransaction.js +12 -0
  212. package/lib-es/bridge/createTransaction.js.map +1 -0
  213. package/lib-es/bridge/createTransaction.test.d.ts +2 -0
  214. package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
  215. package/lib-es/bridge/createTransaction.test.js +10 -0
  216. package/lib-es/bridge/createTransaction.test.js.map +1 -0
  217. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  218. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  219. package/lib-es/bridge/deviceTransactionConfig.js +19 -0
  220. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  221. package/lib-es/bridge/deviceTransactionConfig.test.d.ts +2 -0
  222. package/lib-es/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  223. package/lib-es/bridge/deviceTransactionConfig.test.js +17 -0
  224. package/lib-es/bridge/deviceTransactionConfig.test.js.map +1 -0
  225. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  226. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  227. package/lib-es/bridge/estimateMaxSpendable.js +19 -0
  228. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  229. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  230. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  231. package/lib-es/bridge/getTransactionStatus.js +71 -0
  232. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  233. package/lib-es/bridge/index.d.ts +11 -0
  234. package/lib-es/bridge/index.d.ts.map +1 -0
  235. package/lib-es/bridge/index.js +45 -0
  236. package/lib-es/bridge/index.js.map +1 -0
  237. package/lib-es/bridge/index.test.d.ts +2 -0
  238. package/lib-es/bridge/index.test.d.ts.map +1 -0
  239. package/lib-es/bridge/index.test.js +29 -0
  240. package/lib-es/bridge/index.test.js.map +1 -0
  241. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  242. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  243. package/lib-es/bridge/prepareTransaction.js +13 -0
  244. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  245. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  246. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  247. package/lib-es/bridge/prepareTransaction.test.js +25 -0
  248. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  249. package/lib-es/bridge/signOperation.d.ts +5 -0
  250. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  251. package/lib-es/bridge/signOperation.js +67 -0
  252. package/lib-es/bridge/signOperation.js.map +1 -0
  253. package/lib-es/bridge/sync.d.ts +3 -0
  254. package/lib-es/bridge/sync.d.ts.map +1 -0
  255. package/lib-es/bridge/sync.js +79 -0
  256. package/lib-es/bridge/sync.js.map +1 -0
  257. package/lib-es/bridge/transaction.d.ts +15 -0
  258. package/lib-es/bridge/transaction.d.ts.map +1 -0
  259. package/lib-es/bridge/transaction.js +44 -0
  260. package/lib-es/bridge/transaction.js.map +1 -0
  261. package/lib-es/bridge/updateTransaction.d.ts +4 -0
  262. package/lib-es/bridge/updateTransaction.d.ts.map +1 -0
  263. package/lib-es/bridge/updateTransaction.js +13 -0
  264. package/lib-es/bridge/updateTransaction.js.map +1 -0
  265. package/lib-es/common-logic/account/getBalance.d.ts +3 -0
  266. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -0
  267. package/lib-es/common-logic/account/getBalance.js +7 -0
  268. package/lib-es/common-logic/account/getBalance.js.map +1 -0
  269. package/lib-es/common-logic/account/getNextSequence.d.ts +2 -0
  270. package/lib-es/common-logic/account/getNextSequence.d.ts.map +1 -0
  271. package/lib-es/common-logic/account/getNextSequence.js +6 -0
  272. package/lib-es/common-logic/account/getNextSequence.js.map +1 -0
  273. package/lib-es/common-logic/common.d.ts +3 -0
  274. package/lib-es/common-logic/common.d.ts.map +1 -0
  275. package/lib-es/common-logic/common.js +7 -0
  276. package/lib-es/common-logic/common.js.map +1 -0
  277. package/lib-es/common-logic/history/lastBlock.d.ts +3 -0
  278. package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -0
  279. package/lib-es/common-logic/history/lastBlock.js +10 -0
  280. package/lib-es/common-logic/history/lastBlock.js.map +1 -0
  281. package/lib-es/common-logic/history/listOperations.d.ts +11 -0
  282. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -0
  283. package/lib-es/common-logic/history/listOperations.js +49 -0
  284. package/lib-es/common-logic/history/listOperations.js.map +1 -0
  285. package/lib-es/common-logic/index.d.ts +11 -0
  286. package/lib-es/common-logic/index.d.ts.map +1 -0
  287. package/lib-es/common-logic/index.js +11 -0
  288. package/lib-es/common-logic/index.js.map +1 -0
  289. package/lib-es/common-logic/transaction/broadcast.d.ts +2 -0
  290. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -0
  291. package/lib-es/common-logic/transaction/broadcast.js +6 -0
  292. package/lib-es/common-logic/transaction/broadcast.js.map +1 -0
  293. package/lib-es/common-logic/transaction/combine.d.ts +2 -0
  294. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -0
  295. package/lib-es/common-logic/transaction/combine.js +6 -0
  296. package/lib-es/common-logic/transaction/combine.js.map +1 -0
  297. package/lib-es/common-logic/transaction/craftTransaction.d.ts +15 -0
  298. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -0
  299. package/lib-es/common-logic/transaction/craftTransaction.js +17 -0
  300. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -0
  301. package/lib-es/common-logic/transaction/estimateFees.d.ts +2 -0
  302. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -0
  303. package/lib-es/common-logic/transaction/estimateFees.js +18 -0
  304. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -0
  305. package/lib-es/common-logic/utils.d.ts +6 -0
  306. package/lib-es/common-logic/utils.d.ts.map +1 -0
  307. package/lib-es/common-logic/utils.js +13 -0
  308. package/lib-es/common-logic/utils.js.map +1 -0
  309. package/lib-es/config.d.ts +12 -0
  310. package/lib-es/config.d.ts.map +1 -0
  311. package/lib-es/config.js +4 -0
  312. package/lib-es/config.js.map +1 -0
  313. package/lib-es/index.d.ts +4 -0
  314. package/lib-es/index.d.ts.map +1 -0
  315. package/lib-es/index.js +3 -0
  316. package/lib-es/index.js.map +1 -0
  317. package/lib-es/network/indexer.d.ts +6 -0
  318. package/lib-es/network/indexer.d.ts.map +1 -0
  319. package/lib-es/network/indexer.js +12 -0
  320. package/lib-es/network/indexer.js.map +1 -0
  321. package/lib-es/network/mock-network.d.ts +5 -0
  322. package/lib-es/network/mock-network.d.ts.map +1 -0
  323. package/lib-es/network/mock-network.js +25 -0
  324. package/lib-es/network/mock-network.js.map +1 -0
  325. package/lib-es/network/node.d.ts +12 -0
  326. package/lib-es/network/node.d.ts.map +1 -0
  327. package/lib-es/network/node.js +80 -0
  328. package/lib-es/network/node.js.map +1 -0
  329. package/lib-es/network/types.d.ts +47 -0
  330. package/lib-es/network/types.d.ts.map +1 -0
  331. package/lib-es/network/types.js +4 -0
  332. package/lib-es/network/types.js.map +1 -0
  333. package/lib-es/signer/getAddress.d.ts +6 -0
  334. package/lib-es/signer/getAddress.d.ts.map +1 -0
  335. package/lib-es/signer/getAddress.js +12 -0
  336. package/lib-es/signer/getAddress.js.map +1 -0
  337. package/lib-es/signer/index.d.ts +6 -0
  338. package/lib-es/signer/index.d.ts.map +1 -0
  339. package/lib-es/signer/index.js +6 -0
  340. package/lib-es/signer/index.js.map +1 -0
  341. package/lib-es/test/bot-deviceActions.d.ts +4 -0
  342. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  343. package/lib-es/test/bot-deviceActions.js +41 -0
  344. package/lib-es/test/bot-deviceActions.js.map +1 -0
  345. package/lib-es/test/bot-specs.d.ts +1 -0
  346. package/lib-es/test/bot-specs.d.ts.map +1 -0
  347. package/lib-es/test/bot-specs.js +78 -0
  348. package/lib-es/test/bot-specs.js.map +1 -0
  349. package/lib-es/test/bridgeDatasetTest.d.ts +5 -0
  350. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  351. package/lib-es/test/bridgeDatasetTest.js +142 -0
  352. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  353. package/lib-es/test/cli.d.ts +26 -0
  354. package/lib-es/test/cli.d.ts.map +1 -0
  355. package/lib-es/test/cli.js +30 -0
  356. package/lib-es/test/cli.js.map +1 -0
  357. package/lib-es/test/index.d.ts +5 -0
  358. package/lib-es/test/index.d.ts.map +1 -0
  359. package/lib-es/test/index.js +6 -0
  360. package/lib-es/test/index.js.map +1 -0
  361. package/lib-es/types/bridge.d.ts +23 -0
  362. package/lib-es/types/bridge.d.ts.map +1 -0
  363. package/lib-es/types/bridge.js +2 -0
  364. package/lib-es/types/bridge.js.map +1 -0
  365. package/lib-es/types/errors.d.ts +4 -0
  366. package/lib-es/types/errors.d.ts.map +1 -0
  367. package/lib-es/types/errors.js +3 -0
  368. package/lib-es/types/errors.js.map +1 -0
  369. package/lib-es/types/index.d.ts +13 -0
  370. package/lib-es/types/index.d.ts.map +1 -0
  371. package/lib-es/types/index.js +3 -0
  372. package/lib-es/types/index.js.map +1 -0
  373. package/lib-es/types/signer.d.ts +10 -0
  374. package/lib-es/types/signer.d.ts.map +1 -0
  375. package/lib-es/types/signer.js +2 -0
  376. package/lib-es/types/signer.js.map +1 -0
  377. package/package.json +137 -0
  378. package/src/api/index.test.ts +15 -0
  379. package/src/api/index.ts +65 -0
  380. package/src/bridge/broadcast.test.ts +36 -0
  381. package/src/bridge/broadcast.ts +11 -0
  382. package/src/bridge/createTransaction.test.ts +12 -0
  383. package/src/bridge/createTransaction.ts +14 -0
  384. package/src/bridge/deviceTransactionConfig.test.ts +22 -0
  385. package/src/bridge/deviceTransactionConfig.ts +34 -0
  386. package/src/bridge/estimateMaxSpendable.ts +25 -0
  387. package/src/bridge/getTransactionStatus.ts +88 -0
  388. package/src/bridge/index.test.ts +31 -0
  389. package/src/bridge/index.ts +62 -0
  390. package/src/bridge/prepareTransaction.test.ts +29 -0
  391. package/src/bridge/prepareTransaction.ts +25 -0
  392. package/src/bridge/signOperation.ts +93 -0
  393. package/src/bridge/sync.ts +106 -0
  394. package/src/bridge/transaction.ts +61 -0
  395. package/src/bridge/updateTransaction.ts +17 -0
  396. package/src/common-logic/account/getBalance.ts +8 -0
  397. package/src/common-logic/account/getNextSequence.ts +6 -0
  398. package/src/common-logic/common.ts +9 -0
  399. package/src/common-logic/history/lastBlock.ts +11 -0
  400. package/src/common-logic/history/listOperations.ts +64 -0
  401. package/src/common-logic/index.ts +11 -0
  402. package/src/common-logic/transaction/broadcast.ts +6 -0
  403. package/src/common-logic/transaction/combine.ts +6 -0
  404. package/src/common-logic/transaction/craftTransaction.ts +36 -0
  405. package/src/common-logic/transaction/estimateFees.ts +16 -0
  406. package/src/common-logic/utils.ts +18 -0
  407. package/src/config.ts +12 -0
  408. package/src/index.ts +4 -0
  409. package/src/network/indexer.ts +17 -0
  410. package/src/network/mock-network.ts +25 -0
  411. package/src/network/node.ts +94 -0
  412. package/src/network/types.ts +51 -0
  413. package/src/signer/getAddress.ts +20 -0
  414. package/src/signer/index.ts +7 -0
  415. package/src/test/bot-deviceActions.ts +48 -0
  416. package/src/test/bot-specs.ts +76 -0
  417. package/src/test/bridgeDatasetTest.ts +147 -0
  418. package/src/test/cli.ts +44 -0
  419. package/src/test/index.ts +6 -0
  420. package/src/types/bridge.ts +33 -0
  421. package/src/types/errors.ts +3 -0
  422. package/src/types/index.ts +13 -0
  423. package/src/types/signer.ts +11 -0
  424. package/tsconfig.json +12 -0
@@ -0,0 +1,88 @@
1
+ import {
2
+ AmountRequired,
3
+ FeeNotLoaded,
4
+ FeeRequired,
5
+ FeeTooHigh,
6
+ InvalidAddress,
7
+ InvalidAddressBecauseDestinationIsAlsoSource,
8
+ NotEnoughBalanceBecauseDestinationNotCreated,
9
+ NotEnoughSpendableBalance,
10
+ RecipientRequired,
11
+ } from "@ledgerhq/errors";
12
+ import BigNumber from "bignumber.js";
13
+ import { Account, AccountBridge } from "@ledgerhq/types-live";
14
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
15
+ import { Transaction, TransactionStatus } from "../types";
16
+ import { isRecipientValid } from "../common-logic/utils";
17
+ import coinConfig from "../config";
18
+
19
+ export const getTransactionStatus: AccountBridge<
20
+ Transaction,
21
+ Account,
22
+ TransactionStatus
23
+ >["getTransactionStatus"] = async (account, transaction) => {
24
+ const errors: Record<string, Error> = {};
25
+ const warnings: Record<string, Error> = {};
26
+
27
+ // reserveAmount is the minimum amount of currency that an account must hold in order to stay activated
28
+ const reserveAmount = new BigNumber(coinConfig.getCoinConfig().minReserve);
29
+ const estimatedFees = new BigNumber(transaction.fee || 0);
30
+ const totalSpent = new BigNumber(transaction.amount).plus(estimatedFees);
31
+ const amount = new BigNumber(transaction.amount);
32
+
33
+ if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
34
+ // if the fee is more than 10 times the amount, we warn the user that fee is high compared to what he is sending
35
+ warnings.feeTooHigh = new FeeTooHigh();
36
+ }
37
+
38
+ if (!transaction.fee) {
39
+ // if the fee is not loaded, we can't do much
40
+ errors.fee = new FeeNotLoaded();
41
+ } else if (transaction.fee.eq(0)) {
42
+ // On some chains, 0 fee could still work so this is optional
43
+ errors.fee = new FeeRequired();
44
+ } else if (totalSpent.gt(account.balance.minus(reserveAmount))) {
45
+ // if the total spent is greater than the balance minus the reserve amount, tx is invalid
46
+ errors.amount = new NotEnoughSpendableBalance("", {
47
+ minimumAmount: formatCurrencyUnit(account.currency.units[0], reserveAmount, {
48
+ disableRounding: true,
49
+ useGrouping: false,
50
+ showCode: true,
51
+ }),
52
+ });
53
+ } else if (transaction.recipient && transaction.amount.lt(reserveAmount)) {
54
+ // if we send an amount lower than reserve amount AND target account is new, we need to warn the user that the target account will not be activated
55
+ errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
56
+ minimalAmount: formatCurrencyUnit(account.currency.units[0], reserveAmount, {
57
+ disableRounding: true,
58
+ useGrouping: false,
59
+ showCode: true,
60
+ }),
61
+ });
62
+ }
63
+
64
+ if (!transaction.recipient) {
65
+ errors.recipient = new RecipientRequired("");
66
+ } else if (account.freshAddress === transaction.recipient) {
67
+ // we want to prevent user from sending to themselves (even if it's technically feasible)
68
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
69
+ } else if (!isRecipientValid(transaction.recipient)) {
70
+ // We want to prevent user from sending to an invalid address
71
+ errors.recipient = new InvalidAddress("", {
72
+ currencyName: account.currency.name,
73
+ });
74
+ }
75
+
76
+ if (!errors.amount && amount.eq(0)) {
77
+ // if the amount is 0, we prevent the user from sending the tx (even if it's technically feasible)
78
+ errors.amount = new AmountRequired();
79
+ }
80
+
81
+ return {
82
+ errors,
83
+ warnings,
84
+ estimatedFees,
85
+ amount,
86
+ totalSpent,
87
+ };
88
+ };
@@ -0,0 +1,31 @@
1
+ import { createBridges } from ".";
2
+
3
+ describe("createBridges", () => {
4
+ it("should return both bridges interface", () => {
5
+ const bridges = createBridges(undefined as any, {} as any);
6
+ expect(bridges.accountBridge).toBeDefined();
7
+ expect(bridges.currencyBridge).toBeDefined();
8
+ });
9
+
10
+ it("should have a currency bridge with required methods", () => {
11
+ const bridges = createBridges(undefined as any, {} as any);
12
+ expect(bridges.currencyBridge).toBeDefined();
13
+ expect(bridges.currencyBridge.preload).toBeDefined();
14
+ expect(bridges.currencyBridge.hydrate).toBeDefined();
15
+ expect(bridges.currencyBridge.scanAccounts).toBeDefined();
16
+ });
17
+
18
+ it("should have an account bridge with required methods", () => {
19
+ const bridges = createBridges(undefined as any, {} as any);
20
+ expect(bridges.accountBridge).toBeDefined();
21
+ expect(bridges.accountBridge.broadcast).toBeDefined();
22
+ expect(bridges.accountBridge.createTransaction).toBeDefined();
23
+ expect(bridges.accountBridge.estimateMaxSpendable).toBeDefined();
24
+ expect(bridges.accountBridge.getTransactionStatus).toBeDefined();
25
+ expect(bridges.accountBridge.prepareTransaction).toBeDefined();
26
+ expect(bridges.accountBridge.receive).toBeDefined();
27
+ expect(bridges.accountBridge.signOperation).toBeDefined();
28
+ expect(bridges.accountBridge.sync).toBeDefined();
29
+ expect(bridges.accountBridge.updateTransaction).toBeDefined();
30
+ });
31
+ });
@@ -0,0 +1,62 @@
1
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import {
3
+ getSerializedAddressParameters,
4
+ makeAccountBridgeReceive,
5
+ makeScanAccounts,
6
+ makeSync,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import { CoinConfig } from "@ledgerhq/coin-framework/config";
9
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
10
+ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
11
+ import cantonCoinConfig, { type CantonCoinConfig } from "../config";
12
+ import resolver from "../signer";
13
+ import { BoilerplateSigner } from "../types";
14
+ import type { Transaction } from "../types";
15
+ import { broadcast } from "./broadcast";
16
+ import { createTransaction } from "./createTransaction";
17
+ import { estimateMaxSpendable } from "./estimateMaxSpendable";
18
+ import { getTransactionStatus } from "./getTransactionStatus";
19
+ import { prepareTransaction } from "./prepareTransaction";
20
+ import { buildSignOperation } from "./signOperation";
21
+ import { getAccountShape } from "./sync";
22
+ import { updateTransaction } from "./updateTransaction";
23
+
24
+ export function createBridges(
25
+ signerContext: SignerContext<BoilerplateSigner>,
26
+ coinConfig: CoinConfig<CantonCoinConfig>,
27
+ ) {
28
+ cantonCoinConfig.setCoinConfig(coinConfig);
29
+
30
+ const getAddress = resolver(signerContext);
31
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
32
+
33
+ const scanAccounts = makeScanAccounts({ getAccountShape, getAddressFn: getAddress });
34
+ const currencyBridge: CurrencyBridge = {
35
+ preload: () => Promise.resolve({}),
36
+ hydrate: () => {},
37
+ scanAccounts,
38
+ };
39
+
40
+ const signOperation = buildSignOperation(signerContext);
41
+ const sync = makeSync({ getAccountShape });
42
+ // we want one method per file
43
+ const accountBridge: AccountBridge<Transaction> = {
44
+ broadcast,
45
+ createTransaction,
46
+ updateTransaction,
47
+ // NOTE: use updateTransaction: defaultUpdateTransaction<Transaction>,
48
+ // if you don't need to update the transaction patch object
49
+ prepareTransaction,
50
+ getTransactionStatus,
51
+ estimateMaxSpendable,
52
+ sync,
53
+ receive,
54
+ signOperation,
55
+ getSerializedAddressParameters,
56
+ };
57
+
58
+ return {
59
+ currencyBridge,
60
+ accountBridge,
61
+ };
62
+ }
@@ -0,0 +1,29 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { craftTransaction, estimateFees } from "../common-logic";
3
+ import { getNextSequence } from "../network/node";
4
+ import { prepareTransaction } from "./prepareTransaction";
5
+ import { Account } from "@ledgerhq/types-live";
6
+ import { Transaction } from "../types";
7
+
8
+ jest.mock("../network/node");
9
+ jest.mock("../common-logic");
10
+
11
+ describe("prepareTransaction", () => {
12
+ let estimateFeesSpy: jest.SpyInstance;
13
+ let getNextSequenceSpy: jest.SpyInstance;
14
+ let craftTransactionSpy: jest.SpyInstance;
15
+ beforeEach(() => {
16
+ getNextSequenceSpy = jest.spyOn({ getNextSequence }, "getNextSequence");
17
+ estimateFeesSpy = jest.spyOn({ estimateFees }, "estimateFees");
18
+ craftTransactionSpy = jest.spyOn({ craftTransaction }, "craftTransaction");
19
+ craftTransactionSpy.mockReturnValue({ serializedTransaction: "serialized" });
20
+ });
21
+
22
+ it("should update fee field if it's different", async () => {
23
+ getNextSequenceSpy.mockResolvedValue(42);
24
+ const oldTx = { fee: new BigNumber(0) };
25
+ estimateFeesSpy.mockResolvedValue(BigInt(1));
26
+ const newTx = await prepareTransaction({} as Account, oldTx as Transaction);
27
+ expect(newTx.fee).toEqual(new BigNumber(1));
28
+ });
29
+ });
@@ -0,0 +1,25 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import { Transaction } from "../types";
3
+ import { craftTransaction, estimateFees } from "../common-logic";
4
+ import { getNextSequence } from "../network/node";
5
+ import BigNumber from "bignumber.js";
6
+
7
+ export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"] = async (
8
+ account,
9
+ transaction,
10
+ ) => {
11
+ const seq = await getNextSequence(account.freshAddress);
12
+
13
+ const craftedTransaction = await craftTransaction(
14
+ { address: account.freshAddress, nextSequenceNumber: seq },
15
+ { amount: transaction.amount, recipient: transaction.recipient },
16
+ );
17
+
18
+ const fee = await estimateFees(craftedTransaction.serializedTransaction);
19
+
20
+ if (transaction.fee !== new BigNumber(fee.toString())) {
21
+ return { ...transaction, fee: new BigNumber(fee.toString()) };
22
+ }
23
+
24
+ return transaction;
25
+ };
@@ -0,0 +1,93 @@
1
+ import { Observable } from "rxjs";
2
+ import { FeeNotLoaded } from "@ledgerhq/errors";
3
+ import { AccountBridge, Operation } from "@ledgerhq/types-live";
4
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
5
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
+ import { combine, craftTransaction, getNextValidSequence } from "../common-logic";
7
+ import { Transaction, BoilerplateSigner, BoilerplateNativeTransaction } from "../types";
8
+
9
+ export const buildSignOperation =
10
+ (signerContext: SignerContext<BoilerplateSigner>): AccountBridge<Transaction>["signOperation"] =>
11
+ ({ account, deviceId, transaction }) =>
12
+ new Observable(o => {
13
+ async function main() {
14
+ const { fee } = transaction;
15
+ if (!fee) throw new FeeNotLoaded();
16
+
17
+ try {
18
+ // o observables allows to define steps of the signing process with the device
19
+ o.next({
20
+ type: "device-signature-requested",
21
+ });
22
+
23
+ const nextSequenceNumber = await getNextValidSequence(account.freshAddress);
24
+
25
+ const signature = await signerContext(deviceId, async signer => {
26
+ const { freshAddressPath: derivationPath } = account;
27
+ const { publicKey } = await signer.getAddress(derivationPath);
28
+
29
+ const { nativeTransaction, serializedTransaction } = await craftTransaction(
30
+ {
31
+ address: account.freshAddress,
32
+ publicKey,
33
+ },
34
+ {
35
+ recipient: transaction.recipient,
36
+ amount: transaction.amount,
37
+ fee: fee,
38
+ },
39
+ );
40
+
41
+ const transactionSignature = await signer.signTransaction(
42
+ derivationPath,
43
+ serializedTransaction,
44
+ );
45
+
46
+ return combine(serializedTransaction, transactionSignature, publicKey);
47
+ });
48
+
49
+ o.next({
50
+ type: "device-signature-granted",
51
+ });
52
+
53
+ // We create an optimistic operation here, the framework will then replace this transaction with the one returned by the indexer
54
+ const hash = "";
55
+ const operation: Operation = {
56
+ id: encodeOperationId(account.id, hash, "OUT"),
57
+ hash,
58
+ accountId: account.id,
59
+ type: "OUT",
60
+ value: transaction.amount,
61
+ fee,
62
+ blockHash: null,
63
+ blockHeight: null,
64
+ senders: [account.freshAddress],
65
+ recipients: [transaction.recipient],
66
+ date: new Date(),
67
+ transactionSequenceNumber: nextSequenceNumber,
68
+ extra: {},
69
+ };
70
+
71
+ o.next({
72
+ type: "signed",
73
+ signedOperation: {
74
+ operation,
75
+ signature,
76
+ },
77
+ });
78
+ } catch (e) {
79
+ if (e instanceof Error) {
80
+ throw new Error(
81
+ (e as Error & { data?: { resultMessage?: string } })?.data?.resultMessage,
82
+ );
83
+ }
84
+
85
+ throw e;
86
+ }
87
+ }
88
+
89
+ main().then(
90
+ () => o.complete(),
91
+ e => o.error(e),
92
+ );
93
+ });
@@ -0,0 +1,106 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Operation } from "@ledgerhq/types-live";
3
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
4
+ import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
5
+ import { getTransactions } from "../network/indexer";
6
+ import { getAccountInfo, getBlockHeight } from "../network/node";
7
+
8
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
9
+ import { BoilerplateOperation } from "../network/types";
10
+ import coinConfig from "../config";
11
+
12
+ const operationAdapter =
13
+ (accountId: string, address: string) =>
14
+ ({
15
+ meta: { delivered_amount },
16
+ tx: { Fee, hash, inLedger, date, Account, Destination, Sequence },
17
+ }: BoilerplateOperation) => {
18
+ const type = Account === address ? "OUT" : "IN";
19
+ let value =
20
+ delivered_amount && typeof delivered_amount === "string"
21
+ ? new BigNumber(delivered_amount)
22
+ : new BigNumber(0);
23
+ const feeValue = new BigNumber(Fee);
24
+
25
+ if (type === "OUT") {
26
+ if (!Number.isNaN(feeValue)) {
27
+ value = value.plus(feeValue);
28
+ }
29
+ }
30
+
31
+ const op: Operation = {
32
+ id: encodeOperationId(accountId, hash, type),
33
+ hash: hash,
34
+ accountId,
35
+ type,
36
+ value,
37
+ fee: feeValue,
38
+ blockHash: null,
39
+ blockHeight: inLedger,
40
+ senders: [Account],
41
+ recipients: [Destination],
42
+ date: new Date(),
43
+ transactionSequenceNumber: Sequence,
44
+ extra: {},
45
+ };
46
+
47
+ return op;
48
+ };
49
+
50
+ const filterOperations = (
51
+ transactions: BoilerplateOperation[],
52
+ accountId: string,
53
+ address: string,
54
+ ) => {
55
+ return transactions
56
+ .filter(
57
+ ({ tx, meta }: BoilerplateOperation) =>
58
+ tx.TransactionType === "Payment" && typeof meta.delivered_amount === "string",
59
+ )
60
+ .map(operationAdapter(accountId, address))
61
+ .filter((op): op is Operation => Boolean(op));
62
+ };
63
+
64
+ export const getAccountShape: GetAccountShape = async info => {
65
+ const { address, initialAccount, currency, derivationMode } = info;
66
+
67
+ const accountId = encodeAccountId({
68
+ type: "js",
69
+ version: "2",
70
+ currencyId: currency.id,
71
+ xpubOrAddress: address,
72
+ derivationMode,
73
+ });
74
+
75
+ // blockheight retrieval
76
+ const blockHeight = await getBlockHeight();
77
+
78
+ // Account info retrieval + spendable balance calculation
79
+ const accountInfo = await getAccountInfo(address);
80
+ const balance = new BigNumber(accountInfo.account_data.Balance);
81
+ const reserveMin = coinConfig.getCoinConfig().minReserve;
82
+ const spendableBalance = new BigNumber(accountInfo.account_data.Balance).minus(reserveMin);
83
+
84
+ // Tx history fetching
85
+ const oldOperations = initialAccount?.operations || [];
86
+ const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
87
+ const newTransactions = await getTransactions(address, {
88
+ from: startAt,
89
+ size: 100,
90
+ });
91
+ const newOperations = filterOperations(newTransactions, accountId, address);
92
+ const operations = mergeOps(oldOperations, newOperations as Operation[]);
93
+
94
+ // We return the new account shape
95
+ const shape = {
96
+ id: accountId,
97
+ xpub: address,
98
+ blockHeight,
99
+ balance,
100
+ spendableBalance,
101
+ operations,
102
+ operationsCount: operations.length,
103
+ };
104
+
105
+ return shape;
106
+ };
@@ -0,0 +1,61 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { Transaction, TransactionRaw } from "../types";
3
+ import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
4
+ import {
5
+ fromTransactionCommonRaw,
6
+ fromTransactionStatusRawCommon as fromTransactionStatusRaw,
7
+ toTransactionCommonRaw,
8
+ toTransactionStatusRawCommon as toTransactionStatusRaw,
9
+ } from "@ledgerhq/coin-framework/serialization/transaction";
10
+ import type { Account } from "@ledgerhq/types-live";
11
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
12
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
13
+
14
+ export const formatTransaction = (
15
+ { amount, recipient, fee, useAllAmount }: Transaction,
16
+ account: Account,
17
+ ): string => `
18
+ SEND ${
19
+ useAllAmount
20
+ ? "MAX"
21
+ : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
22
+ showCode: true,
23
+ disableRounding: true,
24
+ })
25
+ }
26
+ TO ${recipient}
27
+ with fee=${
28
+ !fee
29
+ ? "?"
30
+ : formatCurrencyUnit(getAccountCurrency(account).units[0], fee, {
31
+ showCode: true,
32
+ disableRounding: true,
33
+ })
34
+ }`;
35
+
36
+ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
37
+ const common = fromTransactionCommonRaw(tr);
38
+ return {
39
+ ...common,
40
+ family: tr.family,
41
+ fee: tr.fee ? new BigNumber(tr.fee) : null,
42
+ };
43
+ };
44
+
45
+ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
46
+ const common = toTransactionCommonRaw(t);
47
+ return {
48
+ ...common,
49
+ family: t.family,
50
+ fee: t.fee ? t.fee.toString() : null,
51
+ };
52
+ };
53
+
54
+ export default {
55
+ formatTransaction,
56
+ fromTransactionRaw,
57
+ toTransactionRaw,
58
+ fromTransactionStatusRaw,
59
+ toTransactionStatusRaw,
60
+ formatTransactionStatus,
61
+ };
@@ -0,0 +1,17 @@
1
+ import { updateTransaction as defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import type { Transaction } from "../types";
4
+
5
+ // NOTE: this method is optional, use defaultUpdateTransaction
6
+ // acts as a middleware to update the transaction patch object
7
+
8
+ // NOTE: here is an example transaction updater function
9
+ // in this case, it resets fee to null depending on the patch content
10
+ export const updateTransaction: AccountBridge<Transaction>["updateTransaction"] = (tx, patch) => {
11
+ // eslint-disable-next-line no-constant-condition
12
+ if (patch.recipient === "boilerplate1" || true) {
13
+ patch = { ...patch, fee: null };
14
+ }
15
+
16
+ return defaultUpdateTransaction(tx, patch);
17
+ };
@@ -0,0 +1,8 @@
1
+ import { Balance } from "@ledgerhq/coin-framework/api/types";
2
+ import { getAccountInfo } from "../../network/node";
3
+
4
+ // Could be getAccountInfo so it is used in both bridge and api
5
+ export async function getBalance(address: string): Promise<Balance[]> {
6
+ const accountInfo = await getAccountInfo(address);
7
+ return [{ asset: { type: "native" }, value: BigInt(accountInfo.account_data.Balance) }];
8
+ }
@@ -0,0 +1,6 @@
1
+ import { getNextSequence } from "../../network/node";
2
+
3
+ // Could be getAccountInfo so it is used in both bridge and api
4
+ export async function getNextValidSequence(address: string): Promise<number> {
5
+ return await getNextSequence(address);
6
+ }
@@ -0,0 +1,9 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
3
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
4
+
5
+ // NOTE: replace ripple by your currency id, it should be found in
6
+ // libs/ledgerjs/packages/cryptoassets/src/currencies.ts
7
+ const boilerplateUnit = getCryptoCurrencyById("ripple").units[0];
8
+ export const parseAPIValue = (value: string): BigNumber =>
9
+ parseCurrencyUnit(boilerplateUnit, value);
@@ -0,0 +1,11 @@
1
+ import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
2
+ import { getLastBlock } from "../../network/node";
3
+
4
+ export async function lastBlock(): Promise<BlockInfo> {
5
+ const result = await getLastBlock();
6
+ return {
7
+ height: result.blockHeight,
8
+ hash: result.blockHash,
9
+ time: new Date(result.timestamp),
10
+ };
11
+ }
@@ -0,0 +1,64 @@
1
+ import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
2
+ import { getTransactions } from "../../network/indexer";
3
+ import { BoilerplateOperation } from "../../network/types";
4
+
5
+ /**
6
+ * Returns list of operations associated to an account.
7
+ * @param address Account address
8
+ * @param pagination Pagination options
9
+ * @returns Operations found and the next "id" or "index" to use for pagination (i.e. `start` property).\
10
+ * If `0` is returns, no pagination needed.
11
+ * This "id" or "index" value, thus it has functional meaning, is different for each blockchain.
12
+ */
13
+ export async function listOperations(
14
+ address: string,
15
+ page: Pagination,
16
+ ): Promise<[Operation[], string]> {
17
+ const transactions = await getTransactions(address, { from: page.minHeight });
18
+ return [transactions.map(convertToCoreOperation(address)), ""];
19
+ }
20
+
21
+ const convertToCoreOperation =
22
+ (address: string) =>
23
+ (operation: BoilerplateOperation): Operation => {
24
+ const {
25
+ meta: { delivered_amount },
26
+ tx: { Fee, hash, inLedger, date, Account, Destination },
27
+ } = operation;
28
+
29
+ const type = Account === address ? "OUT" : "IN";
30
+ let value =
31
+ delivered_amount && typeof delivered_amount === "string"
32
+ ? BigInt(delivered_amount)
33
+ : BigInt(0);
34
+
35
+ const feeValue = BigInt(Fee);
36
+ if (type === "OUT") {
37
+ if (!Number.isNaN(feeValue)) {
38
+ value = value + feeValue;
39
+ }
40
+ }
41
+
42
+ return {
43
+ /**
44
+ * Note: The operation ID must be concatenated with another
45
+ * value if the transaction hash is not enough to identify it
46
+ */
47
+ id: hash,
48
+ asset: { type: "native" },
49
+ tx: {
50
+ hash,
51
+ fees: feeValue,
52
+ date: new Date(date),
53
+ block: {
54
+ height: inLedger,
55
+ hash,
56
+ time: new Date(date),
57
+ },
58
+ },
59
+ type,
60
+ value,
61
+ senders: [Account],
62
+ recipients: [Destination],
63
+ };
64
+ };
@@ -0,0 +1,11 @@
1
+ export { broadcast } from "./transaction/broadcast";
2
+ export { combine } from "./transaction/combine";
3
+ export { craftTransaction } from "./transaction/craftTransaction";
4
+ export { estimateFees } from "./transaction/estimateFees";
5
+ export { getBalance } from "./account/getBalance";
6
+ export { lastBlock } from "./history/lastBlock";
7
+ export { listOperations } from "./history/listOperations";
8
+ export { isRecipientValid } from "./utils";
9
+ export { getNextValidSequence } from "./account/getNextSequence";
10
+
11
+ export { parseAPIValue } from "./common";
@@ -0,0 +1,6 @@
1
+ import { submit } from "../../network/node";
2
+
3
+ export async function broadcast(signedTx: string): Promise<string> {
4
+ const submittedPayment = await submit(signedTx);
5
+ return submittedPayment.tx_hash;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { encode } from "../utils";
2
+
3
+ // Combines signature with raw transaction
4
+ export function combine(transaction: string, signature: string, publicKey?: string): string {
5
+ return encode(transaction, signature, publicKey || "");
6
+ }