@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-alpha.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 (322) hide show
  1. package/bin/aesophia_cli +0 -0
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +4206 -1127
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/AeSdkBase.d.ts +3 -3
  9. package/es/AeSdkBase.mjs +4 -0
  10. package/es/AeSdkBase.mjs.map +1 -1
  11. package/es/AeSdkMethods.d.ts +3 -4
  12. package/es/AeSdkMethods.mjs.map +1 -1
  13. package/es/Node.d.ts +4 -3
  14. package/es/Node.mjs +1 -1
  15. package/es/Node.mjs.map +1 -1
  16. package/es/account/Base.d.ts +2 -2
  17. package/es/account/Base.mjs.map +1 -1
  18. package/es/account/Generalized.mjs +5 -3
  19. package/es/account/Generalized.mjs.map +1 -1
  20. package/es/account/Ledger.mjs +2 -1
  21. package/es/account/Ledger.mjs.map +1 -1
  22. package/es/account/Memory.mjs +2 -1
  23. package/es/account/Memory.mjs.map +1 -1
  24. package/es/aens.d.ts +1 -1
  25. package/es/aens.mjs +5 -1
  26. package/es/aens.mjs.map +1 -1
  27. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  28. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -4
  29. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  30. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +1 -1
  31. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  32. package/es/chain.d.ts +9 -1
  33. package/es/chain.mjs +4 -1
  34. package/es/chain.mjs.map +1 -1
  35. package/es/channel/Base.d.ts +6 -1
  36. package/es/channel/Base.mjs +9 -6
  37. package/es/channel/Base.mjs.map +1 -1
  38. package/es/channel/Contract.d.ts +8 -7
  39. package/es/channel/Contract.mjs +1 -1
  40. package/es/channel/Contract.mjs.map +1 -1
  41. package/es/channel/Spend.d.ts +3 -1
  42. package/es/channel/Spend.mjs +4 -2
  43. package/es/channel/Spend.mjs.map +1 -1
  44. package/es/channel/handlers.mjs +11 -9
  45. package/es/channel/handlers.mjs.map +1 -1
  46. package/es/channel/internal.mjs +3 -1
  47. package/es/channel/internal.mjs.map +1 -1
  48. package/es/contract/Contract.d.ts +21 -46
  49. package/es/contract/Contract.mjs +69 -52
  50. package/es/contract/Contract.mjs.map +1 -1
  51. package/es/contract/compiler/Base.d.ts +81 -0
  52. package/es/contract/compiler/Base.mjs +5 -0
  53. package/es/contract/compiler/Base.mjs.map +1 -0
  54. package/es/contract/compiler/Cli.d.ts +23 -0
  55. package/es/contract/compiler/Cli.mjs +155 -0
  56. package/es/contract/compiler/Cli.mjs.map +1 -0
  57. package/es/contract/compiler/Http.d.ts +32 -0
  58. package/es/contract/{CompilerHttp.mjs → compiler/Http.mjs} +64 -9
  59. package/es/contract/compiler/Http.mjs.map +1 -0
  60. package/es/contract/compiler/HttpNode.d.ts +17 -0
  61. package/es/contract/compiler/HttpNode.mjs +26 -0
  62. package/es/contract/compiler/HttpNode.mjs.map +1 -0
  63. package/es/contract/compiler/getFileSystem.d.ts +6 -0
  64. package/es/contract/compiler/getFileSystem.mjs +40 -0
  65. package/es/contract/compiler/getFileSystem.mjs.map +1 -0
  66. package/es/contract/ga.d.ts +5 -4
  67. package/es/contract/ga.mjs +11 -2
  68. package/es/contract/ga.mjs.map +1 -1
  69. package/es/index-browser.d.ts +39 -0
  70. package/es/index-browser.mjs +55 -0
  71. package/es/index-browser.mjs.map +1 -0
  72. package/es/index.d.ts +4 -38
  73. package/es/index.mjs +4 -53
  74. package/es/index.mjs.map +1 -1
  75. package/es/oracle.mjs +1 -1
  76. package/es/oracle.mjs.map +1 -1
  77. package/es/spend.mjs +1 -3
  78. package/es/spend.mjs.map +1 -1
  79. package/es/tx/builder/constants.d.ts +28 -1
  80. package/es/tx/builder/constants.mjs +32 -3
  81. package/es/tx/builder/constants.mjs.map +1 -1
  82. package/es/tx/builder/field-types/abi-version.d.ts +10 -0
  83. package/es/tx/builder/field-types/abi-version.mjs +20 -0
  84. package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
  85. package/es/tx/builder/field-types/address.d.ts +5 -6
  86. package/es/tx/builder/field-types/address.mjs +17 -8
  87. package/es/tx/builder/field-types/address.mjs.map +1 -1
  88. package/es/tx/builder/field-types/array.d.ts +7 -0
  89. package/es/tx/builder/field-types/array.mjs +11 -0
  90. package/es/tx/builder/field-types/array.mjs.map +1 -0
  91. package/es/tx/builder/field-types/boolean.d.ts +6 -0
  92. package/es/tx/builder/field-types/boolean.mjs +13 -0
  93. package/es/tx/builder/field-types/boolean.mjs.map +1 -0
  94. package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
  95. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  96. package/es/tx/builder/field-types/ct-version.d.ts +30 -0
  97. package/es/tx/builder/field-types/ct-version.mjs +48 -0
  98. package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
  99. package/es/tx/builder/field-types/deposit.d.ts +1 -1
  100. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  101. package/es/tx/builder/field-types/encoded.d.ts +6 -0
  102. package/es/tx/builder/field-types/encoded.mjs +21 -0
  103. package/es/tx/builder/field-types/encoded.mjs.map +1 -0
  104. package/es/tx/builder/field-types/entry.d.ts +11 -0
  105. package/es/tx/builder/field-types/entry.mjs +31 -0
  106. package/es/tx/builder/field-types/entry.mjs.map +1 -0
  107. package/es/tx/builder/field-types/enumeration.d.ts +5 -3
  108. package/es/tx/builder/field-types/enumeration.mjs +11 -2
  109. package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
  110. package/es/tx/builder/field-types/fee.d.ts +10 -7
  111. package/es/tx/builder/field-types/fee.mjs +24 -20
  112. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  113. package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
  114. package/es/tx/builder/field-types/gas-limit.mjs +9 -6
  115. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  116. package/es/tx/builder/field-types/gas-price.d.ts +1 -1
  117. package/es/tx/builder/field-types/index.d.ts +66 -28
  118. package/es/tx/builder/field-types/index.mjs +30 -12
  119. package/es/tx/builder/field-types/index.mjs.map +1 -1
  120. package/es/tx/builder/field-types/mptree.d.ts +37 -0
  121. package/es/tx/builder/field-types/mptree.mjs +268 -0
  122. package/es/tx/builder/field-types/mptree.mjs.map +1 -0
  123. package/es/tx/builder/field-types/name-fee.d.ts +1 -2
  124. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  125. package/es/tx/builder/field-types/name-id.mjs +2 -1
  126. package/es/tx/builder/field-types/name-id.mjs.map +1 -1
  127. package/es/tx/builder/field-types/pointers.mjs +2 -2
  128. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  129. package/es/tx/builder/field-types/raw.d.ts +6 -0
  130. package/es/tx/builder/field-types/raw.mjs +13 -0
  131. package/es/tx/builder/field-types/raw.mjs.map +1 -0
  132. package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  133. package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
  134. package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
  135. package/es/tx/builder/field-types/string.d.ts +6 -0
  136. package/es/tx/builder/field-types/string.mjs +10 -0
  137. package/es/tx/builder/field-types/string.mjs.map +1 -0
  138. package/es/tx/builder/field-types/u-int.d.ts +1 -2
  139. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  140. package/es/tx/builder/index.d.ts +11 -29
  141. package/es/tx/builder/index.mjs +50 -211
  142. package/es/tx/builder/index.mjs.map +1 -1
  143. package/es/tx/builder/schema.d.ts +2111 -571
  144. package/es/tx/builder/schema.mjs +57 -125
  145. package/es/tx/builder/schema.mjs.map +1 -1
  146. package/es/tx/index.d.ts +5 -20
  147. package/es/tx/index.mjs +31 -88
  148. package/es/tx/index.mjs.map +1 -1
  149. package/es/tx/validator.d.ts +3 -5
  150. package/es/tx/validator.mjs +82 -95
  151. package/es/tx/validator.mjs.map +1 -1
  152. package/es/utils/bytes.mjs +1 -1
  153. package/es/utils/bytes.mjs.map +1 -1
  154. package/es/utils/errors.d.ts +3 -8
  155. package/es/utils/errors.mjs +1 -11
  156. package/es/utils/errors.mjs.map +1 -1
  157. package/es/utils/other.d.ts +1 -1
  158. package/package.json +35 -27
  159. package/src/AeSdkBase.ts +6 -3
  160. package/src/AeSdkMethods.ts +3 -4
  161. package/src/Node.ts +6 -3
  162. package/src/account/Base.ts +2 -2
  163. package/src/account/Generalized.ts +2 -2
  164. package/src/account/Ledger.ts +1 -1
  165. package/src/account/Memory.ts +1 -1
  166. package/src/aens.ts +3 -2
  167. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -7
  168. package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
  169. package/src/chain.ts +5 -3
  170. package/src/channel/Base.ts +13 -5
  171. package/src/channel/Contract.ts +11 -10
  172. package/src/channel/Spend.ts +7 -2
  173. package/src/channel/handlers.ts +10 -9
  174. package/src/channel/internal.ts +1 -1
  175. package/src/contract/Contract.ts +69 -79
  176. package/src/contract/compiler/Base.ts +94 -0
  177. package/src/contract/compiler/Cli.ts +134 -0
  178. package/src/contract/compiler/Http.ts +124 -0
  179. package/src/contract/compiler/HttpNode.ts +26 -0
  180. package/src/contract/compiler/getFileSystem.ts +42 -0
  181. package/src/contract/ga.ts +9 -6
  182. package/src/index-browser.ts +58 -0
  183. package/src/index.ts +4 -56
  184. package/src/oracle.ts +1 -1
  185. package/src/spend.ts +1 -1
  186. package/src/tx/builder/constants.ts +32 -3
  187. package/src/tx/builder/field-types/abi-version.ts +21 -0
  188. package/src/tx/builder/field-types/address.ts +23 -13
  189. package/src/tx/builder/field-types/array.ts +19 -0
  190. package/src/tx/builder/field-types/boolean.ts +9 -0
  191. package/src/tx/builder/field-types/coin-amount.ts +2 -1
  192. package/src/tx/builder/field-types/ct-version.ts +50 -0
  193. package/src/tx/builder/field-types/deposit.ts +1 -1
  194. package/src/tx/builder/field-types/encoded.ts +27 -0
  195. package/src/tx/builder/field-types/entry.ts +31 -0
  196. package/src/tx/builder/field-types/enumeration.ts +15 -4
  197. package/src/tx/builder/field-types/fee.ts +38 -18
  198. package/src/tx/builder/field-types/gas-limit.ts +12 -7
  199. package/src/tx/builder/field-types/index.ts +46 -17
  200. package/src/tx/builder/field-types/mptree.ts +242 -0
  201. package/src/tx/builder/field-types/name-fee.ts +1 -2
  202. package/src/tx/builder/field-types/name-id.ts +1 -1
  203. package/src/tx/builder/field-types/pointers.ts +2 -2
  204. package/src/tx/builder/field-types/raw.ts +9 -0
  205. package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
  206. package/src/tx/builder/field-types/string.ts +11 -0
  207. package/src/tx/builder/field-types/u-int.ts +1 -3
  208. package/src/tx/builder/index.ts +63 -247
  209. package/src/tx/builder/schema.ts +273 -323
  210. package/src/tx/index.ts +37 -104
  211. package/src/tx/validator.ts +72 -95
  212. package/src/utils/bytes.ts +1 -1
  213. package/src/utils/errors.ts +4 -13
  214. package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
  215. package/types-legacy/ts4.2/AeSdkMethods.d.ts +3 -4
  216. package/types-legacy/ts4.2/Node.d.ts +3 -3
  217. package/types-legacy/ts4.2/account/Base.d.ts +2 -2
  218. package/types-legacy/ts4.2/aens.d.ts +1 -1
  219. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  220. package/types-legacy/ts4.2/chain.d.ts +9 -1
  221. package/types-legacy/ts4.2/channel/Base.d.ts +6 -1
  222. package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
  223. package/types-legacy/ts4.2/channel/Spend.d.ts +3 -1
  224. package/types-legacy/ts4.2/contract/Contract.d.ts +21 -46
  225. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
  226. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
  227. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
  228. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
  229. package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
  230. package/types-legacy/ts4.2/contract/ga.d.ts +5 -4
  231. package/types-legacy/ts4.2/index-browser.d.ts +39 -0
  232. package/types-legacy/ts4.2/index.d.ts +4 -38
  233. package/types-legacy/ts4.2/tx/builder/constants.d.ts +28 -1
  234. package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
  235. package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
  236. package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
  237. package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
  238. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
  239. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
  240. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
  241. package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
  242. package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
  243. package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
  244. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +10 -7
  245. package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +5 -2
  246. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +1 -1
  247. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +72 -28
  248. package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
  249. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -2
  250. package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
  251. package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  252. package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
  253. package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
  254. package/types-legacy/ts4.2/tx/builder/index.d.ts +11 -29
  255. package/types-legacy/ts4.2/tx/builder/schema.d.ts +2380 -668
  256. package/types-legacy/ts4.2/tx/index.d.ts +5 -20
  257. package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
  258. package/types-legacy/ts4.2/utils/errors.d.ts +3 -8
  259. package/types-legacy/ts4.2/utils/other.d.ts +1 -1
  260. package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
  261. package/types-legacy/ts4.5/AeSdkMethods.d.ts +3 -4
  262. package/types-legacy/ts4.5/Node.d.ts +3 -3
  263. package/types-legacy/ts4.5/account/Base.d.ts +2 -2
  264. package/types-legacy/ts4.5/aens.d.ts +1 -1
  265. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  266. package/types-legacy/ts4.5/chain.d.ts +9 -1
  267. package/types-legacy/ts4.5/channel/Base.d.ts +6 -1
  268. package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
  269. package/types-legacy/ts4.5/channel/Spend.d.ts +3 -1
  270. package/types-legacy/ts4.5/contract/Contract.d.ts +21 -46
  271. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
  272. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
  273. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
  274. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
  275. package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
  276. package/types-legacy/ts4.5/contract/ga.d.ts +5 -4
  277. package/types-legacy/ts4.5/index-browser.d.ts +39 -0
  278. package/types-legacy/ts4.5/index.d.ts +4 -38
  279. package/types-legacy/ts4.5/tx/builder/constants.d.ts +28 -1
  280. package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
  281. package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
  282. package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
  283. package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
  284. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
  285. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
  286. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
  287. package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
  288. package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
  289. package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
  290. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +10 -7
  291. package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +5 -2
  292. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +1 -1
  293. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +72 -28
  294. package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
  295. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -2
  296. package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
  297. package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
  298. package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
  299. package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
  300. package/types-legacy/ts4.5/tx/builder/index.d.ts +11 -29
  301. package/types-legacy/ts4.5/tx/builder/schema.d.ts +2380 -668
  302. package/types-legacy/ts4.5/tx/index.d.ts +5 -20
  303. package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
  304. package/types-legacy/ts4.5/utils/errors.d.ts +3 -8
  305. package/types-legacy/ts4.5/utils/other.d.ts +1 -1
  306. package/es/contract/CompilerHttp.d.ts +0 -18
  307. package/es/contract/CompilerHttp.mjs.map +0 -1
  308. package/es/tx/builder/field-types/addresses.d.ts +0 -6
  309. package/es/tx/builder/field-types/addresses.mjs +0 -13
  310. package/es/tx/builder/field-types/addresses.mjs.map +0 -1
  311. package/es/utils/mptree.d.ts +0 -26
  312. package/es/utils/mptree.mjs +0 -143
  313. package/es/utils/mptree.mjs.map +0 -1
  314. package/src/contract/CompilerHttp.ts +0 -67
  315. package/src/tx/builder/field-types/addresses.ts +0 -18
  316. package/src/utils/mptree.ts +0 -145
  317. package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
  318. package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
  319. package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
  320. package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
  321. package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
  322. package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
@@ -4,166 +4,19 @@ import {
4
4
  } from '../../utils/encoder';
5
5
  import { AE_AMOUNT_FORMATS } from '../../utils/amount-formatter';
6
6
  import { hash } from '../../utils/crypto';
7
- import { Field } from './field-types';
7
+ import { BinaryData, Field } from './field-types';
8
8
  import {
9
- FIELD_TYPES,
10
- RawTxObject,
11
- TX_SCHEMA,
12
- TxField,
13
- TxParamsCommon,
14
- TxSchema,
15
- TxTypeSchemas,
9
+ RawTxObject, TX_SCHEMA, TxField, TxSchema, TxTypeSchemas,
16
10
  } from './schema';
17
11
  import { Tag } from './constants';
18
12
  import { buildContractId, readInt } from './helpers';
19
- import { toBytes } from '../../utils/bytes';
20
- import MPTree, { MPTreeBinary } from '../../utils/mptree';
21
- import {
22
- ArgumentError,
23
- DecodeError,
24
- InvalidTxParamsError,
25
- SchemaNotFoundError,
26
- } from '../../utils/errors';
13
+ import { ArgumentError, DecodeError, SchemaNotFoundError } from '../../utils/errors';
27
14
  import { isKeyOfObject } from '../../utils/other';
28
15
 
29
16
  /**
30
17
  * JavaScript-based Transaction builder
31
18
  */
32
19
 
33
- // SERIALIZE AND DESERIALIZE PART
34
- function deserializeField(
35
- value: any,
36
- type: FIELD_TYPES | Field,
37
- prefix?: Encoding | Encoding[],
38
- ): any {
39
- if (value == null) return '';
40
- switch (type) {
41
- case FIELD_TYPES.ctVersion: {
42
- const [vm, , abi] = value;
43
- return {
44
- vmVersion: readInt(Buffer.from([vm])),
45
- abiVersion: readInt(Buffer.from([abi])),
46
- };
47
- }
48
- case FIELD_TYPES.bool:
49
- return value[0] === 1;
50
- case FIELD_TYPES.binary:
51
- return encode(value, prefix as Encoding);
52
- case FIELD_TYPES.stateTree:
53
- return encode(value, Encoding.StateTrees);
54
- case FIELD_TYPES.string:
55
- return value.toString();
56
- case FIELD_TYPES.payload:
57
- return encode(value, Encoding.Bytearray);
58
- case FIELD_TYPES.rlpBinary:
59
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
60
- return unpackTx(encode(value, Encoding.Transaction));
61
- case FIELD_TYPES.rlpBinaries:
62
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
63
- return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));
64
- case FIELD_TYPES.rawBinary:
65
- return value;
66
- case FIELD_TYPES.hex:
67
- return value.toString('hex');
68
- case FIELD_TYPES.offChainUpdates:
69
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
70
- return value.map((v: Buffer) => unpackTx(encode(v, Encoding.Transaction)));
71
- case FIELD_TYPES.callStack:
72
- // TODO: fix this
73
- return [readInt(value)];
74
- case FIELD_TYPES.mptrees:
75
- return value.map((t: MPTreeBinary) => new MPTree(t));
76
- case FIELD_TYPES.sophiaCodeTypeInfo:
77
- return value.reduce(
78
- (acc: object, [funHash, fnName, argType, outType]: [
79
- funHash: Buffer,
80
- fnName: string,
81
- argType: string,
82
- outType: string,
83
- ]) => ({
84
- ...acc,
85
- [fnName.toString()]: { funHash, argType, outType },
86
- }),
87
- {},
88
- );
89
- default:
90
- if (typeof type === 'number') return value;
91
- return type.deserialize(value);
92
- }
93
- }
94
-
95
- function serializeField(value: any, type: FIELD_TYPES | Field, params: any): any {
96
- switch (type) {
97
- case FIELD_TYPES.bool:
98
- return Buffer.from([(value === true) ? 1 : 0]);
99
- case FIELD_TYPES.binary:
100
- return decode(value);
101
- case FIELD_TYPES.stateTree:
102
- return decode(value);
103
- case FIELD_TYPES.hex:
104
- return Buffer.from(value, 'hex');
105
- case FIELD_TYPES.signatures:
106
- return value.map(Buffer.from);
107
- case FIELD_TYPES.payload:
108
- return typeof value === 'string' && value.split('_')[0] === 'ba'
109
- ? decode(value as Encoded.Bytearray)
110
- : toBytes(value);
111
- case FIELD_TYPES.string:
112
- return toBytes(value);
113
- case FIELD_TYPES.rlpBinary:
114
- return value.rlpEncoded ?? value;
115
- case FIELD_TYPES.mptrees:
116
- return value.map((t: MPTree) => t.serialize());
117
- case FIELD_TYPES.ctVersion:
118
- return Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
119
- default:
120
- if (typeof type === 'number') return value;
121
- return type.serialize(value, params);
122
- }
123
- }
124
-
125
- function validateField(
126
- value: any,
127
- type: FIELD_TYPES | Field,
128
- ): string | undefined {
129
- // All fields are required
130
- if (value == null) return 'Field is required';
131
-
132
- // Validate type of value
133
- switch (type) {
134
- case FIELD_TYPES.ctVersion:
135
- if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
136
- return 'Value must be an object with "vmVersion" and "abiVersion" fields';
137
- }
138
- return undefined;
139
- default:
140
- return undefined;
141
- }
142
- }
143
-
144
- /**
145
- * Validate transaction params
146
- * @category transaction builder
147
- * @param params - Object with tx params
148
- * @param schema - Transaction schema
149
- * @param excludeKeys - Array of keys to exclude for validation
150
- * @returns Object with validation errors
151
- */
152
- function validateParams(
153
- params: any,
154
- schema: TxField[],
155
- { excludeKeys = [] }: { excludeKeys: string[] },
156
- ): object {
157
- const optionalFields = ['payload', 'nameFee', 'deposit', 'gasPrice', 'fee', 'gasLimit', 'amount'];
158
- return Object.fromEntries(
159
- schema
160
- // TODO: allow optional keys in schema
161
- .filter(([key]) => !excludeKeys.includes(key) && !optionalFields.includes(key))
162
- .map(([key, type]) => [key, validateField(params[key], type)])
163
- .filter(([, message]) => message),
164
- );
165
- }
166
-
167
20
  /**
168
21
  * Unpack binary transaction
169
22
  * @category transaction builder
@@ -175,34 +28,29 @@ function unpackRawTx<Tx extends TxSchema>(
175
28
  binary: Uint8Array | NestedUint8Array,
176
29
  schema: TxField[],
177
30
  ): RawTxObject<Tx> {
31
+ if (binary.length !== schema.length) {
32
+ throw new ArgumentError('Transaction RLP length', schema.length, binary.length);
33
+ }
178
34
  return schema
179
35
  .reduce<any>(
180
36
  (
181
37
  acc,
182
- [key, fieldType, prefix],
38
+ [name, field],
183
39
  index,
184
- ) => Object.assign(acc, { [key]: deserializeField(binary[index], fieldType, prefix) }),
40
+ ) => {
41
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
42
+ const deserialized = field.deserialize(binary[index] as BinaryData, { unpackTx });
43
+ return { ...acc, [name]: deserialized };
44
+ },
185
45
  {},
186
46
  );
187
47
  }
188
48
 
189
- /**
190
- * @category transaction builder
191
- */
192
- export interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {
193
- tx: Encoded.Generic<Prefix>;
194
- rlpEncoded: Uint8Array;
195
- binary: Uint8Array;
196
- txObject: RawTxObject<Tx>;
197
- }
198
-
199
49
  /**
200
50
  * Build transaction hash
201
51
  * @category transaction builder
202
- * @param _params - Object with tx params
203
- * @param type - Transaction type
52
+ * @param params - Object with tx params
204
53
  * @param options - options
205
- * @param options.excludeKeys - Array of keys to exclude for validation and build
206
54
  * @param options.denomination - Denomination of amounts
207
55
  * @param options.prefix - Prefix of transaction
208
56
  * @throws {@link InvalidTxParamsError}
@@ -211,78 +59,51 @@ export interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {
211
59
  * @returns object.rlpEncoded rlp encoded transaction
212
60
  * @returns object.binary binary transaction
213
61
  */
214
- export function buildTx<TxType extends Tag, Prefix>(
215
- _params: Omit<TxTypeSchemas[TxType], 'tag' | 'VSN'> & { VSN?: number },
216
- type: TxType,
62
+ export function buildTx<
63
+ TxType extends Tag,
64
+ E extends Encoding = Encoding.Transaction,
65
+ >(
66
+ params: { tag: TxType; version?: number } & Omit<TxTypeSchemas[TxType], 'tag' | 'version'>
67
+ // TODO: get it from gas-limit.ts somehow
68
+ & (TxType extends Tag.ContractCreateTx | Tag.ContractCallTx
69
+ | Tag.ChannelOffChainUpdateCallContract | Tag.GaAttachTx | Tag.GaMetaTx
70
+ ? { gasMax?: number } : {}),
217
71
  {
218
- excludeKeys = [],
219
- prefix = Encoding.Transaction,
220
- vsn,
72
+ prefix,
221
73
  denomination = AE_AMOUNT_FORMATS.AETTOS,
222
74
  }: {
223
- excludeKeys?: string[];
224
- prefix?: Encoding;
225
- vsn?: number;
75
+ prefix?: E;
226
76
  denomination?: AE_AMOUNT_FORMATS;
227
77
  } = {},
228
- ): BuiltTx<TxSchema, Prefix extends Encoding ? Prefix : Encoding.Transaction> {
229
- const schemas = TX_SCHEMA[type];
230
-
231
- vsn ??= Math.max(...Object.keys(schemas).map((a) => +a));
232
- if (!isKeyOfObject(vsn, schemas)) throw new SchemaNotFoundError('serialization', Tag[type], vsn);
233
-
234
- const schema = schemas[vsn] as unknown as TxField[];
235
-
236
- const params = _params as TxParamsCommon & { onNode: Node; denomination?: AE_AMOUNT_FORMATS };
237
- params.VSN = vsn;
238
- params.tag = type;
239
- params.denomination = denomination;
240
- const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key));
241
-
242
- // Validation
243
- const valid = validateParams(params, schema, { excludeKeys });
244
- if (Object.keys(valid).length > 0) {
245
- throw new InvalidTxParamsError(`Transaction build error. ${JSON.stringify(valid)}`);
78
+ ): Encoded.Generic<E> {
79
+ const schemas = TX_SCHEMA[params.tag];
80
+ params.version ??= Math.max(...Object.keys(schemas).map((a) => +a));
81
+ if (!isKeyOfObject(params.version, schemas)) {
82
+ throw new SchemaNotFoundError('serialization', Tag[params.tag], params.version);
246
83
  }
247
-
248
- const binary = filteredSchema
249
- .map(([key, fieldType]: [keyof TxSchema, FIELD_TYPES, Encoding]) => (
250
- serializeField(
251
- params[key],
252
- fieldType,
253
- {
254
- ...params,
255
- txType: type,
256
- rebuildTx: (overrideParams: any) => buildTx(
257
- { ...params, ...overrideParams },
258
- type,
259
- {
260
- excludeKeys, prefix: Encoding.Transaction, vsn, denomination,
261
- },
262
- ),
263
- },
264
- )
265
- ))
266
- .filter((e) => e !== undefined);
267
-
268
- const rlpEncoded = rlpEncode(binary);
269
- const tx = encode(rlpEncoded, prefix);
270
- return {
271
- tx,
272
- rlpEncoded,
273
- binary,
274
- txObject: unpackRawTx<TxTypeSchemas[Tag]>(binary, schema),
275
- } as any;
84
+ const schema = schemas[params.version] as unknown as TxField[];
85
+
86
+ const binary = schema.map(([key, field]: [keyof TxSchema, Field]) => (
87
+ field.serialize(
88
+ params[key],
89
+ {
90
+ ...params,
91
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
92
+ unpackTx,
93
+ buildTx,
94
+ denomination,
95
+ rebuildTx: (overrideParams: any) => buildTx(
96
+ { ...params, ...overrideParams },
97
+ { denomination },
98
+ ),
99
+ },
100
+ )
101
+ ));
102
+
103
+ // @ts-expect-error looks like a TypeScript edge case
104
+ return encode(rlpEncode(binary), prefix ?? Encoding.Transaction);
276
105
  }
277
106
 
278
- /**
279
- * @category transaction builder
280
- */
281
- export interface TxUnpacked<Tx extends TxSchema> {
282
- txType: Tag;
283
- tx: RawTxObject<Tx>;
284
- rlpEncoded: Uint8Array;
285
- }
286
107
  /**
287
108
  * Unpack transaction hash
288
109
  * @category transaction builder
@@ -295,20 +116,15 @@ export interface TxUnpacked<Tx extends TxSchema> {
295
116
  export function unpackTx<TxType extends Tag>(
296
117
  encodedTx: Encoded.Transaction | Encoded.Poi,
297
118
  txType?: TxType,
298
- ): TxUnpacked<TxTypeSchemas[TxType]> {
299
- const rlpEncoded = decode(encodedTx);
300
- const binary = rlpDecode(rlpEncoded);
301
- const objId = +readInt(binary[0] as Buffer);
302
- if (!isKeyOfObject(objId, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${objId}`);
303
- if (txType != null && txType !== objId) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[objId]} instead`);
304
- const vsn = +readInt(binary[1] as Buffer);
305
- if (!isKeyOfObject(vsn, TX_SCHEMA[objId])) throw new SchemaNotFoundError('deserialization', `tag ${objId}`, vsn);
306
- const schema = TX_SCHEMA[objId][vsn];
307
- return {
308
- txType: objId,
309
- tx: unpackRawTx<TxTypeSchemas[TxType]>(binary, schema),
310
- rlpEncoded,
311
- };
119
+ ): RawTxObject<TxTypeSchemas[TxType]> {
120
+ const binary = rlpDecode(decode(encodedTx));
121
+ const tag = +readInt(binary[0] as Buffer);
122
+ if (!isKeyOfObject(tag, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${tag}`);
123
+ if (txType != null && txType !== tag) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[tag]} instead`);
124
+ const version = +readInt(binary[1] as Buffer);
125
+ if (!isKeyOfObject(version, TX_SCHEMA[tag])) throw new SchemaNotFoundError('deserialization', `tag ${tag}`, version);
126
+ const schema = TX_SCHEMA[tag][version];
127
+ return unpackRawTx<TxTypeSchemas[TxType]>(binary, schema);
312
128
  }
313
129
 
314
130
  /**
@@ -333,9 +149,9 @@ export function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.Tx
333
149
  export function buildContractIdByContractTx(
334
150
  contractTx: Encoded.Transaction,
335
151
  ): Encoded.ContractAddress {
336
- const { txType, tx } = unpackTx<Tag.ContractCreateTx | Tag.GaAttachTx>(contractTx);
337
- if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {
338
- throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);
152
+ const { tag, ownerId, nonce } = unpackTx<Tag.ContractCreateTx | Tag.GaAttachTx>(contractTx);
153
+ if (![Tag.ContractCreateTx, Tag.GaAttachTx].includes(tag)) {
154
+ throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', tag);
339
155
  }
340
- return buildContractId(tx.ownerId, +tx.nonce);
156
+ return buildContractId(ownerId, +nonce);
341
157
  }