@aeternity/aepp-sdk 13.2.1 → 13.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (509) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/bin/aesophia_cli +0 -0
  4. package/bin/aesophia_cli_8 +0 -0
  5. package/dist/aepp-sdk.browser-script.js +1 -1
  6. package/dist/aepp-sdk.browser-script.js.map +1 -1
  7. package/dist/aepp-sdk.browser.js +1 -1
  8. package/dist/aepp-sdk.browser.js.map +1 -1
  9. package/dist/aepp-sdk.js +7288 -9464
  10. package/dist/aepp-sdk.js.map +1 -1
  11. package/es/AeSdk.d.ts +3 -0
  12. package/es/AeSdk.mjs +12 -12
  13. package/es/AeSdk.mjs.map +1 -1
  14. package/es/AeSdkAepp.d.ts +0 -1
  15. package/es/AeSdkAepp.mjs +12 -16
  16. package/es/AeSdkAepp.mjs.map +1 -1
  17. package/es/AeSdkBase.d.ts +61 -6
  18. package/es/AeSdkBase.mjs +150 -69
  19. package/es/AeSdkBase.mjs.map +1 -1
  20. package/es/AeSdkMethods.d.ts +19 -7
  21. package/es/AeSdkMethods.mjs +39 -38
  22. package/es/AeSdkMethods.mjs.map +1 -1
  23. package/es/AeSdkWallet.mjs +86 -55
  24. package/es/AeSdkWallet.mjs.map +1 -1
  25. package/es/Middleware.d.ts +1 -1
  26. package/es/Middleware.mjs +32 -28
  27. package/es/Middleware.mjs.map +1 -1
  28. package/es/MiddlewareSubscriber.mjs +5 -14
  29. package/es/MiddlewareSubscriber.mjs.map +1 -1
  30. package/es/Node.d.ts +11 -3
  31. package/es/Node.mjs +65 -57
  32. package/es/Node.mjs.map +1 -1
  33. package/es/account/Base.d.ts +39 -3
  34. package/es/account/Base.mjs +35 -1
  35. package/es/account/Base.mjs.map +1 -1
  36. package/es/account/Generalized.d.ts +2 -0
  37. package/es/account/Generalized.mjs +15 -6
  38. package/es/account/Generalized.mjs.map +1 -1
  39. package/es/account/Ledger.d.ts +2 -0
  40. package/es/account/Ledger.mjs +14 -5
  41. package/es/account/Ledger.mjs.map +1 -1
  42. package/es/account/LedgerFactory.mjs +4 -6
  43. package/es/account/LedgerFactory.mjs.map +1 -1
  44. package/es/account/Memory.d.ts +15 -4
  45. package/es/account/Memory.mjs +96 -31
  46. package/es/account/Memory.mjs.map +1 -1
  47. package/es/account/Rpc.d.ts +16 -5
  48. package/es/account/Rpc.mjs +94 -21
  49. package/es/account/Rpc.mjs.map +1 -1
  50. package/es/aens.d.ts +17 -44
  51. package/es/aens.mjs +32 -71
  52. package/es/aens.mjs.map +1 -1
  53. package/es/aepp-wallet-communication/connection/Browser.mjs +3 -4
  54. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  55. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  56. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +7 -5
  57. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  58. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +8 -9
  59. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  60. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +7 -7
  61. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  62. package/es/aepp-wallet-communication/rpc/types.d.ts +14 -0
  63. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  64. package/es/aepp-wallet-communication/schema.d.ts +2 -0
  65. package/es/aepp-wallet-communication/schema.mjs +2 -0
  66. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  67. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  68. package/es/aepp-wallet-communication/wallet-detector.mjs +13 -9
  69. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  70. package/es/apis/compiler/compiler.mjs.map +1 -1
  71. package/es/apis/compiler/models/index.d.ts +1 -0
  72. package/es/apis/compiler/models/index.mjs.map +1 -1
  73. package/es/apis/compiler/models/mappers.mjs +13 -0
  74. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -1
  76. package/es/apis/middleware/middleware.d.ts +23 -5
  77. package/es/apis/middleware/middleware.mjs +114 -18
  78. package/es/apis/middleware/middleware.mjs.map +1 -1
  79. package/es/apis/middleware/models/index.d.ts +164 -15
  80. package/es/apis/middleware/models/index.mjs +53 -3
  81. package/es/apis/middleware/models/index.mjs.map +1 -1
  82. package/es/apis/middleware/models/mappers.d.ts +8 -1
  83. package/es/apis/middleware/models/mappers.mjs +376 -3
  84. package/es/apis/middleware/models/mappers.mjs.map +1 -1
  85. package/es/apis/middleware/models/parameters.d.ts +6 -3
  86. package/es/apis/middleware/models/parameters.mjs +38 -11
  87. package/es/apis/middleware/models/parameters.mjs.map +1 -1
  88. package/es/apis/node/models/index.d.ts +66 -2
  89. package/es/apis/node/models/index.mjs.map +1 -1
  90. package/es/apis/node/models/mappers.d.ts +5 -1
  91. package/es/apis/node/models/mappers.mjs +229 -7
  92. package/es/apis/node/models/mappers.mjs.map +1 -1
  93. package/es/apis/node/models/parameters.d.ts +2 -2
  94. package/es/apis/node/models/parameters.mjs +2 -2
  95. package/es/apis/node/models/parameters.mjs.map +1 -1
  96. package/es/apis/node/node.d.ts +24 -3
  97. package/es/apis/node/node.mjs +135 -3
  98. package/es/apis/node/node.mjs.map +1 -1
  99. package/es/chain.d.ts +14 -44
  100. package/es/chain.mjs +125 -219
  101. package/es/chain.mjs.map +1 -1
  102. package/es/channel/Base.d.ts +3 -47
  103. package/es/channel/Base.mjs +21 -54
  104. package/es/channel/Base.mjs.map +1 -1
  105. package/es/channel/Contract.d.ts +16 -25
  106. package/es/channel/Contract.mjs +39 -63
  107. package/es/channel/Contract.mjs.map +1 -1
  108. package/es/channel/Spend.d.ts +0 -8
  109. package/es/channel/Spend.mjs +17 -29
  110. package/es/channel/Spend.mjs.map +1 -1
  111. package/es/channel/handlers.mjs +1 -1
  112. package/es/channel/handlers.mjs.map +1 -1
  113. package/es/channel/internal.d.ts +104 -5
  114. package/es/channel/internal.mjs +26 -34
  115. package/es/channel/internal.mjs.map +1 -1
  116. package/es/contract/Contract.d.ts +10 -2
  117. package/es/contract/Contract.mjs +83 -79
  118. package/es/contract/Contract.mjs.map +1 -1
  119. package/es/contract/compiler/Base.d.ts +14 -8
  120. package/es/contract/compiler/Base.mjs.map +1 -1
  121. package/es/contract/compiler/Cli.d.ts +12 -11
  122. package/es/contract/compiler/Cli.mjs +52 -25
  123. package/es/contract/compiler/Cli.mjs.map +1 -1
  124. package/es/contract/compiler/Cli8.d.ts +13 -0
  125. package/es/contract/compiler/Cli8.mjs +22 -0
  126. package/es/contract/compiler/Cli8.mjs.map +1 -0
  127. package/es/contract/compiler/Http.d.ts +3 -9
  128. package/es/contract/compiler/Http.mjs +28 -16
  129. package/es/contract/compiler/Http.mjs.map +1 -1
  130. package/es/contract/compiler/HttpNode.d.ts +2 -5
  131. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  132. package/es/contract/delegation-signature.d.ts +2 -1
  133. package/es/contract/delegation-signature.mjs +18 -14
  134. package/es/contract/delegation-signature.mjs.map +1 -1
  135. package/es/contract/ga.d.ts +1 -2
  136. package/es/contract/ga.mjs +23 -25
  137. package/es/contract/ga.mjs.map +1 -1
  138. package/es/deprecated.d.ts +48 -0
  139. package/es/deprecated.mjs +66 -1
  140. package/es/deprecated.mjs.map +1 -1
  141. package/es/index-browser.d.ts +11 -6
  142. package/es/index-browser.mjs +10 -6
  143. package/es/index-browser.mjs.map +1 -1
  144. package/es/index.d.ts +1 -0
  145. package/es/index.mjs +1 -0
  146. package/es/index.mjs.map +1 -1
  147. package/es/oracle.d.ts +6 -37
  148. package/es/oracle.mjs +32 -66
  149. package/es/oracle.mjs.map +1 -1
  150. package/es/send-transaction.d.ts +53 -0
  151. package/es/send-transaction.mjs +109 -0
  152. package/es/send-transaction.mjs.map +1 -0
  153. package/es/spend.d.ts +4 -3
  154. package/es/spend.mjs +6 -1
  155. package/es/spend.mjs.map +1 -1
  156. package/es/tx/builder/common.d.ts +29 -0
  157. package/es/tx/builder/common.mjs +42 -0
  158. package/es/tx/builder/common.mjs.map +1 -0
  159. package/es/tx/builder/constants.d.ts +6 -5
  160. package/es/tx/builder/constants.mjs +7 -15
  161. package/es/tx/builder/constants.mjs.map +1 -1
  162. package/es/tx/builder/delegation/index.d.ts +20 -0
  163. package/es/tx/builder/delegation/index.mjs +24 -0
  164. package/es/tx/builder/delegation/index.mjs.map +1 -0
  165. package/es/tx/builder/delegation/schema.d.ts +130 -0
  166. package/es/tx/builder/delegation/schema.generated.d.ts +141 -0
  167. package/es/tx/builder/delegation/schema.generated.mjs +2 -0
  168. package/es/tx/builder/delegation/schema.generated.mjs.map +1 -0
  169. package/es/tx/builder/delegation/schema.mjs +54 -0
  170. package/es/tx/builder/delegation/schema.mjs.map +1 -0
  171. package/es/tx/builder/field-types/abi-version.mjs +8 -11
  172. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  173. package/es/tx/builder/field-types/address.mjs +1 -4
  174. package/es/tx/builder/field-types/address.mjs.map +1 -1
  175. package/es/tx/builder/field-types/coin-amount.d.ts +2 -2
  176. package/es/tx/builder/field-types/coin-amount.mjs +6 -6
  177. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  178. package/es/tx/builder/field-types/ct-version.d.ts +1 -1
  179. package/es/tx/builder/field-types/ct-version.mjs +4 -5
  180. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  181. package/es/tx/builder/field-types/entry.mjs +7 -13
  182. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  183. package/es/tx/builder/field-types/fee.d.ts +19 -11
  184. package/es/tx/builder/field-types/fee.mjs +57 -39
  185. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  186. package/es/tx/builder/field-types/gas-limit.mjs +13 -15
  187. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  188. package/es/tx/builder/field-types/gas-price.d.ts +10 -2
  189. package/es/tx/builder/field-types/gas-price.mjs +53 -4
  190. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  191. package/es/tx/builder/field-types/index.d.ts +31 -29
  192. package/es/tx/builder/field-types/index.mjs +31 -29
  193. package/es/tx/builder/field-types/index.mjs.map +1 -1
  194. package/es/tx/builder/field-types/map.mjs +20 -31
  195. package/es/tx/builder/field-types/map.mjs.map +1 -1
  196. package/es/tx/builder/field-types/mptree.mjs +14 -29
  197. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  198. package/es/tx/builder/field-types/name-fee.d.ts +1 -1
  199. package/es/tx/builder/field-types/name-fee.mjs +1 -1
  200. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  201. package/es/tx/builder/field-types/nonce.d.ts +1 -0
  202. package/es/tx/builder/field-types/nonce.mjs +2 -0
  203. package/es/tx/builder/field-types/nonce.mjs.map +1 -1
  204. package/es/tx/builder/field-types/pointers.mjs +4 -7
  205. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  206. package/es/tx/builder/field-types/pointers2.d.ts +23 -0
  207. package/es/tx/builder/field-types/pointers2.mjs +65 -0
  208. package/es/tx/builder/field-types/pointers2.mjs.map +1 -0
  209. package/es/tx/builder/field-types/query-fee.d.ts +19 -0
  210. package/es/tx/builder/field-types/query-fee.mjs +20 -0
  211. package/es/tx/builder/field-types/query-fee.mjs.map +1 -0
  212. package/es/tx/builder/field-types/ttl.d.ts +9 -1
  213. package/es/tx/builder/field-types/ttl.mjs +19 -8
  214. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  215. package/es/tx/builder/field-types/with-default.d.ts +7 -0
  216. package/es/tx/builder/field-types/with-default.mjs +9 -0
  217. package/es/tx/builder/field-types/with-default.mjs.map +1 -0
  218. package/es/tx/builder/field-types/with-formatting.d.ts +7 -0
  219. package/es/tx/builder/field-types/with-formatting.mjs +9 -0
  220. package/es/tx/builder/field-types/with-formatting.mjs.map +1 -0
  221. package/es/tx/builder/field-types/wrapped.mjs +6 -8
  222. package/es/tx/builder/field-types/wrapped.mjs.map +1 -1
  223. package/es/tx/builder/helpers.d.ts +2 -2
  224. package/es/tx/builder/helpers.mjs +12 -21
  225. package/es/tx/builder/helpers.mjs.map +1 -1
  226. package/es/tx/builder/index.d.ts +17 -10
  227. package/es/tx/builder/index.mjs +39 -65
  228. package/es/tx/builder/index.mjs.map +1 -1
  229. package/es/tx/builder/schema.d.ts +478 -257
  230. package/es/tx/builder/schema.generated.d.ts +39 -3
  231. package/es/tx/builder/schema.generated.mjs.map +1 -1
  232. package/es/tx/builder/schema.mjs +48 -36
  233. package/es/tx/builder/schema.mjs.map +1 -1
  234. package/es/tx/execution-cost.d.ts +6 -5
  235. package/es/tx/execution-cost.mjs +16 -17
  236. package/es/tx/execution-cost.mjs.map +1 -1
  237. package/es/tx/transaction-signer.mjs +1 -4
  238. package/es/tx/transaction-signer.mjs.map +1 -1
  239. package/es/tx/validator.mjs +61 -42
  240. package/es/tx/validator.mjs.map +1 -1
  241. package/es/utils/amount-formatter.mjs +15 -22
  242. package/es/utils/amount-formatter.mjs.map +1 -1
  243. package/es/utils/autorest.d.ts +2 -3
  244. package/es/utils/autorest.mjs +41 -25
  245. package/es/utils/autorest.mjs.map +1 -1
  246. package/es/utils/bytes.mjs +1 -2
  247. package/es/utils/bytes.mjs.map +1 -1
  248. package/es/utils/crypto.d.ts +9 -5
  249. package/es/utils/crypto.mjs +18 -14
  250. package/es/utils/crypto.mjs.map +1 -1
  251. package/es/utils/errors.d.ts +6 -0
  252. package/es/utils/errors.mjs +12 -6
  253. package/es/utils/errors.mjs.map +1 -1
  254. package/es/utils/hd-wallet.d.ts +2 -0
  255. package/es/utils/hd-wallet.mjs +6 -5
  256. package/es/utils/hd-wallet.mjs.map +1 -1
  257. package/es/utils/json-big.mjs +2 -10
  258. package/es/utils/json-big.mjs.map +1 -1
  259. package/es/utils/jwt.d.ts +53 -0
  260. package/es/utils/jwt.mjs +120 -0
  261. package/es/utils/jwt.mjs.map +1 -0
  262. package/es/utils/keystore.d.ts +6 -2
  263. package/es/utils/keystore.mjs +8 -16
  264. package/es/utils/keystore.mjs.map +1 -1
  265. package/es/utils/typed-data.d.ts +0 -2
  266. package/es/utils/typed-data.mjs +8 -23
  267. package/es/utils/typed-data.mjs.map +1 -1
  268. package/es/utils/wrap-proxy.d.ts +2 -0
  269. package/es/utils/wrap-proxy.mjs +15 -0
  270. package/es/utils/wrap-proxy.mjs.map +1 -0
  271. package/package.json +57 -51
  272. package/src/AeSdk.ts +3 -0
  273. package/src/AeSdkAepp.ts +0 -1
  274. package/src/AeSdkBase.ts +97 -10
  275. package/src/AeSdkMethods.ts +37 -33
  276. package/src/AeSdkWallet.ts +22 -3
  277. package/src/Middleware.ts +17 -9
  278. package/src/MiddlewareSubscriber.ts +1 -1
  279. package/src/Node.ts +51 -21
  280. package/src/account/Base.ts +62 -3
  281. package/src/account/Generalized.ts +10 -0
  282. package/src/account/Ledger.ts +10 -0
  283. package/src/account/Memory.ts +83 -9
  284. package/src/account/Rpc.ts +69 -6
  285. package/src/aens.ts +35 -56
  286. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +3 -0
  287. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +2 -2
  288. package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -2
  289. package/src/aepp-wallet-communication/rpc/types.ts +14 -1
  290. package/src/aepp-wallet-communication/schema.ts +2 -0
  291. package/src/aepp-wallet-communication/wallet-detector.ts +10 -10
  292. package/src/apis/compiler/compiler.ts +93 -93
  293. package/src/apis/compiler/models/index.ts +1 -0
  294. package/src/apis/compiler/models/mappers.ts +178 -165
  295. package/src/apis/compiler/models/parameters.ts +18 -18
  296. package/src/apis/middleware/middleware.ts +462 -341
  297. package/src/apis/middleware/models/index.ts +258 -56
  298. package/src/apis/middleware/models/mappers.ts +2357 -1919
  299. package/src/apis/middleware/models/parameters.ts +172 -142
  300. package/src/apis/node/models/index.ts +79 -2
  301. package/src/apis/node/models/mappers.ts +1529 -1302
  302. package/src/apis/node/models/parameters.ts +51 -51
  303. package/src/apis/node/node.ts +420 -275
  304. package/src/chain.ts +42 -128
  305. package/src/channel/Base.ts +14 -47
  306. package/src/channel/Contract.ts +18 -26
  307. package/src/channel/Spend.ts +0 -8
  308. package/src/channel/internal.ts +115 -13
  309. package/src/contract/Contract.ts +36 -12
  310. package/src/contract/compiler/Base.ts +15 -8
  311. package/src/contract/compiler/Cli.ts +44 -23
  312. package/src/contract/compiler/Cli8.ts +17 -0
  313. package/src/contract/compiler/Http.ts +24 -14
  314. package/src/contract/compiler/HttpNode.ts +2 -2
  315. package/src/contract/delegation-signature.ts +11 -5
  316. package/src/contract/ga.ts +4 -3
  317. package/src/deprecated.ts +55 -1
  318. package/src/index-browser.ts +18 -11
  319. package/src/index.ts +1 -0
  320. package/src/oracle.ts +11 -54
  321. package/src/send-transaction.ts +136 -0
  322. package/src/spend.ts +25 -11
  323. package/src/tx/builder/common.ts +74 -0
  324. package/src/tx/builder/constants.ts +7 -9
  325. package/src/tx/builder/delegation/index.ts +28 -0
  326. package/src/tx/builder/delegation/schema.generated.ts +143 -0
  327. package/src/tx/builder/delegation/schema.ts +61 -0
  328. package/src/tx/builder/field-types/coin-amount.ts +3 -2
  329. package/src/tx/builder/field-types/ct-version.ts +1 -1
  330. package/src/tx/builder/field-types/entry.ts +1 -4
  331. package/src/tx/builder/field-types/fee.ts +72 -44
  332. package/src/tx/builder/field-types/gas-limit.ts +4 -4
  333. package/src/tx/builder/field-types/gas-price.ts +59 -3
  334. package/src/tx/builder/field-types/index.ts +31 -59
  335. package/src/tx/builder/field-types/name-fee.ts +1 -1
  336. package/src/tx/builder/field-types/nonce.ts +7 -1
  337. package/src/tx/builder/field-types/pointers2.ts +62 -0
  338. package/src/tx/builder/field-types/query-fee.ts +25 -0
  339. package/src/tx/builder/field-types/ttl.ts +13 -3
  340. package/src/tx/builder/field-types/with-default.ts +18 -0
  341. package/src/tx/builder/field-types/with-formatting.ts +18 -0
  342. package/src/tx/builder/helpers.ts +2 -2
  343. package/src/tx/builder/index.ts +42 -59
  344. package/src/tx/builder/schema.generated.ts +39 -3
  345. package/src/tx/builder/schema.ts +55 -29
  346. package/src/tx/execution-cost.ts +6 -5
  347. package/src/tx/validator.ts +31 -5
  348. package/src/utils/autorest.ts +37 -28
  349. package/src/utils/crypto.ts +24 -14
  350. package/src/utils/errors.ts +10 -0
  351. package/src/utils/hd-wallet.ts +2 -0
  352. package/src/utils/jwt.ts +126 -0
  353. package/src/utils/keystore.ts +6 -2
  354. package/src/utils/typed-data.ts +4 -30
  355. package/src/utils/wrap-proxy.ts +24 -0
  356. package/types-legacy/ts4.2/AeSdk.d.ts +3 -0
  357. package/types-legacy/ts4.2/AeSdkAepp.d.ts +0 -1
  358. package/types-legacy/ts4.2/AeSdkBase.d.ts +61 -6
  359. package/types-legacy/ts4.2/AeSdkMethods.d.ts +19 -7
  360. package/types-legacy/ts4.2/Middleware.d.ts +1 -1
  361. package/types-legacy/ts4.2/Node.d.ts +15 -2
  362. package/types-legacy/ts4.2/account/Base.d.ts +39 -3
  363. package/types-legacy/ts4.2/account/Generalized.d.ts +2 -0
  364. package/types-legacy/ts4.2/account/Ledger.d.ts +2 -0
  365. package/types-legacy/ts4.2/account/Memory.d.ts +15 -4
  366. package/types-legacy/ts4.2/account/Rpc.d.ts +16 -5
  367. package/types-legacy/ts4.2/aens.d.ts +17 -44
  368. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  369. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +14 -0
  370. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -0
  371. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  372. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -0
  373. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +23 -5
  374. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +164 -15
  375. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +8 -1
  376. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +6 -3
  377. package/types-legacy/ts4.2/apis/node/models/index.d.ts +66 -2
  378. package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +5 -1
  379. package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
  380. package/types-legacy/ts4.2/apis/node/node.d.ts +24 -3
  381. package/types-legacy/ts4.2/chain.d.ts +14 -44
  382. package/types-legacy/ts4.2/channel/Base.d.ts +3 -47
  383. package/types-legacy/ts4.2/channel/Contract.d.ts +16 -25
  384. package/types-legacy/ts4.2/channel/Spend.d.ts +0 -8
  385. package/types-legacy/ts4.2/channel/internal.d.ts +104 -5
  386. package/types-legacy/ts4.2/contract/Contract.d.ts +10 -2
  387. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +14 -8
  388. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +12 -11
  389. package/types-legacy/ts4.2/contract/compiler/Cli8.d.ts +13 -0
  390. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +3 -9
  391. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +2 -5
  392. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  393. package/types-legacy/ts4.2/contract/ga.d.ts +1 -2
  394. package/types-legacy/ts4.2/deprecated.d.ts +48 -0
  395. package/types-legacy/ts4.2/index-browser.d.ts +11 -6
  396. package/types-legacy/ts4.2/index.d.ts +1 -0
  397. package/types-legacy/ts4.2/oracle.d.ts +6 -37
  398. package/types-legacy/ts4.2/send-transaction.d.ts +53 -0
  399. package/types-legacy/ts4.2/spend.d.ts +4 -3
  400. package/types-legacy/ts4.2/tx/builder/common.d.ts +32 -0
  401. package/types-legacy/ts4.2/tx/builder/constants.d.ts +6 -5
  402. package/types-legacy/ts4.2/tx/builder/delegation/index.d.ts +20 -0
  403. package/types-legacy/ts4.2/tx/builder/delegation/schema.d.ts +136 -0
  404. package/types-legacy/ts4.2/tx/builder/delegation/schema.generated.d.ts +141 -0
  405. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +2 -2
  406. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +1 -1
  407. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +19 -11
  408. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +10 -2
  409. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +31 -29
  410. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -1
  411. package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +1 -0
  412. package/types-legacy/ts4.2/tx/builder/field-types/pointers2.d.ts +26 -0
  413. package/types-legacy/ts4.2/tx/builder/field-types/query-fee.d.ts +19 -0
  414. package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +9 -1
  415. package/types-legacy/ts4.2/tx/builder/field-types/with-default.d.ts +7 -0
  416. package/types-legacy/ts4.2/tx/builder/field-types/with-formatting.d.ts +7 -0
  417. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +2 -2
  418. package/types-legacy/ts4.2/tx/builder/index.d.ts +17 -10
  419. package/types-legacy/ts4.2/tx/builder/schema.d.ts +482 -257
  420. package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +39 -3
  421. package/types-legacy/ts4.2/tx/execution-cost.d.ts +6 -5
  422. package/types-legacy/ts4.2/utils/autorest.d.ts +2 -3
  423. package/types-legacy/ts4.2/utils/crypto.d.ts +9 -5
  424. package/types-legacy/ts4.2/utils/errors.d.ts +6 -0
  425. package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -0
  426. package/types-legacy/ts4.2/utils/jwt.d.ts +53 -0
  427. package/types-legacy/ts4.2/utils/keystore.d.ts +6 -2
  428. package/types-legacy/ts4.2/utils/typed-data.d.ts +0 -2
  429. package/types-legacy/ts4.2/utils/wrap-proxy.d.ts +2 -0
  430. package/types-legacy/ts4.5/AeSdk.d.ts +3 -0
  431. package/types-legacy/ts4.5/AeSdkAepp.d.ts +0 -1
  432. package/types-legacy/ts4.5/AeSdkBase.d.ts +61 -6
  433. package/types-legacy/ts4.5/AeSdkMethods.d.ts +19 -7
  434. package/types-legacy/ts4.5/Middleware.d.ts +1 -1
  435. package/types-legacy/ts4.5/Node.d.ts +15 -2
  436. package/types-legacy/ts4.5/account/Base.d.ts +39 -3
  437. package/types-legacy/ts4.5/account/Generalized.d.ts +2 -0
  438. package/types-legacy/ts4.5/account/Ledger.d.ts +2 -0
  439. package/types-legacy/ts4.5/account/Memory.d.ts +15 -4
  440. package/types-legacy/ts4.5/account/Rpc.d.ts +16 -5
  441. package/types-legacy/ts4.5/aens.d.ts +17 -44
  442. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  443. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +14 -0
  444. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -0
  445. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  446. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -0
  447. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +23 -5
  448. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +164 -15
  449. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +8 -1
  450. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +6 -3
  451. package/types-legacy/ts4.5/apis/node/models/index.d.ts +66 -2
  452. package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +5 -1
  453. package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
  454. package/types-legacy/ts4.5/apis/node/node.d.ts +24 -3
  455. package/types-legacy/ts4.5/chain.d.ts +14 -44
  456. package/types-legacy/ts4.5/channel/Base.d.ts +3 -47
  457. package/types-legacy/ts4.5/channel/Contract.d.ts +16 -25
  458. package/types-legacy/ts4.5/channel/Spend.d.ts +0 -8
  459. package/types-legacy/ts4.5/channel/internal.d.ts +104 -5
  460. package/types-legacy/ts4.5/contract/Contract.d.ts +10 -2
  461. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +14 -8
  462. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +12 -11
  463. package/types-legacy/ts4.5/contract/compiler/Cli8.d.ts +13 -0
  464. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +3 -9
  465. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +2 -5
  466. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  467. package/types-legacy/ts4.5/contract/ga.d.ts +1 -2
  468. package/types-legacy/ts4.5/deprecated.d.ts +48 -0
  469. package/types-legacy/ts4.5/index-browser.d.ts +11 -6
  470. package/types-legacy/ts4.5/index.d.ts +1 -0
  471. package/types-legacy/ts4.5/oracle.d.ts +6 -37
  472. package/types-legacy/ts4.5/send-transaction.d.ts +53 -0
  473. package/types-legacy/ts4.5/spend.d.ts +4 -3
  474. package/types-legacy/ts4.5/tx/builder/common.d.ts +32 -0
  475. package/types-legacy/ts4.5/tx/builder/constants.d.ts +6 -5
  476. package/types-legacy/ts4.5/tx/builder/delegation/index.d.ts +20 -0
  477. package/types-legacy/ts4.5/tx/builder/delegation/schema.d.ts +136 -0
  478. package/types-legacy/ts4.5/tx/builder/delegation/schema.generated.d.ts +141 -0
  479. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +2 -2
  480. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +1 -1
  481. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +19 -11
  482. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +10 -2
  483. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +31 -29
  484. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -1
  485. package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +1 -0
  486. package/types-legacy/ts4.5/tx/builder/field-types/pointers2.d.ts +26 -0
  487. package/types-legacy/ts4.5/tx/builder/field-types/query-fee.d.ts +19 -0
  488. package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +9 -1
  489. package/types-legacy/ts4.5/tx/builder/field-types/with-default.d.ts +7 -0
  490. package/types-legacy/ts4.5/tx/builder/field-types/with-formatting.d.ts +7 -0
  491. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +2 -2
  492. package/types-legacy/ts4.5/tx/builder/index.d.ts +17 -10
  493. package/types-legacy/ts4.5/tx/builder/schema.d.ts +482 -257
  494. package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +39 -3
  495. package/types-legacy/ts4.5/tx/execution-cost.d.ts +6 -5
  496. package/types-legacy/ts4.5/utils/autorest.d.ts +2 -3
  497. package/types-legacy/ts4.5/utils/crypto.d.ts +9 -5
  498. package/types-legacy/ts4.5/utils/errors.d.ts +6 -0
  499. package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -0
  500. package/types-legacy/ts4.5/utils/jwt.d.ts +53 -0
  501. package/types-legacy/ts4.5/utils/keystore.d.ts +6 -2
  502. package/types-legacy/ts4.5/utils/typed-data.d.ts +0 -2
  503. package/types-legacy/ts4.5/utils/wrap-proxy.d.ts +2 -0
  504. package/es/tx/builder/field-types/deposit.d.ts +0 -15
  505. package/es/tx/builder/field-types/deposit.mjs +0 -18
  506. package/es/tx/builder/field-types/deposit.mjs.map +0 -1
  507. package/src/tx/builder/field-types/deposit.ts +0 -23
  508. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +0 -15
  509. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +0 -15
@@ -8,14 +8,14 @@ import { ChannelCallError, ChannelPingTimedOutError, UnexpectedTsError, UnknownC
8
8
  import { encodeContractAddress } from "../utils/crypto.mjs";
9
9
  import { buildTx } from "../tx/builder/index.mjs";
10
10
  import { ensureError } from "../utils/other.mjs"; // TODO: SignTx shouldn't return number or null
11
+ /**
12
+ * @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}
13
+ */
11
14
  // Send ping message every 10 seconds
12
15
  const PING_TIMEOUT_MS = 10000;
13
16
  // Close connection if pong message is not received within 15 seconds
14
17
  const PONG_TIMEOUT_MS = 15000;
15
- export function emit(channel) {
16
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17
- args[_key - 1] = arguments[_key];
18
- }
18
+ export function emit(channel, ...args) {
19
19
  const [eventName, ...rest] = args;
20
20
  channel._eventEmitter.emit(eventName, ...rest);
21
21
  }
@@ -24,6 +24,7 @@ function enterState(channel, nextState) {
24
24
  if (nextState == null) {
25
25
  throw new UnknownChannelStateError();
26
26
  }
27
+ channel._debug('enter state', nextState.handler.name);
27
28
  channel._fsm = nextState;
28
29
  if ((nextState === null || nextState === void 0 || (_nextState$handler = nextState.handler) === null || _nextState$handler === void 0 ? void 0 : _nextState$handler.enter) != null) {
29
30
  nextState.handler.enter(channel);
@@ -34,7 +35,8 @@ function enterState(channel, nextState) {
34
35
 
35
36
  // TODO: rewrite to enum
36
37
 
37
- export function changeStatus(channel, newStatus) {
38
+ export function changeStatus(channel, newStatus, debug) {
39
+ channel._debug(newStatus, `(prev. ${channel._status})`, debug !== null && debug !== void 0 ? debug : '');
38
40
  if (newStatus === channel._status) return;
39
41
  channel._status = newStatus;
40
42
  emit(channel, 'statusChanged', newStatus);
@@ -44,14 +46,13 @@ export function changeState(channel, newState) {
44
46
  emit(channel, 'stateChanged', newState);
45
47
  }
46
48
  function send(channel, message) {
47
- if (channel._options.debug) console.log('Send message: ', message);
49
+ channel._debug('send message', message.method, message.params);
48
50
  channel._websocket.send(JsonBig.stringify({
49
51
  jsonrpc: '2.0',
50
52
  ...message
51
53
  }));
52
54
  }
53
- export function notify(channel, method) {
54
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
55
+ export function notify(channel, method, params = {}) {
55
56
  send(channel, {
56
57
  method,
57
58
  params
@@ -141,7 +142,7 @@ function ping(channel) {
141
142
  }
142
143
  function onMessage(channel, data) {
143
144
  const message = JsonBig.parse(data);
144
- if (channel._options.debug) console.log('Receive message: ', message);
145
+ channel._debug('received message', message.method, message.params);
145
146
  if (message.id != null) {
146
147
  const callback = channel._rpcCallbacks.get(message.id);
147
148
  if (callback == null) {
@@ -186,35 +187,25 @@ export async function call(channel, method, params) {
186
187
  });
187
188
  });
188
189
  }
189
- export async function initialize(channel, connectionHandler, openHandler, _ref) {
190
- let {
191
- url,
192
- ...channelOptions
193
- } = _ref;
190
+ export async function initialize(channel, connectionHandler, openHandler, {
191
+ url,
192
+ ...channelOptions
193
+ }) {
194
194
  channel._options = {
195
195
  url,
196
196
  ...channelOptions
197
197
  };
198
- channel._fsm = {
199
- handler: connectionHandler
200
- };
201
198
  const wsUrl = new URL(url);
202
- Object.entries(channelOptions).filter(_ref2 => {
203
- let [key] = _ref2;
204
- return !['sign', 'debug'].includes(key);
205
- }).forEach(_ref3 => {
206
- let [key, value] = _ref3;
207
- return wsUrl.searchParams.set(pascalToSnake(key), value.toString());
208
- });
199
+ Object.entries(channelOptions).filter(([key]) => !['sign', 'debug'].includes(key)).forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value.toString()));
209
200
  wsUrl.searchParams.set('protocol', 'json-rpc');
210
201
  changeStatus(channel, 'connecting');
211
202
  channel._websocket = new W3CWebSocket(wsUrl.toString());
212
203
  await new Promise((resolve, reject) => {
213
204
  Object.assign(channel._websocket, {
214
205
  onerror: reject,
215
- onopen: async () => {
206
+ onopen: async event => {
216
207
  resolve();
217
- changeStatus(channel, 'connected');
208
+ changeStatus(channel, 'connected', event);
218
209
  if (channelOptions.reconnectTx != null) {
219
210
  enterState(channel, {
220
211
  handler: openHandler
@@ -226,19 +217,20 @@ export async function initialize(channel, connectionHandler, openHandler, _ref)
226
217
  throw new ChannelError('`signedTx` missed in state while reconnection');
227
218
  }
228
219
  changeState(channel, buildTx(signedTx));
220
+ } else {
221
+ enterState(channel, {
222
+ handler: connectionHandler
223
+ });
229
224
  }
230
225
  ping(channel);
231
226
  },
232
- onclose: () => {
233
- changeStatus(channel, 'disconnected');
227
+ onclose: event => {
228
+ changeStatus(channel, 'disconnected', event);
234
229
  clearTimeout(channel._pingTimeoutId);
235
230
  },
236
- onmessage: _ref4 => {
237
- let {
238
- data
239
- } = _ref4;
240
- return onMessage(channel, data);
241
- }
231
+ onmessage: ({
232
+ data
233
+ }) => onMessage(channel, data)
242
234
  });
243
235
  });
244
236
  }
@@ -1 +1 @@
1
- {"version":3,"file":"internal.mjs","names":["_websocket","w3cwebsocket","W3CWebSocket","JsonBig","pascalToSnake","ChannelCallError","ChannelPingTimedOutError","UnexpectedTsError","UnknownChannelStateError","ChannelIncomingMessageError","ChannelError","encodeContractAddress","buildTx","ensureError","PING_TIMEOUT_MS","PONG_TIMEOUT_MS","emit","channel","_len","arguments","length","args","Array","_key","eventName","rest","_eventEmitter","enterState","nextState","_nextState$handler","_fsm","handler","enter","dequeueAction","changeStatus","newStatus","_status","changeState","newState","_state","send","message","_options","debug","console","log","stringify","jsonrpc","notify","method","params","undefined","_isActionQueueLocked","queue","_actionQueue","index","findIndex","action","guard","filter","_","i","enqueueAction","promise","Promise","resolve","reject","push","res","state","handleMessage","_message$params","st","data","updates","op","name","_message$params2","round","owner","dequeueMessage","_isMessageQueueLocked","_messageQueue","shift","error","disconnect","close","clearTimeout","_pingTimeoutId","ping","setTimeout","onMessage","parse","id","callback","_rpcCallbacks","get","delete","channel_id","_channelId","call","_nextRpcMessageId","set","_message$error$data$","details","result","initialize","connectionHandler","openHandler","_ref","url","channelOptions","wsUrl","URL","Object","entries","_ref2","key","includes","forEach","_ref3","value","searchParams","toString","assign","onerror","onopen","reconnectTx","signedTx","onclose","onmessage","_ref4"],"sources":["../../src/channel/internal.ts"],"sourcesContent":["import { w3cwebsocket as W3CWebSocket } from 'websocket';\nimport BigNumber from 'bignumber.js';\nimport type Channel from './Base';\nimport JsonBig from '../utils/json-big';\nimport { pascalToSnake } from '../utils/string';\nimport { Encoded } from '../utils/encoder';\nimport {\n BaseError,\n ChannelCallError,\n ChannelPingTimedOutError,\n UnexpectedTsError,\n UnknownChannelStateError,\n ChannelIncomingMessageError,\n ChannelError,\n} from '../utils/errors';\nimport { encodeContractAddress } from '../utils/crypto';\nimport { buildTx } from '../tx/builder';\nimport { ensureError } from '../utils/other';\n\nexport interface ChannelEvents {\n statusChanged: (status: ChannelStatus) => void;\n stateChanged: (tx: Encoded.Transaction | '') => void;\n depositLocked: () => void;\n ownDepositLocked: () => void;\n withdrawLocked: () => void;\n ownWithdrawLocked: () => void;\n peerDisconnected: () => void;\n channelReestablished: () => void;\n error: (error: Error) => void;\n onChainTx: (tx: Encoded.Transaction, details: { info: string; type: string }) => void;\n message: (message: string | Object) => void;\n newContract: (contractAddress: Encoded.ContractAddress) => void;\n}\n\nexport interface ChannelAction {\n guard: (channel: Channel, state?: ChannelFsm) => boolean;\n action: (channel: Channel, state?: ChannelFsm) => ChannelFsm;\n}\n\ninterface SignOptions {\n updates?: any[];\n [k: string]: any;\n}\nexport type SignTxWithTag = (tag: string, tx: Encoded.Transaction, options?: SignOptions) => (\n Promise<Encoded.Transaction>\n);\n// TODO: SignTx shouldn't return number or null\nexport type SignTx = (tx: Encoded.Transaction, options?: SignOptions) => (\n Promise<Encoded.Transaction | number | null>\n);\n\nexport interface ChannelOptions {\n existingFsmId?: Encoded.Bytearray;\n url: string;\n\n /**\n * @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}\n */\n initiatorId: Encoded.AccountAddress;\n responderId: Encoded.AccountAddress;\n lockPeriod: number;\n pushAmount: number;\n initiatorAmount: BigNumber;\n responderAmount: BigNumber;\n channelReserve?: BigNumber | number;\n ttl?: number;\n host: string;\n port: number;\n role: 'initiator' | 'responder';\n minimumDepthStrategy?: 'txfee' | 'plain';\n minimumDepth?: number;\n fee?: BigNumber | number;\n gasPrice?: BigNumber | number;\n\n signedTx?: string;\n existingChannelId?: string;\n offChainTx?: string;\n reconnectTx?: string;\n timeoutIdle?: number;\n timeoutFundingCreate?: number;\n timeoutFundingSign?: number;\n timeoutFundingLock?: number;\n timeoutSign?: number;\n timeoutAccept?: number;\n timeoutInitialized?: number;\n timeoutAwaitingOpen?: number;\n statePassword?: string;\n debug: boolean;\n sign: SignTxWithTag;\n offchainTx?: string;\n}\n\nexport interface ChannelHandler extends Function {\n enter?: Function;\n}\n\nexport interface ChannelState {\n signedTx: Encoded.Transaction;\n resolve: (r?: any) => void;\n reject: (e: BaseError) => void;\n sign: SignTx;\n handler?: ChannelHandler;\n onOnChainTx?: (tx: Encoded.Transaction) => void;\n onOwnWithdrawLocked?: () => void;\n onWithdrawLocked?: () => void;\n onOwnDepositLocked?: () => void;\n onDepositLocked?: () => void;\n closeTx?: string;\n}\n\nexport interface ChannelFsm {\n handler: ChannelHandler;\n state?: ChannelState | {\n resolve: Function;\n reject: Function;\n };\n}\n\nexport interface ChannelMessage {\n id?: number;\n method: string;\n params: any;\n payload?: any;\n data?: any;\n error?: ChannelMessageError;\n}\n\ninterface ChannelMessageError {\n code: number;\n message: string;\n data: [{\n message: string;\n code: number;\n }];\n request: ChannelMessage;\n}\n\n// Send ping message every 10 seconds\nconst PING_TIMEOUT_MS = 10000;\n// Close connection if pong message is not received within 15 seconds\nconst PONG_TIMEOUT_MS = 15000;\n\nexport function emit<E extends keyof ChannelEvents>(\n channel: Channel,\n ...args: [E, ...Parameters<ChannelEvents[E]>]\n): void {\n const [eventName, ...rest] = args;\n channel._eventEmitter.emit(eventName, ...rest);\n}\n\nfunction enterState(channel: Channel, nextState: ChannelFsm): void {\n if (nextState == null) {\n throw new UnknownChannelStateError();\n }\n channel._fsm = nextState;\n if (nextState?.handler?.enter != null) {\n nextState.handler.enter(channel);\n }\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n void dequeueAction(channel);\n}\n\n// TODO: rewrite to enum\nexport type ChannelStatus = 'connecting' | 'connected' | 'accepted' | 'halfSigned' | 'signed'\n| 'open' | 'closing' | 'closed' | 'died' | 'disconnected';\n\nexport function changeStatus(channel: Channel, newStatus: ChannelStatus): void {\n if (newStatus === channel._status) return;\n channel._status = newStatus;\n emit(channel, 'statusChanged', newStatus);\n}\n\nexport function changeState(channel: Channel, newState: Encoded.Transaction | ''): void {\n channel._state = newState;\n emit(channel, 'stateChanged', newState);\n}\n\nfunction send(channel: Channel, message: ChannelMessage): void {\n if (channel._options.debug) console.log('Send message: ', message);\n channel._websocket.send(JsonBig.stringify({ jsonrpc: '2.0', ...message }));\n}\n\nexport function notify(channel: Channel, method: string, params: object = {}): void {\n send(channel, { method, params });\n}\n\nasync function dequeueAction(channel: Channel): Promise<void> {\n if (channel._isActionQueueLocked) return;\n const queue = channel._actionQueue;\n if (queue.length === 0) return;\n const index = queue.findIndex((action) => action.guard(channel, channel._fsm));\n if (index === -1) return;\n channel._actionQueue = queue.filter((_, i) => index !== i);\n channel._isActionQueueLocked = true;\n const nextState: ChannelFsm = await queue[index].action(channel, channel._fsm);\n channel._isActionQueueLocked = false;\n enterState(channel, nextState);\n}\n\nexport async function enqueueAction(\n channel: Channel,\n guard: ChannelAction['guard'],\n action: () => { handler: ChannelHandler; state?: Partial<ChannelState> },\n): Promise<any> {\n const promise = new Promise((resolve, reject) => {\n channel._actionQueue.push({\n guard,\n action() {\n const res = action();\n return { ...res, state: { ...res.state, resolve, reject } };\n },\n });\n });\n void dequeueAction(channel);\n return promise;\n}\n\nasync function handleMessage(channel: Channel, message: ChannelMessage): Promise<void> {\n const { handler, state: st } = channel._fsm;\n const nextState = await Promise.resolve(handler(channel, message, st));\n enterState(channel, nextState);\n // TODO: emit message and handler name (?) to move this code to Contract constructor\n if (\n message?.params?.data?.updates?.[0]?.op === 'OffChainNewContract'\n // if name is channelOpen, the contract was created by other participant\n && nextState?.handler.name === 'channelOpen'\n ) {\n const round = channel.round();\n if (round == null) throw new UnexpectedTsError('Round is null');\n const owner = message?.params?.data?.updates?.[0]?.owner;\n emit(channel, 'newContract', encodeContractAddress(owner, round + 1));\n }\n}\n\nasync function dequeueMessage(channel: Channel): Promise<void> {\n if (channel._isMessageQueueLocked) return;\n channel._isMessageQueueLocked = true;\n while (channel._messageQueue.length > 0) {\n const message = channel._messageQueue.shift();\n if (message == null) throw new UnexpectedTsError();\n try {\n await handleMessage(channel, message);\n } catch (error) {\n ensureError(error);\n emit(channel, 'error', new ChannelIncomingMessageError(error, message));\n }\n }\n channel._isMessageQueueLocked = false;\n}\n\nexport function disconnect(channel: Channel): void {\n channel._websocket.close();\n clearTimeout(channel._pingTimeoutId);\n}\n\nfunction ping(channel: Channel): void {\n clearTimeout(channel._pingTimeoutId);\n channel._pingTimeoutId = setTimeout(() => {\n notify(channel, 'channels.system', { action: 'ping' });\n channel._pingTimeoutId = setTimeout(() => {\n disconnect(channel);\n emit(channel, 'error', new ChannelPingTimedOutError());\n }, PONG_TIMEOUT_MS);\n }, PING_TIMEOUT_MS);\n}\n\nfunction onMessage(channel: Channel, data: string): void {\n const message = JsonBig.parse(data);\n if (channel._options.debug) console.log('Receive message: ', message);\n if (message.id != null) {\n const callback = channel._rpcCallbacks.get(message.id);\n if (callback == null) {\n emit(channel, 'error', new ChannelError(`Can't find callback by id: ${message.id}`));\n return;\n }\n try {\n callback(message);\n } finally {\n channel._rpcCallbacks.delete(message.id);\n }\n return;\n }\n if (message.method === 'channels.message') {\n emit(channel, 'message', message.params.data.message);\n return;\n }\n if (message.method === 'channels.system.pong') {\n if (message.params.channel_id === channel._channelId || channel._channelId == null) {\n ping(channel);\n }\n return;\n }\n channel._messageQueue.push(message);\n void dequeueMessage(channel);\n}\n\nexport async function call(channel: Channel, method: string, params: any): Promise<any> {\n return new Promise((resolve, reject) => {\n const id = channel._nextRpcMessageId;\n channel._nextRpcMessageId += 1;\n channel._rpcCallbacks.set(id, (\n message: { result: PromiseLike<any>; error?: ChannelMessageError },\n ) => {\n if (message.error != null) {\n const details = message.error.data[0].message ?? '';\n reject(new ChannelCallError(message.error.message + details));\n } else resolve(message.result);\n });\n send(channel, { method, id, params });\n });\n}\n\nexport async function initialize(\n channel: Channel,\n connectionHandler: Function,\n openHandler: Function,\n { url, ...channelOptions }: ChannelOptions,\n): Promise<void> {\n channel._options = { url, ...channelOptions };\n channel._fsm = { handler: connectionHandler };\n\n const wsUrl = new URL(url);\n Object.entries(channelOptions)\n .filter(([key]) => !['sign', 'debug'].includes(key))\n .forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value.toString()));\n wsUrl.searchParams.set('protocol', 'json-rpc');\n changeStatus(channel, 'connecting');\n channel._websocket = new W3CWebSocket(wsUrl.toString());\n await new Promise<void>((resolve, reject) => {\n Object.assign(channel._websocket, {\n onerror: reject,\n onopen: async () => {\n resolve();\n changeStatus(channel, 'connected');\n if (channelOptions.reconnectTx != null) {\n enterState(channel, { handler: openHandler });\n const { signedTx } = await channel.state();\n if (signedTx == null) {\n throw new ChannelError('`signedTx` missed in state while reconnection');\n }\n changeState(channel, buildTx(signedTx));\n }\n ping(channel);\n },\n onclose: () => {\n changeStatus(channel, 'disconnected');\n clearTimeout(channel._pingTimeoutId);\n },\n onmessage: ({ data }: { data: string }) => onMessage(channel, data),\n });\n });\n}\n"],"mappings":"AAAA,OAAAA,UAAA,MAA6C,WAAW;AAAC;EAAAC,YAAA,EAAAC;AAAA,IAAAF,UAAA;AAAA,OAGlDG,OAAO;AAAA,SACLC,aAAa;AAAA,SAIpBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,YAAY;AAAA,SAELC,qBAAqB;AAAA,SACrBC,OAAO;AAAA,SACPC,WAAW,8BA6BpB;AA2FA;AACA,MAAMC,eAAe,GAAG,KAAK;AAC7B;AACA,MAAMC,eAAe,GAAG,KAAK;AAE7B,OAAO,S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;EACvD,MAAM,IAAI3D,OAAO,CAAO,CAACC,OAAO,EAAEC,MAAM,KAAK;IAC3CgD,MAAM,CAACU,MAAM,CAAC3G,OAAO,CAACjB,UAAU,EAAE;MAChC6H,OAAO,EAAE3D,MAAM;MACf4D,MAAM,EAAE,MAAAA,CAAA,KAAY;QAClB7D,OAAO,CAAC,CAAC;QACT/B,YAAY,CAACjB,OAAO,EAAE,WAAW,CAAC;QAClC,IAAI8F,cAAc,CAACgB,WAAW,IAAI,IAAI,EAAE;UACtCpG,UAAU,CAACV,OAAO,EAAE;YAAEc,OAAO,EAAE6E;UAAY,CAAC,CAAC;UAC7C,MAAM;YAAEoB;UAAS,CAAC,GAAG,MAAM/G,OAAO,CAACoD,KAAK,CAAC,CAAC;UAC1C,IAAI2D,QAAQ,IAAI,IAAI,EAAE;YACpB,MAAM,IAAItH,YAAY,CAAC,+CAA+C,CAAC;UACzE;UACA2B,WAAW,CAACpB,OAAO,EAAEL,OAAO,CAACoH,QAAQ,CAAC,CAAC;QACzC;QACAvC,IAAI,CAACxE,OAAO,CAAC;MACf,CAAC;MACDgH,OAAO,EAAEA,CAAA,KAAM;QACb/F,YAAY,CAACjB,OAAO,EAAE,cAAc,CAAC;QACrCsE,YAAY,CAACtE,OAAO,CAACuE,cAAc,CAAC;MACtC,CAAC;MACD0C,SAAS,EAAEC,KAAA;QAAA,IAAC;UAAE1D;QAAuB,CAAC,GAAA0D,KAAA;QAAA,OAAKxC,SAAS,CAAC1E,OAAO,EAAEwD,IAAI,CAAC;MAAA;IACrE,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"internal.mjs","names":["_websocket","w3cwebsocket","W3CWebSocket","JsonBig","pascalToSnake","ChannelCallError","ChannelPingTimedOutError","UnexpectedTsError","UnknownChannelStateError","ChannelIncomingMessageError","ChannelError","encodeContractAddress","buildTx","ensureError","PING_TIMEOUT_MS","PONG_TIMEOUT_MS","emit","channel","args","eventName","rest","_eventEmitter","enterState","nextState","_nextState$handler","_debug","handler","name","_fsm","enter","dequeueAction","changeStatus","newStatus","debug","_status","changeState","newState","_state","send","message","method","params","stringify","jsonrpc","notify","_isActionQueueLocked","queue","_actionQueue","length","index","findIndex","action","guard","filter","_","i","enqueueAction","promise","Promise","resolve","reject","push","res","state","handleMessage","_message$params","st","data","updates","op","_message$params2","round","owner","dequeueMessage","_isMessageQueueLocked","_messageQueue","shift","error","disconnect","close","clearTimeout","_pingTimeoutId","ping","setTimeout","onMessage","parse","id","callback","_rpcCallbacks","get","delete","channel_id","_channelId","call","_nextRpcMessageId","set","_message$error$data$","details","result","initialize","connectionHandler","openHandler","url","channelOptions","_options","wsUrl","URL","Object","entries","key","includes","forEach","value","searchParams","toString","assign","onerror","onopen","event","reconnectTx","signedTx","onclose","onmessage"],"sources":["../../src/channel/internal.ts"],"sourcesContent":["import { w3cwebsocket as W3CWebSocket, ICloseEvent } from 'websocket';\nimport BigNumber from 'bignumber.js';\nimport type Channel from './Base';\nimport JsonBig from '../utils/json-big';\nimport { pascalToSnake } from '../utils/string';\nimport { Encoded } from '../utils/encoder';\nimport {\n BaseError,\n ChannelCallError,\n ChannelPingTimedOutError,\n UnexpectedTsError,\n UnknownChannelStateError,\n ChannelIncomingMessageError,\n ChannelError,\n} from '../utils/errors';\nimport { encodeContractAddress } from '../utils/crypto';\nimport { buildTx } from '../tx/builder';\nimport { ensureError } from '../utils/other';\n\nexport interface ChannelEvents {\n statusChanged: (status: ChannelStatus) => void;\n stateChanged: (tx: Encoded.Transaction | '') => void;\n depositLocked: () => void;\n ownDepositLocked: () => void;\n withdrawLocked: () => void;\n ownWithdrawLocked: () => void;\n peerDisconnected: () => void;\n channelReestablished: () => void;\n error: (error: Error) => void;\n onChainTx: (tx: Encoded.Transaction, details: { info: string; type: string }) => void;\n message: (message: string | Object) => void;\n newContract: (contractAddress: Encoded.ContractAddress) => void;\n}\n\nexport interface ChannelAction {\n guard: (channel: Channel, state?: ChannelFsm) => boolean;\n action: (channel: Channel, state?: ChannelFsm) => ChannelFsm;\n}\n\ninterface SignOptions {\n updates?: any[];\n [k: string]: any;\n}\nexport type SignTxWithTag = (tag: string, tx: Encoded.Transaction, options?: SignOptions) => (\n Promise<Encoded.Transaction>\n);\n// TODO: SignTx shouldn't return number or null\nexport type SignTx = (tx: Encoded.Transaction, options?: SignOptions) => (\n Promise<Encoded.Transaction | number | null>\n);\n\n/**\n * @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}\n */\nexport interface ChannelOptions {\n existingFsmId?: Encoded.Bytearray;\n /**\n * Channel url (for example: \"ws://localhost:3001\")\n */\n url: string;\n\n /**\n * Initiator's public key\n */\n initiatorId: Encoded.AccountAddress;\n /**\n * Responder's public key\n */\n responderId: Encoded.AccountAddress;\n /**\n * Amount of blocks for disputing a solo close\n */\n lockPeriod: number;\n /**\n * Initial deposit in favour of the responder by the initiator\n */\n pushAmount: number;\n /**\n * Amount of coins the initiator has committed to the channel\n */\n initiatorAmount: BigNumber | number;\n /**\n * Amount of coins the responder has committed to the channel\n */\n responderAmount: BigNumber | number;\n /**\n * The minimum amount both peers need to maintain\n */\n channelReserve?: BigNumber | number;\n /**\n * Minimum block height to include the channel_create_tx\n */\n ttl?: number;\n /**\n * Host of the responder's node\n */\n host: string;\n /**\n * The port of the responders node\n */\n port: number;\n /**\n * Participant role\n */\n role: 'initiator' | 'responder';\n /**\n * How to calculate minimum depth (default: txfee)\n */\n minimumDepthStrategy?: 'txfee' | 'plain';\n /**\n * The minimum amount of blocks to be mined\n */\n minimumDepth?: number;\n /**\n * The fee to be used for the channel open transaction\n */\n fee?: BigNumber | number;\n /**\n * Used for the fee computation of the channel open transaction\n */\n gasPrice?: BigNumber | number;\n\n signedTx?: string;\n /**\n * Existing channel id (required if reestablishing a channel)\n */\n existingChannelId?: string;\n /**\n * Offchain transaction (required if reestablishing a channel)\n */\n offChainTx?: string;\n reconnectTx?: string;\n /**\n * The time waiting for a new event to be initiated (default: 600000)\n */\n timeoutIdle?: number;\n /**\n * The time waiting for the initiator to produce the create channel transaction after the noise\n * session had been established (default: 120000)\n */\n timeoutFundingCreate?: number;\n /**\n * The time frame the other client has to sign an off-chain update after our client had initiated\n * and signed it. This applies only for double signed on-chain intended updates: channel create\n * transaction, deposit, withdrawal and etc. (default: 120000)\n */\n timeoutFundingSign?: number;\n /**\n * The time frame the other client has to confirm an on-chain transaction reaching maturity\n * (passing minimum depth) after the local node has detected this. This applies only for double\n * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.\n * (default: 360000)\n */\n timeoutFundingLock?: number;\n /**\n * The time frame the client has to return a signed off-chain update or to decline it.\n * This applies for all off-chain updates (default: 500000)\n */\n timeoutSign?: number;\n /**\n * The time frame the other client has to react to an event. This applies for all off-chain\n * updates that are not meant to land on-chain, as well as some special cases: opening a noise\n * connection, mutual closing acknowledgement and reestablishing an existing channel\n * (default: 120000)\n */\n timeoutAccept?: number;\n /**\n * the time frame the responder has to accept an incoming noise session.\n * Applicable only for initiator (default: timeout_accept's value)\n */\n timeoutInitialized?: number;\n /**\n * The time frame the initiator has to start an outgoing noise session to the responder's node.\n * Applicable only for responder (default: timeout_idle's value)\n */\n timeoutAwaitingOpen?: number;\n statePassword?: string;\n /**\n * Log websocket communication and state changes\n */\n debug?: boolean;\n /**\n * Function which verifies and signs transactions\n */\n sign: SignTxWithTag;\n offchainTx?: string;\n}\n\nexport interface ChannelHandler extends Function {\n enter?: Function;\n}\n\nexport interface ChannelState {\n signedTx: Encoded.Transaction;\n resolve: (r?: any) => void;\n reject: (e: BaseError) => void;\n sign: SignTx;\n handler?: ChannelHandler;\n /**\n * Called when transaction has been posted on chain\n */\n onOnChainTx?: (tx: Encoded.Transaction) => void;\n onOwnWithdrawLocked?: () => void;\n onWithdrawLocked?: () => void;\n onOwnDepositLocked?: () => void;\n onDepositLocked?: () => void;\n closeTx?: string;\n}\n\nexport interface ChannelFsm {\n handler: ChannelHandler;\n state?: ChannelState | {\n resolve: Function;\n reject: Function;\n };\n}\n\nexport interface ChannelMessage {\n id?: number;\n method: string;\n params: any;\n payload?: any;\n data?: any;\n error?: ChannelMessageError;\n}\n\ninterface ChannelMessageError {\n code: number;\n message: string;\n data: [{\n message: string;\n code: number;\n }];\n request: ChannelMessage;\n}\n\n// Send ping message every 10 seconds\nconst PING_TIMEOUT_MS = 10000;\n// Close connection if pong message is not received within 15 seconds\nconst PONG_TIMEOUT_MS = 15000;\n\nexport function emit<E extends keyof ChannelEvents>(\n channel: Channel,\n ...args: [E, ...Parameters<ChannelEvents[E]>]\n): void {\n const [eventName, ...rest] = args;\n channel._eventEmitter.emit(eventName, ...rest);\n}\n\nfunction enterState(channel: Channel, nextState: ChannelFsm): void {\n if (nextState == null) {\n throw new UnknownChannelStateError();\n }\n channel._debug('enter state', nextState.handler.name);\n channel._fsm = nextState;\n if (nextState?.handler?.enter != null) {\n nextState.handler.enter(channel);\n }\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n void dequeueAction(channel);\n}\n\n// TODO: rewrite to enum\nexport type ChannelStatus = 'connecting' | 'connected' | 'accepted' | 'halfSigned' | 'signed'\n| 'open' | 'closing' | 'closed' | 'died' | 'disconnected';\n\nexport function changeStatus(channel: Channel, newStatus: ChannelStatus, debug?: unknown): void {\n channel._debug(newStatus, `(prev. ${channel._status})`, debug ?? '');\n if (newStatus === channel._status) return;\n channel._status = newStatus;\n emit(channel, 'statusChanged', newStatus);\n}\n\nexport function changeState(channel: Channel, newState: Encoded.Transaction | ''): void {\n channel._state = newState;\n emit(channel, 'stateChanged', newState);\n}\n\nfunction send(channel: Channel, message: ChannelMessage): void {\n channel._debug('send message', message.method, message.params);\n channel._websocket.send(JsonBig.stringify({ jsonrpc: '2.0', ...message }));\n}\n\nexport function notify(channel: Channel, method: string, params: object = {}): void {\n send(channel, { method, params });\n}\n\nasync function dequeueAction(channel: Channel): Promise<void> {\n if (channel._isActionQueueLocked) return;\n const queue = channel._actionQueue;\n if (queue.length === 0) return;\n const index = queue.findIndex((action) => action.guard(channel, channel._fsm));\n if (index === -1) return;\n channel._actionQueue = queue.filter((_, i) => index !== i);\n channel._isActionQueueLocked = true;\n const nextState: ChannelFsm = await queue[index].action(channel, channel._fsm);\n channel._isActionQueueLocked = false;\n enterState(channel, nextState);\n}\n\nexport async function enqueueAction(\n channel: Channel,\n guard: ChannelAction['guard'],\n action: () => { handler: ChannelHandler; state?: Partial<ChannelState> },\n): Promise<any> {\n const promise = new Promise((resolve, reject) => {\n channel._actionQueue.push({\n guard,\n action() {\n const res = action();\n return { ...res, state: { ...res.state, resolve, reject } };\n },\n });\n });\n void dequeueAction(channel);\n return promise;\n}\n\nasync function handleMessage(channel: Channel, message: ChannelMessage): Promise<void> {\n const { handler, state: st } = channel._fsm;\n const nextState = await Promise.resolve(handler(channel, message, st));\n enterState(channel, nextState);\n // TODO: emit message and handler name (?) to move this code to Contract constructor\n if (\n message?.params?.data?.updates?.[0]?.op === 'OffChainNewContract'\n // if name is channelOpen, the contract was created by other participant\n && nextState?.handler.name === 'channelOpen'\n ) {\n const round = channel.round();\n if (round == null) throw new UnexpectedTsError('Round is null');\n const owner = message?.params?.data?.updates?.[0]?.owner;\n emit(channel, 'newContract', encodeContractAddress(owner, round + 1));\n }\n}\n\nasync function dequeueMessage(channel: Channel): Promise<void> {\n if (channel._isMessageQueueLocked) return;\n channel._isMessageQueueLocked = true;\n while (channel._messageQueue.length > 0) {\n const message = channel._messageQueue.shift();\n if (message == null) throw new UnexpectedTsError();\n try {\n await handleMessage(channel, message);\n } catch (error) {\n ensureError(error);\n emit(channel, 'error', new ChannelIncomingMessageError(error, message));\n }\n }\n channel._isMessageQueueLocked = false;\n}\n\nexport function disconnect(channel: Channel): void {\n channel._websocket.close();\n clearTimeout(channel._pingTimeoutId);\n}\n\nfunction ping(channel: Channel): void {\n clearTimeout(channel._pingTimeoutId);\n channel._pingTimeoutId = setTimeout(() => {\n notify(channel, 'channels.system', { action: 'ping' });\n channel._pingTimeoutId = setTimeout(() => {\n disconnect(channel);\n emit(channel, 'error', new ChannelPingTimedOutError());\n }, PONG_TIMEOUT_MS);\n }, PING_TIMEOUT_MS);\n}\n\nfunction onMessage(channel: Channel, data: string): void {\n const message = JsonBig.parse(data);\n channel._debug('received message', message.method, message.params);\n if (message.id != null) {\n const callback = channel._rpcCallbacks.get(message.id);\n if (callback == null) {\n emit(channel, 'error', new ChannelError(`Can't find callback by id: ${message.id}`));\n return;\n }\n try {\n callback(message);\n } finally {\n channel._rpcCallbacks.delete(message.id);\n }\n return;\n }\n if (message.method === 'channels.message') {\n emit(channel, 'message', message.params.data.message);\n return;\n }\n if (message.method === 'channels.system.pong') {\n if (message.params.channel_id === channel._channelId || channel._channelId == null) {\n ping(channel);\n }\n return;\n }\n channel._messageQueue.push(message);\n void dequeueMessage(channel);\n}\n\nexport async function call(channel: Channel, method: string, params: any): Promise<any> {\n return new Promise((resolve, reject) => {\n const id = channel._nextRpcMessageId;\n channel._nextRpcMessageId += 1;\n channel._rpcCallbacks.set(id, (\n message: { result: PromiseLike<any>; error?: ChannelMessageError },\n ) => {\n if (message.error != null) {\n const details = message.error.data[0].message ?? '';\n reject(new ChannelCallError(message.error.message + details));\n } else resolve(message.result);\n });\n send(channel, { method, id, params });\n });\n}\n\nexport async function initialize(\n channel: Channel,\n connectionHandler: Function,\n openHandler: Function,\n { url, ...channelOptions }: ChannelOptions,\n): Promise<void> {\n channel._options = { url, ...channelOptions };\n\n const wsUrl = new URL(url);\n Object.entries(channelOptions)\n .filter(([key]) => !['sign', 'debug'].includes(key))\n .forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value.toString()));\n wsUrl.searchParams.set('protocol', 'json-rpc');\n changeStatus(channel, 'connecting');\n channel._websocket = new W3CWebSocket(wsUrl.toString());\n await new Promise<void>((resolve, reject) => {\n Object.assign(channel._websocket, {\n onerror: reject,\n onopen: async (event: Event) => {\n resolve();\n changeStatus(channel, 'connected', event);\n if (channelOptions.reconnectTx != null) {\n enterState(channel, { handler: openHandler });\n const { signedTx } = await channel.state();\n if (signedTx == null) {\n throw new ChannelError('`signedTx` missed in state while reconnection');\n }\n changeState(channel, buildTx(signedTx));\n } else {\n enterState(channel, { handler: connectionHandler });\n }\n ping(channel);\n },\n onclose: (event: ICloseEvent) => {\n changeStatus(channel, 'disconnected', event);\n clearTimeout(channel._pingTimeoutId);\n },\n onmessage: ({ data }: { data: string }) => onMessage(channel, data),\n });\n });\n}\n"],"mappings":"AAAA,OAAAA,UAAA,MAA0D,WAAW;AAAC;EAAAC,YAAA,EAAAC;AAAA,IAAAF,UAAA;AAAA,OAG/DG,OAAO;AAAA,SACLC,aAAa;AAAA,SAIpBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,YAAY;AAAA,SAELC,qBAAqB;AAAA,SACrBC,OAAO;AAAA,SACPC,WAAW,8BA6BpB;AAKA;AACA;AACA;AAuLA;AACA,MAAMC,eAAe,GAAG,KAAK;AAC7B;AACA,MAAMC,eAAe,GAAG,KAAK;AAE7B,OAAO,SAASC,IAAIA,CAClBC,OAAgB,EAChB,GAAGC,IAA0C,EACvC;EACN,MAAM,CAACC,SAAS,EAAE,GAAGC,IAAI,CAAC,GAAGF,IAAI;EACjCD,OAAO,CAACI,aAAa,CAACL,IAAI,CAACG,SAAS,EAAE,GAAGC,IAAI,CAAC;AAChD;AAEA,SAASE,UAAUA,CAACL,OAAgB,EAAEM,SAAqB,EAAQ;EAAA,IAAAC,kBAAA;EACjE,IAAID,SAAS,IAAI,IAAI,EAAE;IACrB,MAAM,IAAIf,wBAAwB,CAAC,CAAC;EACtC;EACAS,OAAO,CAACQ,MAAM,CAAC,aAAa,EAAEF,SAAS,CAACG,OAAO,CAACC,IAAI,CAAC;EACrDV,OAAO,CAACW,IAAI,GAAGL,SAAS;EACxB,IAAI,CAAAA,SAAS,aAATA,SAAS,gBAAAC,kBAAA,GAATD,SAAS,C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;MACDwG,OAAO,EAAGH,KAAkB,IAAK;QAC/BvF,YAAY,CAACd,OAAO,EAAE,cAAc,EAAEqG,KAAK,CAAC;QAC5CtC,YAAY,CAAC/D,OAAO,CAACgE,cAAc,CAAC;MACtC,CAAC;MACDyC,SAAS,EAAEA,CAAC;QAAEvD;MAAuB,CAAC,KAAKiB,SAAS,CAACnE,OAAO,EAAEkD,IAAI;IACpE,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"}
@@ -11,7 +11,8 @@ import { Encoded } from '../utils/encoder';
11
11
  import { ContractCallObject as NodeContractCallObject, Event as NodeEvent } from '../apis/node';
12
12
  import CompilerBase, { Aci } from './compiler/Base';
13
13
  import Node, { TransformNodeType } from '../Node';
14
- import { txDryRun, sendTransaction, SendTransactionOptions } from '../chain';
14
+ import { txDryRun } from '../chain';
15
+ import { sendTransaction, SendTransactionOptions } from '../send-transaction';
15
16
  import AccountBase from '../account/Base';
16
17
  import { TxUnpacked } from '../tx/builder/schema.generated';
17
18
  interface Event extends NodeEvent {
@@ -79,7 +80,7 @@ interface GetCallResultByHashReturnType<M extends ContractMethodsBase, Fn extend
79
80
  * const staticCallResult = await contractIns.$call('setState', [123], { callStatic: true })
80
81
  * ```
81
82
  * Also you can call contract like: `await contractIns.setState(123, options)`
82
- * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
83
+ * Then sdk decide to make on-chain or static call (dry-run API) transaction based on function is
83
84
  * stateful or not
84
85
  */
85
86
  declare class Contract<M extends ContractMethodsBase> {
@@ -135,12 +136,19 @@ declare class Contract<M extends ContractMethodsBase> {
135
136
  _name: string;
136
137
  _calldata: Calldata;
137
138
  $options: Omit<ConstructorParameters<typeof Contract>[0], 'aci'>;
139
+ /**
140
+ * @param options - Options
141
+ */
138
142
  constructor({ aci, ...otherOptions }: {
139
143
  onCompiler?: CompilerBase;
140
144
  onNode: Node;
141
145
  bytecode?: Encoded.ContractBytearray;
142
146
  aci: Aci;
143
147
  address?: Encoded.ContractAddress;
148
+ /**
149
+ * Supported only in Ceres
150
+ */
151
+ name?: AensName;
144
152
  sourceCodePath?: Parameters<CompilerBase['compile']>[0];
145
153
  sourceCode?: Parameters<CompilerBase['compileBySourceCode']>[0];
146
154
  fileSystem?: Parameters<CompilerBase['compileBySourceCode']>[1];
@@ -1,9 +1,11 @@
1
1
  import _classPrivateFieldSet from "@babel/runtime-corejs3/helpers/classPrivateFieldSet";
2
2
  import _classPrivateFieldGet from "@babel/runtime-corejs3/helpers/classPrivateFieldGet";
3
+ var _Contract;
3
4
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
4
5
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
5
6
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
6
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
7
+ function _classPrivateMethodGet(receiver, privateSet, fn) { _assertClassBrand(privateSet, receiver); return fn; }
8
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
7
9
  /**
8
10
  * Contract module - routines to interact with the æternity contract
9
11
  *
@@ -15,13 +17,15 @@ import _aeternityAeppCalldata from '@aeternity/aepp-calldata';
15
17
  const {
16
18
  Encoder: Calldata
17
19
  } = _aeternityAeppCalldata;
18
- import { DRY_RUN_ACCOUNT } from "../tx/builder/schema.mjs";
19
- import { Tag } from "../tx/builder/constants.mjs";
20
+ import { Tag, ConsensusProtocolVersion, DRY_RUN_ACCOUNT } from "../tx/builder/constants.mjs";
20
21
  import { buildContractIdByContractTx, unpackTx, buildTxAsync, buildTxHash } from "../tx/builder/index.mjs";
21
22
  import { decode } from "../utils/encoder.mjs";
22
23
  import { MissingContractDefError, MissingContractAddressError, InactiveContractError, BytecodeMismatchError, DuplicateContractError, MissingFunctionNameError, InvalidMethodInvocationError, NotPayableFunctionError, TypeError as _TypeError, NodeInvocationError, IllegalArgumentError, NoSuchContractFunctionError, MissingEventDefinitionError, AmbiguousEventDefinitionError, UnexpectedTsError, InternalError, NoWalletConnectedError, ContractError } from "../utils/errors.mjs";
23
24
  import { hash as calcHash } from "../utils/crypto.mjs";
24
- import { getAccount, getContract, getContractByteCode, resolveName, txDryRun, sendTransaction } from "../chain.mjs";
25
+ import { getAccount, getContract, getContractByteCode, resolveName, txDryRun } from "../chain.mjs";
26
+ import { sendTransaction } from "../send-transaction.mjs";
27
+ import { isAccountNotFoundError } from "../utils/other.mjs";
28
+ import { isNameValid, produceNameId } from "../tx/builder/helpers.mjs";
25
29
  var _getCallResult = /*#__PURE__*/new WeakSet();
26
30
  var _sendAndProcess = /*#__PURE__*/new WeakSet();
27
31
  var _getFunctionAci = /*#__PURE__*/new WeakSet();
@@ -41,7 +45,7 @@ var _aciContract = /*#__PURE__*/new WeakMap();
41
45
  * const staticCallResult = await contractIns.$call('setState', [123], { callStatic: true })
42
46
  * ```
43
47
  * Also you can call contract like: `await contractIns.setState(123, options)`
44
- * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
48
+ * Then sdk decide to make on-chain or static call (dry-run API) transaction based on function is
45
49
  * stateful or not
46
50
  */
47
51
  class Contract {
@@ -82,8 +86,7 @@ class Contract {
82
86
  result: callInfoTyped
83
87
  };
84
88
  }
85
- async _estimateGas(name, params) {
86
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
89
+ async _estimateGas(name, params, options = {}) {
87
90
  const {
88
91
  result
89
92
  } = await this.$call(name, params, {
@@ -123,6 +126,7 @@ class Contract {
123
126
  const ownerId = opt.onAccount.address;
124
127
  if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t deploy without bytecode');
125
128
  const tx = await buildTxAsync({
129
+ _isInternalBuild: true,
126
130
  ...opt,
127
131
  tag: Tag.ContractCreateTx,
128
132
  gasLimit: (_opt$gasLimit = opt.gasLimit) !== null && _opt$gasLimit !== void 0 ? _opt$gasLimit : await this._estimateGas('init', params, opt),
@@ -130,7 +134,6 @@ class Contract {
130
134
  code: this.$options.bytecode,
131
135
  ownerId
132
136
  });
133
- this.$options.address = buildContractIdByContractTx(tx);
134
137
  const {
135
138
  hash,
136
139
  ...other
@@ -138,6 +141,7 @@ class Contract {
138
141
  ...opt,
139
142
  onAccount: opt.onAccount
140
143
  });
144
+ this.$options.address = buildContractIdByContractTx(other.rawTx);
141
145
  return {
142
146
  ...other,
143
147
  ...(((_other$result = other.result) === null || _other$result === void 0 ? void 0 : _other$result.log) != null && {
@@ -162,9 +166,8 @@ class Contract {
162
166
  * @param options - Array of function arguments
163
167
  * @returns CallResult
164
168
  */
165
- async $call(fn, params) {
169
+ async $call(fn, params, options = {}) {
166
170
  var _opt$gasLimit2;
167
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
168
171
  const {
169
172
  callStatic,
170
173
  top,
@@ -174,7 +177,12 @@ class Contract {
174
177
  ...options
175
178
  };
176
179
  const fnAci = _classPrivateMethodGet(this, _getFunctionAci, _getFunctionAci2).call(this, fn);
177
- const contractId = this.$options.address;
180
+ const {
181
+ address,
182
+ name
183
+ } = this.$options;
184
+ // TODO: call `produceNameId` on buildTx side
185
+ const contractId = name != null ? produceNameId(name) : address;
178
186
  const {
179
187
  onNode
180
188
  } = opt;
@@ -194,12 +202,21 @@ class Contract {
194
202
  }
195
203
  const callData = this._calldata.encode(this._name, fn, params);
196
204
  if (callStatic === true) {
197
- if (opt.nonce == null && top != null) {
198
- const topKey = typeof top === 'number' ? 'height' : 'hash';
199
- opt.nonce = (await getAccount(callerId, {
200
- [topKey]: top,
205
+ if (opt.nonce == null) {
206
+ const topOption = top != null && {
207
+ [typeof top === 'number' ? 'height' : 'hash']: top
208
+ };
209
+ const account = await getAccount(callerId, {
210
+ ...topOption,
201
211
  onNode
202
- })).nonce + 1;
212
+ }).catch(error => {
213
+ if (!isAccountNotFoundError(error)) throw error;
214
+ return {
215
+ kind: 'basic',
216
+ nonce: 0
217
+ };
218
+ });
219
+ opt.nonce = account.kind === 'generalized' ? 0 : account.nonce + 1;
203
220
  }
204
221
  const txOpt = {
205
222
  ...opt,
@@ -248,6 +265,7 @@ class Contract {
248
265
  if (top != null) throw new IllegalArgumentError('Can\'t handle `top` option in on-chain contract call');
249
266
  if (contractId == null) throw new MissingContractAddressError('Can\'t call contract without address');
250
267
  const tx = await buildTxAsync({
268
+ _isInternalBuild: true,
251
269
  ...opt,
252
270
  tag: Tag.ContractCallTx,
253
271
  gasLimit: (_opt$gasLimit2 = opt.gasLimit) !== null && _opt$gasLimit2 !== void 0 ? _opt$gasLimit2 : await this._estimateGas(fn, params, opt),
@@ -277,11 +295,10 @@ class Contract {
277
295
  * @param options - Options
278
296
  * @returns DecodedEvents
279
297
  */
280
- $decodeEvents(events) {
281
- let {
282
- omitUnknown,
283
- ...opt
284
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
298
+ $decodeEvents(events, {
299
+ omitUnknown,
300
+ ...opt
301
+ } = {}) {
285
302
  return events.map(event => {
286
303
  const topics = event.topics.map(t => BigInt(t));
287
304
  let contractName;
@@ -303,19 +320,18 @@ class Contract {
303
320
  };
304
321
  }).filter(e => e != null);
305
322
  }
306
- static async initialize(_ref) {
307
- let {
308
- onCompiler,
309
- onNode,
310
- bytecode,
311
- aci,
312
- address,
313
- sourceCodePath,
314
- sourceCode,
315
- fileSystem,
316
- validateBytecode,
317
- ...otherOptions
318
- } = _ref;
323
+ static async initialize({
324
+ onCompiler,
325
+ onNode,
326
+ bytecode,
327
+ aci,
328
+ address,
329
+ sourceCodePath,
330
+ sourceCode,
331
+ fileSystem,
332
+ validateBytecode,
333
+ ...otherOptions
334
+ }) {
319
335
  if (aci == null && onCompiler != null) {
320
336
  let res;
321
337
  if (sourceCodePath != null) res = await onCompiler.compile(sourceCodePath);
@@ -327,11 +343,14 @@ class Contract {
327
343
  }
328
344
  }
329
345
  if (aci == null) throw new MissingContractDefError();
346
+ let name;
330
347
  if (address != null) {
331
348
  address = await resolveName(address, 'contract_pubkey', {
332
349
  resolveByNode: true,
333
350
  onNode
334
351
  });
352
+ const isIris = (await onNode.getNodeInfo()).consensusProtocolVersion === ConsensusProtocolVersion.Iris;
353
+ if (!isIris && isNameValid(address)) name = address;
335
354
  }
336
355
  if (address == null && sourceCode == null && sourceCodePath == null && bytecode == null) {
337
356
  throw new MissingContractAddressError('Can\'t create instance by ACI without address');
@@ -367,16 +386,18 @@ class Contract {
367
386
  bytecode,
368
387
  aci,
369
388
  address,
389
+ name,
370
390
  fileSystem,
371
391
  ...otherOptions
372
392
  });
373
393
  }
374
- constructor(_ref2) {
375
- var _this = this;
376
- let {
377
- aci,
378
- ...otherOptions
379
- } = _ref2;
394
+ /**
395
+ * @param options - Options
396
+ */
397
+ constructor({
398
+ aci,
399
+ ...otherOptions
400
+ }) {
380
401
  _classPrivateMethodInitSpec(this, _getContractNameByEvent);
381
402
  _classPrivateMethodInitSpec(this, _getFunctionAci);
382
403
  _classPrivateMethodInitSpec(this, _sendAndProcess);
@@ -409,24 +430,20 @@ class Contract {
409
430
  * await contract.testFunction({ callStatic: false }) // send tx on-chain
410
431
  * ```
411
432
  */
412
- Object.assign(this, Object.fromEntries(_classPrivateFieldGet(this, _aciContract).functions.map(_ref3 => {
413
- let {
414
- name,
415
- arguments: aciArgs,
416
- stateful
417
- } = _ref3;
433
+ Object.assign(this, Object.fromEntries(_classPrivateFieldGet(this, _aciContract).functions.map(({
434
+ name,
435
+ arguments: aciArgs,
436
+ stateful
437
+ }) => {
418
438
  const callStatic = name !== 'init' && !stateful;
419
- return [name, async function () {
420
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
421
- args[_key] = arguments[_key];
422
- }
439
+ return [name, async (...args) => {
423
440
  const options = args.length === aciArgs.length + 1 ? args.pop() : {};
424
441
  if (typeof options !== 'object') throw new _TypeError(`Options should be an object: ${options}`);
425
- if (name === 'init') return _this.$deploy(args, {
442
+ if (name === 'init') return this.$deploy(args, {
426
443
  callStatic,
427
444
  ...options
428
445
  });
429
- return _this.$call(name, args, {
446
+ return this.$call(name, args, {
430
447
  callStatic,
431
448
  ...options
432
449
  });
@@ -434,12 +451,12 @@ class Contract {
434
451
  })));
435
452
  }
436
453
  }
437
- function _getCallResult2(_ref4, fnName, transaction, options) {
438
- let {
439
- returnType,
440
- returnValue,
441
- log
442
- } = _ref4;
454
+ _Contract = Contract;
455
+ function _getCallResult2({
456
+ returnType,
457
+ returnValue,
458
+ log
459
+ }, fnName, transaction, options) {
443
460
  let message;
444
461
  switch (returnType) {
445
462
  case 'ok':
@@ -488,12 +505,11 @@ function _getFunctionAci2(name) {
488
505
  stateful: true
489
506
  };
490
507
  }
491
- throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`);
508
+ throw new NoSuchContractFunctionError(name);
492
509
  }
493
- function _getContractNameByEvent2(ctAddress, nameHash, _ref5) {
494
- let {
495
- contractAddressToName
496
- } = _ref5;
510
+ function _getContractNameByEvent2(ctAddress, nameHash, {
511
+ contractAddressToName
512
+ }) {
497
513
  const addressToName = {
498
514
  ...this.$options.contractAddressToName,
499
515
  ...contractAddressToName
@@ -502,22 +518,10 @@ function _getContractNameByEvent2(ctAddress, nameHash, _ref5) {
502
518
 
503
519
  // TODO: consider using a third-party library
504
520
  const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
505
- const contracts = this._aci.map(_ref6 => {
506
- let {
507
- contract
508
- } = _ref6;
509
- return contract;
510
- }).filter(contract => contract === null || contract === void 0 ? void 0 : contract.event);
511
- const matchedEvents = contracts.map(contract => [contract.name, contract.event.variant]).map(_ref7 => {
512
- let [name, events] = _ref7;
513
- return events.map(event => [name, Object.keys(event)[0], Object.values(event)[0]]);
514
- }).flat().filter(_ref8 => {
515
- let [, eventName] = _ref8;
516
- return BigInt(`0x${calcHash(eventName).toString('hex')}`) === nameHash;
517
- }).filter((_ref9, idx, arr) => {
518
- let [,, type] = _ref9;
519
- return !arr.slice(0, idx).some(el => isEqual(el[2], type));
520
- });
521
+ const contracts = this._aci.map(({
522
+ contract
523
+ }) => contract).filter(contract => contract === null || contract === void 0 ? void 0 : contract.event);
524
+ const matchedEvents = contracts.map(contract => [contract.name, contract.event.variant]).map(([name, events]) => events.map(event => [name, Object.keys(event)[0], Object.values(event)[0]])).flat().filter(([, eventName]) => BigInt(`0x${calcHash(eventName).toString('hex')}`) === nameHash).filter(([,, type], idx, arr) => !arr.slice(0, idx).some(el => isEqual(el[2], type)));
521
525
  switch (matchedEvents.length) {
522
526
  case 0:
523
527
  throw new MissingEventDefinitionError(nameHash.toString(), ctAddress);