@ledgerhq/coin-casper 1.4.0-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 (304) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.unimportedrc.json +49 -0
  3. package/CHANGELOG.md +15 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/lib/api/index.d.ts +11 -0
  7. package/lib/api/index.d.ts.map +1 -0
  8. package/lib/api/index.js +129 -0
  9. package/lib/api/index.js.map +1 -0
  10. package/lib/api/types.d.ts +105 -0
  11. package/lib/api/types.d.ts.map +1 -0
  12. package/lib/api/types.js +3 -0
  13. package/lib/api/types.js.map +1 -0
  14. package/lib/bridge/bridgeHelpers/accountShape.d.ts +3 -0
  15. package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
  16. package/lib/bridge/bridgeHelpers/accountShape.js +38 -0
  17. package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -0
  18. package/lib/bridge/bridgeHelpers/addresses.d.ts +18 -0
  19. package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  20. package/lib/bridge/bridgeHelpers/addresses.js +83 -0
  21. package/lib/bridge/bridgeHelpers/addresses.js.map +1 -0
  22. package/lib/bridge/bridgeHelpers/fee.d.ts +3 -0
  23. package/lib/bridge/bridgeHelpers/fee.d.ts.map +1 -0
  24. package/lib/bridge/bridgeHelpers/fee.js +13 -0
  25. package/lib/bridge/bridgeHelpers/fee.js.map +1 -0
  26. package/lib/bridge/bridgeHelpers/transferId.d.ts +2 -0
  27. package/lib/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
  28. package/lib/bridge/bridgeHelpers/transferId.js +14 -0
  29. package/lib/bridge/bridgeHelpers/transferId.js.map +1 -0
  30. package/lib/bridge/bridgeHelpers/txn.d.ts +9 -0
  31. package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  32. package/lib/bridge/bridgeHelpers/txn.js +100 -0
  33. package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
  34. package/lib/bridge/broadcast.d.ts +4 -0
  35. package/lib/bridge/broadcast.d.ts.map +1 -0
  36. package/lib/bridge/broadcast.js +15 -0
  37. package/lib/bridge/broadcast.js.map +1 -0
  38. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  39. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  40. package/lib/bridge/buildOptimisticOperation.js +27 -0
  41. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  42. package/lib/bridge/createTransaction.d.ts +4 -0
  43. package/lib/bridge/createTransaction.d.ts.map +1 -0
  44. package/lib/bridge/createTransaction.js +19 -0
  45. package/lib/bridge/createTransaction.js.map +1 -0
  46. package/lib/bridge/deviceTransactionConfig.d.ts +18 -0
  47. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  48. package/lib/bridge/deviceTransactionConfig.js +26 -0
  49. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  50. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  51. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  52. package/lib/bridge/estimateMaxSpendable.js +23 -0
  53. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  54. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  55. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  56. package/lib/bridge/getTransactionStatus.js +75 -0
  57. package/lib/bridge/getTransactionStatus.js.map +1 -0
  58. package/lib/bridge/index.d.ts +8 -0
  59. package/lib/bridge/index.d.ts.map +1 -0
  60. package/lib/bridge/index.js +54 -0
  61. package/lib/bridge/index.js.map +1 -0
  62. package/lib/bridge/prepareTransaction.d.ts +4 -0
  63. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  64. package/lib/bridge/prepareTransaction.js +16 -0
  65. package/lib/bridge/prepareTransaction.js.map +1 -0
  66. package/lib/bridge/signOperation.d.ts +6 -0
  67. package/lib/bridge/signOperation.d.ts.map +1 -0
  68. package/lib/bridge/signOperation.js +47 -0
  69. package/lib/bridge/signOperation.js.map +1 -0
  70. package/lib/bridge/transaction.d.ts +14 -0
  71. package/lib/bridge/transaction.d.ts.map +1 -0
  72. package/lib/bridge/transaction.js +53 -0
  73. package/lib/bridge/transaction.js.map +1 -0
  74. package/lib/common-logic/index.d.ts +2 -0
  75. package/lib/common-logic/index.d.ts.map +1 -0
  76. package/lib/common-logic/index.js +13 -0
  77. package/lib/common-logic/index.js.map +1 -0
  78. package/lib/common-logic/utils.d.ts +14 -0
  79. package/lib/common-logic/utils.d.ts.map +1 -0
  80. package/lib/common-logic/utils.js +53 -0
  81. package/lib/common-logic/utils.js.map +1 -0
  82. package/lib/common-logic/utils.unit.test.d.ts +2 -0
  83. package/lib/common-logic/utils.unit.test.d.ts.map +1 -0
  84. package/lib/common-logic/utils.unit.test.js +50 -0
  85. package/lib/common-logic/utils.unit.test.js.map +1 -0
  86. package/lib/consts.d.ts +10 -0
  87. package/lib/consts.d.ts.map +1 -0
  88. package/lib/consts.js +18 -0
  89. package/lib/consts.js.map +1 -0
  90. package/lib/errors.d.ts +10 -0
  91. package/lib/errors.d.ts.map +1 -0
  92. package/lib/errors.js +8 -0
  93. package/lib/errors.js.map +1 -0
  94. package/lib/hw-signMessage.d.ts +23 -0
  95. package/lib/hw-signMessage.d.ts.map +1 -0
  96. package/lib/hw-signMessage.js +24 -0
  97. package/lib/hw-signMessage.js.map +1 -0
  98. package/lib/signer/getAddress.d.ts +6 -0
  99. package/lib/signer/getAddress.d.ts.map +1 -0
  100. package/lib/signer/getAddress.js +25 -0
  101. package/lib/signer/getAddress.js.map +1 -0
  102. package/lib/signer/index.d.ts +3 -0
  103. package/lib/signer/index.d.ts.map +1 -0
  104. package/lib/signer/index.js +8 -0
  105. package/lib/signer/index.js.map +1 -0
  106. package/lib/test/bot-specs.d.ts +7 -0
  107. package/lib/test/bot-specs.d.ts.map +1 -0
  108. package/lib/test/bot-specs.js +110 -0
  109. package/lib/test/bot-specs.js.map +1 -0
  110. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  111. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  112. package/lib/test/bridgeDatasetTest.js +177 -0
  113. package/lib/test/bridgeDatasetTest.js.map +1 -0
  114. package/lib/test/cli.d.ts +15 -0
  115. package/lib/test/cli.d.ts.map +1 -0
  116. package/lib/test/cli.js +30 -0
  117. package/lib/test/cli.js.map +1 -0
  118. package/lib/test/index.d.ts +4 -0
  119. package/lib/test/index.d.ts.map +1 -0
  120. package/lib/test/index.js +20 -0
  121. package/lib/test/index.js.map +1 -0
  122. package/lib/test/speculos-deviceActions.d.ts +4 -0
  123. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  124. package/lib/test/speculos-deviceActions.js +53 -0
  125. package/lib/test/speculos-deviceActions.js.map +1 -0
  126. package/lib/types/common.d.ts +23 -0
  127. package/lib/types/common.d.ts.map +1 -0
  128. package/lib/types/common.js +3 -0
  129. package/lib/types/common.js.map +1 -0
  130. package/lib/types/index.d.ts +3 -0
  131. package/lib/types/index.d.ts.map +1 -0
  132. package/lib/types/index.js +19 -0
  133. package/lib/types/index.js.map +1 -0
  134. package/lib/types/signer.d.ts +21 -0
  135. package/lib/types/signer.d.ts.map +1 -0
  136. package/lib/types/signer.js +3 -0
  137. package/lib/types/signer.js.map +1 -0
  138. package/lib-es/api/index.d.ts +11 -0
  139. package/lib-es/api/index.d.ts.map +1 -0
  140. package/lib-es/api/index.js +118 -0
  141. package/lib-es/api/index.js.map +1 -0
  142. package/lib-es/api/types.d.ts +105 -0
  143. package/lib-es/api/types.d.ts.map +1 -0
  144. package/lib-es/api/types.js +2 -0
  145. package/lib-es/api/types.js.map +1 -0
  146. package/lib-es/bridge/bridgeHelpers/accountShape.d.ts +3 -0
  147. package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
  148. package/lib-es/bridge/bridgeHelpers/accountShape.js +31 -0
  149. package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -0
  150. package/lib-es/bridge/bridgeHelpers/addresses.d.ts +18 -0
  151. package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  152. package/lib-es/bridge/bridgeHelpers/addresses.js +74 -0
  153. package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -0
  154. package/lib-es/bridge/bridgeHelpers/fee.d.ts +3 -0
  155. package/lib-es/bridge/bridgeHelpers/fee.d.ts.map +1 -0
  156. package/lib-es/bridge/bridgeHelpers/fee.js +6 -0
  157. package/lib-es/bridge/bridgeHelpers/fee.js.map +1 -0
  158. package/lib-es/bridge/bridgeHelpers/transferId.d.ts +2 -0
  159. package/lib-es/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
  160. package/lib-es/bridge/bridgeHelpers/transferId.js +10 -0
  161. package/lib-es/bridge/bridgeHelpers/transferId.js.map +1 -0
  162. package/lib-es/bridge/bridgeHelpers/txn.d.ts +9 -0
  163. package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  164. package/lib-es/bridge/bridgeHelpers/txn.js +91 -0
  165. package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
  166. package/lib-es/bridge/broadcast.d.ts +4 -0
  167. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  168. package/lib-es/bridge/broadcast.js +11 -0
  169. package/lib-es/bridge/broadcast.js.map +1 -0
  170. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  171. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  172. package/lib-es/bridge/buildOptimisticOperation.js +23 -0
  173. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  174. package/lib-es/bridge/createTransaction.d.ts +4 -0
  175. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  176. package/lib-es/bridge/createTransaction.js +12 -0
  177. package/lib-es/bridge/createTransaction.js.map +1 -0
  178. package/lib-es/bridge/deviceTransactionConfig.d.ts +18 -0
  179. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  180. package/lib-es/bridge/deviceTransactionConfig.js +24 -0
  181. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  182. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  183. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  184. package/lib-es/bridge/estimateMaxSpendable.js +16 -0
  185. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  186. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  187. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  188. package/lib-es/bridge/getTransactionStatus.js +68 -0
  189. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  190. package/lib-es/bridge/index.d.ts +8 -0
  191. package/lib-es/bridge/index.d.ts.map +1 -0
  192. package/lib-es/bridge/index.js +47 -0
  193. package/lib-es/bridge/index.js.map +1 -0
  194. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  195. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  196. package/lib-es/bridge/prepareTransaction.js +12 -0
  197. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  198. package/lib-es/bridge/signOperation.d.ts +6 -0
  199. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  200. package/lib-es/bridge/signOperation.js +43 -0
  201. package/lib-es/bridge/signOperation.js.map +1 -0
  202. package/lib-es/bridge/transaction.d.ts +14 -0
  203. package/lib-es/bridge/transaction.d.ts.map +1 -0
  204. package/lib-es/bridge/transaction.js +45 -0
  205. package/lib-es/bridge/transaction.js.map +1 -0
  206. package/lib-es/common-logic/index.d.ts +2 -0
  207. package/lib-es/common-logic/index.d.ts.map +1 -0
  208. package/lib-es/common-logic/index.js +2 -0
  209. package/lib-es/common-logic/index.js.map +1 -0
  210. package/lib-es/common-logic/utils.d.ts +14 -0
  211. package/lib-es/common-logic/utils.d.ts.map +1 -0
  212. package/lib-es/common-logic/utils.js +39 -0
  213. package/lib-es/common-logic/utils.js.map +1 -0
  214. package/lib-es/common-logic/utils.unit.test.d.ts +2 -0
  215. package/lib-es/common-logic/utils.unit.test.d.ts.map +1 -0
  216. package/lib-es/common-logic/utils.unit.test.js +48 -0
  217. package/lib-es/common-logic/utils.unit.test.js.map +1 -0
  218. package/lib-es/consts.d.ts +10 -0
  219. package/lib-es/consts.d.ts.map +1 -0
  220. package/lib-es/consts.js +15 -0
  221. package/lib-es/consts.js.map +1 -0
  222. package/lib-es/errors.d.ts +10 -0
  223. package/lib-es/errors.d.ts.map +1 -0
  224. package/lib-es/errors.js +5 -0
  225. package/lib-es/errors.js.map +1 -0
  226. package/lib-es/hw-signMessage.d.ts +23 -0
  227. package/lib-es/hw-signMessage.d.ts.map +1 -0
  228. package/lib-es/hw-signMessage.js +20 -0
  229. package/lib-es/hw-signMessage.js.map +1 -0
  230. package/lib-es/signer/getAddress.d.ts +6 -0
  231. package/lib-es/signer/getAddress.d.ts.map +1 -0
  232. package/lib-es/signer/getAddress.js +23 -0
  233. package/lib-es/signer/getAddress.js.map +1 -0
  234. package/lib-es/signer/index.d.ts +3 -0
  235. package/lib-es/signer/index.d.ts.map +1 -0
  236. package/lib-es/signer/index.js +3 -0
  237. package/lib-es/signer/index.js.map +1 -0
  238. package/lib-es/test/bot-specs.d.ts +7 -0
  239. package/lib-es/test/bot-specs.d.ts.map +1 -0
  240. package/lib-es/test/bot-specs.js +105 -0
  241. package/lib-es/test/bot-specs.js.map +1 -0
  242. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  243. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  244. package/lib-es/test/bridgeDatasetTest.js +171 -0
  245. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  246. package/lib-es/test/cli.d.ts +15 -0
  247. package/lib-es/test/cli.d.ts.map +1 -0
  248. package/lib-es/test/cli.js +24 -0
  249. package/lib-es/test/cli.js.map +1 -0
  250. package/lib-es/test/index.d.ts +4 -0
  251. package/lib-es/test/index.d.ts.map +1 -0
  252. package/lib-es/test/index.js +4 -0
  253. package/lib-es/test/index.js.map +1 -0
  254. package/lib-es/test/speculos-deviceActions.d.ts +4 -0
  255. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  256. package/lib-es/test/speculos-deviceActions.js +50 -0
  257. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  258. package/lib-es/types/common.d.ts +23 -0
  259. package/lib-es/types/common.d.ts.map +1 -0
  260. package/lib-es/types/common.js +2 -0
  261. package/lib-es/types/common.js.map +1 -0
  262. package/lib-es/types/index.d.ts +3 -0
  263. package/lib-es/types/index.d.ts.map +1 -0
  264. package/lib-es/types/index.js +3 -0
  265. package/lib-es/types/index.js.map +1 -0
  266. package/lib-es/types/signer.d.ts +21 -0
  267. package/lib-es/types/signer.d.ts.map +1 -0
  268. package/lib-es/types/signer.js +2 -0
  269. package/lib-es/types/signer.js.map +1 -0
  270. package/package.json +127 -0
  271. package/src/api/index.ts +166 -0
  272. package/src/api/types.ts +113 -0
  273. package/src/bridge/bridgeHelpers/accountShape.ts +39 -0
  274. package/src/bridge/bridgeHelpers/addresses.ts +94 -0
  275. package/src/bridge/bridgeHelpers/fee.ts +6 -0
  276. package/src/bridge/bridgeHelpers/transferId.ts +9 -0
  277. package/src/bridge/bridgeHelpers/txn.ts +121 -0
  278. package/src/bridge/broadcast.ts +18 -0
  279. package/src/bridge/buildOptimisticOperation.ts +31 -0
  280. package/src/bridge/createTransaction.ts +15 -0
  281. package/src/bridge/deviceTransactionConfig.ts +46 -0
  282. package/src/bridge/estimateMaxSpendable.ts +26 -0
  283. package/src/bridge/getTransactionStatus.ts +96 -0
  284. package/src/bridge/index.ts +65 -0
  285. package/src/bridge/prepareTransaction.ts +19 -0
  286. package/src/bridge/signOperation.ts +73 -0
  287. package/src/bridge/transaction.ts +61 -0
  288. package/src/common-logic/index.ts +10 -0
  289. package/src/common-logic/utils.ts +53 -0
  290. package/src/common-logic/utils.unit.test.ts +75 -0
  291. package/src/consts.ts +18 -0
  292. package/src/errors.ts +5 -0
  293. package/src/hw-signMessage.ts +30 -0
  294. package/src/signer/getAddress.ts +31 -0
  295. package/src/signer/index.ts +3 -0
  296. package/src/test/bot-specs.ts +127 -0
  297. package/src/test/bridgeDatasetTest.ts +178 -0
  298. package/src/test/cli.ts +36 -0
  299. package/src/test/index.ts +3 -0
  300. package/src/test/speculos-deviceActions.ts +54 -0
  301. package/src/types/common.ts +38 -0
  302. package/src/types/index.ts +2 -0
  303. package/src/types/signer.ts +20 -0
  304. package/tsconfig.json +15 -0
package/package.json ADDED
@@ -0,0 +1,127 @@
1
+ {
2
+ "name": "@ledgerhq/coin-casper",
3
+ "version": "1.4.0-next.0",
4
+ "description": "Ledger Casper integration",
5
+ "keywords": [
6
+ "Ledger",
7
+ "LedgerWallet",
8
+ "cspr",
9
+ "Casper",
10
+ "Hardware Wallet"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/LedgerHQ/ledger-live.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/LedgerHQ/ledger-live/issues"
18
+ },
19
+ "homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-casper",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ "lib/*": [
26
+ "lib/*"
27
+ ],
28
+ "lib-es/*": [
29
+ "lib-es/*"
30
+ ],
31
+ "specs": [
32
+ "lib/test/bot-specs"
33
+ ],
34
+ "*": [
35
+ "lib/*",
36
+ "lib/api/*",
37
+ "lib/bridge/*",
38
+ "lib/common-logic/*",
39
+ "lib/signer/*",
40
+ "lib/test/*",
41
+ "lib/types/*"
42
+ ]
43
+ }
44
+ },
45
+ "exports": {
46
+ "./lib/*": "./lib/*.js",
47
+ "./lib-es/*": "./lib-es/*.js",
48
+ "./api": {
49
+ "require": "./lib/api/index.js",
50
+ "default": "./lib-es/api/index.js"
51
+ },
52
+ "./deviceTransactionConfig": {
53
+ "require": "./lib/bridge/deviceTransactionConfig.js",
54
+ "default": "./lib-es/bridge/deviceTransactionConfig.js"
55
+ },
56
+ "./logic": {
57
+ "require": "./lib/common-logic/index.js",
58
+ "default": "./lib-es/common-logic/index.js"
59
+ },
60
+ "./signer": {
61
+ "require": "./lib/signer/index.js",
62
+ "default": "./lib-es/signer/index.js"
63
+ },
64
+ "./specs": {
65
+ "require": "./lib/test/bot-specs.js",
66
+ "default": "./lib-es/test/bot-specs.js"
67
+ },
68
+ "./transaction": {
69
+ "require": "./lib/bridge/transaction.js",
70
+ "default": "./lib-es/bridge/transaction.js"
71
+ },
72
+ "./types": {
73
+ "require": "./lib/types/index.js",
74
+ "default": "./lib-es/types/index.js"
75
+ },
76
+ "./*": {
77
+ "require": "./lib/*.js",
78
+ "default": "./lib-es/*.js"
79
+ },
80
+ ".": {
81
+ "require": "./lib/index.js",
82
+ "default": "./lib-es/index.js"
83
+ },
84
+ "./package.json": "./package.json"
85
+ },
86
+ "license": "Apache-2.0",
87
+ "dependencies": {
88
+ "bignumber.js": "^9.1.2",
89
+ "invariant": "^2.2.2",
90
+ "lodash": "^4.17.21",
91
+ "casper-js-sdk": "^2.15.4",
92
+ "blakejs": "^1.2.1",
93
+ "rxjs": "^7.8.1",
94
+ "@ledgerhq/coin-framework": "^2.1.1-next.0",
95
+ "@ledgerhq/cryptoassets": "^13.12.0",
96
+ "@ledgerhq/devices": "8.4.4",
97
+ "@ledgerhq/errors": "^6.19.1",
98
+ "@ledgerhq/live-env": "^2.5.0",
99
+ "@ledgerhq/live-network": "^2.0.4",
100
+ "@ledgerhq/logs": "^6.12.0",
101
+ "@ledgerhq/types-live": "^6.61.0-next.0"
102
+ },
103
+ "devDependencies": {
104
+ "@types/invariant": "^2.2.2",
105
+ "@types/jest": "^29.5.10",
106
+ "@types/lodash": "^4.14.191",
107
+ "@types/semver": "^7.5.8",
108
+ "jest": "^29.7.0",
109
+ "ts-jest": "^29.1.1",
110
+ "expect": "^27.4.6",
111
+ "axios": "1.7.7",
112
+ "@ledgerhq/types-cryptoassets": "^7.19.0"
113
+ },
114
+ "scripts": {
115
+ "clean": "rimraf lib lib-es",
116
+ "build": "tsc --outDir lib --module commonjs --moduleResolution node10 && tsc -m ES6 --outDir lib-es",
117
+ "coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-casper.json",
118
+ "prewatch": "pnpm build",
119
+ "watch": "tsc --watch",
120
+ "watch:es": "tsc --watch -m ES6 --outDir lib-es",
121
+ "doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
122
+ "lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
123
+ "lint:fix": "pnpm lint --fix",
124
+ "test": "jest",
125
+ "unimported": "unimported"
126
+ }
127
+ }
@@ -0,0 +1,166 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
3
+
4
+ import {
5
+ NDeployMessagePutResponse,
6
+ IndexerResponseRoot,
7
+ ITxnHistoryData,
8
+ NAccountBalance,
9
+ NAccountInfo,
10
+ NNetworkStatusResponse,
11
+ NodeResponseRoot,
12
+ NodeRPCPayload,
13
+ NStateRootHashResponse,
14
+ } from "./types";
15
+
16
+ import network from "@ledgerhq/live-network/network";
17
+ import { AccessRights, CLURef, DeployUtil } from "casper-js-sdk";
18
+ import { getEnv } from "@ledgerhq/live-env";
19
+
20
+ const getCasperIndexerURL = (path: string): string => {
21
+ const baseUrl = getEnv("API_CASPER_INDEXER_ENDPOINT");
22
+ if (!baseUrl) throw new Error("API base URL not available");
23
+
24
+ return `${baseUrl}${path}`;
25
+ };
26
+
27
+ const getCasperNodeURL = (): string => {
28
+ const baseUrl = getEnv("API_CASPER_NODE_ENDPOINT");
29
+ if (!baseUrl) throw new Error("API base URL not available");
30
+
31
+ return baseUrl;
32
+ };
33
+
34
+ const casperIndexerWrapper = async <T>(path: string) => {
35
+ const url = getCasperIndexerURL(path);
36
+ const getResponse = async (page: number) => {
37
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
38
+ const opts: AxiosRequestConfig = {
39
+ method: "GET",
40
+ url: `${url}?limit=100&page=${page}`,
41
+ };
42
+
43
+ const rawResponse = await network(opts);
44
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
45
+ const { data } = rawResponse as AxiosResponse<IndexerResponseRoot<T>>;
46
+
47
+ return data;
48
+ };
49
+
50
+ let page = 1;
51
+ const res: T[] = [];
52
+
53
+ const data = await getResponse(page);
54
+ const { pageCount } = data;
55
+ res.push(...data.data);
56
+
57
+ while (page <= pageCount) {
58
+ page++;
59
+ const data = await getResponse(page);
60
+ res.push(...data.data);
61
+ }
62
+
63
+ log("http", url);
64
+ return res;
65
+ };
66
+
67
+ const casperNodeWrapper = async <T>(payload: NodeRPCPayload) => {
68
+ const url = getCasperNodeURL();
69
+
70
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
71
+ const opts: AxiosRequestConfig = {
72
+ method: "POST",
73
+ url,
74
+ data: payload,
75
+ };
76
+ const rawResponse = await network(opts);
77
+
78
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
79
+ const { data } = rawResponse as AxiosResponse<NodeResponseRoot<T>>;
80
+
81
+ log("http", url);
82
+ return data.result;
83
+ };
84
+
85
+ export const fetchAccountStateInfo = async (
86
+ publicKey: string,
87
+ ): Promise<{
88
+ purseUref: CLURef | undefined;
89
+ accountHash: string | undefined;
90
+ }> => {
91
+ const accountStateInfo = await casperNodeWrapper<NAccountInfo>({
92
+ jsonrpc: "2.0",
93
+ method: "state_get_account_info",
94
+ params: {
95
+ public_key: publicKey,
96
+ },
97
+ id: 1,
98
+ });
99
+
100
+ if (!accountStateInfo) {
101
+ return {
102
+ purseUref: undefined,
103
+ accountHash: undefined,
104
+ };
105
+ }
106
+
107
+ const accountHash = accountStateInfo.account.account_hash.split("-")[2];
108
+ const purseURefString = accountStateInfo.account.main_purse.split("-")[1];
109
+
110
+ const uRef = new CLURef(Buffer.from(purseURefString, "hex"), AccessRights.READ_ADD_WRITE);
111
+
112
+ return { purseUref: uRef, accountHash };
113
+ };
114
+
115
+ export const fetchBalance = async (purseUref: CLURef): Promise<NAccountBalance> => {
116
+ const stateRootInfo = await casperNodeWrapper<NStateRootHashResponse>({
117
+ jsonrpc: "2.0",
118
+ method: "chain_get_state_root_hash",
119
+ params: null,
120
+ id: 1,
121
+ });
122
+
123
+ const accountBalance = await casperNodeWrapper<NAccountBalance>({
124
+ jsonrpc: "2.0",
125
+ method: "state_get_balance",
126
+ params: {
127
+ purse_uref: purseUref.toFormattedStr(),
128
+ state_root_hash: stateRootInfo.state_root_hash,
129
+ },
130
+ id: 1,
131
+ });
132
+
133
+ return accountBalance;
134
+ };
135
+
136
+ export const fetchNetworkStatus = async (): Promise<NNetworkStatusResponse> => {
137
+ const payload: NodeRPCPayload = {
138
+ id: 1,
139
+ jsonrpc: "2.0",
140
+ method: "info_get_status",
141
+ params: null,
142
+ };
143
+ const data = await casperNodeWrapper<NNetworkStatusResponse>(payload);
144
+
145
+ return data;
146
+ };
147
+
148
+ export const fetchTxs = async (addr: string): Promise<ITxnHistoryData[]> => {
149
+ const response = await casperIndexerWrapper<ITxnHistoryData>(
150
+ `/accounts/${addr}/ledgerlive-deploys`,
151
+ );
152
+ return response;
153
+ };
154
+
155
+ export const broadcastTx = async (
156
+ deploy: DeployUtil.Deploy,
157
+ ): Promise<NDeployMessagePutResponse> => {
158
+ const response = await casperNodeWrapper<NDeployMessagePutResponse>({
159
+ id: 1,
160
+ jsonrpc: "2.0",
161
+ method: "account_put_deploy",
162
+ params: DeployUtil.deployToJson(deploy),
163
+ });
164
+
165
+ return response;
166
+ };
@@ -0,0 +1,113 @@
1
+ export interface NodeRPCPayload {
2
+ jsonrpc: "2.0";
3
+ method:
4
+ | "info_get_status"
5
+ | "chain_get_state_root_hash"
6
+ | "state_get_account_info"
7
+ | "state_get_balance"
8
+ | "account_put_deploy";
9
+ params: any;
10
+ id: 1;
11
+ }
12
+
13
+ export interface IndexerResponseRoot<T> {
14
+ data: T[];
15
+ pageCount: number;
16
+ itemCount: number;
17
+ pages: { number: number; url: string }[];
18
+ }
19
+
20
+ export interface ITxnHistoryData {
21
+ deploy_hash: string;
22
+ block_hash: string;
23
+ caller_public_key: string;
24
+ execution_type_id: number;
25
+ contract_hash?: any;
26
+ contract_package_hash?: any;
27
+ cost: string;
28
+ payment_amount: string;
29
+ error_message?: string;
30
+ timestamp: string;
31
+ status: string;
32
+ args: {
33
+ id: {
34
+ parsed?: number;
35
+ cl_type: {
36
+ Option: string;
37
+ };
38
+ };
39
+ amount: {
40
+ parsed: string;
41
+ cl_type: string;
42
+ };
43
+ target: {
44
+ parsed: string;
45
+ cl_type:
46
+ | {
47
+ ByteArray: number;
48
+ }
49
+ | string;
50
+ };
51
+ };
52
+ amount: string;
53
+ }
54
+
55
+ export interface NodeResponseRoot<T> {
56
+ jsonrpc: string;
57
+ id: string;
58
+ result: T;
59
+ }
60
+
61
+ export interface NNetworkStatusResponse {
62
+ api_version: string;
63
+ chainspec_name: string;
64
+ starting_state_root_hash: string;
65
+ peers: { node_id: string; address: string }[];
66
+ last_added_block_info: {
67
+ hash: string;
68
+ timestamp: string;
69
+ era_id: number;
70
+ height: number;
71
+ state_root_hash: string;
72
+ creator: string;
73
+ };
74
+ our_public_signing_key: string;
75
+ round_length?: any;
76
+ next_upgrade?: any;
77
+ build_version: string;
78
+ uptime: string;
79
+ }
80
+
81
+ export interface NStateRootHashResponse {
82
+ api_version: string;
83
+ state_root_hash: string;
84
+ }
85
+
86
+ export interface NAccountBalance {
87
+ api_version: string;
88
+ balance_value: string;
89
+ merkle_proof: string;
90
+ }
91
+
92
+ export interface NAccountInfo {
93
+ api_version: string;
94
+ account: {
95
+ account_hash: string;
96
+ named_keys: any[];
97
+ main_purse: string;
98
+ associated_keys: {
99
+ account_hash: string;
100
+ weight: number;
101
+ }[];
102
+ action_thresholds: {
103
+ deployment: number;
104
+ key_management: number;
105
+ };
106
+ };
107
+ merkle_proof: string;
108
+ }
109
+
110
+ export interface NDeployMessagePutResponse {
111
+ api_version: string;
112
+ deploy_hash: string;
113
+ }
@@ -0,0 +1,39 @@
1
+ import flatMap from "lodash/flatMap";
2
+ import { log } from "@ledgerhq/logs";
3
+ import BigNumber from "bignumber.js";
4
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
5
+ import { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
6
+ import { fetchBalance, fetchNetworkStatus, fetchTxs, fetchAccountStateInfo } from "../../api/index";
7
+ import { mapTxToOps } from "./txn";
8
+ import { NAccountBalance, ITxnHistoryData } from "../../api/types";
9
+
10
+ export const getAccountShape: GetAccountShape = async info => {
11
+ const { address, currency, derivationMode } = info;
12
+
13
+ const accountId = encodeAccountId({
14
+ type: "js",
15
+ version: "2",
16
+ currencyId: currency.id,
17
+ xpubOrAddress: address,
18
+ derivationMode,
19
+ });
20
+
21
+ log("debug", `Generation account shape for ${address}`);
22
+
23
+ const { purseUref, accountHash } = await fetchAccountStateInfo(address);
24
+
25
+ const blockHeight = await fetchNetworkStatus();
26
+
27
+ const balance: NAccountBalance = purseUref
28
+ ? await fetchBalance(purseUref)
29
+ : { balance_value: "0", api_version: "", merkle_proof: "" };
30
+ const txs: ITxnHistoryData[] = purseUref ? await fetchTxs(address) : [];
31
+
32
+ return {
33
+ id: accountId,
34
+ balance: new BigNumber(balance.balance_value),
35
+ spendableBalance: new BigNumber(balance.balance_value),
36
+ operations: flatMap(txs, mapTxToOps(accountId, accountHash ?? "")),
37
+ blockHeight: blockHeight.last_added_block_info.height,
38
+ };
39
+ };
@@ -0,0 +1,94 @@
1
+ import { Account } from "@ledgerhq/types-live";
2
+ import { blake2bFinal, blake2bInit, blake2bUpdate } from "blakejs";
3
+ import { CLPublicKey, CLPublicKeyTag } from "casper-js-sdk";
4
+ import { CASPER_CHECKSUM_HEX_LEN } from "../../consts";
5
+
6
+ export const getAddress = (
7
+ a: Account,
8
+ ): {
9
+ address: string;
10
+ derivationPath: string;
11
+ } => ({ address: a.freshAddress, derivationPath: a.freshAddressPath });
12
+
13
+ export function isAddressValid(pubKey: string): boolean {
14
+ try {
15
+ casperGetCLPublicKey(pubKey);
16
+ return true;
17
+ } catch (err) {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ export function casperGetCLPublicKey(pubkey: string): CLPublicKey {
23
+ let checksummed = true;
24
+
25
+ if (pubkey.toLowerCase() === pubkey) checksummed = false;
26
+ if (pubkey.toUpperCase() === pubkey) checksummed = false;
27
+
28
+ return CLPublicKey.fromHex(pubkey, checksummed);
29
+ }
30
+
31
+ export function casperAccountHashFromPublicKey(
32
+ pubKey: string,
33
+ checksummed: boolean = false,
34
+ ): string {
35
+ const accountHashBuff = casperGetCLPublicKey(pubKey).toAccountHash();
36
+
37
+ if (checksummed === false) return Buffer.from(accountHashBuff).toString("hex");
38
+
39
+ return casperAddressEncode(Buffer.from(accountHashBuff));
40
+ }
41
+
42
+ export function casperAddressFromPubKey(pubkey: Buffer, keySig: CLPublicKeyTag): string {
43
+ return `${keySig.toString().padStart(2, "0")}${Buffer.from(pubkey).toString("hex")}`;
44
+ }
45
+
46
+ function numberToBin(num: number) {
47
+ let binStr = (num >>> 0).toString(2);
48
+ while (binStr.length < 8) {
49
+ binStr = "0" + binStr;
50
+ }
51
+ return binStr.split("").reverse().join("");
52
+ }
53
+
54
+ function bytesToBitsString(buf: Buffer | Uint8Array) {
55
+ const bitsArray: string[] = [];
56
+
57
+ for (const num of buf) {
58
+ const bin = numberToBin(num);
59
+ bitsArray.push(bin);
60
+ }
61
+
62
+ return bitsArray.join("");
63
+ }
64
+
65
+ /**
66
+ * Returns the bytes encoded as hexadecimal with mixed-case based checksums following a scheme
67
+ * similar to [EIP-55](https://eips.ethereum.org/EIPS/eip-55).
68
+ */
69
+ export function casperAddressEncode(inputBytes: Buffer): string {
70
+ const context = blake2bInit(CASPER_CHECKSUM_HEX_LEN);
71
+ blake2bUpdate(context, inputBytes);
72
+ const blakeHash = blake2bFinal(context);
73
+
74
+ const nibbles = inputBytes
75
+ .toString("hex")
76
+ .split("")
77
+ .map(v => parseInt(v, 16));
78
+
79
+ const bitsArray = bytesToBitsString(blakeHash);
80
+
81
+ const res: Array<number | string> = [];
82
+
83
+ let steamIndex = -1;
84
+ for (const num of nibbles) {
85
+ if (num < 10) res.push(num);
86
+ else {
87
+ steamIndex += 1;
88
+ if (parseInt(bitsArray[steamIndex], 10)) res.push(num.toString(16).toUpperCase());
89
+ else res.push(num.toString(16).toLowerCase());
90
+ }
91
+ }
92
+
93
+ return res.join("");
94
+ }
@@ -0,0 +1,6 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { CASPER_FEES_MOTES } from "../../consts";
3
+
4
+ export function getEstimatedFees(): BigNumber {
5
+ return new BigNumber(CASPER_FEES_MOTES);
6
+ }
@@ -0,0 +1,9 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { CASPER_MAX_TRANSFER_ID } from "../../consts";
3
+
4
+ export function isTransferIdValid(id?: string): boolean {
5
+ if (!id || !id.length) return true;
6
+ if (/^\d+$/.test(id) && new BigNumber(id).lt(new BigNumber(CASPER_MAX_TRANSFER_ID))) return true;
7
+
8
+ return false;
9
+ }
@@ -0,0 +1,121 @@
1
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
2
+ import { InvalidAddress } from "@ledgerhq/errors";
3
+ import { log } from "@ledgerhq/logs";
4
+ import { Unit } from "@ledgerhq/types-cryptoassets";
5
+ import BigNumber from "bignumber.js";
6
+ import { DeployUtil } from "casper-js-sdk";
7
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
8
+ import { CASPER_NETWORK } from "../../consts";
9
+ import { casperAccountHashFromPublicKey, casperGetCLPublicKey, isAddressValid } from "./addresses";
10
+ import { ITxnHistoryData } from "../../api/types";
11
+ import { getEstimatedFees } from "./fee";
12
+ import { CasperOperation } from "../../types";
13
+ import invariant from "invariant";
14
+
15
+ export const getUnit = (): Unit => getCryptoCurrencyById("casper").units[0];
16
+
17
+ export function mapTxToOps(
18
+ accountId: string,
19
+ addressHash: string,
20
+ fees = getEstimatedFees(),
21
+ ): (tx: ITxnHistoryData) => CasperOperation[] {
22
+ return (tx: ITxnHistoryData): CasperOperation[] => {
23
+ try {
24
+ const ops: CasperOperation[] = [];
25
+ const { timestamp, caller_public_key, args: txArgs, deploy_hash, error_message } = tx;
26
+ const fromAccount = casperAccountHashFromPublicKey(caller_public_key);
27
+ let toAccount;
28
+
29
+ if (txArgs.target.cl_type === "PublicKey") {
30
+ toAccount = casperAccountHashFromPublicKey(txArgs.target.parsed);
31
+ } else {
32
+ toAccount = txArgs.target.parsed;
33
+ }
34
+ invariant(toAccount, "toAccount is required");
35
+ invariant(fromAccount, "fromAccount is required");
36
+
37
+ const date = new Date(timestamp);
38
+ const value = new BigNumber(txArgs.amount.parsed);
39
+ const feeToUse = fees;
40
+
41
+ const isSending = addressHash.toLowerCase() === fromAccount.toLowerCase();
42
+ const isReceiving = addressHash.toLowerCase() === toAccount.toLowerCase();
43
+
44
+ if (isSending) {
45
+ ops.push({
46
+ id: encodeOperationId(accountId, deploy_hash, "OUT"),
47
+ hash: deploy_hash,
48
+ type: "OUT",
49
+ value: value.plus(feeToUse),
50
+ fee: feeToUse,
51
+ blockHeight: 1,
52
+ hasFailed: error_message ? true : false,
53
+ blockHash: null,
54
+ accountId,
55
+ senders: [fromAccount],
56
+ recipients: [toAccount],
57
+ date,
58
+ extra: {
59
+ transferId: txArgs.id.parsed?.toString(),
60
+ },
61
+ });
62
+ }
63
+
64
+ if (isReceiving) {
65
+ ops.push({
66
+ id: encodeOperationId(accountId, deploy_hash, "IN"),
67
+ hash: deploy_hash,
68
+ type: "IN",
69
+ value,
70
+ fee: feeToUse,
71
+ blockHeight: 1,
72
+ blockHash: null,
73
+ hasFailed: error_message ? true : false,
74
+ accountId,
75
+ senders: [fromAccount],
76
+ recipients: [toAccount],
77
+ date,
78
+ extra: {
79
+ transferId: txArgs.id.parsed?.toString(),
80
+ },
81
+ });
82
+ }
83
+
84
+ return ops;
85
+ } catch (err) {
86
+ log("warn", `mapTxToOps failed for casper, skipping operation`, err);
87
+ return [];
88
+ }
89
+ };
90
+ }
91
+
92
+ export const createNewDeploy = (
93
+ sender: string,
94
+ recipient: string,
95
+ amount: BigNumber,
96
+ fees: BigNumber,
97
+ transferId?: string,
98
+ network = CASPER_NETWORK,
99
+ ): DeployUtil.Deploy => {
100
+ log("debug", `Creating new Deploy: ${sender}, ${recipient}, ${network}`);
101
+
102
+ if (recipient && !isAddressValid(recipient)) {
103
+ throw InvalidAddress(`Invalid recipient Address ${recipient}`);
104
+ }
105
+
106
+ const deployParams = new DeployUtil.DeployParams(casperGetCLPublicKey(sender), network);
107
+
108
+ const session = DeployUtil.ExecutableDeployItem.newTransferWithOptionalTransferId(
109
+ amount?.toNumber() ?? 0,
110
+ casperGetCLPublicKey(recipient),
111
+ undefined,
112
+ transferId,
113
+ );
114
+
115
+ const payment = DeployUtil.standardPayment(fees.toString());
116
+ const deploy = DeployUtil.makeDeploy(deployParams, session, payment);
117
+ const txnRaw = DeployUtil.deployToJson(deploy);
118
+ const txnFromRaw = DeployUtil.deployFromJson(txnRaw).unwrap();
119
+
120
+ return txnFromRaw;
121
+ };
@@ -0,0 +1,18 @@
1
+ import { DeployUtil } from "casper-js-sdk";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
4
+ import { Transaction } from "../types";
5
+ import { broadcastTx } from "../api";
6
+
7
+ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
8
+ signedOperation: { signature, operation },
9
+ }) => {
10
+ const tx = DeployUtil.deployFromJson(JSON.parse(signature)).unwrap();
11
+
12
+ const resp = await broadcastTx(tx);
13
+ const { deploy_hash } = resp;
14
+
15
+ const result = patchOperationWithHash(operation, deploy_hash);
16
+
17
+ return result;
18
+ };