@aeternity/aepp-sdk 13.2.2 → 13.3.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 (494) 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 +9171 -7086
  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.mjs +31 -27
  26. package/es/Middleware.mjs.map +1 -1
  27. package/es/MiddlewareSubscriber.mjs +5 -14
  28. package/es/MiddlewareSubscriber.mjs.map +1 -1
  29. package/es/Node.d.ts +10 -2
  30. package/es/Node.mjs +53 -54
  31. package/es/Node.mjs.map +1 -1
  32. package/es/account/Base.d.ts +39 -3
  33. package/es/account/Base.mjs +35 -1
  34. package/es/account/Base.mjs.map +1 -1
  35. package/es/account/Generalized.d.ts +2 -0
  36. package/es/account/Generalized.mjs +15 -6
  37. package/es/account/Generalized.mjs.map +1 -1
  38. package/es/account/Ledger.d.ts +2 -0
  39. package/es/account/Ledger.mjs +14 -5
  40. package/es/account/Ledger.mjs.map +1 -1
  41. package/es/account/LedgerFactory.mjs +4 -6
  42. package/es/account/LedgerFactory.mjs.map +1 -1
  43. package/es/account/Memory.d.ts +15 -4
  44. package/es/account/Memory.mjs +96 -31
  45. package/es/account/Memory.mjs.map +1 -1
  46. package/es/account/Rpc.d.ts +16 -5
  47. package/es/account/Rpc.mjs +94 -21
  48. package/es/account/Rpc.mjs.map +1 -1
  49. package/es/aens.d.ts +17 -44
  50. package/es/aens.mjs +32 -71
  51. package/es/aens.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/connection/Browser.mjs +3 -4
  53. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  54. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  55. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +7 -5
  56. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  57. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +8 -9
  58. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  59. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +7 -7
  60. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  61. package/es/aepp-wallet-communication/rpc/types.d.ts +14 -0
  62. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  63. package/es/aepp-wallet-communication/schema.d.ts +2 -0
  64. package/es/aepp-wallet-communication/schema.mjs +2 -0
  65. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  66. package/es/aepp-wallet-communication/wallet-detector.mjs +4 -5
  67. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  68. package/es/apis/compiler/compiler.mjs.map +1 -1
  69. package/es/apis/compiler/models/index.d.ts +1 -0
  70. package/es/apis/compiler/models/index.mjs.map +1 -1
  71. package/es/apis/compiler/models/mappers.mjs +13 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  73. package/es/apis/compiler/models/parameters.mjs.map +1 -1
  74. package/es/apis/middleware/middleware.d.ts +23 -5
  75. package/es/apis/middleware/middleware.mjs +114 -18
  76. package/es/apis/middleware/middleware.mjs.map +1 -1
  77. package/es/apis/middleware/models/index.d.ts +164 -15
  78. package/es/apis/middleware/models/index.mjs +53 -3
  79. package/es/apis/middleware/models/index.mjs.map +1 -1
  80. package/es/apis/middleware/models/mappers.d.ts +8 -1
  81. package/es/apis/middleware/models/mappers.mjs +376 -3
  82. package/es/apis/middleware/models/mappers.mjs.map +1 -1
  83. package/es/apis/middleware/models/parameters.d.ts +6 -3
  84. package/es/apis/middleware/models/parameters.mjs +38 -11
  85. package/es/apis/middleware/models/parameters.mjs.map +1 -1
  86. package/es/apis/node/models/index.d.ts +66 -2
  87. package/es/apis/node/models/index.mjs.map +1 -1
  88. package/es/apis/node/models/mappers.d.ts +5 -1
  89. package/es/apis/node/models/mappers.mjs +229 -7
  90. package/es/apis/node/models/mappers.mjs.map +1 -1
  91. package/es/apis/node/models/parameters.d.ts +2 -2
  92. package/es/apis/node/models/parameters.mjs +2 -2
  93. package/es/apis/node/models/parameters.mjs.map +1 -1
  94. package/es/apis/node/node.d.ts +24 -3
  95. package/es/apis/node/node.mjs +135 -3
  96. package/es/apis/node/node.mjs.map +1 -1
  97. package/es/chain.d.ts +14 -44
  98. package/es/chain.mjs +125 -219
  99. package/es/chain.mjs.map +1 -1
  100. package/es/channel/Base.d.ts +3 -47
  101. package/es/channel/Base.mjs +21 -54
  102. package/es/channel/Base.mjs.map +1 -1
  103. package/es/channel/Contract.d.ts +16 -25
  104. package/es/channel/Contract.mjs +39 -63
  105. package/es/channel/Contract.mjs.map +1 -1
  106. package/es/channel/Spend.d.ts +0 -8
  107. package/es/channel/Spend.mjs +17 -29
  108. package/es/channel/Spend.mjs.map +1 -1
  109. package/es/channel/handlers.mjs +1 -1
  110. package/es/channel/handlers.mjs.map +1 -1
  111. package/es/channel/internal.d.ts +104 -5
  112. package/es/channel/internal.mjs +26 -34
  113. package/es/channel/internal.mjs.map +1 -1
  114. package/es/contract/Contract.d.ts +9 -1
  115. package/es/contract/Contract.mjs +67 -73
  116. package/es/contract/Contract.mjs.map +1 -1
  117. package/es/contract/compiler/Base.d.ts +14 -8
  118. package/es/contract/compiler/Base.mjs.map +1 -1
  119. package/es/contract/compiler/Cli.d.ts +5 -9
  120. package/es/contract/compiler/Cli.mjs +45 -23
  121. package/es/contract/compiler/Cli.mjs.map +1 -1
  122. package/es/contract/compiler/Cli8.d.ts +13 -0
  123. package/es/contract/compiler/Cli8.mjs +22 -0
  124. package/es/contract/compiler/Cli8.mjs.map +1 -0
  125. package/es/contract/compiler/Http.d.ts +3 -9
  126. package/es/contract/compiler/Http.mjs +28 -16
  127. package/es/contract/compiler/Http.mjs.map +1 -1
  128. package/es/contract/compiler/HttpNode.d.ts +2 -5
  129. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  130. package/es/contract/delegation-signature.d.ts +2 -1
  131. package/es/contract/delegation-signature.mjs +18 -14
  132. package/es/contract/delegation-signature.mjs.map +1 -1
  133. package/es/contract/ga.d.ts +1 -2
  134. package/es/contract/ga.mjs +23 -25
  135. package/es/contract/ga.mjs.map +1 -1
  136. package/es/deprecated.d.ts +38 -0
  137. package/es/deprecated.mjs +45 -0
  138. package/es/deprecated.mjs.map +1 -1
  139. package/es/index-browser.d.ts +10 -5
  140. package/es/index-browser.mjs +9 -5
  141. package/es/index-browser.mjs.map +1 -1
  142. package/es/index.d.ts +1 -0
  143. package/es/index.mjs +1 -0
  144. package/es/index.mjs.map +1 -1
  145. package/es/oracle.d.ts +6 -37
  146. package/es/oracle.mjs +32 -66
  147. package/es/oracle.mjs.map +1 -1
  148. package/es/send-transaction.d.ts +53 -0
  149. package/es/send-transaction.mjs +109 -0
  150. package/es/send-transaction.mjs.map +1 -0
  151. package/es/spend.d.ts +4 -3
  152. package/es/spend.mjs +6 -1
  153. package/es/spend.mjs.map +1 -1
  154. package/es/tx/builder/common.d.ts +29 -0
  155. package/es/tx/builder/common.mjs +42 -0
  156. package/es/tx/builder/common.mjs.map +1 -0
  157. package/es/tx/builder/constants.d.ts +4 -4
  158. package/es/tx/builder/constants.mjs +6 -15
  159. package/es/tx/builder/constants.mjs.map +1 -1
  160. package/es/tx/builder/delegation/index.d.ts +20 -0
  161. package/es/tx/builder/delegation/index.mjs +24 -0
  162. package/es/tx/builder/delegation/index.mjs.map +1 -0
  163. package/es/tx/builder/delegation/schema.d.ts +130 -0
  164. package/es/tx/builder/delegation/schema.generated.d.ts +141 -0
  165. package/es/tx/builder/delegation/schema.generated.mjs +2 -0
  166. package/es/tx/builder/delegation/schema.generated.mjs.map +1 -0
  167. package/es/tx/builder/delegation/schema.mjs +54 -0
  168. package/es/tx/builder/delegation/schema.mjs.map +1 -0
  169. package/es/tx/builder/field-types/abi-version.mjs +8 -11
  170. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  171. package/es/tx/builder/field-types/address.mjs +1 -4
  172. package/es/tx/builder/field-types/address.mjs.map +1 -1
  173. package/es/tx/builder/field-types/coin-amount.d.ts +2 -2
  174. package/es/tx/builder/field-types/coin-amount.mjs +6 -6
  175. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  176. package/es/tx/builder/field-types/ct-version.mjs +3 -4
  177. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  178. package/es/tx/builder/field-types/entry.mjs +7 -13
  179. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  180. package/es/tx/builder/field-types/fee.d.ts +19 -11
  181. package/es/tx/builder/field-types/fee.mjs +56 -38
  182. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  183. package/es/tx/builder/field-types/gas-limit.mjs +13 -15
  184. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  185. package/es/tx/builder/field-types/gas-price.d.ts +10 -2
  186. package/es/tx/builder/field-types/gas-price.mjs +52 -3
  187. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  188. package/es/tx/builder/field-types/index.d.ts +31 -29
  189. package/es/tx/builder/field-types/index.mjs +31 -29
  190. package/es/tx/builder/field-types/index.mjs.map +1 -1
  191. package/es/tx/builder/field-types/map.mjs +20 -31
  192. package/es/tx/builder/field-types/map.mjs.map +1 -1
  193. package/es/tx/builder/field-types/mptree.mjs +14 -29
  194. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  195. package/es/tx/builder/field-types/name-fee.d.ts +1 -1
  196. package/es/tx/builder/field-types/name-fee.mjs +1 -1
  197. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  198. package/es/tx/builder/field-types/nonce.d.ts +1 -0
  199. package/es/tx/builder/field-types/nonce.mjs +2 -0
  200. package/es/tx/builder/field-types/nonce.mjs.map +1 -1
  201. package/es/tx/builder/field-types/pointers.mjs +4 -7
  202. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  203. package/es/tx/builder/field-types/pointers2.d.ts +23 -0
  204. package/es/tx/builder/field-types/pointers2.mjs +65 -0
  205. package/es/tx/builder/field-types/pointers2.mjs.map +1 -0
  206. package/es/tx/builder/field-types/query-fee.d.ts +19 -0
  207. package/es/tx/builder/field-types/query-fee.mjs +20 -0
  208. package/es/tx/builder/field-types/query-fee.mjs.map +1 -0
  209. package/es/tx/builder/field-types/ttl.d.ts +9 -1
  210. package/es/tx/builder/field-types/ttl.mjs +19 -8
  211. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  212. package/es/tx/builder/field-types/with-default.d.ts +7 -0
  213. package/es/tx/builder/field-types/with-default.mjs +9 -0
  214. package/es/tx/builder/field-types/with-default.mjs.map +1 -0
  215. package/es/tx/builder/field-types/with-formatting.d.ts +7 -0
  216. package/es/tx/builder/field-types/with-formatting.mjs +9 -0
  217. package/es/tx/builder/field-types/with-formatting.mjs.map +1 -0
  218. package/es/tx/builder/field-types/wrapped.mjs +6 -8
  219. package/es/tx/builder/field-types/wrapped.mjs.map +1 -1
  220. package/es/tx/builder/helpers.d.ts +2 -2
  221. package/es/tx/builder/helpers.mjs +12 -21
  222. package/es/tx/builder/helpers.mjs.map +1 -1
  223. package/es/tx/builder/index.d.ts +17 -10
  224. package/es/tx/builder/index.mjs +39 -65
  225. package/es/tx/builder/index.mjs.map +1 -1
  226. package/es/tx/builder/schema.d.ts +478 -257
  227. package/es/tx/builder/schema.generated.d.ts +39 -3
  228. package/es/tx/builder/schema.generated.mjs.map +1 -1
  229. package/es/tx/builder/schema.mjs +48 -36
  230. package/es/tx/builder/schema.mjs.map +1 -1
  231. package/es/tx/execution-cost.d.ts +6 -5
  232. package/es/tx/execution-cost.mjs +16 -17
  233. package/es/tx/execution-cost.mjs.map +1 -1
  234. package/es/tx/transaction-signer.mjs +1 -4
  235. package/es/tx/transaction-signer.mjs.map +1 -1
  236. package/es/tx/validator.mjs +61 -42
  237. package/es/tx/validator.mjs.map +1 -1
  238. package/es/utils/amount-formatter.mjs +15 -22
  239. package/es/utils/amount-formatter.mjs.map +1 -1
  240. package/es/utils/autorest.d.ts +2 -3
  241. package/es/utils/autorest.mjs +40 -24
  242. package/es/utils/autorest.mjs.map +1 -1
  243. package/es/utils/bytes.mjs +1 -2
  244. package/es/utils/bytes.mjs.map +1 -1
  245. package/es/utils/crypto.d.ts +8 -4
  246. package/es/utils/crypto.mjs +17 -13
  247. package/es/utils/crypto.mjs.map +1 -1
  248. package/es/utils/errors.d.ts +6 -0
  249. package/es/utils/errors.mjs +12 -6
  250. package/es/utils/errors.mjs.map +1 -1
  251. package/es/utils/hd-wallet.d.ts +2 -0
  252. package/es/utils/hd-wallet.mjs +6 -5
  253. package/es/utils/hd-wallet.mjs.map +1 -1
  254. package/es/utils/json-big.mjs +2 -10
  255. package/es/utils/json-big.mjs.map +1 -1
  256. package/es/utils/jwt.d.ts +53 -0
  257. package/es/utils/jwt.mjs +120 -0
  258. package/es/utils/jwt.mjs.map +1 -0
  259. package/es/utils/keystore.d.ts +6 -2
  260. package/es/utils/keystore.mjs +8 -16
  261. package/es/utils/keystore.mjs.map +1 -1
  262. package/es/utils/typed-data.mjs +1 -0
  263. package/es/utils/typed-data.mjs.map +1 -1
  264. package/es/utils/wrap-proxy.d.ts +2 -0
  265. package/es/utils/wrap-proxy.mjs +15 -0
  266. package/es/utils/wrap-proxy.mjs.map +1 -0
  267. package/package.json +57 -51
  268. package/src/AeSdk.ts +3 -0
  269. package/src/AeSdkAepp.ts +0 -1
  270. package/src/AeSdkBase.ts +97 -10
  271. package/src/AeSdkMethods.ts +37 -33
  272. package/src/AeSdkWallet.ts +22 -3
  273. package/src/Middleware.ts +16 -8
  274. package/src/MiddlewareSubscriber.ts +1 -1
  275. package/src/Node.ts +37 -18
  276. package/src/account/Base.ts +62 -3
  277. package/src/account/Generalized.ts +10 -0
  278. package/src/account/Ledger.ts +10 -0
  279. package/src/account/Memory.ts +83 -9
  280. package/src/account/Rpc.ts +69 -6
  281. package/src/aens.ts +35 -56
  282. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +3 -0
  283. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +2 -2
  284. package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -2
  285. package/src/aepp-wallet-communication/rpc/types.ts +13 -0
  286. package/src/aepp-wallet-communication/schema.ts +2 -0
  287. package/src/apis/compiler/compiler.ts +93 -93
  288. package/src/apis/compiler/models/index.ts +1 -0
  289. package/src/apis/compiler/models/mappers.ts +178 -165
  290. package/src/apis/compiler/models/parameters.ts +18 -18
  291. package/src/apis/middleware/middleware.ts +462 -341
  292. package/src/apis/middleware/models/index.ts +258 -56
  293. package/src/apis/middleware/models/mappers.ts +2357 -1919
  294. package/src/apis/middleware/models/parameters.ts +172 -142
  295. package/src/apis/node/models/index.ts +79 -2
  296. package/src/apis/node/models/mappers.ts +1529 -1302
  297. package/src/apis/node/models/parameters.ts +51 -51
  298. package/src/apis/node/node.ts +420 -275
  299. package/src/chain.ts +42 -128
  300. package/src/channel/Base.ts +14 -47
  301. package/src/channel/Contract.ts +18 -26
  302. package/src/channel/Spend.ts +0 -8
  303. package/src/channel/internal.ts +115 -13
  304. package/src/contract/Contract.ts +26 -8
  305. package/src/contract/compiler/Base.ts +15 -8
  306. package/src/contract/compiler/Cli.ts +37 -21
  307. package/src/contract/compiler/Cli8.ts +17 -0
  308. package/src/contract/compiler/Http.ts +24 -14
  309. package/src/contract/compiler/HttpNode.ts +2 -2
  310. package/src/contract/delegation-signature.ts +11 -5
  311. package/src/contract/ga.ts +4 -3
  312. package/src/deprecated.ts +36 -0
  313. package/src/index-browser.ts +14 -7
  314. package/src/index.ts +1 -0
  315. package/src/oracle.ts +11 -54
  316. package/src/send-transaction.ts +136 -0
  317. package/src/spend.ts +25 -11
  318. package/src/tx/builder/common.ts +74 -0
  319. package/src/tx/builder/constants.ts +6 -9
  320. package/src/tx/builder/delegation/index.ts +28 -0
  321. package/src/tx/builder/delegation/schema.generated.ts +143 -0
  322. package/src/tx/builder/delegation/schema.ts +61 -0
  323. package/src/tx/builder/field-types/coin-amount.ts +3 -2
  324. package/src/tx/builder/field-types/entry.ts +1 -4
  325. package/src/tx/builder/field-types/fee.ts +71 -43
  326. package/src/tx/builder/field-types/gas-limit.ts +4 -4
  327. package/src/tx/builder/field-types/gas-price.ts +70 -14
  328. package/src/tx/builder/field-types/index.ts +31 -59
  329. package/src/tx/builder/field-types/name-fee.ts +1 -1
  330. package/src/tx/builder/field-types/nonce.ts +7 -1
  331. package/src/tx/builder/field-types/pointers2.ts +62 -0
  332. package/src/tx/builder/field-types/query-fee.ts +25 -0
  333. package/src/tx/builder/field-types/ttl.ts +13 -3
  334. package/src/tx/builder/field-types/with-default.ts +18 -0
  335. package/src/tx/builder/field-types/with-formatting.ts +18 -0
  336. package/src/tx/builder/helpers.ts +2 -2
  337. package/src/tx/builder/index.ts +42 -59
  338. package/src/tx/builder/schema.generated.ts +39 -3
  339. package/src/tx/builder/schema.ts +55 -29
  340. package/src/tx/execution-cost.ts +6 -5
  341. package/src/tx/validator.ts +31 -5
  342. package/src/utils/autorest.ts +36 -27
  343. package/src/utils/crypto.ts +23 -13
  344. package/src/utils/errors.ts +10 -0
  345. package/src/utils/hd-wallet.ts +2 -0
  346. package/src/utils/jwt.ts +126 -0
  347. package/src/utils/keystore.ts +6 -2
  348. package/src/utils/wrap-proxy.ts +24 -0
  349. package/types-legacy/ts4.2/AeSdk.d.ts +3 -0
  350. package/types-legacy/ts4.2/AeSdkAepp.d.ts +0 -1
  351. package/types-legacy/ts4.2/AeSdkBase.d.ts +61 -6
  352. package/types-legacy/ts4.2/AeSdkMethods.d.ts +19 -7
  353. package/types-legacy/ts4.2/Node.d.ts +14 -1
  354. package/types-legacy/ts4.2/account/Base.d.ts +39 -3
  355. package/types-legacy/ts4.2/account/Generalized.d.ts +2 -0
  356. package/types-legacy/ts4.2/account/Ledger.d.ts +2 -0
  357. package/types-legacy/ts4.2/account/Memory.d.ts +15 -4
  358. package/types-legacy/ts4.2/account/Rpc.d.ts +16 -5
  359. package/types-legacy/ts4.2/aens.d.ts +17 -44
  360. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  361. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +14 -0
  362. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -0
  363. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -0
  364. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +23 -5
  365. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +164 -15
  366. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +8 -1
  367. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +6 -3
  368. package/types-legacy/ts4.2/apis/node/models/index.d.ts +66 -2
  369. package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +5 -1
  370. package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
  371. package/types-legacy/ts4.2/apis/node/node.d.ts +24 -3
  372. package/types-legacy/ts4.2/chain.d.ts +14 -44
  373. package/types-legacy/ts4.2/channel/Base.d.ts +3 -47
  374. package/types-legacy/ts4.2/channel/Contract.d.ts +16 -25
  375. package/types-legacy/ts4.2/channel/Spend.d.ts +0 -8
  376. package/types-legacy/ts4.2/channel/internal.d.ts +104 -5
  377. package/types-legacy/ts4.2/contract/Contract.d.ts +9 -1
  378. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +14 -8
  379. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +5 -9
  380. package/types-legacy/ts4.2/contract/compiler/Cli8.d.ts +13 -0
  381. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +3 -9
  382. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +2 -5
  383. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  384. package/types-legacy/ts4.2/contract/ga.d.ts +1 -2
  385. package/types-legacy/ts4.2/deprecated.d.ts +38 -0
  386. package/types-legacy/ts4.2/index-browser.d.ts +10 -5
  387. package/types-legacy/ts4.2/index.d.ts +1 -0
  388. package/types-legacy/ts4.2/oracle.d.ts +6 -37
  389. package/types-legacy/ts4.2/send-transaction.d.ts +53 -0
  390. package/types-legacy/ts4.2/spend.d.ts +4 -3
  391. package/types-legacy/ts4.2/tx/builder/common.d.ts +32 -0
  392. package/types-legacy/ts4.2/tx/builder/constants.d.ts +4 -4
  393. package/types-legacy/ts4.2/tx/builder/delegation/index.d.ts +20 -0
  394. package/types-legacy/ts4.2/tx/builder/delegation/schema.d.ts +136 -0
  395. package/types-legacy/ts4.2/tx/builder/delegation/schema.generated.d.ts +141 -0
  396. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +2 -2
  397. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +19 -11
  398. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +10 -2
  399. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +31 -29
  400. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -1
  401. package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +1 -0
  402. package/types-legacy/ts4.2/tx/builder/field-types/pointers2.d.ts +26 -0
  403. package/types-legacy/ts4.2/tx/builder/field-types/query-fee.d.ts +19 -0
  404. package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +9 -1
  405. package/types-legacy/ts4.2/tx/builder/field-types/with-default.d.ts +7 -0
  406. package/types-legacy/ts4.2/tx/builder/field-types/with-formatting.d.ts +7 -0
  407. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +2 -2
  408. package/types-legacy/ts4.2/tx/builder/index.d.ts +17 -10
  409. package/types-legacy/ts4.2/tx/builder/schema.d.ts +482 -257
  410. package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +39 -3
  411. package/types-legacy/ts4.2/tx/execution-cost.d.ts +6 -5
  412. package/types-legacy/ts4.2/utils/autorest.d.ts +2 -3
  413. package/types-legacy/ts4.2/utils/crypto.d.ts +8 -4
  414. package/types-legacy/ts4.2/utils/errors.d.ts +6 -0
  415. package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -0
  416. package/types-legacy/ts4.2/utils/jwt.d.ts +53 -0
  417. package/types-legacy/ts4.2/utils/keystore.d.ts +6 -2
  418. package/types-legacy/ts4.2/utils/wrap-proxy.d.ts +2 -0
  419. package/types-legacy/ts4.5/AeSdk.d.ts +3 -0
  420. package/types-legacy/ts4.5/AeSdkAepp.d.ts +0 -1
  421. package/types-legacy/ts4.5/AeSdkBase.d.ts +61 -6
  422. package/types-legacy/ts4.5/AeSdkMethods.d.ts +19 -7
  423. package/types-legacy/ts4.5/Node.d.ts +14 -1
  424. package/types-legacy/ts4.5/account/Base.d.ts +39 -3
  425. package/types-legacy/ts4.5/account/Generalized.d.ts +2 -0
  426. package/types-legacy/ts4.5/account/Ledger.d.ts +2 -0
  427. package/types-legacy/ts4.5/account/Memory.d.ts +15 -4
  428. package/types-legacy/ts4.5/account/Rpc.d.ts +16 -5
  429. package/types-legacy/ts4.5/aens.d.ts +17 -44
  430. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  431. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +14 -0
  432. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -0
  433. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -0
  434. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +23 -5
  435. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +164 -15
  436. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +8 -1
  437. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +6 -3
  438. package/types-legacy/ts4.5/apis/node/models/index.d.ts +66 -2
  439. package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +5 -1
  440. package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
  441. package/types-legacy/ts4.5/apis/node/node.d.ts +24 -3
  442. package/types-legacy/ts4.5/chain.d.ts +14 -44
  443. package/types-legacy/ts4.5/channel/Base.d.ts +3 -47
  444. package/types-legacy/ts4.5/channel/Contract.d.ts +16 -25
  445. package/types-legacy/ts4.5/channel/Spend.d.ts +0 -8
  446. package/types-legacy/ts4.5/channel/internal.d.ts +104 -5
  447. package/types-legacy/ts4.5/contract/Contract.d.ts +9 -1
  448. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +14 -8
  449. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +5 -9
  450. package/types-legacy/ts4.5/contract/compiler/Cli8.d.ts +13 -0
  451. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +3 -9
  452. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +2 -5
  453. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  454. package/types-legacy/ts4.5/contract/ga.d.ts +1 -2
  455. package/types-legacy/ts4.5/deprecated.d.ts +38 -0
  456. package/types-legacy/ts4.5/index-browser.d.ts +10 -5
  457. package/types-legacy/ts4.5/index.d.ts +1 -0
  458. package/types-legacy/ts4.5/oracle.d.ts +6 -37
  459. package/types-legacy/ts4.5/send-transaction.d.ts +53 -0
  460. package/types-legacy/ts4.5/spend.d.ts +4 -3
  461. package/types-legacy/ts4.5/tx/builder/common.d.ts +32 -0
  462. package/types-legacy/ts4.5/tx/builder/constants.d.ts +4 -4
  463. package/types-legacy/ts4.5/tx/builder/delegation/index.d.ts +20 -0
  464. package/types-legacy/ts4.5/tx/builder/delegation/schema.d.ts +136 -0
  465. package/types-legacy/ts4.5/tx/builder/delegation/schema.generated.d.ts +141 -0
  466. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +2 -2
  467. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +19 -11
  468. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +10 -2
  469. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +31 -29
  470. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -1
  471. package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +1 -0
  472. package/types-legacy/ts4.5/tx/builder/field-types/pointers2.d.ts +26 -0
  473. package/types-legacy/ts4.5/tx/builder/field-types/query-fee.d.ts +19 -0
  474. package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +9 -1
  475. package/types-legacy/ts4.5/tx/builder/field-types/with-default.d.ts +7 -0
  476. package/types-legacy/ts4.5/tx/builder/field-types/with-formatting.d.ts +7 -0
  477. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +2 -2
  478. package/types-legacy/ts4.5/tx/builder/index.d.ts +17 -10
  479. package/types-legacy/ts4.5/tx/builder/schema.d.ts +482 -257
  480. package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +39 -3
  481. package/types-legacy/ts4.5/tx/execution-cost.d.ts +6 -5
  482. package/types-legacy/ts4.5/utils/autorest.d.ts +2 -3
  483. package/types-legacy/ts4.5/utils/crypto.d.ts +8 -4
  484. package/types-legacy/ts4.5/utils/errors.d.ts +6 -0
  485. package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -0
  486. package/types-legacy/ts4.5/utils/jwt.d.ts +53 -0
  487. package/types-legacy/ts4.5/utils/keystore.d.ts +6 -2
  488. package/types-legacy/ts4.5/utils/wrap-proxy.d.ts +2 -0
  489. package/es/tx/builder/field-types/deposit.d.ts +0 -15
  490. package/es/tx/builder/field-types/deposit.mjs +0 -18
  491. package/es/tx/builder/field-types/deposit.mjs.map +0 -1
  492. package/src/tx/builder/field-types/deposit.ts +0 -23
  493. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +0 -15
  494. 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,SAASC,IAAIA,CAClBC,OAAgB,EAEV;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EADHC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAEP,MAAM,CAACC,SAAS,EAAE,GAAGC,IAAI,CAAC,GAAGJ,IAAI;EACjCJ,OAAO,CAACS,aAAa,CAACV,IAAI,CAACQ,SAAS,EAAE,GAAGC,IAAI,CAAC;AAChD;AAEA,SAASE,UAAUA,CAACV,OAAgB,EAAEW,SAAqB,EAAQ;EAAA,IAAAC,kBAAA;EACjE,IAAID,SAAS,IAAI,IAAI,EAAE;IACrB,MAAM,IAAIpB,wBAAwB,CAAC,CAAC;EACtC;EACAS,OAAO,CAACa,IAAI,GAAGF,SAAS;EACxB,IAAI,CAAAA,SAAS,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Q,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;AAuL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yD,MAAM,EAAE,MAAOC,KAAY,IAAK;QAC9B3D,OAAO,CAAC,CAAC;QACT5B,YAAY,CAACd,OAAO,EAAE,WAAW,EAAEqG,KAAK,CAAC;QACzC,IAAIf,cAAc,CAACgB,WAAW,IAAI,IAAI,EAAE;UACtCjG,UAAU,CAACL,OAAO,EAAE;YAAES,OAAO,EAAE2E;UAAY,CAAC,CAAC;UAC7C,MAAM;YAAEmB;UAAS,CAAC,GAAG,MAAMvG,OAAO,CAAC8C,KAAK,CAAC,CAAC;UAC1C,IAAIyD,QAAQ,IAAI,IAAI,EAAE;YACpB,MAAM,IAAI9G,YAAY,CAAC,+CAA+C,CAAC;UACzE;UACAyB,WAAW,CAAClB,OAAO,EAAEL,OAAO,CAAC4G,QAAQ,CAAC,CAAC;QACzC,CAAC,MAAM;UACLlG,UAAU,CAACL,OAAO,EAAE;YAAES,OAAO,EAAE0E;UAAkB,CAAC,CAAC;QACrD;QACAlB,IAAI,CAACjE,OAAO,CAAC;MACf,CAAC;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 {
@@ -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,14 +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";
25
27
  import { isAccountNotFoundError } from "../utils/other.mjs";
28
+ import { isNameValid, produceNameId } from "../tx/builder/helpers.mjs";
26
29
  var _getCallResult = /*#__PURE__*/new WeakSet();
27
30
  var _sendAndProcess = /*#__PURE__*/new WeakSet();
28
31
  var _getFunctionAci = /*#__PURE__*/new WeakSet();
@@ -83,8 +86,7 @@ class Contract {
83
86
  result: callInfoTyped
84
87
  };
85
88
  }
86
- async _estimateGas(name, params) {
87
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
89
+ async _estimateGas(name, params, options = {}) {
88
90
  const {
89
91
  result
90
92
  } = await this.$call(name, params, {
@@ -124,6 +126,7 @@ class Contract {
124
126
  const ownerId = opt.onAccount.address;
125
127
  if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t deploy without bytecode');
126
128
  const tx = await buildTxAsync({
129
+ _isInternalBuild: true,
127
130
  ...opt,
128
131
  tag: Tag.ContractCreateTx,
129
132
  gasLimit: (_opt$gasLimit = opt.gasLimit) !== null && _opt$gasLimit !== void 0 ? _opt$gasLimit : await this._estimateGas('init', params, opt),
@@ -138,7 +141,7 @@ class Contract {
138
141
  ...opt,
139
142
  onAccount: opt.onAccount
140
143
  });
141
- this.$options.address = buildContractIdByContractTx(tx);
144
+ this.$options.address = buildContractIdByContractTx(other.rawTx);
142
145
  return {
143
146
  ...other,
144
147
  ...(((_other$result = other.result) === null || _other$result === void 0 ? void 0 : _other$result.log) != null && {
@@ -163,9 +166,8 @@ class Contract {
163
166
  * @param options - Array of function arguments
164
167
  * @returns CallResult
165
168
  */
166
- async $call(fn, params) {
169
+ async $call(fn, params, options = {}) {
167
170
  var _opt$gasLimit2;
168
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
169
171
  const {
170
172
  callStatic,
171
173
  top,
@@ -175,7 +177,12 @@ class Contract {
175
177
  ...options
176
178
  };
177
179
  const fnAci = _classPrivateMethodGet(this, _getFunctionAci, _getFunctionAci2).call(this, fn);
178
- 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;
179
186
  const {
180
187
  onNode
181
188
  } = opt;
@@ -258,6 +265,7 @@ class Contract {
258
265
  if (top != null) throw new IllegalArgumentError('Can\'t handle `top` option in on-chain contract call');
259
266
  if (contractId == null) throw new MissingContractAddressError('Can\'t call contract without address');
260
267
  const tx = await buildTxAsync({
268
+ _isInternalBuild: true,
261
269
  ...opt,
262
270
  tag: Tag.ContractCallTx,
263
271
  gasLimit: (_opt$gasLimit2 = opt.gasLimit) !== null && _opt$gasLimit2 !== void 0 ? _opt$gasLimit2 : await this._estimateGas(fn, params, opt),
@@ -287,11 +295,10 @@ class Contract {
287
295
  * @param options - Options
288
296
  * @returns DecodedEvents
289
297
  */
290
- $decodeEvents(events) {
291
- let {
292
- omitUnknown,
293
- ...opt
294
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
298
+ $decodeEvents(events, {
299
+ omitUnknown,
300
+ ...opt
301
+ } = {}) {
295
302
  return events.map(event => {
296
303
  const topics = event.topics.map(t => BigInt(t));
297
304
  let contractName;
@@ -313,19 +320,18 @@ class Contract {
313
320
  };
314
321
  }).filter(e => e != null);
315
322
  }
316
- static async initialize(_ref) {
317
- let {
318
- onCompiler,
319
- onNode,
320
- bytecode,
321
- aci,
322
- address,
323
- sourceCodePath,
324
- sourceCode,
325
- fileSystem,
326
- validateBytecode,
327
- ...otherOptions
328
- } = _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
+ }) {
329
335
  if (aci == null && onCompiler != null) {
330
336
  let res;
331
337
  if (sourceCodePath != null) res = await onCompiler.compile(sourceCodePath);
@@ -337,11 +343,14 @@ class Contract {
337
343
  }
338
344
  }
339
345
  if (aci == null) throw new MissingContractDefError();
346
+ let name;
340
347
  if (address != null) {
341
348
  address = await resolveName(address, 'contract_pubkey', {
342
349
  resolveByNode: true,
343
350
  onNode
344
351
  });
352
+ const isIris = (await onNode.getNodeInfo()).consensusProtocolVersion === ConsensusProtocolVersion.Iris;
353
+ if (!isIris && isNameValid(address)) name = address;
345
354
  }
346
355
  if (address == null && sourceCode == null && sourceCodePath == null && bytecode == null) {
347
356
  throw new MissingContractAddressError('Can\'t create instance by ACI without address');
@@ -377,16 +386,18 @@ class Contract {
377
386
  bytecode,
378
387
  aci,
379
388
  address,
389
+ name,
380
390
  fileSystem,
381
391
  ...otherOptions
382
392
  });
383
393
  }
384
- constructor(_ref2) {
385
- var _this = this;
386
- let {
387
- aci,
388
- ...otherOptions
389
- } = _ref2;
394
+ /**
395
+ * @param options - Options
396
+ */
397
+ constructor({
398
+ aci,
399
+ ...otherOptions
400
+ }) {
390
401
  _classPrivateMethodInitSpec(this, _getContractNameByEvent);
391
402
  _classPrivateMethodInitSpec(this, _getFunctionAci);
392
403
  _classPrivateMethodInitSpec(this, _sendAndProcess);
@@ -419,24 +430,20 @@ class Contract {
419
430
  * await contract.testFunction({ callStatic: false }) // send tx on-chain
420
431
  * ```
421
432
  */
422
- Object.assign(this, Object.fromEntries(_classPrivateFieldGet(this, _aciContract).functions.map(_ref3 => {
423
- let {
424
- name,
425
- arguments: aciArgs,
426
- stateful
427
- } = _ref3;
433
+ Object.assign(this, Object.fromEntries(_classPrivateFieldGet(this, _aciContract).functions.map(({
434
+ name,
435
+ arguments: aciArgs,
436
+ stateful
437
+ }) => {
428
438
  const callStatic = name !== 'init' && !stateful;
429
- return [name, async function () {
430
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
431
- args[_key] = arguments[_key];
432
- }
439
+ return [name, async (...args) => {
433
440
  const options = args.length === aciArgs.length + 1 ? args.pop() : {};
434
441
  if (typeof options !== 'object') throw new _TypeError(`Options should be an object: ${options}`);
435
- if (name === 'init') return _this.$deploy(args, {
442
+ if (name === 'init') return this.$deploy(args, {
436
443
  callStatic,
437
444
  ...options
438
445
  });
439
- return _this.$call(name, args, {
446
+ return this.$call(name, args, {
440
447
  callStatic,
441
448
  ...options
442
449
  });
@@ -444,12 +451,12 @@ class Contract {
444
451
  })));
445
452
  }
446
453
  }
447
- function _getCallResult2(_ref4, fnName, transaction, options) {
448
- let {
449
- returnType,
450
- returnValue,
451
- log
452
- } = _ref4;
454
+ _Contract = Contract;
455
+ function _getCallResult2({
456
+ returnType,
457
+ returnValue,
458
+ log
459
+ }, fnName, transaction, options) {
453
460
  let message;
454
461
  switch (returnType) {
455
462
  case 'ok':
@@ -498,12 +505,11 @@ function _getFunctionAci2(name) {
498
505
  stateful: true
499
506
  };
500
507
  }
501
- throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`);
508
+ throw new NoSuchContractFunctionError(name);
502
509
  }
503
- function _getContractNameByEvent2(ctAddress, nameHash, _ref5) {
504
- let {
505
- contractAddressToName
506
- } = _ref5;
510
+ function _getContractNameByEvent2(ctAddress, nameHash, {
511
+ contractAddressToName
512
+ }) {
507
513
  const addressToName = {
508
514
  ...this.$options.contractAddressToName,
509
515
  ...contractAddressToName
@@ -512,22 +518,10 @@ function _getContractNameByEvent2(ctAddress, nameHash, _ref5) {
512
518
 
513
519
  // TODO: consider using a third-party library
514
520
  const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
515
- const contracts = this._aci.map(_ref6 => {
516
- let {
517
- contract
518
- } = _ref6;
519
- return contract;
520
- }).filter(contract => contract === null || contract === void 0 ? void 0 : contract.event);
521
- const matchedEvents = contracts.map(contract => [contract.name, contract.event.variant]).map(_ref7 => {
522
- let [name, events] = _ref7;
523
- return events.map(event => [name, Object.keys(event)[0], Object.values(event)[0]]);
524
- }).flat().filter(_ref8 => {
525
- let [, eventName] = _ref8;
526
- return BigInt(`0x${calcHash(eventName).toString('hex')}`) === nameHash;
527
- }).filter((_ref9, idx, arr) => {
528
- let [,, type] = _ref9;
529
- return !arr.slice(0, idx).some(el => isEqual(el[2], type));
530
- });
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)));
531
525
  switch (matchedEvents.length) {
532
526
  case 0:
533
527
  throw new MissingEventDefinitionError(nameHash.toString(), ctAddress);