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