@aeternity/aepp-sdk 11.0.1 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +37 -0
  10. package/es/AeSdk.mjs +81 -0
  11. package/es/AeSdk.mjs.map +1 -0
  12. package/es/AeSdkAepp.d.ts +69 -0
  13. package/es/AeSdkAepp.mjs +175 -0
  14. package/es/AeSdkAepp.mjs.map +1 -0
  15. package/es/AeSdkBase.d.ts +212 -0
  16. package/es/AeSdkBase.mjs +310 -0
  17. package/es/AeSdkBase.mjs.map +1 -0
  18. package/es/AeSdkWallet.d.ts +103 -0
  19. package/es/AeSdkWallet.mjs +322 -0
  20. package/es/AeSdkWallet.mjs.map +1 -0
  21. package/es/Node.d.ts +44 -0
  22. package/es/Node.mjs +141 -0
  23. package/es/Node.mjs.map +1 -0
  24. package/es/account/Base.d.ts +65 -0
  25. package/es/account/Base.mjs +123 -0
  26. package/es/account/Base.mjs.map +1 -0
  27. package/es/account/Memory.d.ts +25 -0
  28. package/es/account/Memory.mjs +81 -0
  29. package/es/account/Memory.mjs.map +1 -0
  30. package/es/account/Rpc.d.ts +27 -0
  31. package/es/account/Rpc.mjs +79 -0
  32. package/es/account/Rpc.mjs.map +1 -0
  33. package/es/aens.d.ts +209 -0
  34. package/es/aens.mjs +332 -0
  35. package/es/aens.mjs.map +1 -0
  36. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  37. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  46. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  47. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  51. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  52. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  54. package/es/aepp-wallet-communication/schema.d.ts +90 -46
  55. package/es/aepp-wallet-communication/schema.mjs +214 -0
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  60. package/es/apis/compiler/compiler.d.ts +92 -0
  61. package/es/apis/compiler/compiler.mjs +576 -0
  62. package/es/apis/compiler/compiler.mjs.map +1 -0
  63. package/es/apis/compiler/index.d.ts +2 -0
  64. package/es/apis/compiler/index.mjs +3 -0
  65. package/es/apis/compiler/index.mjs.map +1 -0
  66. package/es/apis/compiler/models/index.d.ts +248 -0
  67. package/es/apis/compiler/models/index.mjs +48 -0
  68. package/es/apis/compiler/models/index.mjs.map +1 -0
  69. package/es/apis/compiler/models/mappers.d.ts +23 -0
  70. package/es/apis/compiler/models/mappers.mjs +585 -0
  71. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  72. package/es/apis/compiler/models/parameters.d.ts +13 -0
  73. package/es/apis/compiler/models/parameters.mjs +71 -0
  74. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  75. package/es/apis/node/index.d.ts +2 -0
  76. package/es/apis/node/index.mjs +3 -0
  77. package/es/apis/node/index.mjs.map +1 -0
  78. package/es/apis/node/models/index.d.ts +1061 -0
  79. package/es/apis/node/models/index.mjs +2 -0
  80. package/es/apis/node/models/index.mjs.map +1 -0
  81. package/es/apis/node/models/mappers.d.ts +95 -0
  82. package/es/apis/node/models/mappers.mjs +4164 -0
  83. package/es/apis/node/models/mappers.mjs.map +1 -0
  84. package/es/apis/node/models/parameters.d.ts +17 -0
  85. package/es/apis/node/models/parameters.mjs +165 -0
  86. package/es/apis/node/models/parameters.mjs.map +1 -0
  87. package/es/apis/node/node.d.ts +215 -0
  88. package/es/apis/node/node.mjs +1165 -0
  89. package/es/apis/node/node.mjs.map +1 -0
  90. package/es/chain.d.ts +220 -0
  91. package/es/chain.mjs +524 -0
  92. package/es/chain.mjs.map +1 -0
  93. package/es/channel/handlers.d.ts +34 -0
  94. package/es/channel/handlers.mjs +147 -112
  95. package/es/channel/handlers.mjs.map +1 -1
  96. package/es/channel/index.d.ts +634 -0
  97. package/es/channel/index.mjs +898 -900
  98. package/es/channel/index.mjs.map +1 -1
  99. package/es/channel/internal.d.ts +100 -0
  100. package/es/channel/internal.mjs +97 -51
  101. package/es/channel/internal.mjs.map +1 -1
  102. package/es/contract/Compiler.d.ts +17 -0
  103. package/es/contract/Compiler.mjs +67 -0
  104. package/es/contract/Compiler.mjs.map +1 -0
  105. package/es/contract/aci.d.ts +125 -0
  106. package/es/contract/aci.mjs +199 -180
  107. package/es/contract/aci.mjs.map +1 -1
  108. package/es/contract/ga.d.ts +68 -0
  109. package/es/contract/ga.mjs +190 -0
  110. package/es/contract/ga.mjs.map +1 -0
  111. package/es/contract/methods.d.ts +68 -0
  112. package/es/contract/methods.mjs +101 -0
  113. package/es/contract/methods.mjs.map +1 -0
  114. package/es/index.d.ts +32 -0
  115. package/es/index.mjs +32 -40
  116. package/es/index.mjs.map +1 -1
  117. package/es/oracle.d.ts +154 -0
  118. package/es/oracle.mjs +288 -0
  119. package/es/oracle.mjs.map +1 -0
  120. package/es/spend.d.ts +61 -0
  121. package/es/spend.mjs +122 -0
  122. package/es/spend.mjs.map +1 -0
  123. package/es/tx/builder/constants.d.ts +41 -0
  124. package/es/tx/builder/constants.mjs +11 -19
  125. package/es/tx/builder/constants.mjs.map +1 -1
  126. package/es/tx/builder/field-types.d.ts +62 -0
  127. package/es/tx/builder/field-types.mjs +62 -10
  128. package/es/tx/builder/field-types.mjs.map +1 -1
  129. package/es/tx/builder/helpers.d.ts +131 -0
  130. package/es/tx/builder/helpers.mjs +71 -169
  131. package/es/tx/builder/helpers.mjs.map +1 -1
  132. package/es/tx/builder/index.d.ts +75 -0
  133. package/es/tx/builder/index.mjs +141 -323
  134. package/es/tx/builder/index.mjs.map +1 -1
  135. package/es/tx/builder/schema.d.ts +350 -0
  136. package/es/tx/builder/schema.mjs +173 -510
  137. package/es/tx/builder/schema.mjs.map +1 -1
  138. package/es/tx/index.d.ts +63 -0
  139. package/es/tx/index.mjs +171 -265
  140. package/es/tx/index.mjs.map +1 -1
  141. package/es/tx/min-fee.d.ts +20 -0
  142. package/es/tx/min-fee.mjs +148 -0
  143. package/es/tx/min-fee.mjs.map +1 -0
  144. package/es/tx/validator.d.ts +19 -0
  145. package/es/tx/validator.mjs +64 -71
  146. package/es/tx/validator.mjs.map +1 -1
  147. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  149. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  151. package/es/typings/bip32-path/index.d.mjs +2 -0
  152. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  153. package/es/typings/blakejs/index.d.mjs.map +1 -1
  154. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  155. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  156. package/es/utils/amount-formatter.d.ts +42 -0
  157. package/es/utils/amount-formatter.mjs +28 -41
  158. package/es/utils/amount-formatter.mjs.map +1 -1
  159. package/es/utils/autorest.d.ts +6 -0
  160. package/es/utils/autorest.mjs +97 -0
  161. package/es/utils/autorest.mjs.map +1 -0
  162. package/es/utils/bignumber.d.ts +13 -0
  163. package/es/utils/bignumber.mjs +10 -8
  164. package/es/utils/bignumber.mjs.map +1 -1
  165. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  166. package/es/utils/bytes.mjs +10 -14
  167. package/es/utils/bytes.mjs.map +1 -1
  168. package/es/utils/crypto.d.ts +103 -0
  169. package/es/utils/crypto.mjs +60 -68
  170. package/es/utils/crypto.mjs.map +1 -1
  171. package/es/utils/encoder.d.ts +26 -0
  172. package/es/utils/encoder.mjs +47 -51
  173. package/es/utils/encoder.mjs.map +1 -1
  174. package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
  175. package/es/utils/errors.mjs +318 -125
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.d.ts +34 -0
  178. package/es/utils/hd-wallet.mjs +27 -16
  179. package/es/utils/hd-wallet.mjs.map +1 -1
  180. package/es/utils/json-big.d.ts +5 -0
  181. package/es/utils/json-big.mjs +10 -14
  182. package/es/utils/json-big.mjs.map +1 -1
  183. package/es/utils/keystore.d.ts +51 -0
  184. package/es/utils/keystore.mjs +98 -193
  185. package/es/utils/keystore.mjs.map +1 -1
  186. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  187. package/es/utils/mptree.mjs +13 -14
  188. package/es/utils/mptree.mjs.map +1 -1
  189. package/es/utils/other.d.ts +14 -0
  190. package/es/utils/other.mjs +21 -36
  191. package/es/utils/other.mjs.map +1 -1
  192. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  193. package/es/utils/semver-satisfies.mjs.map +1 -1
  194. package/es/utils/string.d.ts +24 -0
  195. package/es/utils/string.mjs +8 -10
  196. package/es/utils/string.mjs.map +1 -1
  197. package/package.json +49 -39
  198. package/src/AeSdk.ts +65 -0
  199. package/src/AeSdkAepp.ts +167 -0
  200. package/src/AeSdkBase.ts +320 -0
  201. package/src/AeSdkWallet.ts +332 -0
  202. package/src/Node.ts +167 -0
  203. package/src/account/Base.ts +114 -0
  204. package/src/account/Memory.ts +83 -0
  205. package/src/account/Rpc.ts +67 -0
  206. package/src/aens.ts +391 -0
  207. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  208. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  209. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  210. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
  211. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  212. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  213. package/src/aepp-wallet-communication/schema.ts +181 -0
  214. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  215. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  216. package/src/apis/compiler/compiler.ts +585 -0
  217. package/src/apis/compiler/index.ts +2 -0
  218. package/src/apis/compiler/models/index.ts +301 -0
  219. package/src/apis/compiler/models/mappers.ts +583 -0
  220. package/src/apis/compiler/models/parameters.ts +93 -0
  221. package/src/apis/node/code-model-v4.yaml +10046 -0
  222. package/src/apis/node/index.ts +2 -0
  223. package/src/apis/node/models/index.ts +1253 -0
  224. package/src/apis/node/models/mappers.ts +4278 -0
  225. package/src/apis/node/models/parameters.ts +188 -0
  226. package/src/apis/node/node.ts +1299 -0
  227. package/src/chain.ts +444 -0
  228. package/src/channel/{handlers.js → handlers.ts} +220 -128
  229. package/src/channel/index.ts +991 -0
  230. package/src/channel/internal.ts +345 -0
  231. package/src/contract/Compiler.ts +66 -0
  232. package/src/contract/aci.ts +529 -0
  233. package/src/contract/ga.ts +178 -0
  234. package/src/contract/methods.ts +118 -0
  235. package/src/index.ts +51 -0
  236. package/src/oracle.ts +342 -0
  237. package/src/spend.ts +152 -0
  238. package/src/tx/builder/{constants.js → constants.ts} +12 -16
  239. package/src/tx/builder/field-types.ts +111 -0
  240. package/src/tx/builder/helpers.ts +253 -0
  241. package/src/tx/builder/index.ts +394 -0
  242. package/src/tx/builder/schema.ts +771 -0
  243. package/src/tx/index.ts +199 -0
  244. package/src/tx/min-fee.ts +136 -0
  245. package/src/tx/validator.ts +226 -0
  246. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  247. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  248. package/src/typings/bip32-path/index.d.ts +33 -0
  249. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  250. package/src/utils/amount-formatter.ts +29 -42
  251. package/src/utils/autorest.ts +90 -0
  252. package/src/utils/bignumber.ts +9 -11
  253. package/src/utils/bytes.ts +12 -14
  254. package/src/utils/crypto.ts +217 -0
  255. package/src/utils/encoder.ts +52 -55
  256. package/src/utils/errors.ts +268 -134
  257. package/src/utils/hd-wallet.ts +134 -0
  258. package/src/utils/json-big.ts +26 -0
  259. package/src/utils/keystore.ts +179 -0
  260. package/src/utils/mptree.ts +14 -14
  261. package/src/utils/other.ts +28 -43
  262. package/src/utils/string.ts +8 -10
  263. package/es/account/base.mjs +0 -179
  264. package/es/account/base.mjs.map +0 -1
  265. package/es/account/memory.mjs +0 -99
  266. package/es/account/memory.mjs.map +0 -1
  267. package/es/account/multiple.mjs +0 -179
  268. package/es/account/multiple.mjs.map +0 -1
  269. package/es/ae/aens.mjs +0 -404
  270. package/es/ae/aens.mjs.map +0 -1
  271. package/es/ae/aepp.mjs +0 -45
  272. package/es/ae/aepp.mjs.map +0 -1
  273. package/es/ae/contract.mjs +0 -159
  274. package/es/ae/contract.mjs.map +0 -1
  275. package/es/ae/index.mjs +0 -207
  276. package/es/ae/index.mjs.map +0 -1
  277. package/es/ae/oracle.mjs +0 -339
  278. package/es/ae/oracle.mjs.map +0 -1
  279. package/es/ae/universal.mjs +0 -45
  280. package/es/ae/universal.mjs.map +0 -1
  281. package/es/ae/wallet.mjs +0 -50
  282. package/es/ae/wallet.mjs.map +0 -1
  283. package/es/amount-formatter.d.ts +0 -58
  284. package/es/bignumber.d.ts +0 -18
  285. package/es/chain/index.mjs +0 -272
  286. package/es/chain/index.mjs.map +0 -1
  287. package/es/chain/node.mjs +0 -442
  288. package/es/chain/node.mjs.map +0 -1
  289. package/es/contract/compiler.mjs +0 -115
  290. package/es/contract/compiler.mjs.map +0 -1
  291. package/es/contract/ga/helpers.mjs +0 -30
  292. package/es/contract/ga/helpers.mjs.map +0 -1
  293. package/es/contract/ga/index.mjs +0 -178
  294. package/es/contract/ga/index.mjs.map +0 -1
  295. package/es/crypto-ts.d.ts +0 -9
  296. package/es/encoder.d.ts +0 -26
  297. package/es/node-pool/index.mjs +0 -188
  298. package/es/node-pool/index.mjs.map +0 -1
  299. package/es/node.mjs +0 -133
  300. package/es/node.mjs.map +0 -1
  301. package/es/other.d.ts +0 -31
  302. package/es/string.d.ts +0 -26
  303. package/es/tx/tx-object.mjs +0 -283
  304. package/es/tx/tx-object.mjs.map +0 -1
  305. package/es/tx/tx.mjs +0 -938
  306. package/es/tx/tx.mjs.map +0 -1
  307. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  308. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  309. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  310. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  311. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  312. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  313. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  314. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  315. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  316. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  317. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  318. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  319. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  320. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  321. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  322. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  323. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  324. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  325. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  326. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  327. package/es/utils/async-init.mjs +0 -64
  328. package/es/utils/async-init.mjs.map +0 -1
  329. package/es/utils/crypto-ts.mjs.map +0 -1
  330. package/es/utils/swagger.mjs +0 -164
  331. package/es/utils/swagger.mjs.map +0 -1
  332. package/src/account/base.js +0 -153
  333. package/src/account/memory.js +0 -83
  334. package/src/account/multiple.js +0 -162
  335. package/src/ae/aens.js +0 -361
  336. package/src/ae/aepp.js +0 -45
  337. package/src/ae/contract.js +0 -148
  338. package/src/ae/index.js +0 -168
  339. package/src/ae/oracle.js +0 -311
  340. package/src/ae/universal.js +0 -47
  341. package/src/ae/wallet.js +0 -50
  342. package/src/chain/index.js +0 -269
  343. package/src/chain/node.js +0 -320
  344. package/src/channel/index.js +0 -903
  345. package/src/channel/internal.js +0 -236
  346. package/src/contract/aci.js +0 -376
  347. package/src/contract/compiler.js +0 -100
  348. package/src/contract/ga/helpers.js +0 -19
  349. package/src/contract/ga/index.js +0 -150
  350. package/src/index.js +0 -89
  351. package/src/node-pool/index.js +0 -172
  352. package/src/node.js +0 -116
  353. package/src/tx/builder/field-types.js +0 -61
  354. package/src/tx/builder/helpers.js +0 -334
  355. package/src/tx/builder/index.js +0 -465
  356. package/src/tx/builder/schema.js +0 -1100
  357. package/src/tx/index.js +0 -301
  358. package/src/tx/tx-object.js +0 -187
  359. package/src/tx/tx.js +0 -631
  360. package/src/tx/validator.js +0 -181
  361. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  362. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  363. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  364. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  365. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  366. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  367. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  368. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  369. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  370. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  371. package/src/utils/async-init.js +0 -45
  372. package/src/utils/crypto.js +0 -219
  373. package/src/utils/hd-wallet.js +0 -100
  374. package/src/utils/json-big.js +0 -26
  375. package/src/utils/keystore.js +0 -219
  376. package/src/utils/swagger.js +0 -156
@@ -1,4 +1,5 @@
1
1
  import _buffer from "buffer";
2
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
3
  const {
3
4
  Buffer: _Buffer
4
5
  } = _buffer;
@@ -10,26 +11,19 @@ const {
10
11
  } = _rlp;
11
12
  import { AE_AMOUNT_FORMATS, formatAmount } from "../../utils/amount-formatter.mjs";
12
13
  import { hash } from "../../utils/crypto.mjs";
13
- import { Field } from "./field-types.mjs";
14
- import { DEFAULT_FEE, FIELD_TYPES, OBJECT_ID_TX_TYPE, TX_DESERIALIZATION_SCHEMA, TX_FEE_BASE_GAS, TX_FEE_OTHER_GAS, TX_SERIALIZATION_SCHEMA, TX_TYPE, VSN } from "./schema.mjs";
15
- import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode } from "./helpers.mjs";
14
+ import { FIELD_TYPES, TX_SCHEMA, TX_TYPE } from "./schema.mjs";
15
+ import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode, buildContractId } from "./helpers.mjs";
16
16
  import { toBytes } from "../../utils/bytes.mjs";
17
17
  import MPTree from "../../utils/mptree.mjs";
18
- import { InvalidTxParamsError, SchemaNotFoundError } from "../../utils/errors.mjs";
18
+ import { ArgumentError, InvalidTxParamsError, SchemaNotFoundError, DecodeError } from "../../utils/errors.mjs";
19
+ import { isKeyOfObject } from "../../utils/other.mjs";
19
20
  /**
20
21
  * JavaScript-based Transaction builder
21
- * @module @aeternity/aepp-sdk/es/tx/builder
22
- * @export TxBuilder
23
- * @example import { TxBuilder } from '@aeternity/aepp-sdk'
24
22
  */
25
-
26
- const ORACLE_TTL_TYPES = {
27
- delta: 'delta',
28
- block: 'block'
29
- }; // SERIALIZE AND DESERIALIZE PART
23
+ // SERIALIZE AND DESERIALIZE PART
30
24
 
31
25
  function deserializeField(value, type, prefix) {
32
- if (!value) return '';
26
+ if (value == null) return '';
33
27
 
34
28
  switch (type) {
35
29
  case FIELD_TYPES.ctVersion:
@@ -43,8 +37,13 @@ function deserializeField(value, type, prefix) {
43
37
 
44
38
  case FIELD_TYPES.amount:
45
39
  case FIELD_TYPES.int:
40
+ case FIELD_TYPES.abiVersion:
41
+ case FIELD_TYPES.ttlType:
46
42
  return readInt(value);
47
43
 
44
+ case FIELD_TYPES.shortInt:
45
+ return +readInt(value);
46
+
48
47
  case FIELD_TYPES.id:
49
48
  return readId(value);
50
49
 
@@ -70,10 +69,10 @@ function deserializeField(value, type, prefix) {
70
69
  return readPointers(value);
71
70
 
72
71
  case FIELD_TYPES.rlpBinary:
73
- return unpackTx(value, true);
72
+ return unpackTx(encode(value, 'tx'));
74
73
 
75
74
  case FIELD_TYPES.rlpBinaries:
76
- return value.map(v => unpackTx(v, true));
75
+ return value.map(v => unpackTx(encode(v, 'tx')));
77
76
 
78
77
  case FIELD_TYPES.rawBinary:
79
78
  return value;
@@ -82,7 +81,7 @@ function deserializeField(value, type, prefix) {
82
81
  return value.toString('hex');
83
82
 
84
83
  case FIELD_TYPES.offChainUpdates:
85
- return value.map(v => unpackTx(v, true));
84
+ return value.map(v => unpackTx(encode(v, 'tx')));
86
85
 
87
86
  case FIELD_TYPES.callStack:
88
87
  // TODO: fix this
@@ -119,17 +118,20 @@ function deserializeField(value, type, prefix) {
119
118
  }, {});
120
119
 
121
120
  default:
122
- if (type.prototype instanceof Field) return type.deserialize(value);
121
+ if (type instanceof Object && 'deserialize' in type) return type.deserialize(value);
123
122
  return value;
124
123
  }
125
124
  }
126
125
 
127
- function serializeField(value, type, prefix, params) {
126
+ function serializeField(value, type, params) {
128
127
  var _value$rlpEncoded;
129
128
 
130
129
  switch (type) {
131
130
  case FIELD_TYPES.amount:
132
131
  case FIELD_TYPES.int:
132
+ case FIELD_TYPES.shortInt:
133
+ case FIELD_TYPES.abiVersion:
134
+ case FIELD_TYPES.ttlType:
133
135
  return writeInt(value);
134
136
 
135
137
  case FIELD_TYPES.id:
@@ -139,13 +141,13 @@ function serializeField(value, type, prefix, params) {
139
141
  return value.map(writeId);
140
142
 
141
143
  case FIELD_TYPES.bool:
142
- return _Buffer.from([value ? 1 : 0]);
144
+ return _Buffer.from([value === true ? 1 : 0]);
143
145
 
144
146
  case FIELD_TYPES.binary:
145
- return decode(value, prefix);
147
+ return decode(value);
146
148
 
147
149
  case FIELD_TYPES.stateTree:
148
- return decode(value, 'ss');
150
+ return decode(value);
149
151
 
150
152
  case FIELD_TYPES.hex:
151
153
  return _Buffer.from(value, 'hex');
@@ -154,7 +156,7 @@ function serializeField(value, type, prefix, params) {
154
156
  return value.map(_Buffer.from);
155
157
 
156
158
  case FIELD_TYPES.payload:
157
- return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value, 'ba') : toBytes(value);
159
+ return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value) : toBytes(value);
158
160
 
159
161
  case FIELD_TYPES.string:
160
162
  return toBytes(value);
@@ -166,7 +168,7 @@ function serializeField(value, type, prefix, params) {
166
168
  return (_value$rlpEncoded = value.rlpEncoded) !== null && _value$rlpEncoded !== void 0 ? _value$rlpEncoded : value;
167
169
 
168
170
  case FIELD_TYPES.mptrees:
169
- return value.map(t => t.serialize());
171
+ return value.map(t => t.serialize(''));
170
172
 
171
173
  case FIELD_TYPES.ctVersion:
172
174
  return _Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
@@ -187,24 +189,25 @@ function serializeField(value, type, prefix, params) {
187
189
  }
188
190
 
189
191
  default:
190
- if (type.prototype instanceof Field) return type.serialize(value, params);
192
+ if (type instanceof Object && 'serialize' in type) return type.serialize(value, params);
191
193
  return value;
192
194
  }
193
195
  }
194
196
 
195
197
  function validateField(value, type, prefix) {
196
198
  // All fields are required
197
- if (value === undefined || value === null) return 'Field is required'; // Validate type of value
199
+ if (value == null) return 'Field is required'; // Validate type of value
198
200
 
199
201
  switch (type) {
200
202
  case FIELD_TYPES.amount:
201
203
  case FIELD_TYPES.int:
204
+ case FIELD_TYPES.shortInt:
202
205
  {
203
206
  if (isNaN(value) && !BigNumber.isBigNumber(value)) {
204
- return `${value} is not of type Number or BigNumber`;
207
+ return `${String(value)} is not of type Number or BigNumber`;
205
208
  }
206
209
 
207
- if (new BigNumber(value).lt(0)) return `${value} must be >= 0`;
210
+ if (new BigNumber(value).lt(0)) return `${String(value)} must be >= 0`;
208
211
  return;
209
212
  }
210
213
 
@@ -212,15 +215,19 @@ function validateField(value, type, prefix) {
212
215
  {
213
216
  const prefixes = Array.isArray(prefix) ? prefix : [prefix];
214
217
 
215
- if (!prefixes.includes(value.split('_')[0])) {
216
- return `'${value}' prefix doesn't match expected prefix '${prefix}'`;
218
+ if (!_includesInstanceProperty(prefixes).call(prefixes, value.split('_')[0])) {
219
+ if (prefix == null) {
220
+ return `'${String(value)}' prefix doesn't exist'`;
221
+ }
222
+
223
+ return `'${String(value)}' prefix doesn't match expected prefix '${prefix.toString()}'`;
217
224
  }
218
225
 
219
226
  return;
220
227
  }
221
228
 
222
229
  case FIELD_TYPES.ctVersion:
223
- if (!(value !== null && value !== void 0 && value.abiVersion) || !(value !== null && value !== void 0 && value.vmVersion)) {
230
+ if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
224
231
  return 'Value must be an object with "vmVersion" and "abiVersion" fields';
225
232
  }
226
233
 
@@ -229,7 +236,7 @@ function validateField(value, type, prefix) {
229
236
  case FIELD_TYPES.pointers:
230
237
  if (!Array.isArray(value)) return 'Value must be of type Array';
231
238
 
232
- if (value.some(p => !(p !== null && p !== void 0 && p.key) || !(p !== null && p !== void 0 && p.id))) {
239
+ if (value.some(p => !(Boolean(p.key) && Boolean(p.id)))) {
233
240
  return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\'';
234
241
  }
235
242
 
@@ -245,9 +252,9 @@ function transformParams(params, schema) {
245
252
  denomination
246
253
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
247
254
  params = schema.filter(_ref2 => {
248
- let [_, t] = _ref2;
255
+ let [, t] = _ref2;
249
256
  return t === FIELD_TYPES.amount;
250
- }).reduce((acc, _ref3) => {
257
+ }).reduce((params, _ref3) => {
251
258
  let [key] = _ref3;
252
259
  return { ...params,
253
260
  [key]: formatAmount(params[key], {
@@ -255,290 +262,101 @@ function transformParams(params, schema) {
255
262
  })
256
263
  };
257
264
  }, params);
258
- const schemaKeys = schema.map(_ref4 => {
259
- let [k] = _ref4;
260
- return k;
261
- });
262
- return Object.entries(params).reduce((acc, _ref5) => {
263
- let [key, value] = _ref5;
264
- if (schemaKeys.includes(key)) acc[key] = value;
265
-
266
- if (['oracleTtl', 'queryTtl', 'responseTtl'].includes(key)) {
267
- acc[`${key}Type`] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
268
- acc[`${key}Value`] = value.value;
269
- }
270
-
271
- return acc;
272
- }, {});
273
- } // INTERFACE
274
-
275
-
276
- function getOracleRelativeTtl(params, txType) {
277
- const ttlKey = {
278
- [TX_TYPE.oracleRegister]: 'oracleTtl',
279
- [TX_TYPE.oracleExtend]: 'oracleTtl',
280
- [TX_TYPE.oracleQuery]: 'queryTtl',
281
- [TX_TYPE.oracleResponse]: 'responseTtl'
282
- }[txType];
283
-
284
- if (params[ttlKey] || params[`${ttlKey}Value`]) {
285
- return params[`${ttlKey}Value`] || params[ttlKey].value;
286
- }
287
-
288
- return 1;
289
- }
290
- /**
291
- * Calculate min fee
292
- * @function
293
- * @alias module:@aeternity/aepp-sdk/es/tx/builder/index
294
- * @rtype (txType, { gas = 0, params }) => String
295
- * @param {String} txType - Transaction type
296
- * @param {Options} options - Options object
297
- * @param {String|Number} options.gas - Gas amount
298
- * @param {Object} options.params - Tx params
299
- * @return {String|Number}
300
- * @example calculateMinFee('spendTx', { gas, params })
301
- */
302
-
303
-
304
- export function calculateMinFee(txType, _ref6) {
305
- let {
306
- gas = 0,
307
- params,
308
- vsn
309
- } = _ref6;
310
- const multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
311
-
312
- if (!params) return BigNumber(DEFAULT_FEE).times(multiplier).toString(10);
313
- let actualFee = buildFee(txType, {
314
- params: { ...params,
315
- fee: 0
316
- },
317
- multiplier,
318
- gas,
319
- vsn
320
- });
321
- let expected = BigNumber(0);
322
-
323
- while (!actualFee.eq(expected)) {
324
- actualFee = buildFee(txType, {
325
- params: { ...params,
326
- fee: actualFee
327
- },
328
- multiplier,
329
- gas,
330
- vsn
331
- });
332
- expected = actualFee;
333
- }
334
-
335
- return expected.toString(10);
336
- }
337
- /**
338
- * Calculate fee based on tx type and params
339
- * @param txType
340
- * @param params
341
- * @param gas
342
- * @param multiplier
343
- * @param vsn
344
- * @return {BigNumber}
345
- */
346
-
347
- function buildFee(txType, _ref7) {
348
- let {
349
- params,
350
- gas = 0,
351
- multiplier,
352
- vsn
353
- } = _ref7;
354
- const {
355
- rlpEncoded: txWithOutFee
356
- } = buildTx({ ...params
357
- }, txType, {
358
- vsn
359
- });
360
- const txSize = txWithOutFee.length;
361
- return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, txSize, {
362
- relativeTtl: getOracleRelativeTtl(params, txType),
363
- innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
364
- })).times(multiplier);
365
- }
366
- /**
367
- * Calculate fee
368
- * @function
369
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
370
- * @rtype (fee, txType, gas = 0) => String
371
- * @param {String|Number} fee - fee
372
- * @param {String} txType - Transaction type
373
- * @param {Options} options - Options object
374
- * @param {String|Number} options.gas - Gas amount
375
- * @param {Object} options.params - Tx params
376
- * @return {String|Number}
377
- * @example calculateFee(null, 'spendTx', { gas, params })
378
- */
379
-
380
-
381
- export function calculateFee() {
382
- let fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
383
- let txType = arguments.length > 1 ? arguments[1] : undefined;
384
- let {
385
- gas = 0,
386
- params,
387
- showWarning = true,
388
- vsn
389
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
390
- if (!params && showWarning) console.warn(`Can't build transaction fee, we will use DEFAULT_FEE(${DEFAULT_FEE})`);
391
- return fee || calculateMinFee(txType, {
392
- params,
393
- gas,
394
- vsn
395
- });
265
+ return params;
396
266
  }
397
267
  /**
398
268
  * Validate transaction params
399
- * @function
400
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
401
- * @param {Object} params Object with tx params
402
- * @param {Array} schema Transaction schema
403
- * @param {Array} excludeKeys Array of keys to exclude for validation
404
- * @return {Object} Object with validation errors
269
+ * @param params - Object with tx params
270
+ * @param schema - Transaction schema
271
+ * @param excludeKeys - Array of keys to exclude for validation
272
+ * @returns Object with validation errors
405
273
  */
406
274
 
407
- export function validateParams(params, schema, _ref8) {
275
+
276
+ export function validateParams(params, schema, _ref4) {
408
277
  let {
409
278
  excludeKeys = []
410
- } = _ref8;
279
+ } = _ref4;
411
280
  return Object.fromEntries(schema // TODO: allow optional keys in schema
412
- .filter(_ref9 => {
413
- let [key] = _ref9;
414
- return !excludeKeys.includes(key) && !['payload', 'nameFee', 'deposit'].includes(key);
415
- }).map(_ref10 => {
416
- let [key, type, prefix] = _ref10;
281
+ .filter(_ref5 => {
282
+ var _context;
283
+
284
+ let [key] = _ref5;
285
+ return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && !_includesInstanceProperty(_context = ['payload', 'nameFee', 'deposit', 'gasPrice']).call(_context, key);
286
+ }).map(_ref6 => {
287
+ let [key, type, prefix] = _ref6;
417
288
  return [key, validateField(params[key], type, prefix)];
418
- }).filter(_ref11 => {
419
- let [, message] = _ref11;
289
+ }).filter(_ref7 => {
290
+ let [, message] = _ref7;
420
291
  return message;
421
292
  }));
422
293
  }
423
- /**
424
- * Build binary transaction
425
- * @function
426
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
427
- * @param {Object} params Object with tx params
428
- * @param {Array} schema Transaction schema
429
- * @param {Object} [options={}] options
430
- * @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
431
- * @param {String} [options.denomination='aettos'] Denomination of amounts
432
- * @throws {Error} Validation error
433
- * @return {Array} Array with binary fields of transaction
434
- */
435
-
436
- export function buildRawTx(params, schema) {
437
- let {
438
- excludeKeys = [],
439
- denomination = AE_AMOUNT_FORMATS.AETTOS
440
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
441
- const filteredSchema = schema.filter(_ref12 => {
442
- let [key] = _ref12;
443
- return !excludeKeys.includes(key);
444
- }); // Transform `amount` type fields to `aettos`
445
-
446
- params = transformParams(params, filteredSchema, {
447
- denomination
448
- }); // Validation
449
-
450
- const valid = validateParams(params, schema, {
451
- excludeKeys
452
- });
453
-
454
- if (Object.keys(valid).length) {
455
- throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid));
456
- }
457
-
458
- return filteredSchema.map(_ref13 => {
459
- let [key, fieldType, prefix] = _ref13;
460
- return serializeField(params[key], fieldType, prefix, params);
461
- });
462
- }
463
294
  /**
464
295
  * Unpack binary transaction
465
- * @function
466
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
467
- * @param {Array} binary Array with binary transaction field's
468
- * @param {Array} schema Transaction schema
469
- * @return {Object} Object with transaction field's
296
+ * @param binary - Array with binary transaction field's
297
+ * @param schema - Transaction schema
298
+ * @returns Object with transaction field's
470
299
  */
471
300
 
472
301
  export function unpackRawTx(binary, schema) {
473
- return schema.reduce((acc, _ref14, index) => {
474
- let [key, fieldType, prefix] = _ref14;
302
+ return schema.reduce((acc, _ref8, index) => {
303
+ let [key, fieldType, prefix] = _ref8;
475
304
  return Object.assign(acc, {
476
305
  [key]: deserializeField(binary[index], fieldType, prefix)
477
306
  });
478
307
  }, {});
479
308
  }
480
- /**
481
- * Get transaction serialization/deserialization schema
482
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
483
- * @param {{ vsn: String, objId: Number, type: String }}
484
- * @throws {Error} Schema not found error
485
- * @return {Object} Schema
486
- */
487
-
488
- const getSchema = _ref15 => {
489
- let {
490
- vsn,
491
- objId,
492
- type
493
- } = _ref15;
494
- const isDeserialize = !!objId;
495
- const firstKey = isDeserialize ? objId : type;
496
- const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
497
-
498
- if (!schema[firstKey]) {
499
- throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`);
500
- }
501
309
 
502
- if (!schema[firstKey][vsn]) {
503
- throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`);
504
- }
505
-
506
- return schema[firstKey][vsn];
507
- };
508
310
  /**
509
311
  * Build transaction hash
510
- * @function
511
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
512
- * @param {Object} params Object with tx params
513
- * @param {String} type Transaction type
514
- * @param {Object} [options={}] options
515
- * @param {String[]} [options.excludeKeys] Array of keys to exclude for validation and build
516
- * @param {String} [options.prefix] Prefix of transaction
517
- * @throws {Error} Validation error
518
- * @returns {Object} object
519
- * @returns {String} object.tx Base64Check transaction hash with 'tx_' prefix
520
- * @returns {Buffer} object.rlpEncoded rlp encoded transaction
521
- * @returns {Array<Buffer>} object.binary binary transaction
312
+ * @param _params - Object with tx params
313
+ * @param type - Transaction type
314
+ * @param options - options
315
+ * @param options.excludeKeys - Array of keys to exclude for validation and build
316
+ * @param options.denomination - Denomination of amounts
317
+ * @param options.prefix - Prefix of transaction
318
+ * @throws {@link InvalidTxParamsError}
319
+ * @returns object
320
+ * @returns object.tx Base64Check transaction hash with 'tx_' prefix
321
+ * @returns object.rlpEncoded rlp encoded transaction
322
+ * @returns object.binary binary transaction
522
323
  */
324
+ export function buildTx(_params, type) {
325
+ var _vsn;
523
326
 
524
-
525
- export function buildTx(params, type) {
526
327
  let {
527
328
  excludeKeys = [],
528
329
  prefix = 'tx',
529
- vsn = VSN,
330
+ vsn,
530
331
  denomination = AE_AMOUNT_FORMATS.AETTOS
531
332
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
532
- const [schema, tag] = getSchema({
533
- type,
534
- vsn
333
+ const schemas = TX_SCHEMA[type];
334
+ (_vsn = vsn) !== null && _vsn !== void 0 ? _vsn : vsn = Math.max(...Object.keys(schemas).map(a => +a));
335
+ if (!isKeyOfObject(vsn, schemas)) throw new SchemaNotFoundError('serialization', TX_TYPE[type], vsn);
336
+ const schema = schemas[vsn];
337
+ let params = _params;
338
+ params.VSN = vsn;
339
+ params.tag = type;
340
+ const filteredSchema = schema.filter(_ref9 => {
341
+ let [key] = _ref9;
342
+ return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
343
+ }); // Transform `amount` type fields to `aettos`
344
+
345
+ params = transformParams(params, filteredSchema, {
346
+ denomination
347
+ }); // Validation
348
+
349
+ const valid = validateParams(params, schema, {
350
+ excludeKeys
535
351
  });
536
- const binary = buildRawTx({ ...params,
537
- VSN: vsn,
538
- tag
539
- }, schema, {
540
- excludeKeys,
541
- denomination: params.denomination || denomination
352
+
353
+ if (Object.keys(valid).length > 0) {
354
+ throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid));
355
+ }
356
+
357
+ const binary = filteredSchema.map(_ref10 => {
358
+ let [key, fieldType] = _ref10;
359
+ return serializeField(params[key], fieldType, params);
542
360
  }).filter(e => e !== undefined);
543
361
  const rlpEncoded = rlpEncode(binary);
544
362
  const tx = encode(rlpEncoded, prefix);
@@ -549,58 +367,58 @@ export function buildTx(params, type) {
549
367
  txObject: unpackRawTx(binary, schema)
550
368
  };
551
369
  }
370
+
552
371
  /**
553
372
  * Unpack transaction hash
554
- * @function
555
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
556
- * @param {String|Buffer} encodedTx String or RLP encoded transaction array
557
- * (if fromRlpBinary flag is true)
558
- * @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
559
- * @param {String} prefix - Prefix of data
560
- * @returns {Object} object
561
- * @returns {Object} object.tx Object with transaction param's
562
- * @returns {Buffer} object.rlpEncoded rlp encoded transaction
563
- * @returns {Array<Buffer>} object.binary binary transaction
373
+ * @param encodedTx - Transaction to unpack
374
+ * @param txType - Expected transaction type
375
+ * @returns object
376
+ * @returns object.tx Object with transaction param's
377
+ * @returns object.txType Transaction type
564
378
  */
565
-
566
- export function unpackTx(encodedTx) {
567
- let fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
568
- let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
569
- const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
379
+ export function unpackTx(encodedTx, txType) {
380
+ const rlpEncoded = decode(encodedTx);
570
381
  const binary = rlpDecode(rlpEncoded);
571
- const objId = readInt(binary[0]);
572
- const vsn = readInt(binary[1]);
573
- const [schema] = getSchema({
574
- objId,
575
- vsn
576
- });
382
+ const objId = +readInt(binary[0]);
383
+ if (!isKeyOfObject(objId, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${objId}`);
384
+ if (txType != null && txType !== objId) throw new DecodeError(`Expected transaction to have ${TX_TYPE[txType]} tag, got ${TX_TYPE[objId]} instead`);
385
+ const vsn = +readInt(binary[1]);
386
+ if (!isKeyOfObject(vsn, TX_SCHEMA[objId])) throw new SchemaNotFoundError('deserialization', `tag ${objId}`, vsn);
387
+ const schema = TX_SCHEMA[objId][vsn];
577
388
  return {
578
- txType: OBJECT_ID_TX_TYPE[objId],
389
+ txType: objId,
579
390
  tx: unpackRawTx(binary, schema),
580
- rlpEncoded,
581
- binary
391
+ rlpEncoded
582
392
  };
583
393
  }
584
394
  /**
585
395
  * Build a transaction hash
586
- * @function
587
- * @alias module:@aeternity/aepp-sdk/es/tx/builder
588
- * @param {String | Buffer} rawTx base64 or rlp encoded transaction
589
- * @return {String} Transaction hash
396
+ * @param rawTx - base64 or rlp encoded transaction
397
+ * @returns Transaction hash
590
398
  */
591
399
 
592
400
  export function buildTxHash(rawTx) {
593
- const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx, 'tx') : rawTx;
401
+ const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;
594
402
  return encode(hash(data), 'th');
595
403
  }
596
- export default {
597
- calculateMinFee,
598
- calculateFee,
599
- unpackTx,
600
- unpackRawTx,
601
- buildTx,
602
- buildRawTx,
603
- validateParams,
604
- buildTxHash
605
- };
404
+ /**
405
+ * Build a contract public key by contractCreateTx or gaAttach
406
+ * @param contractTx - Transaction
407
+ * @returns Contract public key
408
+ */
409
+
410
+ export function buildContractIdByContractTx(contractTx) {
411
+ var _context2;
412
+
413
+ const {
414
+ txType,
415
+ tx
416
+ } = unpackTx(contractTx);
417
+
418
+ if (!_includesInstanceProperty(_context2 = [TX_TYPE.contractCreate, TX_TYPE.gaAttach]).call(_context2, txType)) {
419
+ throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);
420
+ }
421
+
422
+ return buildContractId(tx.ownerId, +tx.nonce);
423
+ }
606
424
  //# sourceMappingURL=index.mjs.map