@aeternity/aepp-sdk 11.0.1 → 12.1.1

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