@aeternity/aepp-sdk 12.1.2 → 13.0.0-alpha.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 (475) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.map +1 -1
  3. package/dist/aepp-sdk.browser.js +1 -1
  4. package/dist/aepp-sdk.browser.js.map +1 -1
  5. package/dist/aepp-sdk.js +6580 -8860
  6. package/dist/aepp-sdk.js.map +1 -1
  7. package/es/AeSdk.d.ts +7 -3
  8. package/es/AeSdk.mjs +17 -22
  9. package/es/AeSdk.mjs.map +1 -1
  10. package/es/AeSdkAepp.d.ts +6 -5
  11. package/es/AeSdkAepp.mjs +7 -30
  12. package/es/AeSdkAepp.mjs.map +1 -1
  13. package/es/AeSdkBase.d.ts +18 -140
  14. package/es/AeSdkBase.mjs +27 -185
  15. package/es/AeSdkBase.mjs.map +1 -1
  16. package/es/AeSdkMethods.d.ts +124 -0
  17. package/es/AeSdkMethods.mjs +122 -0
  18. package/es/AeSdkMethods.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +7 -21
  20. package/es/AeSdkWallet.mjs +38 -86
  21. package/es/AeSdkWallet.mjs.map +1 -1
  22. package/es/Node.d.ts +7 -12
  23. package/es/Node.mjs +34 -47
  24. package/es/Node.mjs.map +1 -1
  25. package/es/account/Base.d.ts +24 -40
  26. package/es/account/Base.mjs +1 -101
  27. package/es/account/Base.mjs.map +1 -1
  28. package/es/account/Generalized.d.ts +16 -0
  29. package/es/account/Generalized.mjs +111 -0
  30. package/es/account/Generalized.mjs.map +1 -0
  31. package/es/account/Ledger.d.ts +28 -0
  32. package/es/account/Ledger.mjs +101 -0
  33. package/es/account/Ledger.mjs.map +1 -0
  34. package/es/account/LedgerFactory.d.ts +39 -0
  35. package/es/account/LedgerFactory.mjs +81 -0
  36. package/es/account/LedgerFactory.mjs.map +1 -0
  37. package/es/account/Memory.d.ts +13 -17
  38. package/es/account/Memory.mjs +43 -65
  39. package/es/account/Memory.mjs.map +1 -1
  40. package/es/account/Rpc.d.ts +6 -8
  41. package/es/account/Rpc.mjs +14 -32
  42. package/es/account/Rpc.mjs.map +1 -1
  43. package/es/aens.d.ts +3 -3
  44. package/es/aens.mjs +42 -41
  45. package/es/aens.mjs.map +1 -1
  46. package/es/aepp-wallet-communication/connection/Browser.mjs +9 -13
  47. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  48. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +3 -7
  49. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -1
  51. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +0 -31
  52. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  53. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  54. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +3 -3
  55. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +4 -41
  56. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  57. package/es/aepp-wallet-communication/rpc/types.d.ts +7 -1
  58. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  59. package/es/aepp-wallet-communication/schema.mjs +14 -68
  60. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  61. package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
  62. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  63. package/es/apis/compiler/compiler.d.ts +23 -29
  64. package/es/apis/compiler/compiler.mjs +128 -189
  65. package/es/apis/compiler/compiler.mjs.map +1 -1
  66. package/es/apis/compiler/index.mjs.map +1 -1
  67. package/es/apis/compiler/models/index.d.ts +82 -135
  68. package/es/apis/compiler/models/index.mjs +1 -47
  69. package/es/apis/compiler/models/index.mjs.map +1 -1
  70. package/es/apis/compiler/models/mappers.d.ts +8 -8
  71. package/es/apis/compiler/models/mappers.mjs +165 -183
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  73. package/es/apis/compiler/models/parameters.d.ts +0 -1
  74. package/es/apis/compiler/models/parameters.mjs +5 -9
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -1
  76. package/es/apis/node/index.mjs.map +1 -1
  77. package/es/apis/node/models/index.d.ts +48 -48
  78. package/es/apis/node/models/mappers.mjs +12 -6
  79. package/es/apis/node/models/mappers.mjs.map +1 -1
  80. package/es/apis/node/models/parameters.mjs.map +1 -1
  81. package/es/apis/node/node.mjs +43 -84
  82. package/es/apis/node/node.mjs.map +1 -1
  83. package/es/chain.d.ts +1 -1
  84. package/es/chain.mjs +33 -58
  85. package/es/chain.mjs.map +1 -1
  86. package/es/channel/Base.d.ts +195 -0
  87. package/es/channel/Base.mjs +290 -0
  88. package/es/channel/Base.mjs.map +1 -0
  89. package/es/channel/Contract.d.ts +247 -0
  90. package/es/channel/Contract.mjs +420 -0
  91. package/es/channel/Contract.mjs.map +1 -0
  92. package/es/channel/Spend.d.ts +217 -0
  93. package/es/channel/Spend.mjs +383 -0
  94. package/es/channel/Spend.mjs.map +1 -0
  95. package/es/channel/handlers.d.ts +8 -21
  96. package/es/channel/handlers.mjs +141 -891
  97. package/es/channel/handlers.mjs.map +1 -1
  98. package/es/channel/internal.d.ts +27 -21
  99. package/es/channel/internal.mjs +98 -190
  100. package/es/channel/internal.mjs.map +1 -1
  101. package/es/contract/{Compiler.d.ts → CompilerHttp.d.ts} +3 -3
  102. package/es/contract/{Compiler.mjs → CompilerHttp.mjs} +8 -13
  103. package/es/contract/CompilerHttp.mjs.map +1 -0
  104. package/es/contract/Contract.d.ts +235 -0
  105. package/es/contract/Contract.mjs +534 -0
  106. package/es/contract/Contract.mjs.map +1 -0
  107. package/es/contract/ga.d.ts +7 -33
  108. package/es/contract/ga.mjs +20 -112
  109. package/es/contract/ga.mjs.map +1 -1
  110. package/es/index.d.ts +9 -6
  111. package/es/index.mjs +8 -6
  112. package/es/index.mjs.map +1 -1
  113. package/es/oracle.d.ts +5 -5
  114. package/es/oracle.mjs +33 -39
  115. package/es/oracle.mjs.map +1 -1
  116. package/es/spend.d.ts +3 -3
  117. package/es/spend.mjs +17 -20
  118. package/es/spend.mjs.map +1 -1
  119. package/es/tx/builder/constants.d.ts +2 -1
  120. package/es/tx/builder/constants.mjs +12 -12
  121. package/es/tx/builder/constants.mjs.map +1 -1
  122. package/es/tx/builder/field-types/address.d.ts +15 -0
  123. package/es/tx/builder/field-types/address.mjs +42 -0
  124. package/es/tx/builder/field-types/address.mjs.map +1 -0
  125. package/es/tx/builder/field-types/addresses.d.ts +6 -0
  126. package/es/tx/builder/field-types/addresses.mjs +13 -0
  127. package/es/tx/builder/field-types/addresses.mjs.map +1 -0
  128. package/es/tx/builder/field-types/coin-amount.d.ts +1 -2
  129. package/es/tx/builder/field-types/coin-amount.mjs +4 -12
  130. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  131. package/es/tx/builder/field-types/deposit.d.ts +0 -1
  132. package/es/tx/builder/field-types/deposit.mjs +2 -4
  133. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  134. package/es/tx/builder/field-types/enumeration.d.ts +5 -0
  135. package/es/tx/builder/field-types/enumeration.mjs +21 -0
  136. package/es/tx/builder/field-types/enumeration.mjs.map +1 -0
  137. package/es/tx/builder/field-types/fee.d.ts +1 -9
  138. package/es/tx/builder/field-types/fee.mjs +9 -25
  139. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  140. package/es/tx/builder/field-types/field.mjs +0 -2
  141. package/es/tx/builder/field-types/field.mjs.map +1 -1
  142. package/es/tx/builder/field-types/gas-limit.mjs +4 -9
  143. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  144. package/es/tx/builder/field-types/gas-price.d.ts +1 -2
  145. package/es/tx/builder/field-types/gas-price.mjs +3 -7
  146. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  147. package/es/tx/builder/field-types/index.d.ts +23 -11
  148. package/es/tx/builder/field-types/index.mjs +10 -3
  149. package/es/tx/builder/field-types/index.mjs.map +1 -1
  150. package/es/tx/builder/field-types/name-fee.d.ts +0 -1
  151. package/es/tx/builder/field-types/name-fee.mjs +3 -5
  152. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  153. package/es/tx/builder/field-types/name-id.d.ts +1 -4
  154. package/es/tx/builder/field-types/name-id.mjs +4 -10
  155. package/es/tx/builder/field-types/name-id.mjs.map +1 -1
  156. package/es/tx/builder/field-types/name.mjs +0 -2
  157. package/es/tx/builder/field-types/name.mjs.map +1 -1
  158. package/es/tx/builder/field-types/pointers.d.ts +23 -0
  159. package/es/tx/builder/field-types/pointers.mjs +36 -0
  160. package/es/tx/builder/field-types/pointers.mjs.map +1 -0
  161. package/es/tx/builder/field-types/short-u-int.mjs +0 -2
  162. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -1
  163. package/es/tx/builder/field-types/u-int.d.ts +1 -1
  164. package/es/tx/builder/field-types/u-int.mjs +3 -4
  165. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  166. package/es/tx/builder/helpers.d.ts +2 -32
  167. package/es/tx/builder/helpers.mjs +19 -71
  168. package/es/tx/builder/helpers.mjs.map +1 -1
  169. package/es/tx/builder/index.d.ts +1 -21
  170. package/es/tx/builder/index.mjs +29 -148
  171. package/es/tx/builder/index.mjs.map +1 -1
  172. package/es/tx/builder/schema.d.ts +336 -176
  173. package/es/tx/builder/schema.mjs +71 -78
  174. package/es/tx/builder/schema.mjs.map +1 -1
  175. package/es/tx/index.d.ts +3 -33
  176. package/es/tx/index.mjs +26 -43
  177. package/es/tx/index.mjs.map +1 -1
  178. package/es/tx/validator.d.ts +2 -2
  179. package/es/tx/validator.mjs +86 -59
  180. package/es/tx/validator.mjs.map +1 -1
  181. package/es/typings/{@aeternity__argon2-browser → @aeternity__aepp-calldata}/index.d.mjs +0 -0
  182. package/es/typings/@aeternity__aepp-calldata/index.d.mjs.map +1 -0
  183. package/es/utils/amount-formatter.mjs +4 -10
  184. package/es/utils/amount-formatter.mjs.map +1 -1
  185. package/es/utils/autorest.d.ts +1 -0
  186. package/es/utils/autorest.mjs +17 -19
  187. package/es/utils/autorest.mjs.map +1 -1
  188. package/es/utils/bignumber.mjs +4 -7
  189. package/es/utils/bignumber.mjs.map +1 -1
  190. package/es/utils/bytes.d.ts +0 -17
  191. package/es/utils/bytes.mjs +6 -35
  192. package/es/utils/bytes.mjs.map +1 -1
  193. package/es/utils/crypto.d.ts +15 -8
  194. package/es/utils/crypto.mjs +40 -40
  195. package/es/utils/crypto.mjs.map +1 -1
  196. package/es/utils/encoder-types.d.ts +28 -28
  197. package/es/utils/encoder-types.mjs +0 -1
  198. package/es/utils/encoder-types.mjs.map +1 -1
  199. package/es/utils/encoder.d.ts +0 -1
  200. package/es/utils/encoder.mjs +7 -15
  201. package/es/utils/encoder.mjs.map +1 -1
  202. package/es/utils/errors.d.ts +12 -6
  203. package/es/utils/errors.mjs +87 -163
  204. package/es/utils/errors.mjs.map +1 -1
  205. package/es/utils/hd-wallet.d.ts +27 -19
  206. package/es/utils/hd-wallet.mjs +42 -26
  207. package/es/utils/hd-wallet.mjs.map +1 -1
  208. package/es/utils/json-big.mjs +0 -8
  209. package/es/utils/json-big.mjs.map +1 -1
  210. package/es/utils/keystore.d.ts +2 -0
  211. package/es/utils/keystore.mjs +37 -36
  212. package/es/utils/keystore.mjs.map +1 -1
  213. package/es/utils/mptree.d.ts +1 -1
  214. package/es/utils/mptree.mjs +4 -26
  215. package/es/utils/mptree.mjs.map +1 -1
  216. package/es/utils/other.d.ts +3 -1
  217. package/es/utils/other.mjs +11 -7
  218. package/es/utils/other.mjs.map +1 -1
  219. package/es/utils/semver-satisfies.mjs +0 -3
  220. package/es/utils/semver-satisfies.mjs.map +1 -1
  221. package/es/utils/string.d.ts +0 -12
  222. package/es/utils/string.mjs +1 -21
  223. package/es/utils/string.mjs.map +1 -1
  224. package/package.json +87 -48
  225. package/src/AeSdk.ts +15 -11
  226. package/src/AeSdkAepp.ts +9 -7
  227. package/src/AeSdkBase.ts +28 -202
  228. package/src/AeSdkMethods.ts +170 -0
  229. package/src/AeSdkWallet.ts +16 -47
  230. package/src/Node.ts +11 -15
  231. package/src/account/Base.ts +29 -75
  232. package/src/account/Generalized.ts +98 -0
  233. package/src/account/Ledger.ts +131 -0
  234. package/src/account/LedgerFactory.ts +86 -0
  235. package/src/account/Memory.ts +46 -60
  236. package/src/account/Rpc.ts +17 -26
  237. package/src/aens.ts +10 -9
  238. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +5 -4
  239. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +3 -3
  240. package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
  241. package/src/aepp-wallet-communication/rpc/types.ts +11 -1
  242. package/src/aepp-wallet-communication/schema.ts +18 -18
  243. package/src/apis/compiler/code-model-v4.yaml +681 -888
  244. package/src/apis/compiler/compiler.ts +113 -154
  245. package/src/apis/compiler/models/index.ts +80 -140
  246. package/src/apis/compiler/models/mappers.ts +165 -183
  247. package/src/apis/compiler/models/parameters.ts +6 -12
  248. package/src/chain.ts +6 -3
  249. package/src/channel/Base.ts +327 -0
  250. package/src/channel/Contract.ts +487 -0
  251. package/src/channel/Spend.ts +403 -0
  252. package/src/channel/handlers.ts +154 -573
  253. package/src/channel/internal.ts +113 -142
  254. package/src/contract/{Compiler.ts → CompilerHttp.ts} +5 -5
  255. package/src/contract/Contract.ts +620 -0
  256. package/src/contract/ga.ts +18 -104
  257. package/src/index.ts +9 -8
  258. package/src/oracle.ts +7 -7
  259. package/src/spend.ts +5 -13
  260. package/src/tx/builder/constants.ts +1 -0
  261. package/src/tx/builder/field-types/address.ts +52 -0
  262. package/src/tx/builder/field-types/addresses.ts +18 -0
  263. package/src/tx/builder/field-types/coin-amount.ts +2 -8
  264. package/src/tx/builder/field-types/enumeration.ts +21 -0
  265. package/src/tx/builder/field-types/fee.ts +1 -3
  266. package/src/tx/builder/field-types/gas-limit.ts +2 -2
  267. package/src/tx/builder/field-types/gas-price.ts +0 -2
  268. package/src/tx/builder/field-types/index.ts +16 -6
  269. package/src/tx/builder/field-types/name-fee.ts +1 -1
  270. package/src/tx/builder/field-types/name-id.ts +7 -10
  271. package/src/tx/builder/field-types/pointers.ts +41 -0
  272. package/src/tx/builder/field-types/u-int.ts +3 -2
  273. package/src/tx/builder/helpers.ts +10 -60
  274. package/src/tx/builder/index.ts +6 -65
  275. package/src/tx/builder/schema.ts +89 -100
  276. package/src/tx/index.ts +19 -15
  277. package/src/tx/validator.ts +36 -18
  278. package/src/typings/@aeternity__aepp-calldata/index.d.ts +20 -0
  279. package/src/utils/autorest.ts +16 -1
  280. package/src/utils/bytes.ts +5 -33
  281. package/src/utils/crypto.ts +23 -16
  282. package/src/utils/encoder.ts +0 -1
  283. package/src/utils/errors.ts +18 -12
  284. package/src/utils/hd-wallet.ts +30 -9
  285. package/src/utils/keystore.ts +24 -21
  286. package/src/utils/other.ts +16 -1
  287. package/src/utils/string.ts +0 -20
  288. package/types-legacy/ts4.2/AeSdk.d.ts +41 -0
  289. package/types-legacy/ts4.2/AeSdkAepp.d.ts +71 -0
  290. package/types-legacy/ts4.2/AeSdkBase.d.ts +91 -0
  291. package/types-legacy/ts4.2/AeSdkMethods.d.ts +141 -0
  292. package/types-legacy/ts4.2/AeSdkWallet.d.ts +90 -0
  293. package/types-legacy/ts4.2/Node.d.ts +78 -0
  294. package/types-legacy/ts4.2/account/Base.d.ts +52 -0
  295. package/types-legacy/ts4.2/account/Generalized.d.ts +16 -0
  296. package/types-legacy/ts4.2/account/Ledger.d.ts +28 -0
  297. package/types-legacy/ts4.2/account/LedgerFactory.d.ts +39 -0
  298. package/types-legacy/ts4.2/account/Memory.d.ts +22 -0
  299. package/types-legacy/ts4.2/account/Rpc.d.ts +25 -0
  300. package/types-legacy/ts4.2/aens.d.ts +222 -0
  301. package/types-legacy/ts4.2/aepp-wallet-communication/connection/Browser.d.ts +33 -0
  302. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
  303. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
  304. package/types-legacy/ts4.2/aepp-wallet-communication/connection-proxy.d.ts +11 -0
  305. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
  306. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +83 -0
  307. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +133 -0
  308. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +25 -0
  309. package/types-legacy/ts4.2/apis/compiler/compiler.d.ts +86 -0
  310. package/types-legacy/ts4.2/apis/compiler/index.d.ts +2 -0
  311. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +195 -0
  312. package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +23 -0
  313. package/types-legacy/ts4.2/apis/compiler/models/parameters.d.ts +12 -0
  314. package/types-legacy/ts4.2/apis/node/index.d.ts +2 -0
  315. package/types-legacy/ts4.2/apis/node/models/index.d.ts +1065 -0
  316. package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +95 -0
  317. package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +17 -0
  318. package/types-legacy/ts4.2/apis/node/node.d.ts +215 -0
  319. package/types-legacy/ts4.2/chain.d.ts +248 -0
  320. package/types-legacy/ts4.2/channel/Base.d.ts +194 -0
  321. package/types-legacy/ts4.2/channel/Contract.d.ts +247 -0
  322. package/types-legacy/ts4.2/channel/Spend.d.ts +217 -0
  323. package/types-legacy/ts4.2/channel/handlers.d.ts +21 -0
  324. package/types-legacy/ts4.2/channel/internal.d.ts +107 -0
  325. package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +18 -0
  326. package/types-legacy/ts4.2/contract/Contract.d.ts +237 -0
  327. package/types-legacy/ts4.2/contract/ga.d.ts +43 -0
  328. package/types-legacy/ts4.2/globals.d.ts +16 -0
  329. package/types-legacy/ts4.2/index.d.ts +39 -0
  330. package/types-legacy/ts4.2/oracle.d.ts +161 -0
  331. package/types-legacy/ts4.2/spend.d.ts +62 -0
  332. package/types-legacy/ts4.2/tx/builder/constants.d.ts +71 -0
  333. package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +22 -0
  334. package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +6 -0
  335. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +12 -0
  336. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +14 -0
  337. package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -0
  338. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +17 -0
  339. package/types-legacy/ts4.2/tx/builder/field-types/field.d.ts +6 -0
  340. package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +12 -0
  341. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +7 -0
  342. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +85 -0
  343. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +19 -0
  344. package/types-legacy/ts4.2/tx/builder/field-types/name-id.d.ts +11 -0
  345. package/types-legacy/ts4.2/tx/builder/field-types/name.d.ts +13 -0
  346. package/types-legacy/ts4.2/tx/builder/field-types/pointers.d.ts +26 -0
  347. package/types-legacy/ts4.2/tx/builder/field-types/short-u-int.d.ts +6 -0
  348. package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +8 -0
  349. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +112 -0
  350. package/types-legacy/ts4.2/tx/builder/index.d.ts +68 -0
  351. package/types-legacy/ts4.2/tx/builder/schema.d.ts +2963 -0
  352. package/types-legacy/ts4.2/tx/index.d.ts +34 -0
  353. package/types-legacy/ts4.2/tx/validator.d.ts +20 -0
  354. package/types-legacy/ts4.2/utils/amount-formatter.d.ts +42 -0
  355. package/types-legacy/ts4.2/utils/autorest.d.ts +7 -0
  356. package/types-legacy/ts4.2/utils/bignumber.d.ts +13 -0
  357. package/types-legacy/ts4.2/utils/bytes.d.ts +9 -0
  358. package/types-legacy/ts4.2/utils/crypto.d.ts +95 -0
  359. package/types-legacy/ts4.2/utils/encoder-types.d.ts +61 -0
  360. package/types-legacy/ts4.2/utils/encoder.d.ts +24 -0
  361. package/types-legacy/ts4.2/utils/errors.d.ts +480 -0
  362. package/types-legacy/ts4.2/utils/hd-wallet.d.ts +65 -0
  363. package/types-legacy/ts4.2/utils/json-big.d.ts +5 -0
  364. package/types-legacy/ts4.2/utils/keystore.d.ts +53 -0
  365. package/types-legacy/ts4.2/utils/mptree.d.ts +32 -0
  366. package/types-legacy/ts4.2/utils/other.d.ts +31 -0
  367. package/types-legacy/ts4.2/utils/semver-satisfies.d.ts +1 -0
  368. package/types-legacy/ts4.2/utils/string.d.ts +12 -0
  369. package/types-legacy/ts4.5/AeSdk.d.ts +41 -0
  370. package/types-legacy/ts4.5/AeSdkAepp.d.ts +71 -0
  371. package/types-legacy/ts4.5/AeSdkBase.d.ts +91 -0
  372. package/types-legacy/ts4.5/AeSdkMethods.d.ts +141 -0
  373. package/types-legacy/ts4.5/AeSdkWallet.d.ts +90 -0
  374. package/types-legacy/ts4.5/Node.d.ts +78 -0
  375. package/types-legacy/ts4.5/account/Base.d.ts +52 -0
  376. package/types-legacy/ts4.5/account/Generalized.d.ts +16 -0
  377. package/types-legacy/ts4.5/account/Ledger.d.ts +28 -0
  378. package/types-legacy/ts4.5/account/LedgerFactory.d.ts +39 -0
  379. package/types-legacy/ts4.5/account/Memory.d.ts +22 -0
  380. package/types-legacy/ts4.5/account/Rpc.d.ts +25 -0
  381. package/types-legacy/ts4.5/aens.d.ts +222 -0
  382. package/types-legacy/ts4.5/aepp-wallet-communication/connection/Browser.d.ts +33 -0
  383. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
  384. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
  385. package/types-legacy/ts4.5/aepp-wallet-communication/connection-proxy.d.ts +11 -0
  386. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
  387. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +83 -0
  388. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +133 -0
  389. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +25 -0
  390. package/types-legacy/ts4.5/apis/compiler/compiler.d.ts +86 -0
  391. package/types-legacy/ts4.5/apis/compiler/index.d.ts +2 -0
  392. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +195 -0
  393. package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +23 -0
  394. package/types-legacy/ts4.5/apis/compiler/models/parameters.d.ts +12 -0
  395. package/types-legacy/ts4.5/apis/node/index.d.ts +2 -0
  396. package/types-legacy/ts4.5/apis/node/models/index.d.ts +1065 -0
  397. package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +95 -0
  398. package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +17 -0
  399. package/types-legacy/ts4.5/apis/node/node.d.ts +215 -0
  400. package/types-legacy/ts4.5/chain.d.ts +248 -0
  401. package/types-legacy/ts4.5/channel/Base.d.ts +194 -0
  402. package/types-legacy/ts4.5/channel/Contract.d.ts +247 -0
  403. package/types-legacy/ts4.5/channel/Spend.d.ts +217 -0
  404. package/types-legacy/ts4.5/channel/handlers.d.ts +21 -0
  405. package/types-legacy/ts4.5/channel/internal.d.ts +107 -0
  406. package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +18 -0
  407. package/types-legacy/ts4.5/contract/Contract.d.ts +237 -0
  408. package/types-legacy/ts4.5/contract/ga.d.ts +43 -0
  409. package/types-legacy/ts4.5/index.d.ts +38 -0
  410. package/types-legacy/ts4.5/oracle.d.ts +161 -0
  411. package/types-legacy/ts4.5/spend.d.ts +62 -0
  412. package/types-legacy/ts4.5/tx/builder/constants.d.ts +71 -0
  413. package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +22 -0
  414. package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +6 -0
  415. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +12 -0
  416. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +14 -0
  417. package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -0
  418. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +17 -0
  419. package/types-legacy/ts4.5/tx/builder/field-types/field.d.ts +6 -0
  420. package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +12 -0
  421. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +7 -0
  422. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +85 -0
  423. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +19 -0
  424. package/types-legacy/ts4.5/tx/builder/field-types/name-id.d.ts +11 -0
  425. package/types-legacy/ts4.5/tx/builder/field-types/name.d.ts +13 -0
  426. package/types-legacy/ts4.5/tx/builder/field-types/pointers.d.ts +26 -0
  427. package/types-legacy/ts4.5/tx/builder/field-types/short-u-int.d.ts +6 -0
  428. package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +8 -0
  429. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +112 -0
  430. package/types-legacy/ts4.5/tx/builder/index.d.ts +68 -0
  431. package/types-legacy/ts4.5/tx/builder/schema.d.ts +2963 -0
  432. package/types-legacy/ts4.5/tx/index.d.ts +34 -0
  433. package/types-legacy/ts4.5/tx/validator.d.ts +20 -0
  434. package/types-legacy/ts4.5/utils/amount-formatter.d.ts +42 -0
  435. package/types-legacy/ts4.5/utils/autorest.d.ts +7 -0
  436. package/types-legacy/ts4.5/utils/bignumber.d.ts +13 -0
  437. package/types-legacy/ts4.5/utils/bytes.d.ts +9 -0
  438. package/types-legacy/ts4.5/utils/crypto.d.ts +95 -0
  439. package/types-legacy/ts4.5/utils/encoder-types.d.ts +61 -0
  440. package/types-legacy/ts4.5/utils/encoder.d.ts +24 -0
  441. package/types-legacy/ts4.5/utils/errors.d.ts +480 -0
  442. package/types-legacy/ts4.5/utils/hd-wallet.d.ts +65 -0
  443. package/types-legacy/ts4.5/utils/json-big.d.ts +5 -0
  444. package/types-legacy/ts4.5/utils/keystore.d.ts +53 -0
  445. package/types-legacy/ts4.5/utils/mptree.d.ts +32 -0
  446. package/types-legacy/ts4.5/utils/other.d.ts +31 -0
  447. package/types-legacy/ts4.5/utils/semver-satisfies.d.ts +1 -0
  448. package/types-legacy/ts4.5/utils/string.d.ts +12 -0
  449. package/es/channel/index.d.ts +0 -625
  450. package/es/channel/index.mjs +0 -975
  451. package/es/channel/index.mjs.map +0 -1
  452. package/es/contract/Compiler.mjs.map +0 -1
  453. package/es/contract/aci.d.ts +0 -127
  454. package/es/contract/aci.mjs +0 -509
  455. package/es/contract/aci.mjs.map +0 -1
  456. package/es/contract/methods.d.ts +0 -71
  457. package/es/contract/methods.mjs +0 -104
  458. package/es/contract/methods.mjs.map +0 -1
  459. package/es/deprecated/index.d.ts +0 -143
  460. package/es/deprecated/index.mjs +0 -162
  461. package/es/deprecated/index.mjs.map +0 -1
  462. package/es/deprecated/methods.d.ts +0 -18
  463. package/es/deprecated/methods.mjs +0 -26
  464. package/es/deprecated/methods.mjs.map +0 -1
  465. package/es/tx/builder/address.d.ts +0 -25
  466. package/es/tx/builder/address.mjs +0 -45
  467. package/es/tx/builder/address.mjs.map +0 -1
  468. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +0 -1
  469. package/src/channel/index.ts +0 -1025
  470. package/src/contract/aci.ts +0 -538
  471. package/src/contract/methods.ts +0 -123
  472. package/src/deprecated/index.ts +0 -172
  473. package/src/deprecated/methods.ts +0 -25
  474. package/src/tx/builder/address.ts +0 -50
  475. package/src/typings/@aeternity__argon2-browser/index.d.ts +0 -3
package/es/tx/index.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
-
3
1
  /*
4
2
  * ISC License (ISC)
5
3
  * Copyright (c) 2022 aeternity developers
@@ -16,7 +14,6 @@ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/ins
16
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
15
  * PERFORMANCE OF THIS SOFTWARE.
18
16
  */
19
-
20
17
  /**
21
18
  * Transaction methods
22
19
  *
@@ -28,10 +25,9 @@ import { ABI_VERSIONS, PROTOCOL_VM_ABI, TX_TTL } from "./builder/schema.mjs";
28
25
  import { Tag } from "./builder/constants.mjs";
29
26
  import { ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError } from "../utils/errors.mjs";
30
27
  import { buildTx as syncBuildTx, unpackTx } from "./builder/index.mjs";
31
- import { isKeyOfObject } from "../utils/other.mjs";
32
- export async function getVmVersion(txType, _ref) {
28
+ import { isAccountNotFoundError, isKeyOfObject } from "../utils/other.mjs";
29
+ async function getVmVersion(txType, _ref) {
33
30
  var _abiVersion, _vmVersion;
34
-
35
31
  let {
36
32
  vmVersion,
37
33
  abiVersion,
@@ -40,17 +36,13 @@ export async function getVmVersion(txType, _ref) {
40
36
  const {
41
37
  consensusProtocolVersion
42
38
  } = await onNode.getNodeInfo();
43
-
44
39
  if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
45
40
  throw new UnsupportedProtocolError('Not supported consensus protocol version');
46
41
  }
47
-
48
42
  const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
49
-
50
43
  if (!isKeyOfObject(txType, supportedProtocol)) {
51
44
  throw new UnknownTxError('Not supported tx type');
52
45
  }
53
-
54
46
  const protocolForTX = supportedProtocol[txType];
55
47
  (_abiVersion = abiVersion) !== null && _abiVersion !== void 0 ? _abiVersion : abiVersion = protocolForTX.abiVersion[0];
56
48
  (_vmVersion = vmVersion) !== null && _vmVersion !== void 0 ? _vmVersion : vmVersion = protocolForTX.vmVersion[0];
@@ -59,6 +51,7 @@ export async function getVmVersion(txType, _ref) {
59
51
  abiVersion
60
52
  };
61
53
  }
54
+
62
55
  /**
63
56
  * Calculate fee, get absolute ttl (ttl + height), get account nonce
64
57
  * @category transaction builder
@@ -66,10 +59,8 @@ export async function getVmVersion(txType, _ref) {
66
59
  * @param params - Object which contains all tx data
67
60
  * @returns Object with account nonce, absolute ttl and transaction fee
68
61
  */
69
-
70
- export async function prepareTxParams(txType, _ref2) {
62
+ async function prepareTxParams(txType, _ref2) {
71
63
  var _nonce;
72
-
73
64
  let {
74
65
  senderId,
75
66
  nonce,
@@ -80,28 +71,27 @@ export async function prepareTxParams(txType, _ref2) {
80
71
  } = _ref2;
81
72
  (_nonce = nonce) !== null && _nonce !== void 0 ? _nonce : nonce = (await onNode.getAccountNextNonce(senderId, {
82
73
  strategy
83
- }).catch(() => ({
84
- nextNonce: 1
85
- }))).nextNonce;
86
-
74
+ }).catch(error => {
75
+ if (!isAccountNotFoundError(error)) throw error;
76
+ return {
77
+ nextNonce: 1
78
+ };
79
+ })).nextNonce;
87
80
  if (ttl !== 0) {
88
81
  if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl);
89
82
  ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height;
90
83
  }
91
-
92
84
  return {
93
85
  ttl,
94
86
  nonce
95
87
  };
96
88
  }
97
- // TODO: find a better name or rearrange methods
98
89
 
90
+ // TODO: find a better name or rearrange methods
99
91
  /**
100
92
  * @category transaction builder
101
93
  */
102
94
  export async function _buildTx(txType, _ref3) {
103
- var _context;
104
-
105
95
  let {
106
96
  denomination,
107
97
  absoluteTtl,
@@ -110,13 +100,11 @@ export async function _buildTx(txType, _ref3) {
110
100
  // TODO: avoid this assertion
111
101
  const params = _params;
112
102
  let senderKey;
113
-
114
103
  switch (txType) {
115
104
  case Tag.SpendTx:
116
105
  case Tag.OracleQueryTx:
117
106
  senderKey = 'senderId';
118
107
  break;
119
-
120
108
  case Tag.NameClaimTx:
121
109
  case Tag.NameUpdateTx:
122
110
  case Tag.NameRevokeTx:
@@ -125,62 +113,57 @@ export async function _buildTx(txType, _ref3) {
125
113
  case Tag.OracleRegisterTx:
126
114
  senderKey = 'accountId';
127
115
  break;
128
-
129
116
  case Tag.ContractCreateTx:
130
117
  case Tag.GaAttachTx:
131
118
  senderKey = 'ownerId';
132
119
  break;
133
-
120
+ case Tag.GaMetaTx:
121
+ senderKey = 'gaId';
122
+ break;
134
123
  case Tag.ContractCallTx:
135
124
  case Tag.OracleExtendTx:
136
125
  case Tag.OracleResponseTx:
137
126
  senderKey = 'callerId';
138
127
  break;
139
-
140
128
  case Tag.ChannelCloseSoloTx:
141
129
  case Tag.ChannelSlashTx:
142
130
  case Tag.ChannelSettleTx:
143
131
  case Tag.ChannelSnapshotSoloTx:
144
132
  senderKey = 'fromId';
145
133
  break;
146
-
147
134
  case Tag.PayingForTx:
148
135
  senderKey = 'payerId';
149
136
  break;
150
-
151
137
  default:
152
138
  throw new ArgumentError('txType', 'valid transaction type', txType);
153
- } // TODO: move specific cases to field-types
154
-
155
-
156
- if (_includesInstanceProperty(_context = [Tag.ContractCreateTx, Tag.GaAttachTx]).call(_context, txType)) {
157
- params.ctVersion = await getVmVersion(Tag.ContractCreateTx, { ...params,
139
+ }
140
+ // TODO: move specific cases to field-types
141
+ if ([Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {
142
+ params.ctVersion = await getVmVersion(Tag.ContractCreateTx, {
143
+ ...params,
158
144
  ...params.ctVersion
159
145
  });
160
146
  }
161
-
162
- if (txType === Tag.ContractCallTx) {
147
+ if ([Tag.ContractCallTx, Tag.GaMetaTx].includes(txType)) {
163
148
  params.abiVersion = (await getVmVersion(Tag.ContractCallTx, params)).abiVersion;
164
149
  }
165
-
166
150
  if (txType === Tag.OracleRegisterTx) {
167
151
  var _params$abiVersion;
168
-
169
152
  (_params$abiVersion = params.abiVersion) !== null && _params$abiVersion !== void 0 ? _params$abiVersion : params.abiVersion = ABI_VERSIONS.NO_ABI;
170
153
  }
171
-
172
154
  if (txType === Tag.PayingForTx) {
173
155
  params.tx = unpackTx(params.tx);
174
156
  }
175
-
176
- const senderId = params[senderKey]; // TODO: do this check on TypeScript level
177
-
157
+ const senderId = params[senderKey];
158
+ // TODO: do this check on TypeScript level
178
159
  if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`);
179
- const extraParams = await prepareTxParams(txType, { ...params,
160
+ const extraParams = await prepareTxParams(txType, {
161
+ ...params,
180
162
  senderId,
181
163
  absoluteTtl
182
164
  });
183
- return syncBuildTx({ ...params,
165
+ return syncBuildTx({
166
+ ...params,
184
167
  ...extraParams
185
168
  }, txType, {
186
169
  denomination
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["ABI_VERSIONS","PROTOCOL_VM_ABI","TX_TTL","Tag","ArgumentError","UnsupportedProtocolError","UnknownTxError","InvalidTxParamsError","buildTx","syncBuildTx","unpackTx","isKeyOfObject","getVmVersion","txType","vmVersion","abiVersion","onNode","consensusProtocolVersion","getNodeInfo","supportedProtocol","protocolForTX","prepareTxParams","senderId","nonce","ttl","absoluteTtl","strategy","getAccountNextNonce","catch","nextNonce","getCurrentKeyBlock","height","_buildTx","denomination","_params","params","senderKey","SpendTx","OracleQueryTx","NameClaimTx","NameUpdateTx","NameRevokeTx","NameTransferTx","NamePreclaimTx","OracleRegisterTx","ContractCreateTx","GaAttachTx","ContractCallTx","OracleExtendTx","OracleResponseTx","ChannelCloseSoloTx","ChannelSlashTx","ChannelSettleTx","ChannelSnapshotSoloTx","PayingForTx","ctVersion","NO_ABI","tx","extraParams"],"sources":["../../src/tx/index.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Transaction methods\n *\n * This is implementation of [Tx](api/tx.md) relays\n * the creation of transactions to {@link Node}.\n * These methods provide ability to create native transactions.\n */\nimport BigNumber from 'bignumber.js';\nimport {\n ABI_VERSIONS, CtVersion, PROTOCOL_VM_ABI, TX_TTL, TxParamsCommon,\n} from './builder/schema';\nimport { Tag } from './builder/constants';\nimport {\n ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError,\n} from '../utils/errors';\nimport Node from '../Node';\nimport { Encoded } from '../utils/encoder';\nimport { buildTx as syncBuildTx, unpackTx } from './builder/index';\nimport { isKeyOfObject } from '../utils/other';\nimport { AE_AMOUNT_FORMATS } from '../utils/amount-formatter';\n\ntype Int = number | string | BigNumber;\n\nexport type BuildTxOptions <TxType extends Tag, OmitFields extends string> =\n Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>;\n\n/**\n * Validated vm/abi version or get default based on transaction type and NODE version\n * @category transaction builder\n * @param txType - Type of transaction\n * @param ctVersion - Object with vm and abi version fields\n * @returns Object with vm/abi version\n */\nexport async function getVmVersion(\n txType: Tag.ContractCreateTx, ctVersion: Partial<CtVersion> & { onNode: Node }\n): Promise<CtVersion>;\nexport async function getVmVersion(\n txType: Tag, ctVersion: Partial<Pick<CtVersion, 'abiVersion'>> & { onNode: Node }\n): Promise<Pick<CtVersion, 'abiVersion'>>;\nexport async function getVmVersion(\n txType: Tag,\n { vmVersion, abiVersion, onNode }: Partial<CtVersion> & { onNode: Node },\n): Promise<Partial<CtVersion>> {\n const { consensusProtocolVersion } = await onNode.getNodeInfo();\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError('Not supported consensus protocol version');\n }\n const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];\n if (!isKeyOfObject(txType, supportedProtocol)) {\n throw new UnknownTxError('Not supported tx type');\n }\n const protocolForTX = supportedProtocol[txType];\n abiVersion ??= protocolForTX.abiVersion[0];\n vmVersion ??= protocolForTX.vmVersion[0];\n return { vmVersion, abiVersion };\n}\n\n/**\n * Calculate fee, get absolute ttl (ttl + height), get account nonce\n * @category transaction builder\n * @param txType - Type of transaction\n * @param params - Object which contains all tx data\n * @returns Object with account nonce, absolute ttl and transaction fee\n */\nexport async function prepareTxParams(\n txType: Tag,\n {\n senderId,\n nonce,\n ttl = TX_TTL,\n absoluteTtl,\n strategy,\n onNode,\n }: PrepareTxParamsOptions,\n): Promise<{ ttl: number; nonce: number }> {\n nonce ??= (\n await onNode.getAccountNextNonce(senderId, { strategy }).catch(() => ({ nextNonce: 1 }))\n ).nextNonce;\n\n if (ttl !== 0) {\n if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl);\n ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height;\n }\n\n return { ttl, nonce };\n}\n\ninterface PrepareTxParamsOptions extends Pick<TxParamsCommon, 'nonce' | 'ttl'> {\n senderId: Encoded.AccountAddress;\n absoluteTtl?: boolean;\n strategy?: 'continuity' | 'max';\n onNode: Node;\n}\n\n// TODO: find a better name or rearrange methods\n/**\n * @category transaction builder\n */\nexport async function _buildTx<TxType extends Tag>(\n txType: TxType,\n { denomination, absoluteTtl, ..._params }:\n Omit<Parameters<typeof syncBuildTx<TxType, 'tx'>>[0], 'fee' | 'nonce' | 'ttl' | 'ctVersion' | 'abiVersion'>\n & {\n onNode: Node;\n fee?: Int;\n nonce?: number;\n ttl?: number;\n denomination?: AE_AMOUNT_FORMATS;\n absoluteTtl?: boolean;\n }\n & (TxType extends Tag.OracleExtendTx | Tag.OracleResponseTx\n ? { callerId: Encoded.AccountAddress } : {})\n & (TxType extends Tag.ContractCreateTx | Tag.GaAttachTx ? { ctVersion?: CtVersion } : {})\n & (TxType extends Tag.ContractCallTx | Tag.OracleRegisterTx\n ? { abiVersion?: ABI_VERSIONS } : {}),\n): Promise<Encoded.Transaction> {\n // TODO: avoid this assertion\n const params = _params as unknown as TxParamsCommon & { onNode: Node };\n let senderKey: keyof TxParamsCommon | '<absent>';\n switch (txType) {\n case Tag.SpendTx:\n case Tag.OracleQueryTx:\n senderKey = 'senderId';\n break;\n case Tag.NameClaimTx:\n case Tag.NameUpdateTx:\n case Tag.NameRevokeTx:\n case Tag.NameTransferTx:\n case Tag.NamePreclaimTx:\n case Tag.OracleRegisterTx:\n senderKey = 'accountId';\n break;\n case Tag.ContractCreateTx:\n case Tag.GaAttachTx:\n senderKey = 'ownerId';\n break;\n case Tag.ContractCallTx:\n case Tag.OracleExtendTx:\n case Tag.OracleResponseTx:\n senderKey = 'callerId';\n break;\n case Tag.ChannelCloseSoloTx:\n case Tag.ChannelSlashTx:\n case Tag.ChannelSettleTx:\n case Tag.ChannelSnapshotSoloTx:\n senderKey = 'fromId';\n break;\n case Tag.PayingForTx:\n senderKey = 'payerId';\n break;\n default:\n throw new ArgumentError('txType', 'valid transaction type', txType);\n }\n // TODO: move specific cases to field-types\n if ([Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {\n params.ctVersion = await getVmVersion(\n Tag.ContractCreateTx,\n { ...params, ...params.ctVersion },\n );\n }\n if (txType === Tag.ContractCallTx) {\n params.abiVersion = (await getVmVersion(Tag.ContractCallTx, params)).abiVersion;\n }\n if (txType === Tag.OracleRegisterTx) {\n params.abiVersion ??= ABI_VERSIONS.NO_ABI;\n }\n if (txType === Tag.PayingForTx) {\n params.tx = unpackTx(params.tx);\n }\n const senderId = params[senderKey];\n // TODO: do this check on TypeScript level\n if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`);\n const extraParams = await prepareTxParams(txType, { ...params, senderId, absoluteTtl });\n return syncBuildTx({ ...params, ...extraParams } as any, txType, { denomination }).tx;\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;SAGEA,Y,EAAyBC,e,EAAiBC,M;SAEnCC,G;SAEPC,a,EAAeC,wB,EAA0BC,c,EAAgBC,oB;SAIlDC,OAAO,IAAIC,W,EAAaC,Q;SACxBC,a;AAqBT,OAAO,eAAeC,YAAf,CACLC,MADK,QAGwB;EAAA;;EAAA,IAD7B;IAAEC,SAAF;IAAaC,UAAb;IAAyBC;EAAzB,CAC6B;EAC7B,MAAM;IAAEC;EAAF,IAA+B,MAAMD,MAAM,CAACE,WAAP,EAA3C;;EACA,IAAI,CAACP,aAAa,CAACM,wBAAD,EAA2BhB,eAA3B,CAAlB,EAA+D;IAC7D,MAAM,IAAII,wBAAJ,CAA6B,0CAA7B,CAAN;EACD;;EACD,MAAMc,iBAAiB,GAAGlB,eAAe,CAACgB,wBAAD,CAAzC;;EACA,IAAI,CAACN,aAAa,CAACE,MAAD,EAASM,iBAAT,CAAlB,EAA+C;IAC7C,MAAM,IAAIb,cAAJ,CAAmB,uBAAnB,CAAN;EACD;;EACD,MAAMc,aAAa,GAAGD,iBAAiB,CAACN,MAAD,CAAvC;EACA,eAAAE,UAAU,UAAV,2CAAAA,UAAU,GAAKK,aAAa,CAACL,UAAd,CAAyB,CAAzB,CAAf;EACA,cAAAD,SAAS,UAAT,yCAAAA,SAAS,GAAKM,aAAa,CAACN,SAAd,CAAwB,C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Bf,YAAY,CAACwD,MAAnC;EACD;;EACD,IAAI3C,MAAM,KAAKV,GAAG,CAACmD,WAAnB,EAAgC;IAC9BnB,MAAM,CAACsB,EAAP,GAAY/C,QAAQ,CAACyB,MAAM,CAACsB,EAAR,CAApB;EACD;;EACD,MAAMnC,QAAQ,GAAGa,MAAM,CAACC,SAAD,CAAvB,CAtD8B,CAuD9B;;EACA,IAAId,QAAQ,IAAI,IAAhB,EAAsB,MAAM,IAAIf,oBAAJ,CAA0B,qBAAoB6B,SAAU,YAAxD,CAAN;EACtB,MAAMsB,WAAW,GAAG,MAAMrC,eAAe,CAACR,MAAD,EAAS,EAAE,GAAGsB,MAAL;IAAab,QAAb;IAAuBG;EAAvB,CAAT,CAAzC;EACA,OAAOhB,WAAW,CAAC,EAAE,GAAG0B,MAAL;IAAa,GAAGuB;EAAhB,CAAD,EAAuC7C,MAAvC,EAA+C;IAAEoB;EAAF,CAA/C,CAAX,CAA4EwB,EAAnF;AACD"}
1
+ {"version":3,"file":"index.mjs","names":["ABI_VERSIONS","PROTOCOL_VM_ABI","TX_TTL","Tag","ArgumentError","UnsupportedProtocolError","UnknownTxError","InvalidTxParamsError","buildTx","syncBuildTx","unpackTx","isAccountNotFoundError","isKeyOfObject","getVmVersion","txType","vmVersion","abiVersion","onNode","consensusProtocolVersion","getNodeInfo","supportedProtocol","protocolForTX","prepareTxParams","senderId","nonce","ttl","absoluteTtl","strategy","getAccountNextNonce","catch","error","nextNonce","getCurrentKeyBlock","height","_buildTx","denomination","_params","params","senderKey","SpendTx","OracleQueryTx","NameClaimTx","NameUpdateTx","NameRevokeTx","NameTransferTx","NamePreclaimTx","OracleRegisterTx","ContractCreateTx","GaAttachTx","GaMetaTx","ContractCallTx","OracleExtendTx","OracleResponseTx","ChannelCloseSoloTx","ChannelSlashTx","ChannelSettleTx","ChannelSnapshotSoloTx","PayingForTx","includes","ctVersion","NO_ABI","tx","extraParams"],"sources":["../../src/tx/index.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Transaction methods\n *\n * This is implementation of [Tx](api/tx.md) relays\n * the creation of transactions to {@link Node}.\n * These methods provide ability to create native transactions.\n */\nimport BigNumber from 'bignumber.js';\nimport {\n ABI_VERSIONS, CtVersion, PROTOCOL_VM_ABI, TX_TTL, TxParamsCommon,\n} from './builder/schema';\nimport { Tag } from './builder/constants';\nimport {\n ArgumentError, UnsupportedProtocolError, UnknownTxError, InvalidTxParamsError,\n} from '../utils/errors';\nimport Node from '../Node';\nimport { Encoded } from '../utils/encoder';\nimport { buildTx as syncBuildTx, unpackTx } from './builder/index';\nimport { isAccountNotFoundError, isKeyOfObject } from '../utils/other';\nimport { AE_AMOUNT_FORMATS } from '../utils/amount-formatter';\n\ntype Int = number | string | BigNumber;\n\nexport type BuildTxOptions <TxType extends Tag, OmitFields extends string> =\n Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>;\n\n/**\n * Validated vm/abi version or get default based on transaction type and NODE version\n * @category transaction builder\n * @param txType - Type of transaction\n * @param ctVersion - Object with vm and abi version fields\n * @returns Object with vm/abi version\n */\nasync function getVmVersion(\n txType: Tag.ContractCreateTx, ctVersion: Partial<CtVersion> & { onNode: Node }\n): Promise<CtVersion>;\nasync function getVmVersion(\n txType: Tag, ctVersion: Partial<Pick<CtVersion, 'abiVersion'>> & { onNode: Node }\n): Promise<Pick<CtVersion, 'abiVersion'>>;\nasync function getVmVersion(\n txType: Tag,\n { vmVersion, abiVersion, onNode }: Partial<CtVersion> & { onNode: Node },\n): Promise<Partial<CtVersion>> {\n const { consensusProtocolVersion } = await onNode.getNodeInfo();\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError('Not supported consensus protocol version');\n }\n const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];\n if (!isKeyOfObject(txType, supportedProtocol)) {\n throw new UnknownTxError('Not supported tx type');\n }\n const protocolForTX = supportedProtocol[txType];\n abiVersion ??= protocolForTX.abiVersion[0];\n vmVersion ??= protocolForTX.vmVersion[0];\n return { vmVersion, abiVersion };\n}\n\n/**\n * Calculate fee, get absolute ttl (ttl + height), get account nonce\n * @category transaction builder\n * @param txType - Type of transaction\n * @param params - Object which contains all tx data\n * @returns Object with account nonce, absolute ttl and transaction fee\n */\nasync function prepareTxParams(\n txType: Tag,\n {\n senderId,\n nonce,\n ttl = TX_TTL,\n absoluteTtl,\n strategy,\n onNode,\n }: {\n senderId: Encoded.AccountAddress;\n absoluteTtl?: boolean;\n strategy?: 'continuity' | 'max';\n onNode: Node;\n } & Pick<TxParamsCommon, 'nonce' | 'ttl'>,\n): Promise<{ ttl: number; nonce: number }> {\n nonce ??= (\n await onNode.getAccountNextNonce(senderId, { strategy }).catch((error) => {\n if (!isAccountNotFoundError(error)) throw error;\n return { nextNonce: 1 };\n })\n ).nextNonce;\n\n if (ttl !== 0) {\n if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl);\n ttl += absoluteTtl === true ? 0 : (await onNode.getCurrentKeyBlock()).height;\n }\n\n return { ttl, nonce };\n}\n\n// TODO: find a better name or rearrange methods\n/**\n * @category transaction builder\n */\nexport async function _buildTx<TxType extends Tag>(\n txType: TxType,\n { denomination, absoluteTtl, ..._params }:\n Omit<Parameters<typeof syncBuildTx<TxType, 'tx'>>[0], 'fee' | 'nonce' | 'ttl' | 'ctVersion' | 'abiVersion'>\n & {\n onNode: Node;\n fee?: Int;\n nonce?: number;\n ttl?: number;\n denomination?: AE_AMOUNT_FORMATS;\n absoluteTtl?: boolean;\n }\n & (TxType extends Tag.OracleExtendTx | Tag.OracleResponseTx\n ? { callerId: Encoded.AccountAddress } : {})\n & (TxType extends Tag.ContractCreateTx | Tag.GaAttachTx ? { ctVersion?: CtVersion } : {})\n & (TxType extends Tag.ContractCallTx | Tag.OracleRegisterTx\n ? { abiVersion?: ABI_VERSIONS } : {}),\n): Promise<Encoded.Transaction> {\n // TODO: avoid this assertion\n const params = _params as unknown as TxParamsCommon & { onNode: Node };\n let senderKey: keyof TxParamsCommon | '<absent>';\n switch (txType) {\n case Tag.SpendTx:\n case Tag.OracleQueryTx:\n senderKey = 'senderId';\n break;\n case Tag.NameClaimTx:\n case Tag.NameUpdateTx:\n case Tag.NameRevokeTx:\n case Tag.NameTransferTx:\n case Tag.NamePreclaimTx:\n case Tag.OracleRegisterTx:\n senderKey = 'accountId';\n break;\n case Tag.ContractCreateTx:\n case Tag.GaAttachTx:\n senderKey = 'ownerId';\n break;\n case Tag.GaMetaTx:\n senderKey = 'gaId';\n break;\n case Tag.ContractCallTx:\n case Tag.OracleExtendTx:\n case Tag.OracleResponseTx:\n senderKey = 'callerId';\n break;\n case Tag.ChannelCloseSoloTx:\n case Tag.ChannelSlashTx:\n case Tag.ChannelSettleTx:\n case Tag.ChannelSnapshotSoloTx:\n senderKey = 'fromId';\n break;\n case Tag.PayingForTx:\n senderKey = 'payerId';\n break;\n default:\n throw new ArgumentError('txType', 'valid transaction type', txType);\n }\n // TODO: move specific cases to field-types\n if ([Tag.ContractCreateTx, Tag.GaAttachTx].includes(txType)) {\n params.ctVersion = await getVmVersion(\n Tag.ContractCreateTx,\n { ...params, ...params.ctVersion },\n );\n }\n if ([Tag.ContractCallTx, Tag.GaMetaTx].includes(txType)) {\n params.abiVersion = (await getVmVersion(Tag.ContractCallTx, params)).abiVersion;\n }\n if (txType === Tag.OracleRegisterTx) {\n params.abiVersion ??= ABI_VERSIONS.NO_ABI;\n }\n if (txType === Tag.PayingForTx) {\n params.tx = unpackTx(params.tx);\n }\n const senderId = params[senderKey];\n // TODO: do this check on TypeScript level\n if (senderId == null) throw new InvalidTxParamsError(`Transaction field ${senderKey} is missed`);\n const extraParams = await prepareTxParams(txType, { ...params, senderId, absoluteTtl });\n return syncBuildTx({ ...params, ...extraParams } as any, txType, { denomination }).tx;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SASEA,YAAY,EAAaC,eAAe,EAAEC,MAAM;AAAA,SAEzCC,GAAG;AAAA,SAEVC,aAAa,EAAEC,wBAAwB,EAAEC,cAAc,EAAEC,oBAAoB;AAAA,SAItEC,OAAO,IAAIC,WAAW,EAAEC,QAAQ;AAAA,SAChCC,sBAAsB,EAAEC,aAAa;AAqB9C,eAAeC,YAAY,CACzBC,MAAW,QAEkB;EAAA;EAAA,IAD7B;IAAEC,SAAS;IAAEC,UAAU;IAAEC;EAA8C,CAAC;EAExE,MAAM;IAAEC;EAAyB,CAAC,GAAG,MAAMD,MAAM,CAACE,WAAW,EAAE;EAC/D,IAAI,CAACP,aAAa,CAACM,wBAAwB,EAAEjB,eAAe,CAAC,EAAE;IAC7D,MAAM,IAAII,wBAAwB,CAAC,0CAA0C,CAAC;EAChF;EACA,MAAMe,iBAAiB,GAAGnB,eAAe,CAACiB,wBAAwB,CAAC;EACnE,IAAI,CAACN,aAAa,CAACE,MAAM,EAAEM,iBAAiB,CAAC,EAAE;IAC7C,MAAM,IAAId,cAAc,CAAC,uBAAu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GAAGA,MAAM,CAACsB;IAAU,CAAC,CACnC;EACH;EACA,IAAI,CAACxD,GAAG,CAAC+C,cAAc,EAAE/C,GAAG,CAAC8C,QAAQ,CAAC,CAACS,QAAQ,CAAC5C,MAAM,CAAC,EAAE;IACvDuB,MAAM,CAACrB,UAAU,GAAG,CAAC,MAAMH,YAAY,CAACV,GAAG,CAAC+C,cAAc,EAAEb,MAAM,CAAC,EAAErB,UAAU;EACjF;EACA,IAAIF,MAAM,KAAKX,GAAG,CAAC2C,gBAAgB,EAAE;IAAA;IACnC,sBAAAT,MAAM,CAACrB,UAAU,mEAAjBqB,MAAM,CAACrB,UAAU,GAAKhB,YAAY,CAAC4D,MAAM;EAC3C;EACA,IAAI9C,MAAM,KAAKX,GAAG,CAACsD,WAAW,EAAE;IAC9BpB,MAAM,CAACwB,EAAE,GAAGnD,QAAQ,CAAC2B,MAAM,CAACwB,EAAE,CAAC;EACjC;EACA,MAAMtC,QAAQ,GAAGc,MAAM,CAACC,SAAS,CAAC;EAClC;EACA,IAAIf,QAAQ,IAAI,IAAI,EAAE,MAAM,IAAIhB,oBAAoB,CAAE,qBAAoB+B,SAAU,YAAW,CAAC;EAChG,MAAMwB,WAAW,GAAG,MAAMxC,eAAe,CAACR,MAAM,EAAE;IAAE,GAAGuB,MAAM;IAAEd,QAAQ;IAAEG;EAAY,CAAC,CAAC;EACvF,OAAOjB,WAAW,CAAC;IAAE,GAAG4B,MAAM;IAAE,GAAGyB;EAAY,CAAC,EAAShD,MAAM,EAAE;IAAEqB;EAAa,CAAC,CAAC,CAAC0B,EAAE;AACvF"}
@@ -12,9 +12,9 @@ export interface ValidatorResult {
12
12
  * to make sure it can be posted it to the chain
13
13
  * @category transaction builder
14
14
  * @param transaction - Base64Check-encoded transaction
15
- * @param node - Node to validate transaction against
15
+ * @param nodeNotCached - Node to validate transaction against
16
16
  * @param parentTxTypes - Types of parent transactions
17
17
  * @returns Array with verification errors
18
18
  * @example const errors = await verifyTransaction(transaction, node)
19
19
  */
20
- export default function verifyTransaction(transaction: Encoded.Transaction | Encoded.Poi, node: Node, parentTxTypes?: Tag[]): Promise<ValidatorResult[]>;
20
+ export default function verifyTransaction(transaction: Encoded.Transaction | Encoded.Poi, nodeNotCached: Node, parentTxTypes?: Tag[]): Promise<ValidatorResult[]>;
@@ -1,5 +1,4 @@
1
1
  import _buffer from "buffer";
2
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
3
2
  const {
4
3
  Buffer: _Buffer
5
4
  } = _buffer;
@@ -9,28 +8,39 @@ import { PROTOCOL_VM_ABI } from "./builder/schema.mjs";
9
8
  import { Tag } from "./builder/constants.mjs";
10
9
  import { unpackTx } from "./builder/index.mjs";
11
10
  import { UnsupportedProtocolError } from "../utils/errors.mjs";
12
- import { concatBuffers, isKeyOfObject } from "../utils/other.mjs";
13
- import { decode, encode, Encoding } from "../utils/encoder.mjs";
11
+ import { concatBuffers, isAccountNotFoundError, isKeyOfObject } from "../utils/other.mjs";
12
+ import { encode, Encoding } from "../utils/encoder.mjs";
13
+ import Node from "../Node.mjs";
14
+ import { genAggressiveCacheGetResponsesPolicy } from "../utils/autorest.mjs";
14
15
  const validators = [];
15
-
16
16
  const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'].map(key => tx[key]).filter(a => a).map(a => a === null || a === void 0 ? void 0 : a.toString().replace(/^ok_/, 'ak_'))[0];
17
+
17
18
  /**
18
19
  * Transaction Validator
19
20
  * This function validates some of transaction properties,
20
21
  * to make sure it can be posted it to the chain
21
22
  * @category transaction builder
22
23
  * @param transaction - Base64Check-encoded transaction
23
- * @param node - Node to validate transaction against
24
+ * @param nodeNotCached - Node to validate transaction against
24
25
  * @param parentTxTypes - Types of parent transactions
25
26
  * @returns Array with verification errors
26
27
  * @example const errors = await verifyTransaction(transaction, node)
27
28
  */
28
-
29
-
30
- export default async function verifyTransaction(transaction, node) {
29
+ export default async function verifyTransaction(transaction, nodeNotCached) {
31
30
  var _getSenderAddress;
32
-
33
31
  let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
32
+ let node = nodeNotCached;
33
+ if (!node.pipeline.getOrderedPolicies().some(_ref => {
34
+ let {
35
+ name
36
+ } = _ref;
37
+ return name === 'aggressive-cache-get-responses';
38
+ })) {
39
+ node = new Node(nodeNotCached.$host, {
40
+ ignoreVersion: true
41
+ });
42
+ node.pipeline.addPolicy(genAggressiveCacheGetResponsesPolicy());
43
+ }
34
44
  const {
35
45
  tx,
36
46
  txType
@@ -41,12 +51,17 @@ export default async function verifyTransaction(transaction, node) {
41
51
  }, {
42
52
  consensusProtocolVersion,
43
53
  nodeNetworkId
44
- }] = await Promise.all([address == null ? undefined : node.getAccountByPubkey(address).catch(() => ({
45
- id: address,
46
- balance: 0n,
47
- nonce: 0
48
- })) // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
49
- .then(acc => ({ ...acc,
54
+ }] = await Promise.all([address == null ? undefined : node.getAccountByPubkey(address).catch(error => {
55
+ if (!isAccountNotFoundError(error)) throw error;
56
+ return {
57
+ id: address,
58
+ balance: 0n,
59
+ nonce: 0
60
+ };
61
+ })
62
+ // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
63
+ .then(acc => ({
64
+ ...acc,
50
65
  id: acc.id
51
66
  })), node.getCurrentKeyBlockHeight(), node.getNodeInfo()]);
52
67
  return (await Promise.all(validators.map(v => v(tx, {
@@ -59,50 +74,47 @@ export default async function verifyTransaction(transaction, node) {
59
74
  parentTxTypes
60
75
  })))).flat();
61
76
  }
62
- validators.push((_ref, _ref2) => {
77
+ validators.push((_ref2, _ref3) => {
63
78
  let {
64
79
  encodedTx,
65
80
  signatures
66
- } = _ref;
81
+ } = _ref2;
67
82
  let {
68
83
  account,
69
84
  nodeNetworkId,
70
85
  parentTxTypes
71
- } = _ref2;
86
+ } = _ref3;
72
87
  if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : signatures) === undefined) return [];
73
88
  if (account == null) return [];
74
89
  if (signatures.length !== 1) return []; // TODO: Support multisignature?
75
-
76
- const prefix = _Buffer.from([nodeNetworkId, ...(_includesInstanceProperty(parentTxTypes).call(parentTxTypes, Tag.PayingForTx) ? ['inner_tx'] : [])].join('-'));
77
-
90
+ const prefix = _Buffer.from([nodeNetworkId, ...(parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [])].join('-'));
78
91
  const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);
79
92
  const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);
80
- const decodedPub = decode(account.id);
81
- if (verify(txWithNetworkId, signatures[0], decodedPub) || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
93
+ if (verify(txWithNetworkId, signatures[0], account.id) || verify(txHashWithNetworkId, signatures[0], account.id)) return [];
82
94
  return [{
83
95
  message: 'Signature cannot be verified, please ensure that you transaction have' + ' the correct prefix and the correct private key for the sender address',
84
96
  key: 'InvalidSignature',
85
97
  checkedKeys: ['encodedTx', 'signatures']
86
98
  }];
87
- }, async (_ref3, _ref4) => {
99
+ }, async (_ref4, _ref5) => {
88
100
  let {
89
101
  encodedTx,
90
102
  tx
91
- } = _ref3;
103
+ } = _ref4;
92
104
  let {
93
105
  node,
94
106
  parentTxTypes,
95
107
  txType
96
- } = _ref4;
108
+ } = _ref5;
97
109
  if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx) === undefined) return [];
98
110
  return verifyTransaction(encode((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx).rlpEncoded, Encoding.Transaction), node, [...parentTxTypes, txType]);
99
- }, (_ref5, _ref6) => {
111
+ }, (_ref6, _ref7) => {
100
112
  let {
101
113
  ttl
102
- } = _ref5;
114
+ } = _ref6;
103
115
  let {
104
116
  height
105
- } = _ref6;
117
+ } = _ref7;
106
118
  if (ttl === undefined) return [];
107
119
  ttl = +ttl;
108
120
  if (ttl === 0 || ttl >= height) return [];
@@ -111,43 +123,65 @@ validators.push((_ref, _ref2) => {
111
123
  key: 'ExpiredTTL',
112
124
  checkedKeys: ['ttl']
113
125
  }];
114
- }, (_ref7, _ref8) => {
115
- var _ref9, _fee;
116
-
126
+ }, (_ref8, _ref9) => {
127
+ var _ref10, _fee;
117
128
  let {
118
129
  amount,
119
130
  fee,
120
131
  nameFee,
121
132
  tx
122
- } = _ref7;
133
+ } = _ref8;
123
134
  let {
124
135
  account,
125
136
  parentTxTypes,
126
137
  txType
127
- } = _ref8;
138
+ } = _ref9;
128
139
  if (account == null) return [];
129
- if (((_ref9 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref9 !== void 0 ? _ref9 : nameFee) === undefined) return [];
140
+ if (((_ref10 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref10 !== void 0 ? _ref10 : nameFee) === undefined) return [];
130
141
  (_fee = fee) !== null && _fee !== void 0 ? _fee : fee = 0;
131
- const cost = new BigNumber(fee).plus(nameFee !== null && nameFee !== void 0 ? nameFee : 0).plus(amount !== null && amount !== void 0 ? amount : 0).plus(txType === Tag.PayingForTx ? tx.tx.encodedTx.tx.fee : 0).minus(_includesInstanceProperty(parentTxTypes).call(parentTxTypes, Tag.PayingForTx) ? fee : 0);
142
+ const cost = new BigNumber(fee).plus(nameFee !== null && nameFee !== void 0 ? nameFee : 0).plus(amount !== null && amount !== void 0 ? amount : 0).plus(txType === Tag.PayingForTx ? tx.tx.encodedTx.tx.fee : 0).minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);
132
143
  if (cost.lte(account.balance.toString())) return [];
133
144
  return [{
134
145
  message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,
135
146
  key: 'InsufficientBalance',
136
147
  checkedKeys: ['amount', 'fee', 'nameFee']
137
148
  }];
138
- }, (_ref10, _ref11) => {
149
+ }, (_ref11, _ref12) => {
150
+ let {
151
+ signatures
152
+ } = _ref11;
153
+ let {
154
+ account,
155
+ txType
156
+ } = _ref12;
157
+ if (account == null) return [];
158
+ let message;
159
+ if (txType === Tag.SignedTx && account.kind === 'generalized' && signatures.length !== 0) {
160
+ message = 'Generalized account can\'t be used to generate SignedTx with signatures';
161
+ }
162
+ if (txType === Tag.GaMetaTx && account.kind === 'basic') {
163
+ message = 'Basic account can\'t be used to generate GaMetaTx';
164
+ }
165
+ if (message == null) return [];
166
+ return [{
167
+ message,
168
+ key: 'InvalidAccountType',
169
+ checkedKeys: ['tag']
170
+ }];
171
+ }, (_ref13, _ref14) => {
139
172
  let {
140
173
  nonce
141
- } = _ref10;
174
+ } = _ref13;
142
175
  let {
143
176
  account,
144
177
  parentTxTypes
145
- } = _ref11;
146
- if (nonce == null || account == null || _includesInstanceProperty(parentTxTypes).call(parentTxTypes, Tag.GaMetaTx)) return [];
178
+ } = _ref14;
179
+ if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];
147
180
  nonce = +nonce;
148
181
  const validNonce = account.nonce + 1;
149
182
  if (nonce === validNonce) return [];
150
- return [{ ...(nonce < validNonce ? {
183
+ return [{
184
+ ...(nonce < validNonce ? {
151
185
  message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
152
186
  key: 'NonceAlreadyUsed'
153
187
  } : {
@@ -156,33 +190,29 @@ validators.push((_ref, _ref2) => {
156
190
  }),
157
191
  checkedKeys: ['nonce']
158
192
  }];
159
- }, (_ref12, _ref13) => {
193
+ }, (_ref15, _ref16) => {
160
194
  let {
161
195
  ctVersion,
162
196
  abiVersion
163
- } = _ref12;
197
+ } = _ref15;
164
198
  let {
165
199
  txType,
166
200
  consensusProtocolVersion
167
- } = _ref13;
168
-
201
+ } = _ref16;
169
202
  if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
170
203
  throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);
171
204
  }
205
+ const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
172
206
 
173
- const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]; // If not contract create tx
174
-
207
+ // If not contract create tx
175
208
  if (ctVersion == null) ctVersion = {
176
209
  abiVersion
177
210
  };
178
211
  const txProtocol = protocol[txType];
179
212
  if (txProtocol == null) return [];
180
-
181
- if (Object.entries(ctVersion).some(_ref14 => {
182
- var _context;
183
-
184
- let [key, value] = _ref14;
185
- return !_includesInstanceProperty(_context = txProtocol[key]).call(_context, +value);
213
+ if (Object.entries(ctVersion).some(_ref17 => {
214
+ let [key, value] = _ref17;
215
+ return !txProtocol[key].includes(+value);
186
216
  })) {
187
217
  return [{
188
218
  message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,
@@ -190,19 +220,17 @@ validators.push((_ref, _ref2) => {
190
220
  checkedKeys: ['ctVersion', 'abiVersion']
191
221
  }];
192
222
  }
193
-
194
223
  return [];
195
- }, async (_ref15, _ref16) => {
224
+ }, async (_ref18, _ref19) => {
196
225
  let {
197
226
  contractId
198
- } = _ref15;
227
+ } = _ref18;
199
228
  let {
200
229
  txType,
201
230
  node
202
- } = _ref16;
231
+ } = _ref19;
203
232
  if (Tag.ContractCallTx !== txType) return [];
204
233
  contractId = contractId;
205
-
206
234
  try {
207
235
  const {
208
236
  active
@@ -215,7 +243,6 @@ validators.push((_ref, _ref2) => {
215
243
  }];
216
244
  } catch (error) {
217
245
  var _error$response, _error$response$parse;
218
-
219
246
  if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : (_error$response$parse = _error$response.parsedBody) === null || _error$response$parse === void 0 ? void 0 : _error$response$parse.reason) == null) throw error;
220
247
  return [{
221
248
  message: error.response.parsedBody.reason,
@@ -1 +1 @@
1
- {"version":3,"file":"validator.mjs","names":["BigNumber","hash","verify","PROTOCOL_VM_ABI","Tag","unpackTx","UnsupportedProtocolError","concatBuffers","isKeyOfObject","decode","encode","Encoding","validators","getSenderAddress","tx","map","key","filter","a","toString","replace","verifyTransaction","transaction","node","parentTxTypes","txType","address","SignedTx","encodedTx","undefined","account","height","consensusProtocolVersion","nodeNetworkId","Promise","all","getAccountByPubkey","catch","id","balance","nonce","then","acc","getCurrentKeyBlockHeight","getNodeInfo","v","flat","push","signatures","length","prefix","from","PayingForTx","join","txWithNetworkId","rlpEncoded","txHashWithNetworkId","decodedPub","message","checkedKeys","Transaction","ttl","amount","fee","nameFee","cost","plus","minus","lte","toFixed","GaMetaTx","validNonce","ctVersion","abiVersion","protocol","txProtocol","Object","entries","some","value","JSON","stringify","contractId","ContractCallTx","active","getContract","error","response","parsedBody","reason"],"sources":["../../src/tx/validator.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { hash, verify } from '../utils/crypto';\nimport {\n CtVersion,\n PROTOCOL_VM_ABI,\n RawTxObject,\n TxParamsCommon,\n TxSchema,\n TxTypeSchemas,\n} from './builder/schema';\nimport { Tag } from './builder/constants';\nimport { TxUnpacked, unpackTx } from './builder';\nimport { UnsupportedProtocolError } from '../utils/errors';\nimport { concatBuffers, isKeyOfObject } from '../utils/other';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport Node from '../Node';\n\ninterface Account {\n balance: bigint;\n id: Encoded.AccountAddress;\n nonce: number;\n}\n\nexport interface ValidatorResult {\n message: string;\n key: string;\n checkedKeys: string[];\n}\n\ntype Validator = (\n tx: {\n encodedTx: TxUnpacked<TxSchema>;\n signatures: Buffer[];\n tx: TxUnpacked<TxSchema> & {\n tx: TxTypeSchemas[Tag.SignedTx];\n };\n nonce?: number;\n ttl?: number;\n amount?: number;\n fee?: number;\n nameFee?: number;\n ctVersion?: Partial<CtVersion>;\n abiVersion?: number;\n contractId?: Encoded.ContractAddress;\n },\n options: {\n account?: Account;\n nodeNetworkId: string;\n parentTxTypes: Tag[];\n node: Node;\n txType: Tag;\n height: number;\n consensusProtocolVersion: number;\n }\n) => ValidatorResult[] | Promise<ValidatorResult[]>;\n\nconst validators: Validator[] = [];\n\nconst getSenderAddress = (\n tx: TxParamsCommon | RawTxObject<TxSchema>,\n): Encoded.AccountAddress | undefined => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',\n]\n .map((key: keyof TxSchema) => tx[key])\n .filter((a) => a)\n .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;\n\n/**\n * Transaction Validator\n * This function validates some of transaction properties,\n * to make sure it can be posted it to the chain\n * @category transaction builder\n * @param transaction - Base64Check-encoded transaction\n * @param node - Node to validate transaction against\n * @param parentTxTypes - Types of parent transactions\n * @returns Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction(\n transaction: Encoded.Transaction | Encoded.Poi,\n node: Node,\n parentTxTypes: Tag[] = [],\n): Promise<ValidatorResult[]> {\n const { tx, txType } = unpackTx<Tag.SignedTx>(transaction);\n const address = getSenderAddress(tx)\n ?? (txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined);\n const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([\n address == null\n ? undefined\n : node.getAccountByPubkey(address)\n .catch(() => ({ id: address, balance: 0n, nonce: 0 }))\n // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537\n .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),\n node.getCurrentKeyBlockHeight(),\n node.getNodeInfo(),\n ]);\n\n return (await Promise.all(\n validators.map((v) => v(\n tx as any,\n {\n txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,\n },\n )),\n )).flat();\n}\n\nvalidators.push(\n ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {\n if ((encodedTx ?? signatures) === undefined) return [];\n if (account == null) return [];\n if (signatures.length !== 1) return []; // TODO: Support multisignature?\n const prefix = Buffer.from([\n nodeNetworkId,\n ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],\n ].join('-'));\n const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);\n const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);\n const decodedPub = decode(account.id);\n if (verify(txWithNetworkId, signatures[0], decodedPub)\n || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];\n return [{\n message: 'Signature cannot be verified, please ensure that you transaction have'\n + ' the correct prefix and the correct private key for the sender address',\n key: 'InvalidSignature',\n checkedKeys: ['encodedTx', 'signatures'],\n }];\n },\n async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {\n if ((encodedTx ?? tx) === undefined) return [];\n return verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, Encoding.Transaction),\n node,\n [...parentTxTypes, txType],\n );\n },\n ({ ttl }, { height }) => {\n if (ttl === undefined) return [];\n ttl = +ttl;\n if (ttl === 0 || ttl >= height) return [];\n return [{\n message: `TTL ${ttl} is already expired, current height is ${height}`,\n key: 'ExpiredTTL',\n checkedKeys: ['ttl'],\n }];\n },\n ({\n amount, fee, nameFee, tx,\n }, { account, parentTxTypes, txType }) => {\n if (account == null) return [];\n if ((amount ?? fee ?? nameFee) === undefined) return [];\n fee ??= 0;\n const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)\n .plus(txType === Tag.PayingForTx ? (tx.tx.encodedTx.tx).fee : 0)\n .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);\n if (cost.lte(account.balance.toString())) return [];\n return [{\n message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,\n key: 'InsufficientBalance',\n checkedKeys: ['amount', 'fee', 'nameFee'],\n }];\n },\n ({ nonce }, { account, parentTxTypes }) => {\n if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];\n nonce = +nonce;\n const validNonce = account.nonce + 1;\n if (nonce === validNonce) return [];\n return [{\n ...nonce < validNonce\n ? {\n message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,\n key: 'NonceAlreadyUsed',\n }\n : {\n message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,\n key: 'NonceHigh',\n },\n checkedKeys: ['nonce'],\n }];\n },\n ({ ctVersion, abiVersion }, { txType, consensusProtocolVersion }) => {\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);\n }\n const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];\n\n // If not contract create tx\n if (ctVersion == null) ctVersion = { abiVersion };\n const txProtocol = protocol[txType as keyof typeof protocol];\n if (txProtocol == null) return [];\n if (Object.entries(ctVersion).some(\n ([\n key,\n value,\n ]: [\n key:keyof typeof txProtocol,\n value:any]) => !(txProtocol[key].includes(+value as never)),\n )) {\n return [{\n message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,\n key: 'VmAndAbiVersionMismatch',\n checkedKeys: ['ctVersion', 'abiVersion'],\n }];\n }\n return [];\n },\n async ({ contractId }, { txType, node }) => {\n if (Tag.ContractCallTx !== txType) return [];\n contractId = contractId as Encoded.ContractAddress;\n try {\n const { active } = await node.getContract(contractId);\n if (active) return [];\n return [{\n message: `Contract ${contractId} is not active`,\n key: 'ContractNotActive',\n checkedKeys: ['contractId'],\n }];\n } catch (error) {\n if (error.response?.parsedBody?.reason == null) throw error;\n return [{\n message: error.response.parsedBody.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId'],\n }];\n }\n },\n);\n"],"mappings":";;;;;AAAA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,I,EAAMC,M;SAGbC,e;SAMOC,G;SACYC,Q;SACZC,wB;SACAC,a,EAAeC,a;SAEtBC,M,EAAQC,M,EAAiBC,Q;AA2C3B,MAAMC,UAAuB,GAAG,EAAhC;;AAEA,MAAMC,gBAAgB,GACpBC,EADuB,IAEgB,CACvC,UADuC,EAC3B,WAD2B,EACd,SADc,EACH,UADG,EAEvC,U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Tx","UnsupportedProtocolError","concatBuffers","isAccountNotFoundError","isKeyOfObject","encode","Encoding","Node","genAggressiveCacheGetResponsesPolicy","validators","getSenderAddress","tx","map","key","filter","a","toString","replace","verifyTransaction","transaction","nodeNotCached","parentTxTypes","node","pipeline","getOrderedPolicies","some","name","$host","ignoreVersion","addPolicy","txType","address","SignedTx","encodedTx","undefined","account","height","consensusProtocolVersion","nodeNetworkId","Promise","all","getAccountByPubkey","catch","error","id","balance","nonce","then","acc","getCurrentKeyBlockHeight","getNodeInfo","v","flat","push","signatures","length","prefix","from","includes","PayingForTx","join","txWithNetworkId","rlpEncoded","txHashWithNetworkId","message","checkedKeys","Transaction","ttl","amount","fee","nameFee","cost","plus","minus","lte","toFixed","kind","GaMetaTx","validNonce","ctVersion","abiVersion","protocol","txProtocol","Object","entries","value","JSON","stringify","contractId","ContractCallTx","active","getContract","response","parsedBody","reason"],"sources":["../../src/tx/validator.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { hash, verify } from '../utils/crypto';\nimport {\n CtVersion,\n PROTOCOL_VM_ABI,\n RawTxObject,\n TxParamsCommon,\n TxSchema,\n TxTypeSchemas,\n} from './builder/schema';\nimport { Tag } from './builder/constants';\nimport { TxUnpacked, unpackTx } from './builder';\nimport { UnsupportedProtocolError } from '../utils/errors';\nimport { concatBuffers, isAccountNotFoundError, isKeyOfObject } from '../utils/other';\nimport { encode, Encoded, Encoding } from '../utils/encoder';\nimport Node, { TransformNodeType } from '../Node';\nimport { Account } from '../apis/node';\nimport { genAggressiveCacheGetResponsesPolicy } from '../utils/autorest';\n\nexport interface ValidatorResult {\n message: string;\n key: string;\n checkedKeys: string[];\n}\n\ntype Validator = (\n tx: {\n encodedTx: TxUnpacked<TxSchema>;\n signatures: Buffer[];\n tx: TxUnpacked<TxSchema> & {\n tx: TxTypeSchemas[Tag.SignedTx];\n };\n nonce?: number;\n ttl?: number;\n amount?: number;\n fee?: number;\n nameFee?: number;\n ctVersion?: Partial<CtVersion>;\n abiVersion?: number;\n contractId?: Encoded.ContractAddress;\n },\n options: {\n // TODO: remove after fixing node types\n account?: TransformNodeType<Account> & { id: Encoded.AccountAddress };\n nodeNetworkId: string;\n parentTxTypes: Tag[];\n node: Node;\n txType: Tag;\n height: number;\n consensusProtocolVersion: number;\n }\n) => ValidatorResult[] | Promise<ValidatorResult[]>;\n\nconst validators: Validator[] = [];\n\nconst getSenderAddress = (\n tx: TxParamsCommon | RawTxObject<TxSchema>,\n): Encoded.AccountAddress | undefined => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',\n]\n .map((key: keyof TxSchema) => tx[key])\n .filter((a) => a)\n .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;\n\n/**\n * Transaction Validator\n * This function validates some of transaction properties,\n * to make sure it can be posted it to the chain\n * @category transaction builder\n * @param transaction - Base64Check-encoded transaction\n * @param nodeNotCached - Node to validate transaction against\n * @param parentTxTypes - Types of parent transactions\n * @returns Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction(\n transaction: Encoded.Transaction | Encoded.Poi,\n nodeNotCached: Node,\n parentTxTypes: Tag[] = [],\n): Promise<ValidatorResult[]> {\n let node = nodeNotCached;\n if (\n !node.pipeline.getOrderedPolicies()\n .some(({ name }) => name === 'aggressive-cache-get-responses')\n ) {\n node = new Node(nodeNotCached.$host, { ignoreVersion: true });\n node.pipeline.addPolicy(genAggressiveCacheGetResponsesPolicy());\n }\n\n const { tx, txType } = unpackTx<Tag.SignedTx>(transaction);\n const address = getSenderAddress(tx)\n ?? (txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined);\n const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([\n address == null\n ? undefined\n : node.getAccountByPubkey(address)\n .catch((error) => {\n if (!isAccountNotFoundError(error)) throw error;\n return { id: address, balance: 0n, nonce: 0 };\n })\n // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537\n .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),\n node.getCurrentKeyBlockHeight(),\n node.getNodeInfo(),\n ]);\n\n return (await Promise.all(\n validators.map((v) => v(\n tx as any,\n {\n txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,\n },\n )),\n )).flat();\n}\n\nvalidators.push(\n ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {\n if ((encodedTx ?? signatures) === undefined) return [];\n if (account == null) return [];\n if (signatures.length !== 1) return []; // TODO: Support multisignature?\n const prefix = Buffer.from([\n nodeNetworkId,\n ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],\n ].join('-'));\n const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);\n const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);\n if (verify(txWithNetworkId, signatures[0], account.id)\n || verify(txHashWithNetworkId, signatures[0], account.id)) return [];\n return [{\n message: 'Signature cannot be verified, please ensure that you transaction have'\n + ' the correct prefix and the correct private key for the sender address',\n key: 'InvalidSignature',\n checkedKeys: ['encodedTx', 'signatures'],\n }];\n },\n async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {\n if ((encodedTx ?? tx) === undefined) return [];\n return verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, Encoding.Transaction),\n node,\n [...parentTxTypes, txType],\n );\n },\n ({ ttl }, { height }) => {\n if (ttl === undefined) return [];\n ttl = +ttl;\n if (ttl === 0 || ttl >= height) return [];\n return [{\n message: `TTL ${ttl} is already expired, current height is ${height}`,\n key: 'ExpiredTTL',\n checkedKeys: ['ttl'],\n }];\n },\n ({\n amount, fee, nameFee, tx,\n }, { account, parentTxTypes, txType }) => {\n if (account == null) return [];\n if ((amount ?? fee ?? nameFee) === undefined) return [];\n fee ??= 0;\n const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)\n .plus(txType === Tag.PayingForTx ? (tx.tx.encodedTx.tx).fee : 0)\n .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);\n if (cost.lte(account.balance.toString())) return [];\n return [{\n message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,\n key: 'InsufficientBalance',\n checkedKeys: ['amount', 'fee', 'nameFee'],\n }];\n },\n ({ signatures }, { account, txType }) => {\n if (account == null) return [];\n let message;\n if (txType === Tag.SignedTx && account.kind === 'generalized' && signatures.length !== 0) {\n message = 'Generalized account can\\'t be used to generate SignedTx with signatures';\n }\n if (txType === Tag.GaMetaTx && account.kind === 'basic') {\n message = 'Basic account can\\'t be used to generate GaMetaTx';\n }\n if (message == null) return [];\n return [{ message, key: 'InvalidAccountType', checkedKeys: ['tag'] }];\n },\n ({ nonce }, { account, parentTxTypes }) => {\n if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];\n nonce = +nonce;\n const validNonce = account.nonce + 1;\n if (nonce === validNonce) return [];\n return [{\n ...nonce < validNonce\n ? {\n message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,\n key: 'NonceAlreadyUsed',\n }\n : {\n message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,\n key: 'NonceHigh',\n },\n checkedKeys: ['nonce'],\n }];\n },\n ({ ctVersion, abiVersion }, { txType, consensusProtocolVersion }) => {\n if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {\n throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);\n }\n const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];\n\n // If not contract create tx\n if (ctVersion == null) ctVersion = { abiVersion };\n const txProtocol = protocol[txType as keyof typeof protocol];\n if (txProtocol == null) return [];\n if (Object.entries(ctVersion).some(\n ([\n key,\n value,\n ]: [\n key:keyof typeof txProtocol,\n value:any]) => !(txProtocol[key].includes(+value as never)),\n )) {\n return [{\n message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,\n key: 'VmAndAbiVersionMismatch',\n checkedKeys: ['ctVersion', 'abiVersion'],\n }];\n }\n return [];\n },\n async ({ contractId }, { txType, node }) => {\n if (Tag.ContractCallTx !== txType) return [];\n contractId = contractId as Encoded.ContractAddress;\n try {\n const { active } = await node.getContract(contractId);\n if (active) return [];\n return [{\n message: `Contract ${contractId} is not active`,\n key: 'ContractNotActive',\n checkedKeys: ['contractId'],\n }];\n } catch (error) {\n if (error.response?.parsedBody?.reason == null) throw error;\n return [{\n message: error.response.parsedBody.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId'],\n }];\n }\n },\n);\n"],"mappings":";;;;AAAA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAC5BC,IAAI,EAAEC,MAAM;AAAA,SAGnBC,eAAe;AAAA,SAMRC,GAAG;AAAA,SACSC,QAAQ;AAAA,SACpBC,wBAAwB;AAAA,SACxBC,aAAa,EAAEC,sBAAsB,EAAEC,aAAa;AAAA,SACpDC,MAAM,EAAWC,QAAQ;AAAA,OAC3BC,IAAI;AAAA,SAEFC,oCAAoC;AAoC7C,MAAMC,UAAuB,GAAG,EAAE;AAElC,MAAMC,gBAAgB,GACpBC,EAA0C,IACH,CACvC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAC9C,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CACrD,CACEC,GAAG,CAAEC,GAAmB,IAAKF,EAAE,CAACE,GAAG,CAAC,CAAC,CACrCC,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAAC,CAChBH,GAAG,CAAEG,CAAC,IAAKA,CAAC,aAADA,CAAC,uBAADA,CAAC,CAAEC,QAAQ,EAAE,CAACC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAuC;;AAE5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,e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AW,gBAAe;MAC/C3E,GAAG,EAAE,mBAAmB;MACxBoD,WAAW,EAAE,CAAC,YAAY;IAC5B,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOtB,KAAK,EAAE;IAAA;IACd,IAAI,oBAAAA,KAAK,CAACiD,QAAQ,6EAAd,gBAAgBC,UAAU,0DAA1B,sBAA4BC,MAAM,KAAI,IAAI,EAAE,MAAMnD,KAAK;IAC3D,OAAO,CAAC;MACNqB,OAAO,EAAErB,KAAK,CAACiD,QAAQ,CAACC,UAAU,CAACC,MAAM;MACzCjF,GAAG,EAAE,kBAAkB;MACvBoD,WAAW,EAAE,CAAC,YAAY;IAC5B,CAAC,CAAC;EACJ;AACF,CAAC,CACF"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/@aeternity__aepp-calldata/index.d.ts"],"sourcesContent":["declare module '@aeternity/aepp-calldata' {\n // eslint-disable-next-line import/prefer-default-export\n export class Encoder {\n constructor(aci: object);\n\n encode(contract: string, funName: string, args: any[]): `cb_${string}`;\n\n decode(contract: string, funName: string, data: `cb_${string}`): any;\n\n decodeString(data: `cb_${string}`): Uint8Array;\n\n decodeFateString(data: `cb_${string}`): string;\n\n decodeEvent(\n contract: string,\n encodedData: `cb_${string}`,\n topics: BigInt[],\n ): { [key: string]: any[] };\n }\n}\n"],"mappings":""}