@aeternity/aepp-sdk 10.0.0 → 12.0.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/LICENSE +1 -1
  2. package/README.md +15 -14
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/AeSdk.d.ts +37 -0
  11. package/es/AeSdk.mjs +81 -0
  12. package/es/AeSdk.mjs.map +1 -0
  13. package/es/AeSdkAepp.d.ts +69 -0
  14. package/es/AeSdkAepp.mjs +175 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +212 -0
  17. package/es/AeSdkBase.mjs +310 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +103 -0
  20. package/es/AeSdkWallet.mjs +322 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +44 -0
  23. package/es/Node.mjs +141 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +65 -0
  26. package/es/account/Base.mjs +123 -0
  27. package/es/account/Base.mjs.map +1 -0
  28. package/es/account/Memory.d.ts +25 -0
  29. package/es/account/Memory.mjs +81 -0
  30. package/es/account/Memory.mjs.map +1 -0
  31. package/es/account/Rpc.d.ts +27 -0
  32. package/es/account/Rpc.mjs +79 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +209 -0
  35. package/es/aens.mjs +332 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  54. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  55. package/es/aepp-wallet-communication/schema.d.ts +118 -0
  56. package/es/aepp-wallet-communication/schema.mjs +214 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  60. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  61. package/es/apis/compiler/compiler.d.ts +92 -0
  62. package/es/apis/compiler/compiler.mjs +576 -0
  63. package/es/apis/compiler/compiler.mjs.map +1 -0
  64. package/es/apis/compiler/index.d.ts +2 -0
  65. package/es/apis/compiler/index.mjs +3 -0
  66. package/es/apis/compiler/index.mjs.map +1 -0
  67. package/es/apis/compiler/models/index.d.ts +248 -0
  68. package/es/apis/compiler/models/index.mjs +48 -0
  69. package/es/apis/compiler/models/index.mjs.map +1 -0
  70. package/es/apis/compiler/models/mappers.d.ts +23 -0
  71. package/es/apis/compiler/models/mappers.mjs +585 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  73. package/es/apis/compiler/models/parameters.d.ts +13 -0
  74. package/es/apis/compiler/models/parameters.mjs +71 -0
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  76. package/es/apis/node/index.d.ts +2 -0
  77. package/es/apis/node/index.mjs +3 -0
  78. package/es/apis/node/index.mjs.map +1 -0
  79. package/es/apis/node/models/index.d.ts +1061 -0
  80. package/es/apis/node/models/index.mjs +2 -0
  81. package/es/apis/node/models/index.mjs.map +1 -0
  82. package/es/apis/node/models/mappers.d.ts +95 -0
  83. package/es/apis/node/models/mappers.mjs +4164 -0
  84. package/es/apis/node/models/mappers.mjs.map +1 -0
  85. package/es/apis/node/models/parameters.d.ts +17 -0
  86. package/es/apis/node/models/parameters.mjs +165 -0
  87. package/es/apis/node/models/parameters.mjs.map +1 -0
  88. package/es/apis/node/node.d.ts +215 -0
  89. package/es/apis/node/node.mjs +1165 -0
  90. package/es/apis/node/node.mjs.map +1 -0
  91. package/es/chain.d.ts +220 -0
  92. package/es/chain.mjs +524 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/{handlers.js → handlers.mjs} +163 -130
  96. package/es/channel/handlers.mjs.map +1 -0
  97. package/es/channel/index.d.ts +634 -0
  98. package/es/channel/index.mjs +978 -0
  99. package/es/channel/index.mjs.map +1 -0
  100. package/es/channel/internal.d.ts +100 -0
  101. package/es/channel/internal.mjs +328 -0
  102. package/es/channel/internal.mjs.map +1 -0
  103. package/es/contract/Compiler.d.ts +17 -0
  104. package/es/contract/Compiler.mjs +67 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +125 -0
  107. package/es/contract/aci.mjs +496 -0
  108. package/es/contract/aci.mjs.map +1 -0
  109. package/es/contract/ga.d.ts +68 -0
  110. package/es/contract/ga.mjs +190 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +68 -0
  113. package/es/contract/methods.mjs +101 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/index.d.ts +32 -0
  116. package/es/index.mjs +49 -0
  117. package/es/index.mjs.map +1 -0
  118. package/es/oracle.d.ts +154 -0
  119. package/es/oracle.mjs +288 -0
  120. package/es/oracle.mjs.map +1 -0
  121. package/es/spend.d.ts +61 -0
  122. package/es/spend.mjs +122 -0
  123. package/es/spend.mjs.map +1 -0
  124. package/es/tx/builder/constants.d.ts +41 -0
  125. package/es/tx/builder/constants.mjs +100 -0
  126. package/es/tx/builder/constants.mjs.map +1 -0
  127. package/es/tx/builder/field-types.d.ts +62 -0
  128. package/es/tx/builder/field-types.mjs +126 -0
  129. package/es/tx/builder/field-types.mjs.map +1 -0
  130. package/es/tx/builder/helpers.d.ts +131 -0
  131. package/es/tx/builder/helpers.mjs +223 -0
  132. package/es/tx/builder/helpers.mjs.map +1 -0
  133. package/es/tx/builder/index.d.ts +75 -0
  134. package/es/tx/builder/index.mjs +424 -0
  135. package/es/tx/builder/index.mjs.map +1 -0
  136. package/es/tx/builder/schema.d.ts +350 -0
  137. package/es/tx/builder/schema.mjs +320 -0
  138. package/es/tx/builder/schema.mjs.map +1 -0
  139. package/es/tx/index.d.ts +63 -0
  140. package/es/tx/index.mjs +209 -0
  141. package/es/tx/index.mjs.map +1 -0
  142. package/es/tx/min-fee.d.ts +20 -0
  143. package/es/tx/min-fee.mjs +148 -0
  144. package/es/tx/min-fee.mjs.map +1 -0
  145. package/es/tx/validator.d.ts +19 -0
  146. package/es/tx/validator.mjs +240 -0
  147. package/es/tx/validator.mjs.map +1 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  149. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  151. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  152. package/es/typings/bip32-path/index.d.mjs +2 -0
  153. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  154. package/es/typings/blakejs/index.d.mjs +2 -0
  155. package/es/typings/blakejs/index.d.mjs.map +1 -0
  156. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  157. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  158. package/es/utils/amount-formatter.d.ts +42 -0
  159. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
  160. package/es/utils/amount-formatter.mjs.map +1 -0
  161. package/es/utils/autorest.d.ts +6 -0
  162. package/es/utils/autorest.mjs +97 -0
  163. package/es/utils/autorest.mjs.map +1 -0
  164. package/es/utils/bignumber.d.ts +13 -0
  165. package/es/utils/bignumber.mjs +23 -0
  166. package/es/utils/bignumber.mjs.map +1 -0
  167. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  168. package/es/utils/{bytes.js → bytes.mjs} +26 -22
  169. package/es/utils/bytes.mjs.map +1 -0
  170. package/es/utils/crypto.d.ts +103 -0
  171. package/es/utils/crypto.mjs +221 -0
  172. package/es/utils/crypto.mjs.map +1 -0
  173. package/es/utils/encoder.d.ts +26 -0
  174. package/es/utils/encoder.mjs +102 -0
  175. package/es/utils/encoder.mjs.map +1 -0
  176. package/es/utils/errors.d.ts +481 -0
  177. package/es/utils/errors.mjs +882 -0
  178. package/es/utils/errors.mjs.map +1 -0
  179. package/es/utils/hd-wallet.d.ts +34 -0
  180. package/es/utils/hd-wallet.mjs +122 -0
  181. package/es/utils/hd-wallet.mjs.map +1 -0
  182. package/es/utils/json-big.d.ts +5 -0
  183. package/es/utils/json-big.mjs +41 -0
  184. package/es/utils/json-big.mjs.map +1 -0
  185. package/es/utils/keystore.d.ts +51 -0
  186. package/es/utils/keystore.mjs +145 -0
  187. package/es/utils/keystore.mjs.map +1 -0
  188. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  189. package/es/utils/{mptree.js → mptree.mjs} +33 -25
  190. package/es/utils/mptree.mjs.map +1 -0
  191. package/es/utils/other.d.ts +14 -0
  192. package/es/utils/other.mjs +28 -0
  193. package/es/utils/other.mjs.map +1 -0
  194. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  195. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  196. package/es/utils/semver-satisfies.mjs.map +1 -0
  197. package/es/utils/string.d.ts +24 -0
  198. package/es/utils/{string.js → string.mjs} +9 -11
  199. package/es/utils/string.mjs.map +1 -0
  200. package/package.json +67 -64
  201. package/src/AeSdk.ts +65 -0
  202. package/src/AeSdkAepp.ts +167 -0
  203. package/src/AeSdkBase.ts +320 -0
  204. package/src/AeSdkWallet.ts +332 -0
  205. package/src/Node.ts +167 -0
  206. package/src/account/Base.ts +114 -0
  207. package/src/account/Memory.ts +83 -0
  208. package/src/account/Rpc.ts +67 -0
  209. package/src/aens.ts +391 -0
  210. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  211. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  212. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  213. package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
  214. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  215. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  216. package/src/aepp-wallet-communication/schema.ts +181 -0
  217. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  218. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  219. package/src/apis/compiler/compiler.ts +585 -0
  220. package/src/apis/compiler/index.ts +2 -0
  221. package/src/apis/compiler/models/index.ts +301 -0
  222. package/src/apis/compiler/models/mappers.ts +583 -0
  223. package/src/apis/compiler/models/parameters.ts +93 -0
  224. package/src/apis/node/code-model-v4.yaml +10046 -0
  225. package/src/apis/node/index.ts +2 -0
  226. package/src/apis/node/models/index.ts +1253 -0
  227. package/src/apis/node/models/mappers.ts +4278 -0
  228. package/src/apis/node/models/parameters.ts +188 -0
  229. package/src/apis/node/node.ts +1299 -0
  230. package/src/chain.ts +444 -0
  231. package/src/channel/{handlers.js → handlers.ts} +238 -143
  232. package/src/channel/index.ts +991 -0
  233. package/src/channel/internal.ts +345 -0
  234. package/src/contract/Compiler.ts +66 -0
  235. package/src/contract/aci.ts +529 -0
  236. package/src/contract/ga.ts +178 -0
  237. package/src/contract/methods.ts +118 -0
  238. package/src/index.ts +51 -0
  239. package/src/oracle.ts +342 -0
  240. package/src/spend.ts +152 -0
  241. package/src/tx/builder/constants.ts +96 -0
  242. package/src/tx/builder/field-types.ts +111 -0
  243. package/src/tx/builder/helpers.ts +253 -0
  244. package/src/tx/builder/index.ts +394 -0
  245. package/src/tx/builder/schema.ts +771 -0
  246. package/src/tx/index.ts +199 -0
  247. package/src/tx/min-fee.ts +136 -0
  248. package/src/tx/validator.ts +226 -0
  249. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  250. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  251. package/src/typings/bip32-path/index.d.ts +33 -0
  252. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  253. package/src/utils/amount-formatter.ts +29 -41
  254. package/src/utils/autorest.ts +90 -0
  255. package/src/utils/bignumber.ts +9 -19
  256. package/src/utils/bytes.ts +15 -16
  257. package/src/utils/crypto.ts +217 -0
  258. package/src/utils/encoder.ts +98 -0
  259. package/src/utils/errors.ts +817 -0
  260. package/src/utils/hd-wallet.ts +134 -0
  261. package/src/utils/json-big.ts +26 -0
  262. package/src/utils/keystore.ts +179 -0
  263. package/src/utils/mptree.ts +26 -20
  264. package/src/utils/other.ts +28 -43
  265. package/src/utils/string.ts +8 -10
  266. package/CHANGELOG.md +0 -1603
  267. package/es/account/base.js +0 -169
  268. package/es/account/base.js.map +0 -1
  269. package/es/account/memory.js +0 -84
  270. package/es/account/memory.js.map +0 -1
  271. package/es/account/multiple.js +0 -178
  272. package/es/account/multiple.js.map +0 -1
  273. package/es/ae/aens.js +0 -408
  274. package/es/ae/aens.js.map +0 -1
  275. package/es/ae/aepp.js +0 -45
  276. package/es/ae/aepp.js.map +0 -1
  277. package/es/ae/contract.js +0 -312
  278. package/es/ae/contract.js.map +0 -1
  279. package/es/ae/index.js +0 -206
  280. package/es/ae/index.js.map +0 -1
  281. package/es/ae/oracle.js +0 -322
  282. package/es/ae/oracle.js.map +0 -1
  283. package/es/ae/universal.js +0 -45
  284. package/es/ae/universal.js.map +0 -1
  285. package/es/ae/wallet.js +0 -50
  286. package/es/ae/wallet.js.map +0 -1
  287. package/es/amount-formatter.d.ts +0 -58
  288. package/es/bignumber.d.ts +0 -24
  289. package/es/chain/index.js +0 -256
  290. package/es/chain/index.js.map +0 -1
  291. package/es/chain/node.js +0 -394
  292. package/es/chain/node.js.map +0 -1
  293. package/es/channel/handlers.js.map +0 -1
  294. package/es/channel/index.js +0 -980
  295. package/es/channel/index.js.map +0 -1
  296. package/es/channel/internal.js +0 -266
  297. package/es/channel/internal.js.map +0 -1
  298. package/es/contract/aci/helpers.js +0 -298
  299. package/es/contract/aci/helpers.js.map +0 -1
  300. package/es/contract/aci/index.js +0 -361
  301. package/es/contract/aci/index.js.map +0 -1
  302. package/es/contract/aci/transformation.js +0 -66
  303. package/es/contract/aci/transformation.js.map +0 -1
  304. package/es/contract/compiler.js +0 -244
  305. package/es/contract/compiler.js.map +0 -1
  306. package/es/contract/ga/helpers.js +0 -22
  307. package/es/contract/ga/helpers.js.map +0 -1
  308. package/es/contract/ga/index.js +0 -170
  309. package/es/contract/ga/index.js.map +0 -1
  310. package/es/contract/index.js +0 -162
  311. package/es/contract/index.js.map +0 -1
  312. package/es/crypto-ts.d.ts +0 -9
  313. package/es/index.js +0 -57
  314. package/es/index.js.map +0 -1
  315. package/es/node-pool/index.js +0 -187
  316. package/es/node-pool/index.js.map +0 -1
  317. package/es/node.js +0 -132
  318. package/es/node.js.map +0 -1
  319. package/es/other.d.ts +0 -31
  320. package/es/string.d.ts +0 -26
  321. package/es/tx/builder/helpers.js +0 -305
  322. package/es/tx/builder/helpers.js.map +0 -1
  323. package/es/tx/builder/index.js +0 -595
  324. package/es/tx/builder/index.js.map +0 -1
  325. package/es/tx/builder/schema.js +0 -814
  326. package/es/tx/builder/schema.js.map +0 -1
  327. package/es/tx/index.js +0 -300
  328. package/es/tx/index.js.map +0 -1
  329. package/es/tx/tx-object.js +0 -276
  330. package/es/tx/tx-object.js.map +0 -1
  331. package/es/tx/tx.js +0 -937
  332. package/es/tx/tx.js.map +0 -1
  333. package/es/tx/validator.js +0 -208
  334. package/es/tx/validator.js.map +0 -1
  335. package/es/typings/blakejs/index.d.js +0 -2
  336. package/es/typings/blakejs/index.d.js.map +0 -1
  337. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
  338. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  339. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
  340. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  341. package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
  342. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  343. package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
  344. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  345. package/es/utils/aepp-wallet-communication/helpers.js +0 -103
  346. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  347. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
  348. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  349. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
  350. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  351. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
  352. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  353. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  354. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  355. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
  356. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  357. package/es/utils/amount-formatter.js.map +0 -1
  358. package/es/utils/async-init.js +0 -67
  359. package/es/utils/async-init.js.map +0 -1
  360. package/es/utils/bignumber.js +0 -28
  361. package/es/utils/bignumber.js.map +0 -1
  362. package/es/utils/bytes.js.map +0 -1
  363. package/es/utils/crypto-ts.js.map +0 -1
  364. package/es/utils/crypto.js +0 -304
  365. package/es/utils/crypto.js.map +0 -1
  366. package/es/utils/hd-wallet.js +0 -112
  367. package/es/utils/hd-wallet.js.map +0 -1
  368. package/es/utils/json-big.js +0 -45
  369. package/es/utils/json-big.js.map +0 -1
  370. package/es/utils/keystore.js +0 -228
  371. package/es/utils/keystore.js.map +0 -1
  372. package/es/utils/mptree.js.map +0 -1
  373. package/es/utils/other.js +0 -43
  374. package/es/utils/other.js.map +0 -1
  375. package/es/utils/semver-satisfies.js.map +0 -1
  376. package/es/utils/string.js.map +0 -1
  377. package/es/utils/swagger.js +0 -132
  378. package/es/utils/swagger.js.map +0 -1
  379. package/src/account/base.js +0 -153
  380. package/src/account/memory.js +0 -78
  381. package/src/account/multiple.js +0 -154
  382. package/src/ae/aens.js +0 -366
  383. package/src/ae/aepp.js +0 -45
  384. package/src/ae/contract.js +0 -285
  385. package/src/ae/index.js +0 -167
  386. package/src/ae/oracle.js +0 -296
  387. package/src/ae/universal.js +0 -47
  388. package/src/ae/wallet.js +0 -50
  389. package/src/chain/index.js +0 -250
  390. package/src/chain/node.js +0 -293
  391. package/src/channel/index.js +0 -898
  392. package/src/channel/internal.js +0 -231
  393. package/src/contract/aci/index.js +0 -317
  394. package/src/contract/aci/transformation.js +0 -72
  395. package/src/contract/compiler.js +0 -195
  396. package/src/contract/ga/helpers.js +0 -17
  397. package/src/contract/ga/index.js +0 -147
  398. package/src/contract/index.js +0 -163
  399. package/src/index.js +0 -90
  400. package/src/node-pool/index.js +0 -171
  401. package/src/node.js +0 -118
  402. package/src/tx/builder/helpers.js +0 -325
  403. package/src/tx/builder/index.js +0 -460
  404. package/src/tx/builder/schema.js +0 -1211
  405. package/src/tx/index.js +0 -301
  406. package/src/tx/tx-object.js +0 -186
  407. package/src/tx/tx.js +0 -622
  408. package/src/tx/validator.js +0 -161
  409. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
  410. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
  411. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  412. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
  413. package/src/utils/aepp-wallet-communication/helpers.js +0 -70
  414. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
  415. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
  416. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
  417. package/src/utils/aepp-wallet-communication/schema.js +0 -108
  418. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
  419. package/src/utils/async-init.js +0 -41
  420. package/src/utils/crypto.js +0 -312
  421. package/src/utils/hd-wallet.js +0 -115
  422. package/src/utils/json-big.js +0 -26
  423. package/src/utils/keystore.js +0 -223
  424. package/src/utils/swagger.js +0 -133
@@ -0,0 +1,978 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2018 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+ import { snakeToPascal } from "../utils/string.mjs";
18
+ import { buildTx, unpackTx } from "../tx/builder/index.mjs";
19
+ import { TX_TYPE } from "../tx/builder/schema.mjs";
20
+ import * as handlers from "./handlers.mjs";
21
+ import { eventEmitters, status as channelStatus, state as channelState, initialize, enqueueAction, send, channelId, call, disconnect as channelDisconnect, fsmId as channelFsmId } from "./internal.mjs";
22
+ import { UnknownChannelStateError, ChannelError } from "../utils/errors.mjs";
23
+
24
+ function snakeToPascalObjKeys(obj) {
25
+ return Object.entries(obj).reduce((result, _ref) => {
26
+ let [key, val] = _ref;
27
+ return { ...result,
28
+ [snakeToPascal(key)]: val
29
+ };
30
+ }, {});
31
+ }
32
+
33
+ /**
34
+ * Channel
35
+ * @example
36
+ * ```js
37
+ * await Channel.initialize({
38
+ * url: 'ws://localhost:3001',
39
+ * role: 'initiator'
40
+ * initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
41
+ * responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',
42
+ * initiatorAmount: 1e18,
43
+ * responderAmount: 1e18,
44
+ * pushAmount: 0,
45
+ * channelReserve: 0,
46
+ * ttl: 1000,
47
+ * host: 'localhost',
48
+ * port: 3002,
49
+ * lockPeriod: 10,
50
+ * async sign (tag, tx) => await account.signTransaction(tx)
51
+ * })
52
+ * ```
53
+ */
54
+ export default class Channel {
55
+ /**
56
+ * @param options - Channel params
57
+ * @param options.url - Channel url (for example: "ws://localhost:3001")
58
+ * @param options.role - Participant role ("initiator" or "responder")
59
+ * @param options.initiatorId - Initiator's public key
60
+ * @param options.responderId - Responder's public key
61
+ * @param options.pushAmount - Initial deposit in favour of the responder by the initiator
62
+ * @param options.initiatorAmount - Amount of coins the initiator has committed to
63
+ * the channel
64
+ * @param options.responderAmount - Amount of coins the responder has committed to
65
+ * the channel
66
+ * @param options.channelReserve - The minimum amount both peers need to maintain
67
+ * @param options.ttl - Minimum block height to include the channel_create_tx
68
+ * @param options.host - Host of the responder's node
69
+ * @param options.port - The port of the responders node
70
+ * @param options.lockPeriod - Amount of blocks for disputing a solo close
71
+ * @param options.existingChannelId - Existing channel id (required if reestablishing a
72
+ * channel)
73
+ * @param options.offchainTx - Offchain transaction (required if reestablishing
74
+ * a channel)
75
+ * @param options.timeoutIdle - The time waiting for a new event to be initiated
76
+ * (default: 600000)
77
+ * @param options.timeoutFundingCreate - The time waiting for the initiator to produce
78
+ * the create channel transaction after the noise session had been established (default: 120000)
79
+ * @param options.timeoutFundingSign - The time frame the other client has to sign an
80
+ * off-chain update after our client had initiated and signed it. This applies only for double
81
+ * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.
82
+ * (default: 120000)
83
+ * @param options.timeoutFundingLock - The time frame the other client has to confirm an
84
+ * on-chain transaction reaching maturity (passing minimum depth) after the local node has
85
+ * detected this. This applies only for double signed on-chain intended updates: channel create
86
+ * transaction, deposit, withdrawal and etc. (default: 360000)
87
+ * @param options.timeoutSign - The time frame the client has to return a signed
88
+ * off-chain update or to decline it. This applies for all off-chain updates (default: 500000)
89
+ * @param options.timeoutAccept - The time frame the other client has to react to an
90
+ * event. This applies for all off-chain updates that are not meant to land on-chain, as well as
91
+ * some special cases: opening a noise connection, mutual closing acknowledgement and
92
+ * reestablishing an existing channel (default: 120000)
93
+ * @param options.timeoutInitialized - the time frame the responder has to accept an
94
+ * incoming noise session. Applicable only for initiator (default: timeout_accept's value)
95
+ * @param options.timeoutAwaitingOpen - The time frame the initiator has to start an
96
+ * outgoing noise session to the responder's node. Applicable only for responder (default:
97
+ * timeout_idle's value)
98
+ * @param options.debug=false - Log websocket communication
99
+ * @param options.sign - Function which verifies and signs transactions
100
+ */
101
+ static async initialize(options) {
102
+ const channel = new Channel();
103
+ await initialize(channel, options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection, handlers.channelOpen, options);
104
+ return channel;
105
+ }
106
+ /**
107
+ * Register event listener function
108
+ *
109
+ * Possible events:
110
+ *
111
+ * - "error"
112
+ * - "onChainTx"
113
+ * - "ownWithdrawLocked"
114
+ * - "withdrawLocked"
115
+ * - "ownDepositLocked"
116
+ * - "depositLocked"
117
+ *
118
+ * TODO: the event list looks outdated
119
+ *
120
+ * @param eventName - Event name
121
+ * @param callback - Callback function
122
+ */
123
+ // TODO define specific callback type depending on the event name
124
+
125
+
126
+ on(eventName, callback) {
127
+ const eventEmitter = eventEmitters.get(this);
128
+ if (eventEmitter == null) throw new UnknownChannelStateError();
129
+ eventEmitter.on(eventName, callback);
130
+ }
131
+ /**
132
+ * Remove event listener function
133
+ * @param eventName - Event name
134
+ * @param callback - Callback function
135
+ */
136
+
137
+
138
+ off(eventName, callback) {
139
+ const eventEmitter = eventEmitters.get(this);
140
+ if (eventEmitter == null) throw new UnknownChannelStateError();
141
+ eventEmitter.removeListener(eventName, callback);
142
+ }
143
+ /**
144
+ * Close the connection
145
+ */
146
+
147
+
148
+ disconnect() {
149
+ return channelDisconnect(this);
150
+ }
151
+ /**
152
+ * Get current status
153
+ *
154
+ */
155
+
156
+
157
+ status() {
158
+ const status = channelStatus.get(this);
159
+ if (status == null) throw new UnknownChannelStateError();
160
+ return status;
161
+ }
162
+ /**
163
+ * Get current state
164
+ */
165
+
166
+
167
+ async state() {
168
+ return await snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
169
+ }
170
+ /**
171
+ * Get current round
172
+ *
173
+ * If round cannot be determined (for example when channel has not been opened)
174
+ * it will return `null`.
175
+ *
176
+ */
177
+
178
+
179
+ round() {
180
+ const state = channelState.get(this);
181
+
182
+ if (state == null) {
183
+ return null;
184
+ }
185
+
186
+ const {
187
+ txType,
188
+ tx
189
+ } = unpackTx(state, TX_TYPE.signed).tx.encodedTx;
190
+
191
+ switch (txType) {
192
+ case TX_TYPE.channelCreate:
193
+ return 1;
194
+
195
+ case TX_TYPE.channelOffChain:
196
+ case TX_TYPE.channelWithdraw:
197
+ case TX_TYPE.channelDeposit:
198
+ return +tx.round;
199
+
200
+ default:
201
+ return null;
202
+ }
203
+ }
204
+ /**
205
+ * Get channel id
206
+ *
207
+ */
208
+
209
+
210
+ id() {
211
+ const id = channelId.get(this);
212
+ if (id == null) throw new ChannelError('Channel is not initialized');
213
+ return id;
214
+ }
215
+ /**
216
+ * Get channel's fsm id
217
+ *
218
+ */
219
+
220
+
221
+ fsmId() {
222
+ const id = channelFsmId.get(this);
223
+ if (id == null) throw new ChannelError('Channel is not initialized');
224
+ return id;
225
+ }
226
+ /**
227
+ * Trigger a transfer update
228
+ *
229
+ * The transfer update is moving coins from one channel account to another.
230
+ * The update is a change to be applied on top of the latest state.
231
+ *
232
+ * Sender and receiver are the channel parties. Both the initiator and responder
233
+ * can take those roles. Any public key outside of the channel is considered invalid.
234
+ *
235
+ * @param from - Sender's public address
236
+ * @param to - Receiver's public address
237
+ * @param amount - Transaction amount
238
+ * @param sign - Function which verifies and signs offchain transaction
239
+ * @param metadata - Metadata
240
+ * @example
241
+ * ```js
242
+ * channel.update(
243
+ * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
244
+ * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',
245
+ * 10,
246
+ * async (tx) => await account.signTransaction(tx)
247
+ * ).then(({ accepted, signedTx }) =>
248
+ * if (accepted) {
249
+ * console.log('Update has been accepted')
250
+ * }
251
+ * )
252
+ * ```
253
+ */
254
+
255
+
256
+ async update(from, to, amount, sign) {
257
+ let metadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
258
+ return await new Promise((resolve, reject) => {
259
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, (channel, _state) => {
260
+ send(channel, {
261
+ jsonrpc: '2.0',
262
+ method: 'channels.update.new',
263
+ params: {
264
+ from,
265
+ to,
266
+ amount,
267
+ meta: metadata
268
+ }
269
+ });
270
+ return {
271
+ handler: handlers.awaitingOffChainTx,
272
+ state: {
273
+ resolve,
274
+ reject,
275
+ sign
276
+ }
277
+ };
278
+ });
279
+ });
280
+ }
281
+ /**
282
+ * Get proof of inclusion
283
+ *
284
+ * If a certain address of an account or a contract is not found
285
+ * in the state tree - the response is an error.
286
+ *
287
+ * @param addresses - Addresses
288
+ * @param addresses.accounts - List of account addresses to include in poi
289
+ * @param addresses.contracts - List of contract addresses to include in poi
290
+ * @example
291
+ * ```js
292
+ * channel.poi({
293
+ * accounts: [
294
+ * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
295
+ * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'
296
+ * ],
297
+ * contracts: ['ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA']
298
+ * }).then(poi => console.log(poi))
299
+ * ```
300
+ */
301
+
302
+
303
+ async poi(_ref2) {
304
+ let {
305
+ accounts,
306
+ contracts
307
+ } = _ref2;
308
+ return (await call(this, 'channels.get.poi', {
309
+ accounts,
310
+ contracts
311
+ })).poi;
312
+ }
313
+ /**
314
+ * Get balances
315
+ *
316
+ * The accounts paramcontains a list of addresses to fetch balances of.
317
+ * Those can be either account balances or a contract ones, encoded as an account addresses.
318
+ *
319
+ * If a certain account address had not being found in the state tree - it is simply
320
+ * skipped in the response.
321
+ *
322
+ * @param accounts - List of addresses to fetch balances from
323
+ * @example
324
+ * ```js
325
+ * channel.balances([
326
+ * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
327
+ * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'
328
+ * 'ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA'
329
+ * ]).then(balances =>
330
+ * console.log(balances['ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'])
331
+ * )
332
+ * ```
333
+ */
334
+
335
+
336
+ async balances(accounts) {
337
+ return Object.fromEntries((await call(this, 'channels.get.balances', {
338
+ accounts
339
+ })).map(item => [item.account, item.balance]));
340
+ }
341
+ /**
342
+ * Leave channel
343
+ *
344
+ * It is possible to leave a channel and then later reestablish the channel
345
+ * off-chain state and continue operation. When a leave method is called,
346
+ * the channel fsm passes it on to the peer fsm, reports the current mutually
347
+ * signed state and then terminates.
348
+ *
349
+ * The channel can be reestablished by instantiating another Channel instance
350
+ * with two extra params: existingChannelId and offchainTx (returned from leave
351
+ * method as channelId and signedTx respectively).
352
+ *
353
+ * @example
354
+ * ```js
355
+ * channel.leave().then(({ channelId, signedTx }) => {
356
+ * console.log(channelId)
357
+ * console.log(signedTx)
358
+ * })
359
+ * ```
360
+ */
361
+
362
+
363
+ async leave() {
364
+ return await new Promise((resolve, reject) => {
365
+ enqueueAction(this, (channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, (channel, _state) => {
366
+ send(channel, {
367
+ jsonrpc: '2.0',
368
+ method: 'channels.leave',
369
+ params: {}
370
+ });
371
+ return {
372
+ handler: handlers.awaitingLeave,
373
+ state: {
374
+ resolve,
375
+ reject
376
+ }
377
+ };
378
+ });
379
+ });
380
+ }
381
+ /**
382
+ * Trigger mutual close
383
+ *
384
+ * At any moment after the channel is opened, a closing procedure can be triggered.
385
+ * This can be done by either of the parties. The process is similar to the off-chain updates.
386
+ *
387
+ * @param sign - Function which verifies and signs mutual close transaction
388
+ * @example
389
+ * ```js
390
+ * channel.shutdown(
391
+ * async (tx) => await account.signTransaction(tx)
392
+ * ).then(tx => console.log('on_chain_tx', tx))
393
+ * ```
394
+ */
395
+
396
+
397
+ async shutdown(sign) {
398
+ return await new Promise((resolve, reject) => {
399
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
400
+ send(channel, {
401
+ jsonrpc: '2.0',
402
+ method: 'channels.shutdown',
403
+ params: {}
404
+ });
405
+ return {
406
+ handler: handlers.awaitingShutdownTx,
407
+ state: {
408
+ sign,
409
+ resolve,
410
+ reject
411
+ }
412
+ };
413
+ });
414
+ });
415
+ }
416
+ /**
417
+ * Withdraw coins from the channel
418
+ *
419
+ * After the channel had been opened any of the participants can initiate a withdrawal.
420
+ * The process closely resembles the update. The most notable difference is that the
421
+ * transaction has been co-signed: it is channel_withdraw_tx and after the procedure
422
+ * is finished - it is being posted on-chain.
423
+ *
424
+ * Any of the participants can initiate a withdrawal. The only requirements are:
425
+ *
426
+ * - Channel is already opened
427
+ * - No off-chain update/deposit/withdrawal is currently being performed
428
+ * - Channel is not being closed or in a solo closing state
429
+ * - The withdrawal amount must be equal to or greater than zero, and cannot exceed
430
+ * the available balance on the channel (minus the channel_reserve)
431
+ *
432
+ * After the other party had signed the withdraw transaction, the transaction is posted
433
+ * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.
434
+ * After computing transaction hash it can be tracked on the chain: entering the mempool,
435
+ * block inclusion and a number of confirmations.
436
+ *
437
+ * After the minimum_depth block confirmations onOwnWithdrawLocked callback is called
438
+ * (without any arguments).
439
+ *
440
+ * When the other party had confirmed that the block height needed is reached
441
+ * onWithdrawLocked callback is called (without any arguments).
442
+ *
443
+ * @param amount - Amount of coins to withdraw
444
+ * @param sign - Function which verifies and signs withdraw transaction
445
+ * @param callbacks - Callbacks
446
+ * @param callbacks.onOnChainTx - Called when withdraw transaction has been posted
447
+ * on chain
448
+ * @param callbacks.onOwnWithdrawLocked
449
+ * @param callbacks.onWithdrawLocked
450
+ * @example
451
+ * ```js
452
+ * channel.withdraw(
453
+ * 100,
454
+ * async (tx) => await account.signTransaction(tx),
455
+ * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }
456
+ * ).then(({ accepted, signedTx }) => {
457
+ * if (accepted) {
458
+ * console.log('Withdrawal has been accepted')
459
+ * } else {
460
+ * console.log('Withdrawal has been rejected')
461
+ * }
462
+ * })
463
+ * ```
464
+ */
465
+
466
+
467
+ async withdraw(amount, sign) {
468
+ let {
469
+ onOnChainTx,
470
+ onOwnWithdrawLocked,
471
+ onWithdrawLocked
472
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
473
+ return await new Promise((resolve, reject) => {
474
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
475
+ send(channel, {
476
+ jsonrpc: '2.0',
477
+ method: 'channels.withdraw',
478
+ params: {
479
+ amount
480
+ }
481
+ });
482
+ return {
483
+ handler: handlers.awaitingWithdrawTx,
484
+ state: {
485
+ sign,
486
+ resolve,
487
+ reject,
488
+ onOnChainTx,
489
+ onOwnWithdrawLocked,
490
+ onWithdrawLocked
491
+ }
492
+ };
493
+ });
494
+ });
495
+ }
496
+ /**
497
+ * Deposit coins into the channel
498
+ *
499
+ * After the channel had been opened any of the participants can initiate a deposit.
500
+ * The process closely resembles the update. The most notable difference is that the
501
+ * transaction has been co-signed: it is channel_deposit_tx and after the procedure
502
+ * is finished - it is being posted on-chain.
503
+ *
504
+ * Any of the participants can initiate a deposit. The only requirements are:
505
+ *
506
+ * - Channel is already opened
507
+ * - No off-chain update/deposit/withdrawal is currently being performed
508
+ * - Channel is not being closed or in a solo closing state
509
+ * - The deposit amount must be equal to or greater than zero, and cannot exceed
510
+ * the available balance on the channel (minus the channel_reserve)
511
+ *
512
+ * After the other party had signed the deposit transaction, the transaction is posted
513
+ * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.
514
+ * After computing transaction hash it can be tracked on the chain: entering the mempool,
515
+ * block inclusion and a number of confirmations.
516
+ *
517
+ * After the minimum_depth block confirmations onOwnDepositLocked callback is called
518
+ * (without any arguments).
519
+ *
520
+ * When the other party had confirmed that the block height needed is reached
521
+ * onDepositLocked callback is called (without any arguments).
522
+ *
523
+ * @param amount - Amount of coins to deposit
524
+ * @param sign - Function which verifies and signs deposit transaction
525
+ * @param callbacks - Callbacks
526
+ * @param callbacks.onOnChainTx - Called when deposit transaction has been posted
527
+ * on chain
528
+ * @param callbacks.onOwnDepositLocked
529
+ * @param callbacks.onDepositLocked
530
+ * @example
531
+ * ```js
532
+ * channel.deposit(
533
+ * 100,
534
+ * async (tx) => await account.signTransaction(tx),
535
+ * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }
536
+ * ).then(({ accepted, state }) => {
537
+ * if (accepted) {
538
+ * console.log('Deposit has been accepted')
539
+ * console.log('The new state is:', state)
540
+ * } else {
541
+ * console.log('Deposit has been rejected')
542
+ * }
543
+ * })
544
+ * ```
545
+ */
546
+
547
+
548
+ async deposit(amount, sign) {
549
+ let {
550
+ onOnChainTx,
551
+ onOwnDepositLocked,
552
+ onDepositLocked
553
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
554
+ return await new Promise((resolve, reject) => {
555
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
556
+ send(channel, {
557
+ jsonrpc: '2.0',
558
+ method: 'channels.deposit',
559
+ params: {
560
+ amount
561
+ }
562
+ });
563
+ return {
564
+ handler: handlers.awaitingDepositTx,
565
+ state: {
566
+ sign,
567
+ resolve,
568
+ reject,
569
+ onOnChainTx,
570
+ onOwnDepositLocked,
571
+ onDepositLocked
572
+ }
573
+ };
574
+ });
575
+ });
576
+ }
577
+ /**
578
+ * Trigger create contract update
579
+ *
580
+ * The create contract update is creating a contract inside the channel's internal state tree.
581
+ * The update is a change to be applied on top of the latest state.
582
+ *
583
+ * That would create a contract with the poster being the owner of it. Poster commits initially
584
+ * a deposit amount of coins to the new contract.
585
+ *
586
+ * @param options - Options
587
+ * @param options.code - Api encoded compiled AEVM byte code
588
+ * @param options.callData - Api encoded compiled AEVM call data for the code
589
+ * @param options.deposit - Initial amount the owner of the contract commits to it
590
+ * @param options.vmVersion - Version of the Virtual Machine
591
+ * @param options.abiVersion - Version of the Application Binary Interface
592
+ * @param sign - Function which verifies and signs create contract transaction
593
+ * @example
594
+ * ```js
595
+ * channel.createContract({
596
+ * code: 'cb_HKtpipK4aCgYb17wZ...',
597
+ * callData: 'cb_1111111111111111...',
598
+ * deposit: 10,
599
+ * vmVersion: 3,
600
+ * abiVersion: 1
601
+ * }).then(({ accepted, signedTx, address }) => {
602
+ * if (accepted) {
603
+ * console.log('New contract has been created')
604
+ * console.log('Contract address:', address)
605
+ * } else {
606
+ * console.log('New contract has been rejected')
607
+ * }
608
+ * })
609
+ * ```
610
+ */
611
+
612
+
613
+ async createContract(_ref3, sign) {
614
+ let {
615
+ code,
616
+ callData,
617
+ deposit,
618
+ vmVersion,
619
+ abiVersion
620
+ } = _ref3;
621
+ return await new Promise((resolve, reject) => {
622
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
623
+ send(channel, {
624
+ jsonrpc: '2.0',
625
+ method: 'channels.update.new_contract',
626
+ params: {
627
+ code,
628
+ call_data: callData,
629
+ deposit,
630
+ vm_version: vmVersion,
631
+ abi_version: abiVersion
632
+ }
633
+ });
634
+ return {
635
+ handler: handlers.awaitingNewContractTx,
636
+ state: {
637
+ sign,
638
+ resolve,
639
+ reject
640
+ }
641
+ };
642
+ });
643
+ });
644
+ }
645
+ /**
646
+ * Trigger call a contract update
647
+ *
648
+ * The call contract update is calling a preexisting contract inside the channel's
649
+ * internal state tree. The update is a change to be applied on top of the latest state.
650
+ *
651
+ * That would call a contract with the poster being the caller of it. Poster commits
652
+ * an amount of coins to the contract.
653
+ *
654
+ * The call would also create a call object inside the channel state tree. It contains
655
+ * the result of the contract call.
656
+ *
657
+ * It is worth mentioning that the gas is not consumed, because this is an off-chain
658
+ * contract call. It would be consumed if it were an on-chain one. This could happen
659
+ * if a call with a similar computation amount is to be forced on-chain.
660
+ *
661
+ * @param options - Options
662
+ * @param options.amount - Amount the caller of the contract commits to it
663
+ * @param options.callData - ABI encoded compiled AEVM call data for the code
664
+ * @param options.contract - Address of the contract to call
665
+ * @param options.abiVersion - Version of the ABI
666
+ * @param sign - Function which verifies and signs contract call transaction
667
+ * @example
668
+ * ```js
669
+ * channel.callContract({
670
+ * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
671
+ * callData: 'cb_1111111111111111...',
672
+ * amount: 0,
673
+ * abiVersion: 1
674
+ * }).then(({ accepted, signedTx }) => {
675
+ * if (accepted) {
676
+ * console.log('Contract called succesfully')
677
+ * } else {
678
+ * console.log('Contract call has been rejected')
679
+ * }
680
+ * })
681
+ * ```
682
+ */
683
+
684
+
685
+ async callContract(_ref4, sign) {
686
+ let {
687
+ amount,
688
+ callData,
689
+ contract,
690
+ abiVersion
691
+ } = _ref4;
692
+ return await new Promise((resolve, reject) => {
693
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
694
+ send(channel, {
695
+ jsonrpc: '2.0',
696
+ method: 'channels.update.call_contract',
697
+ params: {
698
+ amount,
699
+ call_data: callData,
700
+ contract_id: contract,
701
+ abi_version: abiVersion
702
+ }
703
+ });
704
+ return {
705
+ handler: handlers.awaitingCallContractUpdateTx,
706
+ state: {
707
+ resolve,
708
+ reject,
709
+ sign
710
+ }
711
+ };
712
+ });
713
+ });
714
+ }
715
+ /**
716
+ * Trigger a force progress contract call
717
+ * This call is going on-chain
718
+ * @param options - Options
719
+ * @param options.amount - Amount the caller of the contract commits to it
720
+ * @param options.callData - ABI encoded compiled AEVM call data for the code
721
+ * @param options.contract - Address of the contract to call
722
+ * @param options.abiVersion - Version of the ABI
723
+ * @param options.gasPrice=1000000000]
724
+ * @param options.gasLimit=1000000]
725
+ * @param sign - Function which verifies and signs contract force progress transaction
726
+ * @param callbacks - Callbacks
727
+ * @example
728
+ * ```js
729
+ * channel.forceProgress({
730
+ * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
731
+ * callData: 'cb_1111111111111111...',
732
+ * amount: 0,
733
+ * abiVersion: 1,
734
+ * gasPrice: 1000005554
735
+ * }).then(({ accepted, signedTx }) => {
736
+ * if (accepted) {
737
+ * console.log('Contract force progress call successful')
738
+ * } else {
739
+ * console.log('Contract force progress call has been rejected')
740
+ * }
741
+ * })
742
+ * ```
743
+ */
744
+
745
+
746
+ async forceProgress(_ref5, sign) {
747
+ let {
748
+ amount,
749
+ callData,
750
+ contract,
751
+ abiVersion,
752
+ gasLimit = 1000000,
753
+ gasPrice = 1000000000
754
+ } = _ref5;
755
+ let {
756
+ onOnChainTx
757
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
758
+ return await new Promise((resolve, reject) => {
759
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
760
+ send(channel, {
761
+ jsonrpc: '2.0',
762
+ method: 'channels.force_progress',
763
+ params: {
764
+ amount,
765
+ call_data: callData,
766
+ contract_id: contract,
767
+ abi_version: abiVersion,
768
+ gas_price: gasPrice,
769
+ gas: gasLimit
770
+ }
771
+ });
772
+ return {
773
+ handler: handlers.awaitingCallContractForceProgressUpdate,
774
+ state: {
775
+ resolve,
776
+ reject,
777
+ sign,
778
+ onOnChainTx
779
+ }
780
+ };
781
+ });
782
+ });
783
+ }
784
+ /**
785
+ * Call contract using dry-run
786
+ *
787
+ * In order to get the result of a potential contract call, one might need to
788
+ * dry-run a contract call. It takes the exact same arguments as a call would
789
+ * and returns the call object.
790
+ *
791
+ * The call is executed in the channel's state but it does not impact the state
792
+ * whatsoever. It uses as an environment the latest channel's state and the current
793
+ * top of the blockchain as seen by the node.
794
+ *
795
+ * @param options - Options
796
+ * @param options.amount - Amount the caller of the contract commits to it
797
+ * @param options.callData - ABI encoded compiled AEVM call data for the code
798
+ * @param options.contract - Address of the contract to call
799
+ * @param options.abiVersion - Version of the ABI
800
+ * @example
801
+ * ```js
802
+ * channel.callContractStatic({
803
+ * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
804
+ * callData: 'cb_1111111111111111...',
805
+ * amount: 0,
806
+ * abiVersion: 1
807
+ * }).then(({ returnValue, gasUsed }) => {
808
+ * console.log('Returned value:', returnValue)
809
+ * console.log('Gas used:', gasUsed)
810
+ * })
811
+ * ```
812
+ */
813
+
814
+
815
+ async callContractStatic(_ref6) {
816
+ let {
817
+ amount,
818
+ callData,
819
+ contract,
820
+ abiVersion
821
+ } = _ref6;
822
+ return await snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
823
+ amount,
824
+ call_data: callData,
825
+ contract_id: contract,
826
+ abi_version: abiVersion
827
+ }));
828
+ }
829
+ /**
830
+ * Get contract call result
831
+ *
832
+ * The combination of a caller, contract and a round of execution determines the
833
+ * contract call. Providing an incorrect set of those results in an error response.
834
+ *
835
+ * @param options - Options
836
+ * @param options.caller - Address of contract caller
837
+ * @param options.contract - Address of the contract
838
+ * @param options.round - Round when contract was called
839
+ * @example
840
+ * ```js
841
+ * channel.getContractCall({
842
+ * caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
843
+ * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
844
+ * round: 3
845
+ * }).then(({ returnType, returnValue }) => {
846
+ * if (returnType === 'ok') console.log(returnValue)
847
+ * })
848
+ * ```
849
+ */
850
+
851
+
852
+ async getContractCall(_ref7) {
853
+ let {
854
+ caller,
855
+ contract,
856
+ round
857
+ } = _ref7;
858
+ return await snakeToPascalObjKeys(await call(this, 'channels.get.contract_call', {
859
+ caller_id: caller,
860
+ contract_id: contract,
861
+ round
862
+ }));
863
+ }
864
+ /**
865
+ * Get contract latest state
866
+ *
867
+ * @param contract - Address of the contract
868
+ * @example
869
+ * ```js
870
+ * channel.getContractState(
871
+ * 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'
872
+ * ).then(({ contract }) => {
873
+ * console.log('deposit:', contract.deposit)
874
+ * })
875
+ * ```
876
+ */
877
+
878
+
879
+ async getContractState(contract) {
880
+ const result = await call(this, 'channels.get.contract', {
881
+ pubkey: contract
882
+ });
883
+ return await snakeToPascalObjKeys({ ...result,
884
+ contract: snakeToPascalObjKeys(result.contract)
885
+ });
886
+ }
887
+ /**
888
+ * Clean up all locally stored contract calls
889
+ *
890
+ * Contract calls are kept locally in order for the participant to be able to look them up.
891
+ * They consume memory and in order for the participant to free it - one can prune all messages.
892
+ * This cleans up all locally stored contract calls and those will no longer be available for
893
+ * fetching and inspection.
894
+ */
895
+
896
+
897
+ async cleanContractCalls() {
898
+ return await new Promise((resolve, reject) => {
899
+ enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
900
+ send(channel, {
901
+ jsonrpc: '2.0',
902
+ method: 'channels.clean_contract_calls',
903
+ params: {}
904
+ });
905
+ return {
906
+ handler: handlers.awaitingCallsPruned,
907
+ state: {
908
+ resolve,
909
+ reject
910
+ }
911
+ };
912
+ });
913
+ });
914
+ }
915
+ /**
916
+ * Send generic message
917
+ *
918
+ * If message is an object it will be serialized into JSON string
919
+ * before sending.
920
+ *
921
+ * If there is ongoing update that has not yet been finished the message
922
+ * will be sent after that update is finalized.
923
+ *
924
+ * @param message - Message
925
+ * @param recipient - Address of the recipient
926
+ * @example
927
+ * ```js
928
+ * channel.sendMessage(
929
+ * 'hello world',
930
+ * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'
931
+ * )
932
+ * ```
933
+ */
934
+
935
+
936
+ sendMessage(message, recipient) {
937
+ let info = message;
938
+
939
+ if (typeof message === 'object') {
940
+ info = JSON.stringify(message);
941
+ }
942
+
943
+ const doSend = channel => send(channel, {
944
+ jsonrpc: '2.0',
945
+ method: 'channels.message',
946
+ params: {
947
+ info,
948
+ to: recipient
949
+ }
950
+ });
951
+
952
+ if (this.status() === 'connecting') {
953
+ const onStatusChanged = status => {
954
+ if (status !== 'connecting') {
955
+ // For some reason we can't immediately send a message when connection is
956
+ // established. Thus we wait 500ms which seems to work.
957
+ setTimeout(() => doSend(this), 500);
958
+ this.off('statusChanged', onStatusChanged);
959
+ }
960
+ };
961
+
962
+ this.on('statusChanged', onStatusChanged);
963
+ } else {
964
+ doSend(this);
965
+ }
966
+ }
967
+
968
+ static async reconnect(options, txParams) {
969
+ const {
970
+ sign
971
+ } = options;
972
+ return await Channel.initialize({ ...options,
973
+ reconnectTx: await sign('reconnect', buildTx(txParams, TX_TYPE.channelReconnect).tx)
974
+ });
975
+ }
976
+
977
+ }
978
+ //# sourceMappingURL=index.mjs.map