@aeternity/aepp-sdk 11.0.1 → 12.1.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 (444) 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 +0 -22
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +2 -1
  6. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +20765 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/AeSdk.d.ts +37 -0
  11. package/es/AeSdk.mjs +81 -0
  12. package/es/AeSdk.mjs.map +1 -0
  13. package/es/AeSdkAepp.d.ts +70 -0
  14. package/es/AeSdkAepp.mjs +176 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +213 -0
  17. package/es/AeSdkBase.mjs +314 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +104 -0
  20. package/es/AeSdkWallet.mjs +326 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +41 -0
  23. package/es/Node.mjs +147 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +68 -0
  26. package/es/account/Base.mjs +123 -0
  27. package/es/account/Base.mjs.map +1 -0
  28. package/es/account/Memory.d.ts +26 -0
  29. package/es/account/Memory.mjs +103 -0
  30. package/es/account/Memory.mjs.map +1 -0
  31. package/es/account/Rpc.d.ts +27 -0
  32. package/es/account/Rpc.mjs +80 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +222 -0
  35. package/es/aens.mjs +338 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +33 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +73 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +58 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +146 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +11 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +16 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  54. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  55. package/es/aepp-wallet-communication/schema.d.ts +105 -46
  56. package/es/aepp-wallet-communication/schema.mjs +251 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +25 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +62 -0
  60. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  61. package/es/apis/compiler/compiler.d.ts +92 -0
  62. package/es/apis/compiler/compiler.mjs +576 -0
  63. package/es/apis/compiler/compiler.mjs.map +1 -0
  64. package/es/apis/compiler/index.d.ts +2 -0
  65. package/es/apis/compiler/index.mjs +3 -0
  66. package/es/apis/compiler/index.mjs.map +1 -0
  67. package/es/apis/compiler/models/index.d.ts +248 -0
  68. package/es/apis/compiler/models/index.mjs +48 -0
  69. package/es/apis/compiler/models/index.mjs.map +1 -0
  70. package/es/apis/compiler/models/mappers.d.ts +23 -0
  71. package/es/apis/compiler/models/mappers.mjs +585 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  73. package/es/apis/compiler/models/parameters.d.ts +13 -0
  74. package/es/apis/compiler/models/parameters.mjs +71 -0
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  76. package/es/apis/node/index.d.ts +2 -0
  77. package/es/apis/node/index.mjs +3 -0
  78. package/es/apis/node/index.mjs.map +1 -0
  79. package/es/apis/node/models/index.d.ts +1065 -0
  80. package/es/apis/node/models/index.mjs +2 -0
  81. package/es/apis/node/models/index.mjs.map +1 -0
  82. package/es/apis/node/models/mappers.d.ts +95 -0
  83. package/es/apis/node/models/mappers.mjs +4166 -0
  84. package/es/apis/node/models/mappers.mjs.map +1 -0
  85. package/es/apis/node/models/parameters.d.ts +17 -0
  86. package/es/apis/node/models/parameters.mjs +165 -0
  87. package/es/apis/node/models/parameters.mjs.map +1 -0
  88. package/es/apis/node/node.d.ts +215 -0
  89. package/es/apis/node/node.mjs +1165 -0
  90. package/es/apis/node/node.mjs.map +1 -0
  91. package/es/chain.d.ts +248 -0
  92. package/es/chain.mjs +560 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/handlers.mjs +164 -131
  96. package/es/channel/handlers.mjs.map +1 -1
  97. package/es/channel/index.d.ts +625 -0
  98. package/es/channel/index.mjs +897 -902
  99. package/es/channel/index.mjs.map +1 -1
  100. package/es/channel/internal.d.ts +101 -0
  101. package/es/channel/internal.mjs +136 -85
  102. package/es/channel/internal.mjs.map +1 -1
  103. package/es/contract/Compiler.d.ts +18 -0
  104. package/es/contract/Compiler.mjs +68 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +127 -0
  107. package/es/contract/aci.mjs +225 -193
  108. package/es/contract/aci.mjs.map +1 -1
  109. package/es/contract/ga.d.ts +69 -0
  110. package/es/contract/ga.mjs +195 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +71 -0
  113. package/es/contract/methods.mjs +104 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/deprecated/index.d.ts +143 -0
  116. package/es/deprecated/index.mjs +162 -0
  117. package/es/deprecated/index.mjs.map +1 -0
  118. package/es/deprecated/methods.d.ts +18 -0
  119. package/es/deprecated/methods.mjs +26 -0
  120. package/es/deprecated/methods.mjs.map +1 -0
  121. package/es/index.d.ts +35 -0
  122. package/es/index.mjs +35 -40
  123. package/es/index.mjs.map +1 -1
  124. package/es/oracle.d.ts +161 -0
  125. package/es/oracle.mjs +306 -0
  126. package/es/oracle.mjs.map +1 -0
  127. package/es/spend.d.ts +62 -0
  128. package/es/spend.mjs +111 -0
  129. package/es/spend.mjs.map +1 -0
  130. package/es/tx/builder/address.d.ts +25 -0
  131. package/es/tx/builder/address.mjs +45 -0
  132. package/es/tx/builder/address.mjs.map +1 -0
  133. package/es/tx/builder/constants.d.ts +70 -0
  134. package/es/tx/builder/constants.mjs +61 -47
  135. package/es/tx/builder/constants.mjs.map +1 -1
  136. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  137. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  138. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  139. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  140. package/es/tx/builder/field-types/deposit.mjs +19 -0
  141. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  142. package/es/tx/builder/field-types/fee.d.ts +25 -0
  143. package/es/tx/builder/field-types/fee.mjs +150 -0
  144. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  145. package/es/tx/builder/field-types/field.d.ts +6 -0
  146. package/es/tx/builder/field-types/field.mjs +15 -0
  147. package/es/tx/builder/field-types/field.mjs.map +1 -0
  148. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  149. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  150. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  151. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  152. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  153. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  154. package/es/tx/builder/field-types/index.d.ts +70 -0
  155. package/es/tx/builder/field-types/index.mjs +25 -0
  156. package/es/tx/builder/field-types/index.mjs.map +1 -0
  157. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  158. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  159. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  160. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  161. package/es/tx/builder/field-types/name-id.mjs +19 -0
  162. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  163. package/es/tx/builder/field-types/name.d.ts +13 -0
  164. package/es/tx/builder/field-types/name.mjs +18 -0
  165. package/es/tx/builder/field-types/name.mjs.map +1 -0
  166. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  167. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  168. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  169. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  170. package/es/tx/builder/field-types/u-int.mjs +14 -0
  171. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  172. package/es/tx/builder/helpers.d.ts +125 -0
  173. package/es/tx/builder/helpers.mjs +94 -198
  174. package/es/tx/builder/helpers.mjs.map +1 -1
  175. package/es/tx/builder/index.d.ts +88 -0
  176. package/es/tx/builder/index.mjs +167 -358
  177. package/es/tx/builder/index.mjs.map +1 -1
  178. package/es/tx/builder/schema.d.ts +1201 -0
  179. package/es/tx/builder/schema.mjs +175 -561
  180. package/es/tx/builder/schema.mjs.map +1 -1
  181. package/es/tx/index.d.ts +64 -0
  182. package/es/tx/index.mjs +151 -265
  183. package/es/tx/index.mjs.map +1 -1
  184. package/es/tx/validator.d.ts +20 -0
  185. package/es/tx/validator.mjs +104 -124
  186. package/es/tx/validator.mjs.map +1 -1
  187. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  188. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  189. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  190. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  191. package/es/typings/bip32-path/index.d.mjs +2 -0
  192. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  193. package/es/typings/blakejs/index.d.mjs.map +1 -1
  194. package/es/typings/sha-js/index.d.mjs +2 -0
  195. package/es/typings/sha-js/index.d.mjs.map +1 -0
  196. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  197. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  198. package/es/utils/amount-formatter.d.ts +42 -0
  199. package/es/utils/amount-formatter.mjs +36 -49
  200. package/es/utils/amount-formatter.mjs.map +1 -1
  201. package/es/utils/autorest.d.ts +6 -0
  202. package/es/utils/autorest.mjs +97 -0
  203. package/es/utils/autorest.mjs.map +1 -0
  204. package/es/utils/bignumber.d.ts +13 -0
  205. package/es/utils/bignumber.mjs +11 -8
  206. package/es/utils/bignumber.mjs.map +1 -1
  207. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  208. package/es/utils/bytes.mjs +11 -15
  209. package/es/utils/bytes.mjs.map +1 -1
  210. package/es/utils/crypto.d.ts +88 -0
  211. package/es/utils/crypto.mjs +64 -98
  212. package/es/utils/crypto.mjs.map +1 -1
  213. package/es/utils/encoder-types.d.ts +61 -0
  214. package/es/utils/encoder-types.mjs +36 -0
  215. package/es/utils/encoder-types.mjs.map +1 -0
  216. package/es/utils/encoder.d.ts +25 -0
  217. package/es/utils/encoder.mjs +71 -59
  218. package/es/utils/encoder.mjs.map +1 -1
  219. package/es/{errors.d.ts → utils/errors.d.ts} +246 -59
  220. package/es/utils/errors.mjs +313 -136
  221. package/es/utils/errors.mjs.map +1 -1
  222. package/es/utils/hd-wallet.d.ts +50 -0
  223. package/es/utils/hd-wallet.mjs +86 -45
  224. package/es/utils/hd-wallet.mjs.map +1 -1
  225. package/es/utils/json-big.d.ts +5 -0
  226. package/es/utils/json-big.mjs +12 -16
  227. package/es/utils/json-big.mjs.map +1 -1
  228. package/es/utils/keystore.d.ts +51 -0
  229. package/es/utils/keystore.mjs +101 -194
  230. package/es/utils/keystore.mjs.map +1 -1
  231. package/es/{mptree.d.ts → utils/mptree.d.ts} +6 -9
  232. package/es/utils/mptree.mjs +22 -18
  233. package/es/utils/mptree.mjs.map +1 -1
  234. package/es/utils/other.d.ts +20 -0
  235. package/es/utils/other.mjs +32 -35
  236. package/es/utils/other.mjs.map +1 -1
  237. package/es/utils/semver-satisfies.d.ts +1 -0
  238. package/es/utils/semver-satisfies.mjs +2 -2
  239. package/es/utils/semver-satisfies.mjs.map +1 -1
  240. package/es/utils/string.d.ts +24 -0
  241. package/es/utils/string.mjs +8 -10
  242. package/es/utils/string.mjs.map +1 -1
  243. package/package.json +55 -43
  244. package/src/AeSdk.ts +68 -0
  245. package/src/AeSdkAepp.ts +176 -0
  246. package/src/AeSdkBase.ts +338 -0
  247. package/src/AeSdkWallet.ts +348 -0
  248. package/src/Node.ts +173 -0
  249. package/src/account/Base.ts +124 -0
  250. package/src/account/Memory.ts +98 -0
  251. package/src/account/Rpc.ts +69 -0
  252. package/src/aens.ts +407 -0
  253. package/src/aepp-wallet-communication/connection/Browser.ts +71 -0
  254. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +59 -0
  255. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +122 -0
  256. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +18 -18
  257. package/src/aepp-wallet-communication/rpc/RpcClient.ts +143 -0
  258. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  259. package/src/aepp-wallet-communication/schema.ts +224 -0
  260. package/src/aepp-wallet-communication/wallet-detector.ts +72 -0
  261. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  262. package/src/apis/compiler/compiler.ts +585 -0
  263. package/src/apis/compiler/index.ts +2 -0
  264. package/src/apis/compiler/models/index.ts +301 -0
  265. package/src/apis/compiler/models/mappers.ts +583 -0
  266. package/src/apis/compiler/models/parameters.ts +93 -0
  267. package/src/apis/node/code-model-v4.yaml +10080 -0
  268. package/src/apis/node/index.ts +2 -0
  269. package/src/apis/node/models/index.ts +1257 -0
  270. package/src/apis/node/models/mappers.ts +4280 -0
  271. package/src/apis/node/models/parameters.ts +188 -0
  272. package/src/apis/node/node.ts +1299 -0
  273. package/src/chain.ts +502 -0
  274. package/src/channel/handlers.ts +817 -0
  275. package/src/channel/index.ts +1025 -0
  276. package/src/channel/internal.ts +361 -0
  277. package/src/contract/Compiler.ts +67 -0
  278. package/src/contract/aci.ts +538 -0
  279. package/src/contract/ga.ts +199 -0
  280. package/src/contract/methods.ts +123 -0
  281. package/src/deprecated/index.ts +172 -0
  282. package/src/deprecated/methods.ts +25 -0
  283. package/src/index.ts +56 -0
  284. package/src/oracle.ts +364 -0
  285. package/src/spend.ts +164 -0
  286. package/src/tx/builder/address.ts +50 -0
  287. package/src/tx/builder/constants.ts +126 -0
  288. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  289. package/src/tx/builder/field-types/deposit.ts +21 -0
  290. package/src/tx/builder/field-types/fee.ts +143 -0
  291. package/src/tx/builder/field-types/field.ts +9 -0
  292. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  293. package/src/tx/builder/field-types/gas-price.ts +16 -0
  294. package/src/tx/builder/field-types/index.ts +45 -0
  295. package/src/tx/builder/field-types/name-fee.ts +32 -0
  296. package/src/tx/builder/field-types/name-id.ts +20 -0
  297. package/src/tx/builder/field-types/name.ts +18 -0
  298. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  299. package/src/tx/builder/field-types/u-int.ts +16 -0
  300. package/src/tx/builder/helpers.ts +248 -0
  301. package/src/tx/builder/index.ts +400 -0
  302. package/src/tx/builder/schema.ts +727 -0
  303. package/src/tx/index.ts +192 -0
  304. package/src/tx/validator.ts +230 -0
  305. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  306. package/src/typings/@aeternity__uuid/index.d.ts +5 -0
  307. package/src/typings/bip32-path/index.d.ts +33 -0
  308. package/src/typings/blakejs/index.d.ts +4 -32
  309. package/src/typings/sha-js/index.d.ts +5 -0
  310. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  311. package/src/utils/amount-formatter.ts +56 -69
  312. package/src/utils/autorest.ts +93 -0
  313. package/src/utils/bignumber.ts +11 -12
  314. package/src/utils/bytes.ts +29 -31
  315. package/src/utils/crypto.ts +205 -0
  316. package/src/utils/encoder-types.ts +63 -0
  317. package/src/utils/encoder.ts +116 -71
  318. package/src/utils/errors.ts +482 -366
  319. package/src/utils/hd-wallet.ts +166 -0
  320. package/src/utils/json-big.ts +27 -0
  321. package/src/utils/keystore.ts +182 -0
  322. package/src/utils/mptree.ts +64 -61
  323. package/src/utils/other.ts +34 -41
  324. package/src/utils/semver-satisfies.ts +15 -11
  325. package/src/utils/string.ts +18 -20
  326. package/es/account/base.mjs +0 -179
  327. package/es/account/base.mjs.map +0 -1
  328. package/es/account/memory.mjs +0 -99
  329. package/es/account/memory.mjs.map +0 -1
  330. package/es/account/multiple.mjs +0 -179
  331. package/es/account/multiple.mjs.map +0 -1
  332. package/es/ae/aens.mjs +0 -404
  333. package/es/ae/aens.mjs.map +0 -1
  334. package/es/ae/aepp.mjs +0 -45
  335. package/es/ae/aepp.mjs.map +0 -1
  336. package/es/ae/contract.mjs +0 -159
  337. package/es/ae/contract.mjs.map +0 -1
  338. package/es/ae/index.mjs +0 -207
  339. package/es/ae/index.mjs.map +0 -1
  340. package/es/ae/oracle.mjs +0 -339
  341. package/es/ae/oracle.mjs.map +0 -1
  342. package/es/ae/universal.mjs +0 -45
  343. package/es/ae/universal.mjs.map +0 -1
  344. package/es/ae/wallet.mjs +0 -50
  345. package/es/ae/wallet.mjs.map +0 -1
  346. package/es/amount-formatter.d.ts +0 -58
  347. package/es/bignumber.d.ts +0 -18
  348. package/es/chain/index.mjs +0 -272
  349. package/es/chain/index.mjs.map +0 -1
  350. package/es/chain/node.mjs +0 -442
  351. package/es/chain/node.mjs.map +0 -1
  352. package/es/contract/compiler.mjs +0 -115
  353. package/es/contract/compiler.mjs.map +0 -1
  354. package/es/contract/ga/helpers.mjs +0 -30
  355. package/es/contract/ga/helpers.mjs.map +0 -1
  356. package/es/contract/ga/index.mjs +0 -178
  357. package/es/contract/ga/index.mjs.map +0 -1
  358. package/es/crypto-ts.d.ts +0 -9
  359. package/es/encoder.d.ts +0 -26
  360. package/es/node-pool/index.mjs +0 -188
  361. package/es/node-pool/index.mjs.map +0 -1
  362. package/es/node.mjs +0 -133
  363. package/es/node.mjs.map +0 -1
  364. package/es/other.d.ts +0 -31
  365. package/es/semver-satisfies.d.ts +0 -1
  366. package/es/string.d.ts +0 -26
  367. package/es/tx/builder/field-types.mjs +0 -74
  368. package/es/tx/builder/field-types.mjs.map +0 -1
  369. package/es/tx/tx-object.mjs +0 -283
  370. package/es/tx/tx-object.mjs.map +0 -1
  371. package/es/tx/tx.mjs +0 -938
  372. package/es/tx/tx.mjs.map +0 -1
  373. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  374. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  375. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  376. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  377. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  378. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  379. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  380. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  381. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  382. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  383. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  384. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  385. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  386. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  387. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  388. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  389. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  390. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  391. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  392. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  393. package/es/utils/async-init.mjs +0 -64
  394. package/es/utils/async-init.mjs.map +0 -1
  395. package/es/utils/crypto-ts.mjs.map +0 -1
  396. package/es/utils/swagger.mjs +0 -164
  397. package/es/utils/swagger.mjs.map +0 -1
  398. package/src/account/base.js +0 -153
  399. package/src/account/memory.js +0 -83
  400. package/src/account/multiple.js +0 -162
  401. package/src/ae/aens.js +0 -361
  402. package/src/ae/aepp.js +0 -45
  403. package/src/ae/contract.js +0 -148
  404. package/src/ae/index.js +0 -168
  405. package/src/ae/oracle.js +0 -311
  406. package/src/ae/universal.js +0 -47
  407. package/src/ae/wallet.js +0 -50
  408. package/src/chain/index.js +0 -269
  409. package/src/chain/node.js +0 -320
  410. package/src/channel/handlers.js +0 -673
  411. package/src/channel/index.js +0 -903
  412. package/src/channel/internal.js +0 -236
  413. package/src/contract/aci.js +0 -376
  414. package/src/contract/compiler.js +0 -100
  415. package/src/contract/ga/helpers.js +0 -19
  416. package/src/contract/ga/index.js +0 -150
  417. package/src/index.js +0 -89
  418. package/src/node-pool/index.js +0 -172
  419. package/src/node.js +0 -116
  420. package/src/tx/builder/constants.js +0 -100
  421. package/src/tx/builder/field-types.js +0 -61
  422. package/src/tx/builder/helpers.js +0 -334
  423. package/src/tx/builder/index.js +0 -465
  424. package/src/tx/builder/schema.js +0 -1100
  425. package/src/tx/index.js +0 -301
  426. package/src/tx/tx-object.js +0 -187
  427. package/src/tx/tx.js +0 -631
  428. package/src/tx/validator.js +0 -181
  429. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  430. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  431. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  432. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  433. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  434. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  435. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  436. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  437. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  438. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  439. package/src/utils/async-init.js +0 -45
  440. package/src/utils/crypto.js +0 -219
  441. package/src/utils/hd-wallet.js +0 -100
  442. package/src/utils/json-big.js +0 -26
  443. package/src/utils/keystore.js +0 -219
  444. package/src/utils/swagger.js +0 -156
@@ -1,35 +1,31 @@
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;
5
- import BigNumber from 'bignumber.js';
6
6
  import _rlp from 'rlp';
7
7
  const {
8
8
  decode: rlpDecode,
9
9
  encode: rlpEncode
10
10
  } = _rlp;
11
- import { AE_AMOUNT_FORMATS, formatAmount } from "../../utils/amount-formatter.mjs";
11
+ import { decode, encode, Encoding } from "../../utils/encoder.mjs";
12
+ import { AE_AMOUNT_FORMATS } 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 } from "./schema.mjs";
15
+ import { Tag } from "./constants.mjs";
16
+ import { buildContractId, buildPointers, readInt, readPointers, writeInt } from "./helpers.mjs";
17
+ import { readId, writeId } from "./address.mjs";
16
18
  import { toBytes } from "../../utils/bytes.mjs";
17
19
  import MPTree from "../../utils/mptree.mjs";
18
- import { InvalidTxParamsError, SchemaNotFoundError } from "../../utils/errors.mjs";
20
+ import { ArgumentError, DecodeError, InvalidTxParamsError, SchemaNotFoundError } from "../../utils/errors.mjs";
21
+ import { isKeyOfObject } from "../../utils/other.mjs";
22
+
19
23
  /**
20
24
  * JavaScript-based Transaction builder
21
- * @module @aeternity/aepp-sdk/es/tx/builder
22
- * @export TxBuilder
23
- * @example import { TxBuilder } from '@aeternity/aepp-sdk'
24
25
  */
25
-
26
- const ORACLE_TTL_TYPES = {
27
- delta: 'delta',
28
- block: 'block'
29
- }; // SERIALIZE AND DESERIALIZE PART
30
-
26
+ // SERIALIZE AND DESERIALIZE PART
31
27
  function deserializeField(value, type, prefix) {
32
- if (!value) return '';
28
+ if (value == null) return '';
33
29
 
34
30
  switch (type) {
35
31
  case FIELD_TYPES.ctVersion:
@@ -41,8 +37,8 @@ function deserializeField(value, type, prefix) {
41
37
  };
42
38
  }
43
39
 
44
- case FIELD_TYPES.amount:
45
- case FIELD_TYPES.int:
40
+ case FIELD_TYPES.abiVersion:
41
+ case FIELD_TYPES.ttlType:
46
42
  return readInt(value);
47
43
 
48
44
  case FIELD_TYPES.id:
@@ -58,22 +54,24 @@ function deserializeField(value, type, prefix) {
58
54
  return encode(value, prefix);
59
55
 
60
56
  case FIELD_TYPES.stateTree:
61
- return encode(value, 'ss');
57
+ return encode(value, Encoding.StateTrees);
62
58
 
63
59
  case FIELD_TYPES.string:
64
60
  return value.toString();
65
61
 
66
62
  case FIELD_TYPES.payload:
67
- return encode(value, 'ba');
63
+ return encode(value, Encoding.Bytearray);
68
64
 
69
65
  case FIELD_TYPES.pointers:
70
66
  return readPointers(value);
71
67
 
72
68
  case FIELD_TYPES.rlpBinary:
73
- return unpackTx(value, true);
69
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
70
+ return unpackTx(encode(value, Encoding.Transaction));
74
71
 
75
72
  case FIELD_TYPES.rlpBinaries:
76
- return value.map(v => unpackTx(v, true));
73
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
74
+ return value.map(v => unpackTx(encode(v, Encoding.Transaction)));
77
75
 
78
76
  case FIELD_TYPES.rawBinary:
79
77
  return value;
@@ -82,7 +80,8 @@ function deserializeField(value, type, prefix) {
82
80
  return value.toString('hex');
83
81
 
84
82
  case FIELD_TYPES.offChainUpdates:
85
- return value.map(v => unpackTx(v, true));
83
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
84
+ return value.map(v => unpackTx(encode(v, Encoding.Transaction)));
86
85
 
87
86
  case FIELD_TYPES.callStack:
88
87
  // TODO: fix this
@@ -119,17 +118,17 @@ function deserializeField(value, type, prefix) {
119
118
  }, {});
120
119
 
121
120
  default:
122
- if (type.prototype instanceof Field) return type.deserialize(value);
123
- return value;
121
+ if (typeof type === 'number') return value;
122
+ return type.deserialize(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
- case FIELD_TYPES.amount:
132
- case FIELD_TYPES.int:
130
+ case FIELD_TYPES.abiVersion:
131
+ case FIELD_TYPES.ttlType:
133
132
  return writeInt(value);
134
133
 
135
134
  case FIELD_TYPES.id:
@@ -139,13 +138,13 @@ function serializeField(value, type, prefix, params) {
139
138
  return value.map(writeId);
140
139
 
141
140
  case FIELD_TYPES.bool:
142
- return _Buffer.from([value ? 1 : 0]);
141
+ return _Buffer.from([value === true ? 1 : 0]);
143
142
 
144
143
  case FIELD_TYPES.binary:
145
- return decode(value, prefix);
144
+ return decode(value);
146
145
 
147
146
  case FIELD_TYPES.stateTree:
148
- return decode(value, 'ss');
147
+ return decode(value);
149
148
 
150
149
  case FIELD_TYPES.hex:
151
150
  return _Buffer.from(value, 'hex');
@@ -154,7 +153,7 @@ function serializeField(value, type, prefix, params) {
154
153
  return value.map(_Buffer.from);
155
154
 
156
155
  case FIELD_TYPES.payload:
157
- return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value, 'ba') : toBytes(value);
156
+ return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value) : toBytes(value);
158
157
 
159
158
  case FIELD_TYPES.string:
160
159
  return toBytes(value);
@@ -187,49 +186,43 @@ function serializeField(value, type, prefix, params) {
187
186
  }
188
187
 
189
188
  default:
190
- if (type.prototype instanceof Field) return type.serialize(value, params);
191
- return value;
189
+ if (typeof type === 'number') return value; // @ts-expect-error will be solved after removing the whole serializeField function
190
+
191
+ return type.serialize(value, params);
192
192
  }
193
193
  }
194
194
 
195
195
  function validateField(value, type, prefix) {
196
196
  // All fields are required
197
- if (value === undefined || value === null) return 'Field is required'; // Validate type of value
197
+ if (value == null) return 'Field is required'; // Validate type of value
198
198
 
199
199
  switch (type) {
200
- case FIELD_TYPES.amount:
201
- case FIELD_TYPES.int:
202
- {
203
- if (isNaN(value) && !BigNumber.isBigNumber(value)) {
204
- return `${value} is not of type Number or BigNumber`;
205
- }
206
-
207
- if (new BigNumber(value).lt(0)) return `${value} must be >= 0`;
208
- return;
209
- }
210
-
211
200
  case FIELD_TYPES.id:
212
201
  {
213
202
  const prefixes = Array.isArray(prefix) ? prefix : [prefix];
214
203
 
215
- if (!prefixes.includes(value.split('_')[0])) {
216
- return `'${value}' prefix doesn't match expected prefix '${prefix}'`;
204
+ if (!_includesInstanceProperty(prefixes).call(prefixes, value.split('_')[0])) {
205
+ if (prefix == null) {
206
+ return `'${String(value)}' prefix doesn't exist'`;
207
+ }
208
+
209
+ return `'${String(value)}' prefix doesn't match expected prefix '${prefix.toString()}'`;
217
210
  }
218
211
 
219
- return;
212
+ return undefined;
220
213
  }
221
214
 
222
215
  case FIELD_TYPES.ctVersion:
223
- if (!(value !== null && value !== void 0 && value.abiVersion) || !(value !== null && value !== void 0 && value.vmVersion)) {
216
+ if (!(Boolean(value.abiVersion) && Boolean(value.vmVersion))) {
224
217
  return 'Value must be an object with "vmVersion" and "abiVersion" fields';
225
218
  }
226
219
 
227
- return;
220
+ return undefined;
228
221
 
229
222
  case FIELD_TYPES.pointers:
230
223
  if (!Array.isArray(value)) return 'Value must be of type Array';
231
224
 
232
- if (value.some(p => !(p !== null && p !== void 0 && p.key) || !(p !== null && p !== void 0 && p.id))) {
225
+ if (value.some(p => !(Boolean(p.key) && Boolean(p.id)))) {
233
226
  return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\'';
234
227
  }
235
228
 
@@ -237,308 +230,118 @@ function validateField(value, type, prefix) {
237
230
  return `Expected 32 pointers or less, got ${value.length} instead`;
238
231
  }
239
232
 
240
- }
241
- }
242
-
243
- function transformParams(params, schema) {
244
- let {
245
- denomination
246
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
247
- params = schema.filter(_ref2 => {
248
- let [_, t] = _ref2;
249
- return t === FIELD_TYPES.amount;
250
- }).reduce((acc, _ref3) => {
251
- let [key] = _ref3;
252
- return { ...params,
253
- [key]: formatAmount(params[key], {
254
- denomination
255
- })
256
- };
257
- }, 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];
233
+ return undefined;
283
234
 
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;
235
+ default:
236
+ return undefined;
333
237
  }
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
- });
396
238
  }
397
239
  /**
398
240
  * 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
241
+ * @category transaction builder
242
+ * @param params - Object with tx params
243
+ * @param schema - Transaction schema
244
+ * @param excludeKeys - Array of keys to exclude for validation
245
+ * @returns Object with validation errors
405
246
  */
406
247
 
407
- export function validateParams(params, schema, _ref8) {
248
+
249
+ export function validateParams(params, schema, _ref2) {
408
250
  let {
409
251
  excludeKeys = []
410
- } = _ref8;
252
+ } = _ref2;
411
253
  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;
254
+ .filter(_ref3 => {
255
+ var _context;
256
+
257
+ let [key] = _ref3;
258
+ return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && !_includesInstanceProperty(_context = ['payload', 'nameFee', 'deposit', 'gasPrice', 'fee', 'gasLimit']).call(_context, key);
259
+ }).map(_ref4 => {
260
+ let [key, type, prefix] = _ref4;
417
261
  return [key, validateField(params[key], type, prefix)];
418
- }).filter(_ref11 => {
419
- let [, message] = _ref11;
262
+ }).filter(_ref5 => {
263
+ let [, message] = _ref5;
420
264
  return message;
421
265
  }));
422
266
  }
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
267
  /**
464
268
  * 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
269
+ * @category transaction builder
270
+ * @param binary - Array with binary transaction field's
271
+ * @param schema - Transaction schema
272
+ * @returns Object with transaction field's
470
273
  */
471
274
 
472
275
  export function unpackRawTx(binary, schema) {
473
- return schema.reduce((acc, _ref14, index) => {
474
- let [key, fieldType, prefix] = _ref14;
276
+ return schema.reduce((acc, _ref6, index) => {
277
+ let [key, fieldType, prefix] = _ref6;
475
278
  return Object.assign(acc, {
476
279
  [key]: deserializeField(binary[index], fieldType, prefix)
477
280
  });
478
281
  }, {});
479
282
  }
480
283
  /**
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
284
+ * @category transaction builder
486
285
  */
487
286
 
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
-
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
287
  /**
509
288
  * 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
289
+ * @category transaction builder
290
+ * @param _params - Object with tx params
291
+ * @param type - Transaction type
292
+ * @param options - options
293
+ * @param options.excludeKeys - Array of keys to exclude for validation and build
294
+ * @param options.denomination - Denomination of amounts
295
+ * @param options.prefix - Prefix of transaction
296
+ * @throws {@link InvalidTxParamsError}
297
+ * @returns object
298
+ * @returns object.tx Base64Check transaction hash with 'tx_' prefix
299
+ * @returns object.rlpEncoded rlp encoded transaction
300
+ * @returns object.binary binary transaction
522
301
  */
302
+ export function buildTx(_params, type) {
303
+ var _vsn;
523
304
 
524
-
525
- export function buildTx(params, type) {
526
305
  let {
527
306
  excludeKeys = [],
528
- prefix = 'tx',
529
- vsn = VSN,
307
+ prefix = Encoding.Transaction,
308
+ vsn,
530
309
  denomination = AE_AMOUNT_FORMATS.AETTOS
531
310
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
532
- const [schema, tag] = getSchema({
533
- type,
534
- vsn
311
+ const schemas = TX_SCHEMA[type];
312
+ (_vsn = vsn) !== null && _vsn !== void 0 ? _vsn : vsn = Math.max(...Object.keys(schemas).map(a => +a));
313
+ if (!isKeyOfObject(vsn, schemas)) throw new SchemaNotFoundError('serialization', Tag[type], vsn);
314
+ const schema = schemas[vsn];
315
+ const params = _params;
316
+ params.VSN = vsn;
317
+ params.tag = type;
318
+ params.denomination = denomination;
319
+ const filteredSchema = schema.filter(_ref7 => {
320
+ let [key] = _ref7;
321
+ return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
322
+ }); // Validation
323
+
324
+ const valid = validateParams(params, schema, {
325
+ excludeKeys
535
326
  });
536
- const binary = buildRawTx({ ...params,
537
- VSN: vsn,
538
- tag
539
- }, schema, {
540
- excludeKeys,
541
- denomination: params.denomination || denomination
327
+
328
+ if (Object.keys(valid).length > 0) {
329
+ throw new InvalidTxParamsError(`Transaction build error. ${JSON.stringify(valid)}`);
330
+ }
331
+
332
+ const binary = filteredSchema.map(_ref8 => {
333
+ let [key, fieldType] = _ref8;
334
+ return serializeField(params[key], fieldType, { ...params,
335
+ txType: type,
336
+ rebuildTx: overrideParams => buildTx({ ...params,
337
+ ...overrideParams
338
+ }, type, {
339
+ excludeKeys,
340
+ prefix: Encoding.Transaction,
341
+ vsn,
342
+ denomination
343
+ })
344
+ });
542
345
  }).filter(e => e !== undefined);
543
346
  const rlpEncoded = rlpEncode(binary);
544
347
  const tx = encode(rlpEncoded, prefix);
@@ -550,57 +353,63 @@ export function buildTx(params, type) {
550
353
  };
551
354
  }
552
355
  /**
553
- * 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
356
+ * @category transaction builder
564
357
  */
565
358
 
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);
359
+ /**
360
+ * Unpack transaction hash
361
+ * @category transaction builder
362
+ * @param encodedTx - Transaction to unpack
363
+ * @param txType - Expected transaction type
364
+ * @returns object
365
+ * @returns object.tx Object with transaction param's
366
+ * @returns object.txType Transaction type
367
+ */
368
+ export function unpackTx(encodedTx, txType) {
369
+ const rlpEncoded = decode(encodedTx);
570
370
  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
- });
371
+ const objId = +readInt(binary[0]);
372
+ if (!isKeyOfObject(objId, TX_SCHEMA)) throw new DecodeError(`Unknown transaction tag: ${objId}`);
373
+ if (txType != null && txType !== objId) throw new DecodeError(`Expected transaction to have ${Tag[txType]} tag, got ${Tag[objId]} instead`);
374
+ const vsn = +readInt(binary[1]);
375
+ if (!isKeyOfObject(vsn, TX_SCHEMA[objId])) throw new SchemaNotFoundError('deserialization', `tag ${objId}`, vsn);
376
+ const schema = TX_SCHEMA[objId][vsn];
577
377
  return {
578
- txType: OBJECT_ID_TX_TYPE[objId],
378
+ txType: objId,
579
379
  tx: unpackRawTx(binary, schema),
580
- rlpEncoded,
581
- binary
380
+ rlpEncoded
582
381
  };
583
382
  }
584
383
  /**
585
384
  * 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
385
+ * @category transaction builder
386
+ * @param rawTx - base64 or rlp encoded transaction
387
+ * @returns Transaction hash
590
388
  */
591
389
 
592
390
  export function buildTxHash(rawTx) {
593
- const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx, 'tx') : rawTx;
594
- return encode(hash(data), 'th');
391
+ const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;
392
+ return encode(hash(data), Encoding.TxHash);
393
+ }
394
+ /**
395
+ * Build a contract public key by contractCreateTx or gaAttach
396
+ * @category contract
397
+ * @param contractTx - Transaction
398
+ * @returns Contract public key
399
+ */
400
+
401
+ export function buildContractIdByContractTx(contractTx) {
402
+ var _context2;
403
+
404
+ const {
405
+ txType,
406
+ tx
407
+ } = unpackTx(contractTx);
408
+
409
+ if (!_includesInstanceProperty(_context2 = [Tag.ContractCreateTx, Tag.GaAttachTx]).call(_context2, txType)) {
410
+ throw new ArgumentError('contractCreateTx', 'a contractCreateTx or gaAttach', txType);
411
+ }
412
+
413
+ return buildContractId(tx.ownerId, +tx.nonce);
595
414
  }
596
- export default {
597
- calculateMinFee,
598
- calculateFee,
599
- unpackTx,
600
- unpackRawTx,
601
- buildTx,
602
- buildRawTx,
603
- validateParams,
604
- buildTxHash
605
- };
606
415
  //# sourceMappingURL=index.mjs.map