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