@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
@@ -0,0 +1,9 @@
1
+ export default function withDefault(defaultValue, field) {
2
+ return {
3
+ ...field,
4
+ serialize(value, params) {
5
+ return field.serialize(value !== null && value !== void 0 ? value : defaultValue, params);
6
+ }
7
+ };
8
+ }
9
+ //# sourceMappingURL=with-default.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-default.mjs","names":["withDefault","defaultValue","field","serialize","value","params"],"sources":["../../../../src/tx/builder/field-types/with-default.ts"],"sourcesContent":["export default function withDefault<Input, Output, Binary>(\n defaultValue: Input,\n field: {\n serialize: (value: Input, params: unknown) => Binary;\n deserialize: (value: Binary, params: unknown) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: unknown) => Binary;\n deserialize: (value: Binary, params: unknown) => Output;\n } {\n return {\n ...field,\n\n serialize(value, params) {\n return field.serialize(value ?? defaultValue, params);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,WAAWA,CACjCC,YAAmB,EACnBC,KAGC,EAIC;EACF,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAE;MACvB,OAAOH,KAAK,CAACC,SAAS,CAACC,KAAK,aAALA,KAAK,cAALA,KAAK,GAAIH,YAAY,EAAEI,MAAM,CAAC;IACvD;EACF,CAAC;AACH"}
@@ -0,0 +1,7 @@
1
+ export default function withFormatting<Input, Output, Binary, Params, Options>(format: (v: Input | undefined) => Input, field: {
2
+ serialize: (value: Input, params: Params, options: Options) => Binary;
3
+ deserialize: (value: Binary) => Output;
4
+ }): {
5
+ serialize: (value: Input | undefined, params: Params, options: Options) => Binary;
6
+ deserialize: (value: Binary) => Output;
7
+ };
@@ -0,0 +1,9 @@
1
+ export default function withFormatting(format, field) {
2
+ return {
3
+ ...field,
4
+ serialize(value, params, options) {
5
+ return field.serialize(format(value), params, options);
6
+ }
7
+ };
8
+ }
9
+ //# sourceMappingURL=with-formatting.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-formatting.mjs","names":["withFormatting","format","field","serialize","value","params","options"],"sources":["../../../../src/tx/builder/field-types/with-formatting.ts"],"sourcesContent":["export default function withFormatting<Input, Output, Binary, Params, Options>(\n format: (v: Input | undefined) => Input,\n field: {\n serialize: (value: Input, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n } {\n return {\n ...field,\n\n serialize(value, params, options) {\n return field.serialize(format(value), params, options);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,cAAcA,CACpCC,MAAuC,EACvCC,KAGC,EAIC;EACF,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAE;MAChC,OAAOJ,KAAK,CAACC,SAAS,CAACF,MAAM,CAACG,KAAK,CAAC,EAAEC,MAAM,EAAEC,OAAO,CAAC;IACxD;EACF,CAAC;AACH"}
@@ -1,19 +1,17 @@
1
1
  import { encode, Encoding, decode } from "../../../utils/encoder.mjs";
2
2
  export default function genWrappedField(tag) {
3
3
  return {
4
- serialize(payload, _ref) {
5
- let {
6
- buildTx
7
- } = _ref;
4
+ serialize(payload, {
5
+ buildTx
6
+ }) {
8
7
  return decode(buildTx({
9
8
  tag,
10
9
  payload
11
10
  }));
12
11
  },
13
- deserialize(buffer, _ref2) {
14
- let {
15
- unpackTx
16
- } = _ref2;
12
+ deserialize(buffer, {
13
+ unpackTx
14
+ }) {
17
15
  return unpackTx(encode(buffer, Encoding.Transaction), tag).payload;
18
16
  },
19
17
  recursiveType: true
@@ -1 +1 @@
1
- {"version":3,"file":"wrapped.mjs","names":["encode","Encoding","decode","genWrappedField","tag","serialize","payload","_ref","buildTx","deserialize","buffer","_ref2","unpackTx","Transaction","recursiveType"],"sources":["../../../../src/tx/builder/field-types/wrapped.ts"],"sourcesContent":["import { Tag } from '../constants';\nimport { encode, Encoding, decode } from '../../../utils/encoder';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\ntype TagWrapping = Tag.AccountsMtree | Tag.CallsMtree | Tag.ChannelsMtree | Tag.ContractsMtree\n| Tag.NameserviceMtree | Tag.OraclesMtree;\n\nexport default function genWrappedField<T extends TagWrapping>(tag: T): {\n serialize: (\n // TODO: replace with `(TxParams & { tag: T })['payload']`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any, options: { buildTx: typeof buildTxType }\n ) => Buffer;\n deserialize: (\n value: Buffer, options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `(TxUnpacked & { tag: T })['payload']`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n recursiveType: true;\n} {\n return {\n serialize(payload, { buildTx }) {\n return decode(buildTx({ tag, payload }));\n },\n\n deserialize(buffer, { unpackTx }) {\n return unpackTx<TagWrapping>(encode(buffer, Encoding.Transaction), tag).payload;\n },\n\n recursiveType: true,\n };\n}\n"],"mappings":"SACSA,MAAM,EAAEC,QAAQ,EAAEC,MAAM;AAMjC,eAAe,SAASC,eAAeA,CAAwBC,GAAM,EAYnE;EACA,OAAO;IACLC,SAASA,CAACC,OAAO,EAAAC,IAAA,EAAe;MAAA,IAAb;QAAEC;MAAQ,CAAC,GAAAD,IAAA;MAC5B,OAAOL,MAAM,CAACM,OAAO,CAAC;QAAEJ,GAAG;QAAEE;MAAQ,CAAC,CAAC,CAAC;IAC1C,CAAC;IAEDG,WAAWA,CAACC,MAAM,EAAAC,KAAA,EAAgB;MAAA,IAAd;QAAEC;MAAS,CAAC,GAAAD,KAAA;MAC9B,OAAOC,QAAQ,CAAcZ,MAAM,CAACU,MAAM,EAAET,QAAQ,CAACY,WAAW,CAAC,EAAET,GAAG,CAAC,CAACE,OAAO;IACjF,CAAC;IAEDQ,aAAa,EAAE;EACjB,CAAC;AACH"}
1
+ {"version":3,"file":"wrapped.mjs","names":["encode","Encoding","decode","genWrappedField","tag","serialize","payload","buildTx","deserialize","buffer","unpackTx","Transaction","recursiveType"],"sources":["../../../../src/tx/builder/field-types/wrapped.ts"],"sourcesContent":["import { Tag } from '../constants';\nimport { encode, Encoding, decode } from '../../../utils/encoder';\nimport type { unpackTx as unpackTxType, buildTx as buildTxType } from '../index';\n\ntype TagWrapping = Tag.AccountsMtree | Tag.CallsMtree | Tag.ChannelsMtree | Tag.ContractsMtree\n| Tag.NameserviceMtree | Tag.OraclesMtree;\n\nexport default function genWrappedField<T extends TagWrapping>(tag: T): {\n serialize: (\n // TODO: replace with `(TxParams & { tag: T })['payload']`,\n // but fix TS2502 value is referenced directly or indirectly in its own type annotation\n value: any, options: { buildTx: typeof buildTxType }\n ) => Buffer;\n deserialize: (\n value: Buffer, options: { unpackTx: typeof unpackTxType },\n // TODO: replace with `(TxUnpacked & { tag: T })['payload']`,\n // TS2577 Return type annotation circularly references itself\n ) => any;\n recursiveType: true;\n} {\n return {\n serialize(payload, { buildTx }) {\n return decode(buildTx({ tag, payload }));\n },\n\n deserialize(buffer, { unpackTx }) {\n return unpackTx<TagWrapping>(encode(buffer, Encoding.Transaction), tag).payload;\n },\n\n recursiveType: true,\n };\n}\n"],"mappings":"SACSA,MAAM,EAAEC,QAAQ,EAAEC,MAAM;AAMjC,eAAe,SAASC,eAAeA,CAAwBC,GAAM,EAYnE;EACA,OAAO;IACLC,SAASA,CAACC,OAAO,EAAE;MAAEC;IAAQ,CAAC,EAAE;MAC9B,OAAOL,MAAM,CAACK,OAAO,CAAC;QAAEH,GAAG;QAAEE;MAAQ,CAAC,CAAC,CAAC;IAC1C,CAAC;IAEDE,WAAWA,CAACC,MAAM,EAAE;MAAEC;IAAS,CAAC,EAAE;MAChC,OAAOA,QAAQ,CAAcV,MAAM,CAACS,MAAM,EAAER,QAAQ,CAACU,WAAW,CAAC,EAAEP,GAAG,CAAC,CAACE,OAAO;IACjF,CAAC;IAEDM,aAAa,EAAE;EACjB,CAAC;AACH"}
@@ -49,13 +49,13 @@ export declare function readInt(buf?: Buffer): string;
49
49
  /**
50
50
  * Ensure that name is valid AENS name, would throw an exception otherwise
51
51
  * @category AENS
52
- * @param name - AENS name
52
+ * @param maybeName - AENS name
53
53
  */
54
54
  export declare function ensureName(maybeName: string): asserts maybeName is AensName;
55
55
  /**
56
56
  * Is AENS name valid
57
57
  * @category AENS
58
- * @param name - AENS name
58
+ * @param maybeName - AENS name
59
59
  */
60
60
  export declare function isNameValid(maybeName: string): maybeName is AensName;
61
61
  declare const encodingToPointerKey: readonly [readonly [Encoded.Encoding.AccountAddress, "account_pubkey"], readonly [Encoded.Encoding.OracleAddress, "oracle_pubkey"], readonly [Encoded.Encoding.ContractAddress, "contract_pubkey"], readonly [Encoded.Encoding.Channel, "channel"]];
@@ -92,8 +92,7 @@ export function produceNameId(name) {
92
92
  * @param salt - Random number
93
93
  * @returns Commitment hash
94
94
  */
95
- export function commitmentHash(name) {
96
- let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : genSalt();
95
+ export function commitmentHash(name, salt = genSalt()) {
97
96
  return encode(hash(concatBuffers([_Buffer.from(nameToPunycode(name)), _Buffer.from(salt.toString(16).padStart(64, '0'), 'hex')])), Encoding.Commitment);
98
97
  }
99
98
 
@@ -103,15 +102,14 @@ export function commitmentHash(name) {
103
102
  * @param buf - Value
104
103
  * @returns Buffer Buffer from number(BigEndian)
105
104
  */
106
- export function readInt() {
107
- let buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Buffer.from([]);
105
+ export function readInt(buf = _Buffer.from([])) {
108
106
  return new BigNumber(_Buffer.from(buf).toString('hex'), 16).toString(10);
109
107
  }
110
108
 
111
109
  /**
112
110
  * Ensure that name is valid AENS name, would throw an exception otherwise
113
111
  * @category AENS
114
- * @param name - AENS name
112
+ * @param maybeName - AENS name
115
113
  */
116
114
  export function ensureName(maybeName) {
117
115
  nameToPunycode(maybeName);
@@ -120,7 +118,7 @@ export function ensureName(maybeName) {
120
118
  /**
121
119
  * Is AENS name valid
122
120
  * @category AENS
123
- * @param name - AENS name
121
+ * @param maybeName - AENS name
124
122
  */
125
123
  // TODO: consider renaming to isName
126
124
  export function isNameValid(maybeName) {
@@ -142,15 +140,9 @@ export function getDefaultPointerKey(identifier) {
142
140
  var _encodingToPointerKey;
143
141
  decode(identifier);
144
142
  const encoding = identifier.substring(0, 2);
145
- const result = (_encodingToPointerKey = encodingToPointerKey.find(_ref => {
146
- let [e] = _ref;
147
- return e === encoding;
148
- })) === null || _encodingToPointerKey === void 0 ? void 0 : _encodingToPointerKey[1];
143
+ const result = (_encodingToPointerKey = encodingToPointerKey.find(([e]) => e === encoding)) === null || _encodingToPointerKey === void 0 ? void 0 : _encodingToPointerKey[1];
149
144
  if (result != null) return result;
150
- throw new ArgumentError('identifier', `prefixed with one of ${encodingToPointerKey.map(_ref2 => {
151
- let [e] = _ref2;
152
- return `${e}_`;
153
- }).join(', ')}`, identifier);
145
+ throw new ArgumentError('identifier', `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`, identifier);
154
146
  }
155
147
 
156
148
  /**
@@ -173,11 +165,10 @@ export function getMinimumNameFee(name) {
173
165
  * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)
174
166
  * @returns Bid fee
175
167
  */
176
- export function computeBidFee(name) {
177
- let {
178
- startFee,
179
- increment = NAME_FEE_BID_INCREMENT
180
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
168
+ export function computeBidFee(name, {
169
+ startFee,
170
+ increment = NAME_FEE_BID_INCREMENT
171
+ } = {}) {
181
172
  if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);
182
173
  if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);
183
174
  // FIXME: increment should be used somehow here
@@ -193,9 +184,9 @@ export function computeBidFee(name) {
193
184
  * @returns Auction end height
194
185
  */
195
186
  export function computeAuctionEndBlock(name, claimHeight) {
196
- var _ref3, _ref4, _ref5;
187
+ var _ref, _ref2, _ref3;
197
188
  const length = nameToPunycode(name).length - AENS_SUFFIX.length;
198
- const h = (_ref3 = (_ref4 = (_ref5 = length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref5 !== void 0 ? _ref5 : length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref4 !== void 0 ? _ref4 : length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref3 !== void 0 ? _ref3 : 0;
189
+ const h = (_ref = (_ref2 = (_ref3 = length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref3 !== void 0 ? _ref3 : length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref2 !== void 0 ? _ref2 : length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null) !== null && _ref !== void 0 ? _ref : 0;
199
190
  return h + claimHeight;
200
191
  }
201
192
 
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","names":["BigNumber","genSalt","hash","decode","encode","Encoding","toBytes","concatBuffers","NAME_BID_RANGES","NAME_BID_TIMEOUT_BLOCKS","NAME_FEE_BID_INCREMENT","NAME_MAX_LENGTH_FEE","ceil","ArgumentError","IllegalBidFeeError","buildContractId","ownerId","nonce","ownerIdAndNonce","_Buffer","from","b2bHash","ContractAddress","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","OracleQueryId","AENS_SUFFIX","nameToPunycode","maybeName","name","suffix","other","split","slice","test","punycode","u","URL","username","password","port","search","pathname","host","error","TypeError","message","includes","produceNameId","Name","commitmentHash","salt","arguments","undefined","toString","padStart","Commitment","readInt","buf","ensureName","isNameValid","encodingToPointerKey","AccountAddress","OracleAddress","Channel","getDefaultPointerKey","identifier","_encodingToPointerKey","encoding","substring","result","find","_ref","e","map","_ref2","join","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","_ref3","_ref4","_ref5","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { genSalt, hash } from '../../utils/crypto';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { toBytes } from '../../utils/bytes';\nimport { concatBuffers } from '../../utils/other';\nimport {\n AensName,\n NAME_BID_RANGES,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_FEE_BID_INCREMENT,\n NAME_MAX_LENGTH_FEE,\n} from './constants';\nimport { ceil } from '../../utils/bignumber';\nimport { ArgumentError, IllegalBidFeeError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\n/**\n * Build a contract public key\n * @category contract\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId(\n ownerId: Encoded.AccountAddress,\n nonce: number | BigNumber,\n): Encoded.ContractAddress {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)]);\n const b2bHash = hash(ownerIdAndNonce);\n return encode(b2bHash, Encoding.ContractAddress);\n}\n\n/**\n * Build a oracle query id\n * @category oracle\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId(\n senderId: Encoded.AccountAddress,\n nonce: number | BigNumber | string,\n oracleId: Encoded.OracleAddress,\n): Encoded.OracleQueryId {\n function _int32(val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true);\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE]);\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]),\n );\n return encode(b2bHash, Encoding.OracleQueryId);\n}\n\nconst AENS_SUFFIX = '.chain';\n\nexport function nameToPunycode(maybeName: string): AensName {\n const [name, suffix, ...other] = maybeName.split('.');\n if (other.length !== 0) throw new ArgumentError('aens name', 'including only one dot', maybeName);\n if (suffix !== AENS_SUFFIX.slice(1)) {\n throw new ArgumentError('aens name', `suffixed with ${AENS_SUFFIX}`, maybeName);\n }\n if (/\\p{Emoji_Presentation}/u.test(name)) {\n throw new ArgumentError('aens name', 'not containing emoji', maybeName);\n }\n let punycode;\n try {\n const u = new URL(`http://${name}.${suffix}`);\n if (u.username + u.password + u.port + u.search + u.hash !== '' || u.pathname !== '/') {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n punycode = u.host;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes('Invalid URL')) {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n throw error;\n }\n if (!/^[a-z0-9.-]+$/i.test(punycode)) {\n throw new ArgumentError('aens name', 'without illegal chars', maybeName);\n }\n if (punycode.length > 63 + AENS_SUFFIX.length) {\n throw new ArgumentError('aens name', 'not too long', maybeName);\n }\n return punycode as AensName;\n}\n\n/**\n * Encode an AENS name\n * @category AENS\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId(name: AensName): Encoded.Name {\n return encode(hash(nameToPunycode(name)), Encoding.Name);\n}\n\n/**\n * Generate the commitment hash by hashing the salt and\n * name, base 58 encoding the result and prepending 'cm_'\n * @category transaction builder\n * @param name - Name to be registered\n * @param salt - Random number\n * @returns Commitment hash\n */\nexport function commitmentHash(\n name: AensName,\n salt: number = genSalt(),\n): Encoded.Commitment {\n return encode(\n hash(concatBuffers([\n Buffer.from(nameToPunycode(name)),\n Buffer.from(salt.toString(16).padStart(64, '0'), 'hex'),\n ])),\n Encoding.Commitment,\n );\n}\n\n/**\n * Utility function to convert bytes to int\n * @category transaction builder\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt(buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);\n}\n\n/**\n * Ensure that name is valid AENS name, would throw an exception otherwise\n * @category AENS\n * @param name - AENS name\n */\nexport function ensureName(maybeName: string): asserts maybeName is AensName {\n nameToPunycode(maybeName);\n}\n\n/**\n * Is AENS name valid\n * @category AENS\n * @param name - AENS name\n */\n// TODO: consider renaming to isName\nexport function isNameValid(maybeName: string): maybeName is AensName {\n try {\n ensureName(maybeName);\n return true;\n } catch (error) {\n return false;\n }\n}\n\nconst encodingToPointerKey = [\n [Encoding.AccountAddress, 'account_pubkey'],\n [Encoding.OracleAddress, 'oracle_pubkey'],\n [Encoding.ContractAddress, 'contract_pubkey'],\n [Encoding.Channel, 'channel'],\n] as const;\n\n/**\n * @category AENS\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey(\n identifier: Encoded.Generic<typeof encodingToPointerKey[number][0]>,\n): typeof encodingToPointerKey[number][1] {\n decode(identifier);\n const encoding = identifier.substring(0, 2);\n const result = encodingToPointerKey.find(([e]) => e === encoding)?.[1];\n if (result != null) return result;\n throw new ArgumentError(\n 'identifier',\n `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`,\n identifier,\n );\n}\n\n/**\n * Get the minimum AENS name fee\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee(name: AensName): BigNumber {\n const nameLength = nameToPunycode(name).length - AENS_SUFFIX.length;\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];\n}\n\n/**\n * Compute bid fee for AENS auction\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee(\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber; increment?: number } = {},\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1)),\n );\n}\n\n/**\n * Compute auction end height\n * @category AENS\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock(name: AensName, claimHeight: number): number {\n const length = nameToPunycode(name).length - AENS_SUFFIX.length;\n const h = (length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null)\n ?? 0;\n return h + claimHeight;\n}\n\n/**\n * Is name accept going to auction\n * @category AENS\n */\nexport function isAuctionName(name: AensName): boolean {\n return nameToPunycode(name).length < 13 + AENS_SUFFIX.length;\n}\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,OAAO,EAAEC,IAAI;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,OAAO;A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C,KAAA,EAAAC,KAAA,EAAAC,KAAA;EAClF,MAAMnE,MAAM,GAAGG,cAAc,CAACE,IAAI,CAAC,CAACL,MAAM,GAAGE,WAAW,CAACF,MAAM;EAC/D,MAAMoE,CAAC,IAAAH,KAAA,IAAAC,KAAA,IAAAC,KAAA,GAAInE,MAAM,IAAI,CAAC,GAAG,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAwF,KAAA,cAAAA,KAAA,GACtDnE,MAAM,IAAI,CAAC,GAAG,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAuF,KAAA,cAAAA,KAAA,GACjDlE,MAAM,IAAI,EAAE,GAAGrB,uBAAuB,GAAG,IAAI,cAAAsF,KAAA,cAAAA,KAAA,GAC9C,CAAC;EACN,OAAOG,CAAC,GAAGJ,WAAW;AACxB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAAChE,IAAc,EAAW;EACrD,OAAOF,cAAc,CAACE,IAAI,CAAC,CAACL,MAAM,GAAG,EAAE,GAAGE,WAAW,CAACF,MAAM;AAC9D"}
1
+ {"version":3,"file":"helpers.mjs","names":["BigNumber","genSalt","hash","decode","encode","Encoding","toBytes","concatBuffers","NAME_BID_RANGES","NAME_BID_TIMEOUT_BLOCKS","NAME_FEE_BID_INCREMENT","NAME_MAX_LENGTH_FEE","ceil","ArgumentError","IllegalBidFeeError","buildContractId","ownerId","nonce","ownerIdAndNonce","_Buffer","from","b2bHash","ContractAddress","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","OracleQueryId","AENS_SUFFIX","nameToPunycode","maybeName","name","suffix","other","split","slice","test","punycode","u","URL","username","password","port","search","pathname","host","error","TypeError","message","includes","produceNameId","Name","commitmentHash","salt","toString","padStart","Commitment","readInt","buf","ensureName","isNameValid","encodingToPointerKey","AccountAddress","OracleAddress","Channel","getDefaultPointerKey","identifier","_encodingToPointerKey","encoding","substring","result","find","e","map","join","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","_ref","_ref2","_ref3","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { genSalt, hash } from '../../utils/crypto';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { toBytes } from '../../utils/bytes';\nimport { concatBuffers } from '../../utils/other';\nimport {\n AensName,\n NAME_BID_RANGES,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_FEE_BID_INCREMENT,\n NAME_MAX_LENGTH_FEE,\n} from './constants';\nimport { ceil } from '../../utils/bignumber';\nimport { ArgumentError, IllegalBidFeeError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\n/**\n * Build a contract public key\n * @category contract\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId(\n ownerId: Encoded.AccountAddress,\n nonce: number | BigNumber,\n): Encoded.ContractAddress {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)]);\n const b2bHash = hash(ownerIdAndNonce);\n return encode(b2bHash, Encoding.ContractAddress);\n}\n\n/**\n * Build a oracle query id\n * @category oracle\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId(\n senderId: Encoded.AccountAddress,\n nonce: number | BigNumber | string,\n oracleId: Encoded.OracleAddress,\n): Encoded.OracleQueryId {\n function _int32(val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true);\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE]);\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]),\n );\n return encode(b2bHash, Encoding.OracleQueryId);\n}\n\nconst AENS_SUFFIX = '.chain';\n\nexport function nameToPunycode(maybeName: string): AensName {\n const [name, suffix, ...other] = maybeName.split('.');\n if (other.length !== 0) throw new ArgumentError('aens name', 'including only one dot', maybeName);\n if (suffix !== AENS_SUFFIX.slice(1)) {\n throw new ArgumentError('aens name', `suffixed with ${AENS_SUFFIX}`, maybeName);\n }\n if (/\\p{Emoji_Presentation}/u.test(name)) {\n throw new ArgumentError('aens name', 'not containing emoji', maybeName);\n }\n let punycode;\n try {\n const u = new URL(`http://${name}.${suffix}`);\n if (u.username + u.password + u.port + u.search + u.hash !== '' || u.pathname !== '/') {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n punycode = u.host;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes('Invalid URL')) {\n throw new ArgumentError('aens name', 'valid', maybeName);\n }\n throw error;\n }\n if (!/^[a-z0-9.-]+$/i.test(punycode)) {\n throw new ArgumentError('aens name', 'without illegal chars', maybeName);\n }\n if (punycode.length > 63 + AENS_SUFFIX.length) {\n throw new ArgumentError('aens name', 'not too long', maybeName);\n }\n return punycode as AensName;\n}\n\n/**\n * Encode an AENS name\n * @category AENS\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId(name: AensName): Encoded.Name {\n return encode(hash(nameToPunycode(name)), Encoding.Name);\n}\n\n/**\n * Generate the commitment hash by hashing the salt and\n * name, base 58 encoding the result and prepending 'cm_'\n * @category transaction builder\n * @param name - Name to be registered\n * @param salt - Random number\n * @returns Commitment hash\n */\nexport function commitmentHash(\n name: AensName,\n salt: number = genSalt(),\n): Encoded.Commitment {\n return encode(\n hash(concatBuffers([\n Buffer.from(nameToPunycode(name)),\n Buffer.from(salt.toString(16).padStart(64, '0'), 'hex'),\n ])),\n Encoding.Commitment,\n );\n}\n\n/**\n * Utility function to convert bytes to int\n * @category transaction builder\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt(buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);\n}\n\n/**\n * Ensure that name is valid AENS name, would throw an exception otherwise\n * @category AENS\n * @param maybeName - AENS name\n */\nexport function ensureName(maybeName: string): asserts maybeName is AensName {\n nameToPunycode(maybeName);\n}\n\n/**\n * Is AENS name valid\n * @category AENS\n * @param maybeName - AENS name\n */\n// TODO: consider renaming to isName\nexport function isNameValid(maybeName: string): maybeName is AensName {\n try {\n ensureName(maybeName);\n return true;\n } catch (error) {\n return false;\n }\n}\n\nconst encodingToPointerKey = [\n [Encoding.AccountAddress, 'account_pubkey'],\n [Encoding.OracleAddress, 'oracle_pubkey'],\n [Encoding.ContractAddress, 'contract_pubkey'],\n [Encoding.Channel, 'channel'],\n] as const;\n\n/**\n * @category AENS\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey(\n identifier: Encoded.Generic<typeof encodingToPointerKey[number][0]>,\n): typeof encodingToPointerKey[number][1] {\n decode(identifier);\n const encoding = identifier.substring(0, 2);\n const result = encodingToPointerKey.find(([e]) => e === encoding)?.[1];\n if (result != null) return result;\n throw new ArgumentError(\n 'identifier',\n `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`,\n identifier,\n );\n}\n\n/**\n * Get the minimum AENS name fee\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee(name: AensName): BigNumber {\n const nameLength = nameToPunycode(name).length - AENS_SUFFIX.length;\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];\n}\n\n/**\n * Compute bid fee for AENS auction\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee(\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber; increment?: number } = {},\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1)),\n );\n}\n\n/**\n * Compute auction end height\n * @category AENS\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock(name: AensName, claimHeight: number): number {\n const length = nameToPunycode(name).length - AENS_SUFFIX.length;\n const h = (length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null)\n ?? (length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null)\n ?? 0;\n return h + claimHeight;\n}\n\n/**\n * Is name accept going to auction\n * @category AENS\n */\nexport function isAuctionName(name: AensName): boolean {\n return nameToPunycode(name).length < 13 + AENS_SUFFIX.length;\n}\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,OAAO,EAAEC,IAAI;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,OAAO;AAAA,SACPC,aAAa;AAAA,SAGpBC,eAAe,EACfC,uBAAuB,EACvBC,sBAAsB,EACtBC,mBAAmB;AAAA,SAEZC,IAAI;AAAA,SACJC,aAAa,EAAEC,kBAAkB;AAE1C;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,OAA+B,EAC/BC,KAAyB,EACA;EACzB,MAAMC,eAAe,GAAGC,OAAA,CAAOC,IAAI,CAAC,CAAC,GAAGjB,MAAM,CAACa,OAAO,CAAC,EAAE,GAAGV,OA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;AAC9D"}
@@ -8,29 +8,36 @@ import { Tag } from './constants';
8
8
  export declare function getSchema(tag: Tag, version?: number): Array<[string, Field]>;
9
9
  type TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees | Encoding.CallStateTree;
10
10
  /**
11
- * Build transaction hash
11
+ * Build transaction
12
12
  * @category transaction builder
13
- * @param params - Object with tx params
14
- * @param options - options
15
- * @param options.prefix - Prefix of transaction
16
- * @returns object Base64Check transaction hash with 'tx_' prefix
13
+ * @param params - Transaction params
17
14
  */
18
- export declare function buildTx<E extends TxEncoding = Encoding.Transaction>(params: TxParams, { prefix }?: {
19
- prefix?: E;
15
+ export declare function buildTx(params: TxParams): Encoded.Transaction;
16
+ /**
17
+ * Build node entry with a custom encoding
18
+ * @param params - Entry params
19
+ * @param options - Options
20
+ * @param options.prefix - Output encoding
21
+ */
22
+ export declare function buildTx<E extends TxEncoding>(params: TxParams, { prefix }: {
23
+ prefix: E;
20
24
  }): Encoded.Generic<E>;
21
25
  export type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<TxParamsAsync & {
22
26
  tag: TxType;
23
27
  }, 'tag' | OmitFields>;
24
28
  /**
29
+ * Build transaction async (may request node for additional data)
25
30
  * @category transaction builder
31
+ * @param params - Transaction params
32
+ * @returns tx_-encoded transaction
26
33
  */
27
34
  export declare function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction>;
28
35
  /**
29
36
  * Unpack transaction encoded as string
30
37
  * @category transaction builder
31
- * @param encodedTx - Transaction to unpack
38
+ * @param encodedTx - Encoded transaction
32
39
  * @param txType - Expected transaction type
33
- * @returns Object with transaction param's
40
+ * @returns Transaction params
34
41
  */
35
42
  export declare function unpackTx<TxType extends Tag>(encodedTx: Encoded.Generic<TxEncoding>, txType?: TxType): TxUnpacked & {
36
43
  tag: TxType;
@@ -43,7 +50,7 @@ export declare function unpackTx<TxType extends Tag>(encodedTx: Encoded.Generic<
43
50
  */
44
51
  export declare function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash;
45
52
  /**
46
- * Build a contract public key by contractCreateTx or gaAttach
53
+ * Build a contract public key by contractCreateTx, gaAttach or signedTx
47
54
  * @category contract
48
55
  * @param contractTx - Transaction
49
56
  * @returns Contract public key
@@ -1,64 +1,52 @@
1
- import _rlp from 'rlp';
2
- const {
3
- decode: rlpDecode,
4
- encode: rlpEncode
5
- } = _rlp;
6
1
  import { decode, encode, Encoding } from "../../utils/encoder.mjs";
7
2
  import { hash } from "../../utils/crypto.mjs";
8
3
  import { txSchema } from "./schema.mjs";
9
4
  import { Tag } from "./constants.mjs";
10
- import { buildContractId, readInt } from "./helpers.mjs";
11
- import { ArgumentError, DecodeError, SchemaNotFoundError } from "../../utils/errors.mjs";
5
+ import { buildContractId } from "./helpers.mjs";
6
+ import { getSchema as getSchemaCommon, packRecord, unpackRecord } from "./common.mjs";
7
+ import { ArgumentError } from "../../utils/errors.mjs";
12
8
  /**
13
9
  * JavaScript-based Transaction builder
14
10
  */
15
11
  export function getSchema(tag, version) {
16
- var _version;
17
- const schemas = txSchema.filter(s => s.tag.constValue === tag);
18
- if (schemas.length === 0) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, 0);
19
- (_version = version) !== null && _version !== void 0 ? _version : version = Math.max(...schemas.map(schema => schema.version.constValue));
20
- const schema = schemas.find(s => s.version.constValue === version);
21
- if (schema == null) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, version);
22
- return Object.entries(schema);
12
+ return getSchemaCommon(txSchema, Tag, tag, version);
23
13
  }
14
+
24
15
  /**
25
- * Build transaction hash
16
+ * Build transaction
26
17
  * @category transaction builder
27
- * @param params - Object with tx params
28
- * @param options - options
29
- * @param options.prefix - Prefix of transaction
30
- * @returns object Base64Check transaction hash with 'tx_' prefix
18
+ * @param params - Transaction params
31
19
  */
32
- export function buildTx(params) {
33
- let {
34
- prefix
35
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
- const schema = getSchema(params.tag, params.version);
37
- const binary = schema.map(_ref => {
38
- let [key, field] = _ref;
39
- return field.serialize(
40
- // @ts-expect-error the type of `params[key]` can't be determined accurately
41
- params[key], {
42
- ...params,
43
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
44
- unpackTx,
45
- buildTx,
46
- rebuildTx: overrideParams => buildTx({
47
- ...params,
48
- ...overrideParams
49
- })
50
- }, params);
51
- });
52
20
 
53
- // @ts-expect-error looks like a TypeScript edge case
54
- return encode(rlpEncode(binary), prefix !== null && prefix !== void 0 ? prefix : Encoding.Transaction);
21
+ /**
22
+ * Build node entry with a custom encoding
23
+ * @param params - Entry params
24
+ * @param options - Options
25
+ * @param options.prefix - Output encoding
26
+ */
27
+
28
+ export function buildTx(params, {
29
+ prefix
30
+ } = {}) {
31
+ return packRecord(txSchema, Tag, params, {
32
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
33
+ unpackTx,
34
+ buildTx,
35
+ rebuildTx: overrideParams => buildTx({
36
+ ...params,
37
+ ...overrideParams
38
+ })
39
+ }, prefix !== null && prefix !== void 0 ? prefix : Encoding.Transaction);
55
40
  }
41
+ // TODO: require onNode because it is the only reason this builder is async [breaking change]
56
42
  /**
43
+ * Build transaction async (may request node for additional data)
57
44
  * @category transaction builder
45
+ * @param params - Transaction params
46
+ * @returns tx_-encoded transaction
58
47
  */
59
48
  export async function buildTxAsync(params) {
60
- await Promise.all(getSchema(params.tag, params.version).map(async _ref2 => {
61
- let [key, field] = _ref2;
49
+ await Promise.all(getSchema(params.tag, params.version).map(async ([key, field]) => {
62
50
  if (field.prepare == null) return;
63
51
  // @ts-expect-error the type of `params[key]` can't be determined accurately
64
52
  params[key] = await field.prepare(params[key], params, params);
@@ -71,30 +59,15 @@ export async function buildTxAsync(params) {
71
59
  /**
72
60
  * Unpack transaction encoded as string
73
61
  * @category transaction builder
74
- * @param encodedTx - Transaction to unpack
62
+ * @param encodedTx - Encoded transaction
75
63
  * @param txType - Expected transaction type
76
- * @returns Object with transaction param's
64
+ * @returns Transaction params
77
65
  */
78
66
  export function unpackTx(encodedTx, txType) {
79
- const binary = rlpDecode(decode(encodedTx));
80
- const tag = +readInt(binary[0]);
81
- const version = +readInt(binary[1]);
82
- const schema = getSchema(tag, version);
83
- if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);
84
- if (binary.length !== schema.length) {
85
- throw new ArgumentError('Transaction RLP length', schema.length, binary.length);
86
- }
87
- return schema.reduce((acc, _ref3, index) => {
88
- let [name, field] = _ref3;
67
+ return unpackRecord(txSchema, Tag, encodedTx, txType, {
89
68
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
90
- const deserialized = field.deserialize(binary[index], {
91
- unpackTx
92
- });
93
- return {
94
- ...acc,
95
- [name]: deserialized
96
- };
97
- }, {});
69
+ unpackTx
70
+ });
98
71
  }
99
72
 
100
73
  /**
@@ -109,13 +82,14 @@ export function buildTxHash(rawTx) {
109
82
  }
110
83
 
111
84
  /**
112
- * Build a contract public key by contractCreateTx or gaAttach
85
+ * Build a contract public key by contractCreateTx, gaAttach or signedTx
113
86
  * @category contract
114
87
  * @param contractTx - Transaction
115
88
  * @returns Contract public key
116
89
  */
117
90
  export function buildContractIdByContractTx(contractTx) {
118
- const params = unpackTx(contractTx);
91
+ let params = unpackTx(contractTx);
92
+ if (Tag.SignedTx === params.tag) params = params.encodedTx;
119
93
  if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {
120
94
  throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);
121
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["_rlp","decode","rlpDecode","encode","rlpEncode","Encoding","hash","txSchema","Tag","buildContractId","readInt","ArgumentError","DecodeError","SchemaNotFoundError","getSchema","tag","version","_version","schemas","filter","s","constValue","length","Math","max","map","schema","find","Object","entries","buildTx","params","prefix","arguments","undefined","binary","_ref","key","field","serialize","unpackTx","rebuildTx","overrideParams","Transaction","buildTxAsync","Promise","all","_ref2","prepare","encodedTx","txType","reduce","acc","_ref3","index","name","deserialized","deserialize","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode as rlpDecode, encode as rlpEncode } from 'rlp';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { hash } from '../../utils/crypto';\nimport { BinaryData, Field } from './field-types';\nimport { txSchema } from './schema';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated';\nimport { Tag } from './constants';\nimport { buildContractId, readInt } from './helpers';\nimport { ArgumentError, DecodeError, SchemaNotFoundError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n const schemas = txSchema.filter((s) => s.tag.constValue === tag);\n if (schemas.length === 0) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, 0);\n version ??= Math.max(...schemas.map((schema) => schema.version.constValue));\n const schema = schemas.find((s) => s.version.constValue === version);\n if (schema == null) throw new SchemaNotFoundError(`${Tag[tag]} (${tag})`, version);\n return Object.entries(schema);\n}\n\ntype TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees\n| Encoding.CallStateTree;\n\n/**\n * Build transaction hash\n * @category transaction builder\n * @param params - Object with tx params\n * @param options - options\n * @param options.prefix - Prefix of transaction\n * @returns object Base64Check transaction hash with 'tx_' prefix\n */\nexport function buildTx<E extends TxEncoding = Encoding.Transaction>(\n params: TxParams,\n { prefix }: { prefix?: E } = {},\n): Encoded.Generic<E> {\n const schema = getSchema(params.tag, params.version);\n\n const binary = schema.map(([key, field]) => (\n field.serialize(\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key],\n {\n ...params,\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx(\n { ...params, ...overrideParams },\n ),\n },\n params,\n )\n ));\n\n // @ts-expect-error looks like a TypeScript edge case\n return encode(rlpEncode(binary), prefix ?? Encoding.Transaction);\n}\n\nexport type BuildTxOptions <TxType extends Tag, OmitFields extends string> =\n Omit<TxParamsAsync & { tag: TxType }, 'tag' | OmitFields>;\n\n/**\n * @category transaction builder\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n await Promise.all(\n getSchema(params.tag, params.version)\n .map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key] = await field.prepare(params[key], params, params);\n }),\n );\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx(params);\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Transaction to unpack\n * @param txType - Expected transaction type\n * @returns Object with transaction param's\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n const binary = rlpDecode(decode(encodedTx));\n const tag = +readInt(binary[0] as Buffer);\n const version = +readInt(binary[1] as Buffer);\n const schema = getSchema(tag, version);\n if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);\n if (binary.length !== schema.length) {\n throw new ArgumentError('Transaction RLP length', schema.length, binary.length);\n }\n return schema.reduce<any>(\n (acc, [name, field], index) => {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const deserialized = field.deserialize(binary[index] as BinaryData, { unpackTx });\n return { ...acc, [name]: deserialized };\n },\n {},\n ) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_')\n ? decode(rawTx)\n : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx or gaAttach\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n const params = unpackTx(contractTx);\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"AAAA,OAAAA,IAAA,MAAyD,KAAK;AAAC;EAAAC,MAAA,EAAAC,SAAA;EAAAC,MAAA,EAAAC;AAAA,IAAAJ,IAAA;AAAA,SAE7DC,MAAM,EAAEE,MAAM,EAAWE,QAAQ;AAAA,SAE1BC,IAAI;AAAA,SAEJC,QAAQ;AAAA,SAERC,GAAG;AAAA,SACHC,eAAe,EAAEC,OAAO;AAAA,SACxBC,aAAa,EAAEC,WAAW,EAAEC,mBAAmB;AAExD;AACA;AACA;AAEA,OAAO,SAASC,SAASA,CAACC,GAAQ,EAAEC,OAAgB,EAA0B;EAAA,IAAAC,QAAA;EAC5E,MAAMC,OAAO,GAAGX,QAAQ,CAACY,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACL,GAAG,CAACM,UAAU,KAAKN,GAAG,CAAC;EAChE,IAAIG,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE,MAAM,IAAIT,mBAAmB,CAAE,GAAEL,GAAG,CAACO,GAAG,CAAE,KAAIA,GAAI,GAAE,EAAE,CAAC,CAAC;EAClF,CAAAE,QAAA,GAAAD,OAAO,cAAAC,QAAA,cAAAA,QAAA,GAAPD,OAAO,GAAKO,IAAI,CAACC,GAAG,CAAC,GAAGN,OAAO,CAACO,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACV,OAAO,CAACK,UAAU,CAAC,CAAC;EAC3E,MAAMK,MAAM,GAAGR,OAAO,CAACS,IAAI,CAAEP,CAAC,IAAKA,CAA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CAACmB,WAAW,CAACtB,MAAM,CAACmB,KAAK,CAAC,EAAgB;MAAEd;IAAS,CAAC,CAAC;IACjF,OAAO;MAAE,GAAGY,GAAG;MAAE,CAACG,IAAI,GAAGC;IAAa,CAAC;EACzC,CAAC,EACD,CAAC,CACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,WAAWA,CAACC,KAAuC,EAAkB;EACnF,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACE,UAAU,CAAC,KAAK,CAAC,GAC7D5D,MAAM,CAAC0D,KAAK,CAAC,GACbA,KAAK;EACT,OAAOxD,MAAM,CAACG,IAAI,CAACsD,IAAI,CAAC,EAAEvD,QAAQ,CAACyD,MAAM,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CACzCC,UAA+B,EACN;EACzB,MAAMjC,MAAM,GAAGS,QAAQ,CAACwB,UAAU,CAAC;EACnC,IAAIxD,GAAG,CAACyD,gBAAgB,KAAKlC,MAAM,CAAChB,GAAG,IAAIP,GAAG,CAAC0D,UAAU,KAAKnC,MAAM,CAAChB,GAAG,EAAE;IACxE,MAAM,IAAIJ,aAAa,CAAC,YAAY,EAAE,gCAAgC,EAAEoB,MAAM,CAAChB,GAAG,CAAC;EACrF;EACA,OAAON,eAAe,CAACsB,MAAM,CAACoC,OAAO,EAAEpC,MAAM,CAACqC,KAAK,CAAC;AACtD"}
1
+ {"version":3,"file":"index.mjs","names":["decode","encode","Encoding","hash","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","tag","version","buildTx","params","prefix","unpackTx","rebuildTx","overrideParams","Transaction","buildTxAsync","Promise","all","map","key","field","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { hash } from '../../utils/crypto';\nimport { Field } from './field-types';\nimport { txSchema } from './schema';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated';\nimport { Tag } from './constants';\nimport { buildContractId } from './helpers';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common';\nimport { ArgumentError } from '../../utils/errors';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees\n| Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction;\n/**\n * Build node entry with a custom encoding\n * @param params - Entry params\n * @param options - Options\n * @param options.prefix - Output encoding\n */\nexport function buildTx<E extends TxEncoding>(\n params: TxParams,\n { prefix }: { prefix: E },\n): Encoded.Generic<E>;\nexport function buildTx(\n params: TxParams,\n { prefix }: { prefix?: TxEncoding } = {},\n): Encoded.Generic<TxEncoding> {\n return packRecord(txSchema, Tag, params, {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx(\n { ...params, ...overrideParams },\n ),\n }, prefix ?? Encoding.Transaction);\n}\n\nexport type BuildTxOptions <TxType extends Tag, OmitFields extends string> =\n Omit<TxParamsAsync & { tag: TxType }, 'tag' | OmitFields>;\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n await Promise.all(\n getSchema(params.tag, params.version)\n .map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key] = await field.prepare(params[key], params, params);\n }),\n );\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx(params);\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n }) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_')\n ? decode(rawTx)\n : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"SACEA,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,IAAI;AAAA,SAEJC,QAAQ;AAAA,SAERC,GAAG;AAAA,SACHC,eAAe;AAAA,SACfC,SAAS,IAAIC,eAAe,EAAEC,UAAU,EAAEC,YAAY;AAAA,SACtDC,aAAa;AAEtB;AACA;AACA;AAEA,OAAO,SAASJ,SAASA,CAACK,GAAQ,EAAEC,OAAgB,EAA0B;EAC5E,OAAOL,eAAe,CAACJ,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