@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-beta.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 (481) hide show
  1. package/bin/aesophia_cli +0 -0
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +5595 -2249
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/AeSdk.mjs.map +1 -1
  9. package/es/AeSdkAepp.mjs.map +1 -1
  10. package/es/AeSdkBase.d.ts +3 -3
  11. package/es/AeSdkBase.mjs +4 -0
  12. package/es/AeSdkBase.mjs.map +1 -1
  13. package/es/AeSdkMethods.d.ts +12 -14
  14. package/es/AeSdkMethods.mjs +6 -8
  15. package/es/AeSdkMethods.mjs.map +1 -1
  16. package/es/AeSdkWallet.mjs +1 -1
  17. package/es/AeSdkWallet.mjs.map +1 -1
  18. package/es/Node.d.ts +9 -4
  19. package/es/Node.mjs +12 -6
  20. package/es/Node.mjs.map +1 -1
  21. package/es/account/Base.d.ts +13 -8
  22. package/es/account/Base.mjs +0 -17
  23. package/es/account/Base.mjs.map +1 -1
  24. package/es/account/Generalized.mjs +14 -25
  25. package/es/account/Generalized.mjs.map +1 -1
  26. package/es/account/Ledger.mjs +2 -1
  27. package/es/account/Ledger.mjs.map +1 -1
  28. package/es/account/LedgerFactory.mjs.map +1 -1
  29. package/es/account/Memory.d.ts +2 -1
  30. package/es/account/Memory.mjs +11 -22
  31. package/es/account/Memory.mjs.map +1 -1
  32. package/es/account/Rpc.mjs.map +1 -1
  33. package/es/aens.d.ts +12 -14
  34. package/es/aens.mjs +22 -32
  35. package/es/aens.mjs.map +1 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs +0 -16
  37. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -20
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +0 -16
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  43. package/es/aepp-wallet-communication/connection-proxy.mjs +0 -17
  44. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  45. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -6
  46. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/rpc/types.d.ts +6 -2
  48. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  49. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/wallet-detector.mjs +0 -16
  51. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  52. package/es/apis/compiler/compiler.d.ts +1 -1
  53. package/es/apis/compiler/compiler.mjs +4 -20
  54. package/es/apis/compiler/compiler.mjs.map +1 -1
  55. package/es/apis/compiler/models/index.d.ts +3 -2
  56. package/es/apis/compiler/models/index.mjs.map +1 -1
  57. package/es/apis/compiler/models/mappers.d.ts +1 -1
  58. package/es/apis/compiler/models/mappers.mjs +19 -2
  59. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  60. package/es/apis/node/models/index.d.ts +15 -15
  61. package/es/apis/node/models/index.mjs.map +1 -1
  62. package/es/apis/node/models/mappers.d.ts +1 -1
  63. package/es/apis/node/models/mappers.mjs +2 -1
  64. package/es/apis/node/models/mappers.mjs.map +1 -1
  65. package/es/apis/node/models/parameters.d.ts +2 -2
  66. package/es/apis/node/models/parameters.mjs +2 -2
  67. package/es/apis/node/models/parameters.mjs.map +1 -1
  68. package/es/apis/node/node.mjs +3 -19
  69. package/es/apis/node/node.mjs.map +1 -1
  70. package/es/chain.d.ts +17 -9
  71. package/es/chain.mjs +23 -23
  72. package/es/chain.mjs.map +1 -1
  73. package/es/channel/Base.d.ts +27 -9
  74. package/es/channel/Base.mjs +27 -27
  75. package/es/channel/Base.mjs.map +1 -1
  76. package/es/channel/Contract.d.ts +8 -7
  77. package/es/channel/Contract.mjs +8 -21
  78. package/es/channel/Contract.mjs.map +1 -1
  79. package/es/channel/Spend.d.ts +5 -1
  80. package/es/channel/Spend.mjs +4 -18
  81. package/es/channel/Spend.mjs.map +1 -1
  82. package/es/channel/handlers.mjs +16 -26
  83. package/es/channel/handlers.mjs.map +1 -1
  84. package/es/channel/internal.d.ts +19 -2
  85. package/es/channel/internal.mjs +22 -20
  86. package/es/channel/internal.mjs.map +1 -1
  87. package/es/contract/Contract.d.ts +43 -123
  88. package/es/contract/Contract.mjs +230 -250
  89. package/es/contract/Contract.mjs.map +1 -1
  90. package/es/contract/compiler/Base.d.ts +74 -0
  91. package/es/contract/compiler/Base.mjs +5 -0
  92. package/es/contract/compiler/Base.mjs.map +1 -0
  93. package/es/contract/compiler/Cli.d.ts +23 -0
  94. package/es/contract/compiler/Cli.mjs +149 -0
  95. package/es/contract/compiler/Cli.mjs.map +1 -0
  96. package/es/contract/compiler/Http.d.ts +32 -0
  97. package/es/contract/compiler/Http.mjs +94 -0
  98. package/es/contract/compiler/Http.mjs.map +1 -0
  99. package/es/contract/compiler/HttpNode.d.ts +17 -0
  100. package/es/contract/compiler/HttpNode.mjs +26 -0
  101. package/es/contract/compiler/HttpNode.mjs.map +1 -0
  102. package/es/contract/compiler/getFileSystem.d.ts +6 -0
  103. package/es/contract/compiler/getFileSystem.mjs +40 -0
  104. package/es/contract/compiler/getFileSystem.mjs.map +1 -0
  105. package/es/contract/delegation-signature.d.ts +43 -0
  106. package/es/contract/delegation-signature.mjs +45 -0
  107. package/es/contract/delegation-signature.mjs.map +1 -0
  108. package/es/contract/ga.d.ts +27 -10
  109. package/es/contract/ga.mjs +63 -29
  110. package/es/contract/ga.mjs.map +1 -1
  111. package/es/index-browser.d.ts +40 -0
  112. package/es/index-browser.mjs +41 -0
  113. package/es/index-browser.mjs.map +1 -0
  114. package/es/index.d.ts +4 -38
  115. package/es/index.mjs +4 -53
  116. package/es/index.mjs.map +1 -1
  117. package/es/oracle.d.ts +12 -17
  118. package/es/oracle.mjs +29 -49
  119. package/es/oracle.mjs.map +1 -1
  120. package/es/spend.d.ts +19 -27
  121. package/es/spend.mjs +21 -46
  122. package/es/spend.mjs.map +1 -1
  123. package/es/tx/builder/SchemaTypes.d.ts +37 -0
  124. package/es/tx/builder/SchemaTypes.mjs +2 -0
  125. package/es/tx/builder/SchemaTypes.mjs.map +1 -0
  126. package/es/tx/builder/constants.d.ts +31 -2
  127. package/es/tx/builder/constants.mjs +34 -3
  128. package/es/tx/builder/constants.mjs.map +1 -1
  129. package/es/tx/builder/field-types/abi-version.d.ts +19 -0
  130. package/es/tx/builder/field-types/abi-version.mjs +40 -0
  131. package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
  132. package/es/tx/builder/field-types/address.d.ts +5 -6
  133. package/es/tx/builder/field-types/address.mjs +17 -8
  134. package/es/tx/builder/field-types/address.mjs.map +1 -1
  135. package/es/tx/builder/field-types/array.d.ts +7 -0
  136. package/es/tx/builder/field-types/array.mjs +11 -0
  137. package/es/tx/builder/field-types/array.mjs.map +1 -0
  138. package/es/tx/builder/field-types/boolean.d.ts +6 -0
  139. package/es/tx/builder/field-types/boolean.mjs +13 -0
  140. package/es/tx/builder/field-types/boolean.mjs.map +1 -0
  141. package/es/tx/builder/field-types/coin-amount.d.ts +4 -5
  142. package/es/tx/builder/field-types/coin-amount.mjs +4 -5
  143. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  144. package/es/tx/builder/field-types/ct-version.d.ts +49 -0
  145. package/es/tx/builder/field-types/ct-version.mjs +76 -0
  146. package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
  147. package/es/tx/builder/field-types/deposit.d.ts +3 -2
  148. package/es/tx/builder/field-types/deposit.mjs +3 -2
  149. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  150. package/es/tx/builder/field-types/encoded.d.ts +6 -0
  151. package/es/tx/builder/field-types/encoded.mjs +21 -0
  152. package/es/tx/builder/field-types/encoded.mjs.map +1 -0
  153. package/es/tx/builder/field-types/entry.d.ts +11 -0
  154. package/es/tx/builder/field-types/entry.mjs +34 -0
  155. package/es/tx/builder/field-types/entry.mjs.map +1 -0
  156. package/es/tx/builder/field-types/enumeration.d.ts +5 -3
  157. package/es/tx/builder/field-types/enumeration.mjs +11 -2
  158. package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
  159. package/es/tx/builder/field-types/fee.d.ts +12 -7
  160. package/es/tx/builder/field-types/fee.mjs +28 -20
  161. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  162. package/es/tx/builder/field-types/field.mjs.map +1 -1
  163. package/es/tx/builder/field-types/gas-limit.d.ts +7 -3
  164. package/es/tx/builder/field-types/gas-limit.mjs +13 -8
  165. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  166. package/es/tx/builder/field-types/gas-price.d.ts +3 -1
  167. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  168. package/es/tx/builder/field-types/index.d.ts +107 -30
  169. package/es/tx/builder/field-types/index.mjs +38 -12
  170. package/es/tx/builder/field-types/index.mjs.map +1 -1
  171. package/es/tx/builder/field-types/map.d.ts +13 -0
  172. package/es/tx/builder/field-types/map.mjs +49 -0
  173. package/es/tx/builder/field-types/map.mjs.map +1 -0
  174. package/es/tx/builder/field-types/mptree.d.ts +42 -0
  175. package/es/tx/builder/field-types/mptree.mjs +266 -0
  176. package/es/tx/builder/field-types/mptree.mjs.map +1 -0
  177. package/es/tx/builder/field-types/name-fee.d.ts +2 -3
  178. package/es/tx/builder/field-types/name-fee.mjs +2 -2
  179. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  180. package/es/tx/builder/field-types/name-id.mjs +2 -1
  181. package/es/tx/builder/field-types/name-id.mjs.map +1 -1
  182. package/es/tx/builder/field-types/name.mjs.map +1 -1
  183. package/es/tx/builder/field-types/nonce.d.ts +14 -0
  184. package/es/tx/builder/field-types/nonce.mjs +29 -0
  185. package/es/tx/builder/field-types/nonce.mjs.map +1 -0
  186. package/es/tx/builder/field-types/pointers.mjs +2 -2
  187. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  188. package/es/tx/builder/field-types/raw.d.ts +6 -0
  189. package/es/tx/builder/field-types/raw.mjs +13 -0
  190. package/es/tx/builder/field-types/raw.mjs.map +1 -0
  191. package/es/tx/builder/field-types/short-u-int-const.d.ts +7 -0
  192. package/es/tx/builder/field-types/short-u-int-const.mjs +20 -0
  193. package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
  194. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -1
  195. package/es/tx/builder/field-types/string.d.ts +6 -0
  196. package/es/tx/builder/field-types/string.mjs +10 -0
  197. package/es/tx/builder/field-types/string.mjs.map +1 -0
  198. package/es/tx/builder/field-types/ttl.d.ts +11 -0
  199. package/es/tx/builder/field-types/ttl.mjs +21 -0
  200. package/es/tx/builder/field-types/ttl.mjs.map +1 -0
  201. package/es/tx/builder/field-types/u-int.d.ts +1 -2
  202. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  203. package/es/tx/builder/field-types/wrapped.d.ts +14 -0
  204. package/es/tx/builder/field-types/wrapped.mjs +22 -0
  205. package/es/tx/builder/field-types/wrapped.mjs.map +1 -0
  206. package/es/tx/builder/helpers.mjs.map +1 -1
  207. package/es/tx/builder/index.d.ts +18 -36
  208. package/es/tx/builder/index.mjs +65 -236
  209. package/es/tx/builder/index.mjs.map +1 -1
  210. package/es/tx/builder/schema.d.ts +2734 -1324
  211. package/es/tx/builder/schema.generated.d.ts +2011 -0
  212. package/es/tx/builder/schema.generated.mjs +2 -0
  213. package/es/tx/builder/schema.generated.mjs.map +1 -0
  214. package/es/tx/builder/schema.mjs +459 -223
  215. package/es/tx/builder/schema.mjs.map +1 -1
  216. package/es/tx/execution-cost.d.ts +35 -0
  217. package/es/tx/execution-cost.mjs +123 -0
  218. package/es/tx/execution-cost.mjs.map +1 -0
  219. package/es/tx/transaction-signer.d.ts +6 -0
  220. package/es/tx/transaction-signer.mjs +27 -0
  221. package/es/tx/transaction-signer.mjs.map +1 -0
  222. package/es/tx/validator.d.ts +3 -5
  223. package/es/tx/validator.mjs +91 -153
  224. package/es/tx/validator.mjs.map +1 -1
  225. package/es/utils/amount-formatter.mjs +0 -16
  226. package/es/utils/amount-formatter.mjs.map +1 -1
  227. package/es/utils/autorest.d.ts +3 -2
  228. package/es/utils/autorest.mjs +43 -11
  229. package/es/utils/autorest.mjs.map +1 -1
  230. package/es/utils/bytes.mjs +1 -17
  231. package/es/utils/bytes.mjs.map +1 -1
  232. package/es/utils/crypto.mjs +0 -16
  233. package/es/utils/crypto.mjs.map +1 -1
  234. package/es/utils/encoder.mjs.map +1 -1
  235. package/es/utils/errors.d.ts +16 -38
  236. package/es/utils/errors.mjs +3 -43
  237. package/es/utils/errors.mjs.map +1 -1
  238. package/es/utils/hd-wallet.mjs.map +1 -1
  239. package/es/utils/json-big.mjs.map +1 -1
  240. package/es/utils/keystore.mjs.map +1 -1
  241. package/es/utils/other.mjs.map +1 -1
  242. package/es/utils/semver-satisfies.mjs.map +1 -1
  243. package/es/utils/string.mjs +0 -17
  244. package/es/utils/string.mjs.map +1 -1
  245. package/package.json +52 -40
  246. package/src/AeSdkBase.ts +6 -3
  247. package/src/AeSdkMethods.ts +12 -18
  248. package/src/AeSdkWallet.ts +1 -1
  249. package/src/Node.ts +23 -9
  250. package/src/account/Base.ts +13 -24
  251. package/src/account/Generalized.ts +9 -24
  252. package/src/account/Ledger.ts +1 -1
  253. package/src/account/Memory.ts +15 -22
  254. package/src/aens.ts +34 -49
  255. package/src/aepp-wallet-communication/connection/Browser.ts +0 -17
  256. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -24
  257. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +0 -17
  258. package/src/aepp-wallet-communication/connection-proxy.ts +0 -17
  259. package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
  260. package/src/aepp-wallet-communication/rpc/types.ts +6 -2
  261. package/src/aepp-wallet-communication/wallet-detector.ts +0 -17
  262. package/src/apis/compiler/compiler.ts +3 -27
  263. package/src/apis/compiler/models/index.ts +3 -2
  264. package/src/apis/compiler/models/mappers.ts +15 -2
  265. package/src/apis/node/models/index.ts +16 -15
  266. package/src/apis/node/models/mappers.ts +2 -1
  267. package/src/apis/node/models/parameters.ts +2 -2
  268. package/src/apis/node/node.ts +3 -27
  269. package/src/chain.ts +33 -30
  270. package/src/channel/Base.ts +39 -31
  271. package/src/channel/Contract.ts +18 -32
  272. package/src/channel/Spend.ts +8 -18
  273. package/src/channel/handlers.ts +14 -26
  274. package/src/channel/internal.ts +41 -23
  275. package/src/contract/Contract.ts +188 -228
  276. package/src/contract/compiler/Base.ts +87 -0
  277. package/src/contract/compiler/Cli.ts +128 -0
  278. package/src/contract/compiler/Http.ts +105 -0
  279. package/src/contract/compiler/HttpNode.ts +26 -0
  280. package/src/contract/compiler/getFileSystem.ts +42 -0
  281. package/src/contract/delegation-signature.ts +56 -0
  282. package/src/contract/ga.ts +61 -37
  283. package/src/index-browser.ts +50 -0
  284. package/src/index.ts +4 -56
  285. package/src/oracle.ts +47 -57
  286. package/src/spend.ts +34 -68
  287. package/src/tx/builder/SchemaTypes.ts +79 -0
  288. package/src/tx/builder/constants.ts +34 -3
  289. package/src/tx/builder/field-types/abi-version.ts +44 -0
  290. package/src/tx/builder/field-types/address.ts +23 -13
  291. package/src/tx/builder/field-types/array.ts +19 -0
  292. package/src/tx/builder/field-types/boolean.ts +9 -0
  293. package/src/tx/builder/field-types/coin-amount.ts +8 -5
  294. package/src/tx/builder/field-types/ct-version.ts +83 -0
  295. package/src/tx/builder/field-types/deposit.ts +4 -2
  296. package/src/tx/builder/field-types/encoded.ts +27 -0
  297. package/src/tx/builder/field-types/entry.ts +36 -0
  298. package/src/tx/builder/field-types/enumeration.ts +15 -4
  299. package/src/tx/builder/field-types/fee.ts +41 -19
  300. package/src/tx/builder/field-types/gas-limit.ts +13 -8
  301. package/src/tx/builder/field-types/index.ts +60 -17
  302. package/src/tx/builder/field-types/map.ts +45 -0
  303. package/src/tx/builder/field-types/mptree.ts +243 -0
  304. package/src/tx/builder/field-types/name-fee.ts +3 -3
  305. package/src/tx/builder/field-types/name-id.ts +1 -1
  306. package/src/tx/builder/field-types/nonce.ts +40 -0
  307. package/src/tx/builder/field-types/pointers.ts +2 -2
  308. package/src/tx/builder/field-types/raw.ts +9 -0
  309. package/src/tx/builder/field-types/short-u-int-const.ts +30 -0
  310. package/src/tx/builder/field-types/string.ts +11 -0
  311. package/src/tx/builder/field-types/ttl.ts +24 -0
  312. package/src/tx/builder/field-types/u-int.ts +1 -3
  313. package/src/tx/builder/field-types/wrapped.ts +32 -0
  314. package/src/tx/builder/index.ts +82 -280
  315. package/src/tx/builder/schema.generated.ts +2013 -0
  316. package/src/tx/builder/schema.ts +536 -666
  317. package/src/tx/execution-cost.ts +146 -0
  318. package/src/tx/transaction-signer.ts +27 -0
  319. package/src/tx/validator.ts +100 -154
  320. package/src/utils/amount-formatter.ts +0 -16
  321. package/src/utils/autorest.ts +52 -11
  322. package/src/utils/bytes.ts +1 -17
  323. package/src/utils/crypto.ts +0 -16
  324. package/src/utils/errors.ts +18 -56
  325. package/src/utils/string.ts +0 -17
  326. package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
  327. package/types-legacy/ts4.2/AeSdkMethods.d.ts +12 -14
  328. package/types-legacy/ts4.2/Node.d.ts +8 -4
  329. package/types-legacy/ts4.2/account/Base.d.ts +13 -8
  330. package/types-legacy/ts4.2/account/Memory.d.ts +2 -1
  331. package/types-legacy/ts4.2/aens.d.ts +12 -14
  332. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  333. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +6 -2
  334. package/types-legacy/ts4.2/apis/compiler/compiler.d.ts +1 -1
  335. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +3 -2
  336. package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +1 -1
  337. package/types-legacy/ts4.2/apis/node/models/index.d.ts +15 -15
  338. package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +1 -1
  339. package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
  340. package/types-legacy/ts4.2/chain.d.ts +17 -9
  341. package/types-legacy/ts4.2/channel/Base.d.ts +27 -9
  342. package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
  343. package/types-legacy/ts4.2/channel/Spend.d.ts +5 -1
  344. package/types-legacy/ts4.2/channel/internal.d.ts +22 -2
  345. package/types-legacy/ts4.2/contract/Contract.d.ts +42 -122
  346. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +74 -0
  347. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
  348. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
  349. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
  350. package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
  351. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +43 -0
  352. package/types-legacy/ts4.2/contract/ga.d.ts +27 -10
  353. package/types-legacy/ts4.2/index-browser.d.ts +40 -0
  354. package/types-legacy/ts4.2/index.d.ts +4 -38
  355. package/types-legacy/ts4.2/oracle.d.ts +12 -17
  356. package/types-legacy/ts4.2/spend.d.ts +19 -27
  357. package/types-legacy/ts4.2/tx/builder/SchemaTypes.d.ts +37 -0
  358. package/types-legacy/ts4.2/tx/builder/constants.d.ts +31 -2
  359. package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +19 -0
  360. package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
  361. package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
  362. package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
  363. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +4 -5
  364. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +72 -0
  365. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +3 -2
  366. package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
  367. package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
  368. package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
  369. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +12 -7
  370. package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +7 -3
  371. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +3 -1
  372. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +113 -30
  373. package/types-legacy/ts4.2/tx/builder/field-types/map.d.ts +13 -0
  374. package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +48 -0
  375. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +2 -3
  376. package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +14 -0
  377. package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
  378. package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +7 -0
  379. package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
  380. package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +11 -0
  381. package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
  382. package/types-legacy/ts4.2/tx/builder/field-types/wrapped.d.ts +14 -0
  383. package/types-legacy/ts4.2/tx/builder/index.d.ts +21 -36
  384. package/types-legacy/ts4.2/tx/builder/schema.d.ts +2971 -2926
  385. package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +2011 -0
  386. package/types-legacy/ts4.2/tx/execution-cost.d.ts +35 -0
  387. package/types-legacy/ts4.2/tx/transaction-signer.d.ts +6 -0
  388. package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
  389. package/types-legacy/ts4.2/utils/autorest.d.ts +3 -2
  390. package/types-legacy/ts4.2/utils/errors.d.ts +16 -38
  391. package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
  392. package/types-legacy/ts4.5/AeSdkMethods.d.ts +12 -14
  393. package/types-legacy/ts4.5/Node.d.ts +8 -4
  394. package/types-legacy/ts4.5/account/Base.d.ts +13 -8
  395. package/types-legacy/ts4.5/account/Memory.d.ts +2 -1
  396. package/types-legacy/ts4.5/aens.d.ts +12 -14
  397. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  398. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +6 -2
  399. package/types-legacy/ts4.5/apis/compiler/compiler.d.ts +1 -1
  400. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +3 -2
  401. package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +1 -1
  402. package/types-legacy/ts4.5/apis/node/models/index.d.ts +15 -15
  403. package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +1 -1
  404. package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
  405. package/types-legacy/ts4.5/chain.d.ts +17 -9
  406. package/types-legacy/ts4.5/channel/Base.d.ts +27 -9
  407. package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
  408. package/types-legacy/ts4.5/channel/Spend.d.ts +5 -1
  409. package/types-legacy/ts4.5/channel/internal.d.ts +22 -2
  410. package/types-legacy/ts4.5/contract/Contract.d.ts +42 -122
  411. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +74 -0
  412. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
  413. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
  414. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
  415. package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
  416. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +43 -0
  417. package/types-legacy/ts4.5/contract/ga.d.ts +27 -10
  418. package/types-legacy/ts4.5/index-browser.d.ts +40 -0
  419. package/types-legacy/ts4.5/index.d.ts +4 -38
  420. package/types-legacy/ts4.5/oracle.d.ts +12 -17
  421. package/types-legacy/ts4.5/spend.d.ts +19 -27
  422. package/types-legacy/ts4.5/tx/builder/SchemaTypes.d.ts +37 -0
  423. package/types-legacy/ts4.5/tx/builder/constants.d.ts +31 -2
  424. package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +19 -0
  425. package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
  426. package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
  427. package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
  428. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +4 -5
  429. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +72 -0
  430. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +3 -2
  431. package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
  432. package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
  433. package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
  434. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +12 -7
  435. package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +7 -3
  436. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +3 -1
  437. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +113 -30
  438. package/types-legacy/ts4.5/tx/builder/field-types/map.d.ts +13 -0
  439. package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +48 -0
  440. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +2 -3
  441. package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +14 -0
  442. package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
  443. package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +7 -0
  444. package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
  445. package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +11 -0
  446. package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
  447. package/types-legacy/ts4.5/tx/builder/field-types/wrapped.d.ts +14 -0
  448. package/types-legacy/ts4.5/tx/builder/index.d.ts +21 -36
  449. package/types-legacy/ts4.5/tx/builder/schema.d.ts +2971 -2926
  450. package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +2011 -0
  451. package/types-legacy/ts4.5/tx/execution-cost.d.ts +35 -0
  452. package/types-legacy/ts4.5/tx/transaction-signer.d.ts +6 -0
  453. package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
  454. package/types-legacy/ts4.5/utils/autorest.d.ts +3 -2
  455. package/types-legacy/ts4.5/utils/errors.d.ts +16 -38
  456. package/es/contract/CompilerHttp.d.ts +0 -18
  457. package/es/contract/CompilerHttp.mjs +0 -63
  458. package/es/contract/CompilerHttp.mjs.map +0 -1
  459. package/es/tx/builder/field-types/addresses.d.ts +0 -6
  460. package/es/tx/builder/field-types/addresses.mjs +0 -13
  461. package/es/tx/builder/field-types/addresses.mjs.map +0 -1
  462. package/es/tx/index.d.ts +0 -34
  463. package/es/tx/index.mjs +0 -172
  464. package/es/tx/index.mjs.map +0 -1
  465. package/es/utils/mptree.d.ts +0 -26
  466. package/es/utils/mptree.mjs +0 -143
  467. package/es/utils/mptree.mjs.map +0 -1
  468. package/src/apis/compiler/code-model-v4.yaml +0 -2442
  469. package/src/apis/node/code-model-v4.yaml +0 -10080
  470. package/src/contract/CompilerHttp.ts +0 -67
  471. package/src/tx/builder/field-types/addresses.ts +0 -18
  472. package/src/tx/index.ts +0 -196
  473. package/src/utils/mptree.ts +0 -145
  474. package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
  475. package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
  476. package/types-legacy/ts4.2/tx/index.d.ts +0 -34
  477. package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
  478. package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
  479. package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
  480. package/types-legacy/ts4.5/tx/index.d.ts +0 -34
  481. package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
@@ -0,0 +1,146 @@
1
+ import { Encoded } from '../utils/encoder';
2
+ import { buildTx, buildTxHash, unpackTx } from './builder';
3
+ import { Tag } from './builder/constants';
4
+ import { verify } from '../utils/crypto';
5
+ import { getBufferToSign } from '../account/Memory';
6
+ import { IllegalArgumentError, InternalError, TransactionError } from '../utils/errors';
7
+ import Node from '../Node';
8
+ import getTransactionSignerAddress from './transaction-signer';
9
+
10
+ /**
11
+ * Calculates the cost of transaction execution
12
+ * Provides an upper cost of contract-call-related transactions because of `gasLimit`.
13
+ * Also assumes that oracle query fee is 0 unless it is provided in options.
14
+ * @param transaction - Transaction to calculate the cost of
15
+ * @param innerTx - Should be provided if transaction wrapped with Tag.PayingForTx
16
+ * @param gasUsed - Amount of gas actually used to make calculation more accurate
17
+ * @param queryFee - Oracle query fee
18
+ * @param isInitiator - Is transaction signer an initiator of state channel
19
+ */
20
+ export function getExecutionCost(
21
+ transaction: Encoded.Transaction,
22
+ {
23
+ innerTx, gasUsed, queryFee, isInitiator,
24
+ }: {
25
+ innerTx?: 'fee-payer' | 'freeloader';
26
+ gasUsed?: number;
27
+ queryFee?: string;
28
+ isInitiator?: boolean;
29
+ } = {},
30
+ ): bigint {
31
+ const params = unpackTx(transaction);
32
+ if (params.tag === Tag.SignedTx) {
33
+ throw new IllegalArgumentError('Transaction shouldn\'t be a SignedTx, use `getExecutionCostBySignedTx` instead');
34
+ }
35
+
36
+ let res = 0n;
37
+ if ('fee' in params && innerTx !== 'freeloader') {
38
+ res += BigInt(params.fee);
39
+ }
40
+ if (params.tag === Tag.NameClaimTx) {
41
+ res += BigInt(params.nameFee);
42
+ }
43
+ if (params.tag === Tag.OracleQueryTx) {
44
+ res += BigInt(params.queryFee);
45
+ }
46
+ if (params.tag === Tag.OracleResponseTx) {
47
+ res -= BigInt(queryFee ?? 0);
48
+ }
49
+ if (params.tag === Tag.ChannelSettleTx) {
50
+ if (isInitiator === true) res -= BigInt(params.initiatorAmountFinal);
51
+ if (isInitiator === false) res -= BigInt(params.responderAmountFinal);
52
+ }
53
+ if (
54
+ ((params.tag === Tag.SpendTx && params.senderId !== params.recipientId)
55
+ || params.tag === Tag.ContractCreateTx || params.tag === Tag.ContractCallTx
56
+ || params.tag === Tag.ChannelDepositTx) && innerTx !== 'fee-payer'
57
+ ) {
58
+ res += BigInt(params.amount);
59
+ }
60
+ if (params.tag === Tag.ContractCreateTx) res += BigInt(params.deposit);
61
+ if (
62
+ (params.tag === Tag.ContractCreateTx || params.tag === Tag.ContractCallTx
63
+ || params.tag === Tag.GaAttachTx || params.tag === Tag.GaMetaTx)
64
+ && innerTx !== 'freeloader'
65
+ ) {
66
+ res += BigInt(params.gasPrice) * BigInt(gasUsed ?? params.gasLimit);
67
+ }
68
+ if (params.tag === Tag.GaMetaTx || params.tag === Tag.PayingForTx) {
69
+ res += getExecutionCost(
70
+ buildTx(params.tx.encodedTx),
71
+ params.tag === Tag.PayingForTx ? { innerTx: 'fee-payer' } : {},
72
+ );
73
+ }
74
+ return res;
75
+ }
76
+
77
+ /**
78
+ * Calculates the cost of signed transaction execution
79
+ * @param transaction - Transaction to calculate the cost of
80
+ * @param networkId - Network id used to sign the transaction
81
+ * @param options - Options
82
+ */
83
+ export function getExecutionCostBySignedTx(
84
+ transaction: Encoded.Transaction,
85
+ networkId: string,
86
+ options?: Omit<Parameters<typeof getExecutionCost>[1], 'innerTx'>,
87
+ ): bigint {
88
+ const params = unpackTx(transaction, Tag.SignedTx);
89
+ if (params.encodedTx.tag === Tag.GaMetaTx) {
90
+ return getExecutionCost(buildTx(params.encodedTx), options);
91
+ }
92
+
93
+ const tx = buildTx(params.encodedTx);
94
+ const address = getTransactionSignerAddress(tx);
95
+ const [isInnerTx, isNotInnerTx] = [true, false]
96
+ .map((f) => verify(getBufferToSign(tx, networkId, f), params.signatures[0], address));
97
+ if (!isInnerTx && !isNotInnerTx) throw new TransactionError('Can\'t verify signature');
98
+ return getExecutionCost(
99
+ buildTx(params.encodedTx),
100
+ { ...isInnerTx && { innerTx: 'freeloader' }, ...options },
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Calculates the cost of signed and not signed transaction execution using node
106
+ * @param transaction - Transaction to calculate the cost of
107
+ * @param node - Node to use
108
+ * @param isMined - Is transaction already mined or not
109
+ * @param options - Options
110
+ */
111
+ export async function getExecutionCostUsingNode(
112
+ transaction: Encoded.Transaction,
113
+ node: Node,
114
+ { isMined, ...options }: { isMined?: boolean } & Parameters<typeof getExecutionCost>[1] = {},
115
+ ): Promise<bigint> {
116
+ let params = unpackTx(transaction);
117
+ const isSignedTx = params.tag === Tag.SignedTx;
118
+ const txHash = isSignedTx && isMined === true && buildTxHash(transaction);
119
+ if (params.tag === Tag.SignedTx) params = params.encodedTx;
120
+
121
+ // TODO: set gasUsed for PayingForTx after solving https://github.com/aeternity/aeternity/issues/4087
122
+ if (
123
+ options.gasUsed == null && txHash !== false
124
+ && [Tag.ContractCreateTx, Tag.ContractCallTx, Tag.GaAttachTx, Tag.GaMetaTx].includes(params.tag)
125
+ ) {
126
+ const { callInfo, gaInfo } = await node.getTransactionInfoByHash(txHash);
127
+ const combinedInfo = callInfo ?? gaInfo;
128
+ if (combinedInfo == null) {
129
+ throw new InternalError(`callInfo and gaInfo is not available for transaction ${txHash}`);
130
+ }
131
+ options.gasUsed = combinedInfo.gasUsed;
132
+ }
133
+
134
+ if (options.queryFee == null && Tag.OracleResponseTx === params.tag) {
135
+ options.queryFee = (await node.getOracleByPubkey(params.oracleId)).queryFee.toString();
136
+ }
137
+
138
+ if (options.isInitiator == null && Tag.ChannelSettleTx === params.tag && isMined !== true) {
139
+ const { initiatorId } = await node.getChannelByPubkey(params.channelId);
140
+ options.isInitiator = params.fromId === initiatorId;
141
+ }
142
+
143
+ return isSignedTx
144
+ ? getExecutionCostBySignedTx(transaction, await node.getNetworkId(), options)
145
+ : getExecutionCost(transaction, options);
146
+ }
@@ -0,0 +1,27 @@
1
+ import { Encoded } from '../utils/encoder';
2
+ import { buildTx, getSchema, unpackTx } from './builder';
3
+ import { Tag } from './builder/constants';
4
+ import { TransactionError, UnexpectedTsError } from '../utils/errors';
5
+
6
+ /**
7
+ * Returns account address that signed a transaction
8
+ * @param transaction - transaction to get a signer of
9
+ */
10
+ export default function getTransactionSignerAddress(
11
+ transaction: Encoded.Transaction,
12
+ ): Encoded.AccountAddress {
13
+ const params = unpackTx(transaction);
14
+ switch (params.tag) {
15
+ case Tag.SignedTx:
16
+ return getTransactionSignerAddress(buildTx(params.encodedTx));
17
+ case Tag.GaMetaTx:
18
+ return params.gaId;
19
+ default:
20
+ }
21
+
22
+ const nonce = getSchema(params.tag, params.version).find(([name]) => name === 'nonce')?.[1];
23
+ if (nonce == null) throw new TransactionError(`Transaction doesn't have nonce: ${Tag[params.tag]}`);
24
+ if (!('senderKey' in nonce)) throw new UnexpectedTsError();
25
+ const address = params[nonce.senderKey as keyof typeof params] as unknown as string;
26
+ return address.replace(/^ok_/, 'ak_') as Encoded.AccountAddress;
27
+ }
@@ -1,21 +1,16 @@
1
- import BigNumber from 'bignumber.js';
2
1
  import { hash, verify } from '../utils/crypto';
3
- import {
4
- CtVersion,
5
- PROTOCOL_VM_ABI,
6
- RawTxObject,
7
- TxParamsCommon,
8
- TxSchema,
9
- TxTypeSchemas,
10
- } from './builder/schema';
11
- import { Tag } from './builder/constants';
12
- import { TxUnpacked, unpackTx } from './builder';
13
- import { UnsupportedProtocolError } from '../utils/errors';
14
- import { concatBuffers, isAccountNotFoundError, isKeyOfObject } from '../utils/other';
15
- import { encode, Encoded, Encoding } from '../utils/encoder';
2
+ import { TxUnpacked } from './builder/schema.generated';
3
+ import { CtVersion, ProtocolToVmAbi } from './builder/field-types/ct-version';
4
+ import { Tag, ConsensusProtocolVersion } from './builder/constants';
5
+ import { buildTx, unpackTx } from './builder';
6
+ import { concatBuffers, isAccountNotFoundError } from '../utils/other';
7
+ import { Encoded, decode } from '../utils/encoder';
16
8
  import Node, { TransformNodeType } from '../Node';
17
9
  import { Account } from '../apis/node';
18
10
  import { genAggressiveCacheGetResponsesPolicy } from '../utils/autorest';
11
+ import { UnexpectedTsError } from '../utils/errors';
12
+ import getTransactionSignerAddress from './transaction-signer';
13
+ import { getExecutionCostUsingNode } from './execution-cost';
19
14
 
20
15
  export interface ValidatorResult {
21
16
  message: string;
@@ -24,108 +19,83 @@ export interface ValidatorResult {
24
19
  }
25
20
 
26
21
  type Validator = (
27
- tx: {
28
- encodedTx: TxUnpacked<TxSchema>;
29
- signatures: Buffer[];
30
- tx: TxUnpacked<TxSchema> & {
31
- tx: TxTypeSchemas[Tag.SignedTx];
32
- };
33
- nonce?: number;
34
- ttl?: number;
35
- amount?: number;
36
- fee?: number;
37
- nameFee?: number;
38
- ctVersion?: Partial<CtVersion>;
39
- abiVersion?: number;
40
- contractId?: Encoded.ContractAddress;
41
- },
22
+ tx: TxUnpacked,
42
23
  options: {
43
24
  // TODO: remove after fixing node types
44
- account?: TransformNodeType<Account> & { id: Encoded.AccountAddress };
25
+ account: TransformNodeType<Account> & { id: Encoded.AccountAddress };
45
26
  nodeNetworkId: string;
46
27
  parentTxTypes: Tag[];
47
28
  node: Node;
48
- txType: Tag;
49
29
  height: number;
50
- consensusProtocolVersion: number;
30
+ consensusProtocolVersion: ConsensusProtocolVersion;
51
31
  }
52
32
  ) => ValidatorResult[] | Promise<ValidatorResult[]>;
53
33
 
54
34
  const validators: Validator[] = [];
55
35
 
56
- const getSenderAddress = (
57
- tx: TxParamsCommon | RawTxObject<TxSchema>,
58
- ): Encoded.AccountAddress | undefined => [
59
- 'senderId', 'accountId', 'ownerId', 'callerId',
60
- 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',
61
- ]
62
- .map((key: keyof TxSchema) => tx[key])
63
- .filter((a) => a)
64
- .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;
36
+ async function verifyTransactionInternal(
37
+ tx: TxUnpacked,
38
+ node: Node,
39
+ parentTxTypes: Tag[],
40
+ ): Promise<ValidatorResult[]> {
41
+ const address = getTransactionSignerAddress(buildTx(tx));
42
+ const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([
43
+ node.getAccountByPubkey(address)
44
+ .catch((error) => {
45
+ if (!isAccountNotFoundError(error)) throw error;
46
+ return { id: address, balance: 0n, nonce: 0 };
47
+ })
48
+ // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
49
+ .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),
50
+ node.getCurrentKeyBlockHeight(),
51
+ node.getNodeInfo(),
52
+ ]);
53
+
54
+ return (await Promise.all(
55
+ validators.map(async (v) => v(
56
+ tx,
57
+ {
58
+ node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,
59
+ },
60
+ )),
61
+ )).flat();
62
+ }
65
63
 
66
64
  /**
67
65
  * Transaction Validator
68
- * This function validates some of transaction properties,
66
+ * This function validates some transaction properties,
69
67
  * to make sure it can be posted it to the chain
70
68
  * @category transaction builder
71
69
  * @param transaction - Base64Check-encoded transaction
72
70
  * @param nodeNotCached - Node to validate transaction against
73
- * @param parentTxTypes - Types of parent transactions
74
71
  * @returns Array with verification errors
75
72
  * @example const errors = await verifyTransaction(transaction, node)
76
73
  */
77
74
  export default async function verifyTransaction(
78
- transaction: Encoded.Transaction | Encoded.Poi,
75
+ transaction: Parameters<typeof unpackTx>[0],
79
76
  nodeNotCached: Node,
80
- parentTxTypes: Tag[] = [],
81
77
  ): Promise<ValidatorResult[]> {
82
- let node = nodeNotCached;
83
- if (
84
- !node.pipeline.getOrderedPolicies()
85
- .some(({ name }) => name === 'aggressive-cache-get-responses')
86
- ) {
87
- node = new Node(nodeNotCached.$host, { ignoreVersion: true });
88
- node.pipeline.addPolicy(genAggressiveCacheGetResponsesPolicy());
89
- }
90
-
91
- const { tx, txType } = unpackTx<Tag.SignedTx>(transaction);
92
- const address = getSenderAddress(tx)
93
- ?? (txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined);
94
- const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([
95
- address == null
96
- ? undefined
97
- : node.getAccountByPubkey(address)
98
- .catch((error) => {
99
- if (!isAccountNotFoundError(error)) throw error;
100
- return { id: address, balance: 0n, nonce: 0 };
101
- })
102
- // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
103
- .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),
104
- node.getCurrentKeyBlockHeight(),
105
- node.getNodeInfo(),
106
- ]);
107
-
108
- return (await Promise.all(
109
- validators.map((v) => v(
110
- tx as any,
111
- {
112
- txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,
113
- },
114
- )),
115
- )).flat();
78
+ const node = new Node(nodeNotCached.$host, {
79
+ ignoreVersion: true,
80
+ pipeline: nodeNotCached.pipeline.clone(),
81
+ additionalPolicies: [genAggressiveCacheGetResponsesPolicy()],
82
+ });
83
+ return verifyTransactionInternal(unpackTx(transaction), node, []);
116
84
  }
117
85
 
118
86
  validators.push(
119
- ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {
120
- if ((encodedTx ?? signatures) === undefined) return [];
121
- if (account == null) return [];
122
- if (signatures.length !== 1) return []; // TODO: Support multisignature?
87
+ (tx, { account, nodeNetworkId, parentTxTypes }) => {
88
+ if (tx.tag !== Tag.SignedTx) return [];
89
+ const { encodedTx, signatures } = tx;
90
+ if ((encodedTx ?? signatures) == null) return [];
91
+ if (signatures.length !== 1) return []; // TODO: Support multisignature like in state channels
123
92
  const prefix = Buffer.from([
124
93
  nodeNetworkId,
125
94
  ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],
126
95
  ].join('-'));
127
- const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);
128
- const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);
96
+ const txBinary = decode(buildTx(encodedTx));
97
+ const txWithNetworkId = concatBuffers([prefix, txBinary]);
98
+ const txHashWithNetworkId = concatBuffers([prefix, hash(txBinary)]);
129
99
  if (verify(txWithNetworkId, signatures[0], account.id)
130
100
  || verify(txHashWithNetworkId, signatures[0], account.id)) return [];
131
101
  return [{
@@ -135,104 +105,80 @@ validators.push(
135
105
  checkedKeys: ['encodedTx', 'signatures'],
136
106
  }];
137
107
  },
138
- async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {
139
- if ((encodedTx ?? tx) === undefined) return [];
140
- return verifyTransaction(
141
- encode((encodedTx ?? tx).rlpEncoded, Encoding.Transaction),
142
- node,
143
- [...parentTxTypes, txType],
144
- );
108
+ async (tx, { node, parentTxTypes }) => {
109
+ let nestedTx;
110
+ if ('encodedTx' in tx) nestedTx = tx.encodedTx;
111
+ if ('tx' in tx) nestedTx = tx.tx;
112
+ if (nestedTx == null) return [];
113
+ return verifyTransactionInternal(nestedTx, node, [...parentTxTypes, tx.tag]);
145
114
  },
146
- ({ ttl }, { height }) => {
147
- if (ttl === undefined) return [];
148
- ttl = +ttl;
149
- if (ttl === 0 || ttl >= height) return [];
115
+ (tx, { height }) => {
116
+ if (!('ttl' in tx)) return [];
117
+ if (tx.ttl === 0 || tx.ttl >= height) return [];
150
118
  return [{
151
- message: `TTL ${ttl} is already expired, current height is ${height}`,
119
+ message: `TTL ${tx.ttl} is already expired, current height is ${height}`,
152
120
  key: 'ExpiredTTL',
153
121
  checkedKeys: ['ttl'],
154
122
  }];
155
123
  },
156
- ({
157
- amount, fee, nameFee, tx,
158
- }, { account, parentTxTypes, txType }) => {
159
- if (account == null) return [];
160
- if ((amount ?? fee ?? nameFee) === undefined) return [];
161
- fee ??= 0;
162
- const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)
163
- .plus(txType === Tag.PayingForTx ? (tx.tx.encodedTx.tx).fee : 0)
164
- .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);
165
- if (cost.lte(account.balance.toString())) return [];
124
+ async (tx, { account, parentTxTypes, node }) => {
125
+ if (parentTxTypes.length !== 0) return [];
126
+ const cost = await getExecutionCostUsingNode(buildTx(tx), node).catch(() => 0n);
127
+ if (cost <= account.balance) return [];
166
128
  return [{
167
- message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,
129
+ message: `Account balance ${account.balance} is not enough to execute the transaction that costs ${cost}`,
168
130
  key: 'InsufficientBalance',
169
- checkedKeys: ['amount', 'fee', 'nameFee'],
131
+ checkedKeys: ['amount', 'fee', 'nameFee', 'gasLimit', 'gasPrice'],
170
132
  }];
171
133
  },
172
- ({ signatures }, { account, txType }) => {
173
- if (account == null) return [];
134
+ (tx, { account }) => {
174
135
  let message;
175
- if (txType === Tag.SignedTx && account.kind === 'generalized' && signatures.length !== 0) {
136
+ if (tx.tag === Tag.SignedTx && account.kind === 'generalized' && tx.signatures.length !== 0) {
176
137
  message = 'Generalized account can\'t be used to generate SignedTx with signatures';
177
138
  }
178
- if (txType === Tag.GaMetaTx && account.kind === 'basic') {
139
+ if (tx.tag === Tag.GaMetaTx && account.kind === 'basic') {
179
140
  message = 'Basic account can\'t be used to generate GaMetaTx';
180
141
  }
181
142
  if (message == null) return [];
182
143
  return [{ message, key: 'InvalidAccountType', checkedKeys: ['tag'] }];
183
144
  },
184
- ({ nonce }, { account, parentTxTypes }) => {
185
- if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];
186
- nonce = +nonce;
187
- const validNonce = account.nonce + 1;
188
- if (nonce === validNonce) return [];
189
- return [{
190
- ...nonce < validNonce
191
- ? {
192
- message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
193
- key: 'NonceAlreadyUsed',
194
- }
195
- : {
196
- message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
197
- key: 'NonceHigh',
198
- },
199
- checkedKeys: ['nonce'],
200
- }];
201
- },
202
- ({ ctVersion, abiVersion }, { txType, consensusProtocolVersion }) => {
203
- if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
204
- throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);
205
- }
206
- const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
145
+ // TODO: revert nonce check
146
+ (tx, { consensusProtocolVersion }) => {
147
+ const oracleCall = Tag.Oracle === tx.tag || Tag.OracleRegisterTx === tx.tag;
148
+ const contractCreate = Tag.ContractCreateTx === tx.tag || Tag.GaAttachTx === tx.tag;
149
+ const contractCall = Tag.ContractCallTx === tx.tag || Tag.GaMetaTx === tx.tag;
150
+ const type = (oracleCall ? 'oracle-call' : null)
151
+ ?? (contractCreate ? 'contract-create' : null)
152
+ ?? (contractCall ? 'contract-call' : null);
153
+ if (type == null) return [];
154
+ const protocol = ProtocolToVmAbi[consensusProtocolVersion][type] as {
155
+ abiVersion: readonly any[];
156
+ vmVersion: readonly any[];
157
+ };
207
158
 
208
- // If not contract create tx
209
- if (ctVersion == null) ctVersion = { abiVersion };
210
- const txProtocol = protocol[txType as keyof typeof protocol];
211
- if (txProtocol == null) return [];
212
- if (Object.entries(ctVersion).some(
213
- ([
214
- key,
215
- value,
216
- ]: [
217
- key:keyof typeof txProtocol,
218
- value:any]) => !(txProtocol[key].includes(+value as never)),
219
- )) {
159
+ let ctVersion: Partial<CtVersion> | undefined;
160
+ if ('abiVersion' in tx) ctVersion = { abiVersion: tx.abiVersion };
161
+ if ('ctVersion' in tx) ctVersion = tx.ctVersion;
162
+ if (ctVersion == null) throw new UnexpectedTsError();
163
+ if (
164
+ !protocol.abiVersion.includes(ctVersion.abiVersion)
165
+ || (contractCreate && !protocol.vmVersion.includes(ctVersion.vmVersion))
166
+ ) {
220
167
  return [{
221
- message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,
168
+ message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(protocol)}`,
222
169
  key: 'VmAndAbiVersionMismatch',
223
170
  checkedKeys: ['ctVersion', 'abiVersion'],
224
171
  }];
225
172
  }
226
173
  return [];
227
174
  },
228
- async ({ contractId }, { txType, node }) => {
229
- if (Tag.ContractCallTx !== txType) return [];
230
- contractId = contractId as Encoded.ContractAddress;
175
+ async (tx, { node }) => {
176
+ if (Tag.ContractCallTx !== tx.tag) return [];
231
177
  try {
232
- const { active } = await node.getContract(contractId);
178
+ const { active } = await node.getContract(tx.contractId);
233
179
  if (active) return [];
234
180
  return [{
235
- message: `Contract ${contractId} is not active`,
181
+ message: `Contract ${tx.contractId} is not active`,
236
182
  key: 'ContractNotActive',
237
183
  checkedKeys: ['contractId'],
238
184
  }];
@@ -1,19 +1,3 @@
1
- /*
2
- * ISC License (ISC)
3
- * Copyright (c) 2018 aeternity developers
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software for any
6
- * purpose with or without fee is hereby granted, provided that the above
7
- * copyright notice and this permission notice appear in all copies.
8
- *
9
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- * PERFORMANCE OF THIS SOFTWARE.
16
- */
17
1
  import BigNumber from 'bignumber.js';
18
2
  import { isBigNumber } from './bignumber';
19
3
  import { ArgumentError } from './errors';
@@ -2,7 +2,7 @@ import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pi
2
2
  import { AdditionalPolicyConfig } from '@azure/core-client';
3
3
  import { pause } from './other';
4
4
  import semverSatisfies from './semver-satisfies';
5
- import { UnsupportedVersionError } from './errors';
5
+ import { UnexpectedTsError, UnsupportedVersionError } from './errors';
6
6
 
7
7
  export const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {
8
8
  const requestQueues = new Map<string, Promise<unknown>>();
@@ -48,18 +48,21 @@ export const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {
48
48
  };
49
49
  };
50
50
 
51
- export const genAggressiveCacheGetResponsesPolicy = (): PipelinePolicy => {
51
+ export const genAggressiveCacheGetResponsesPolicy = (): AdditionalPolicyConfig => {
52
52
  const getRequests = new Map<string, Promise<PipelineResponse>>();
53
53
 
54
54
  return {
55
- name: 'aggressive-cache-get-responses',
56
- async sendRequest(request, next) {
57
- if (request.method !== 'GET') return next(request);
58
- const key = JSON.stringify([request.url, request.body]);
59
- const response = getRequests.get(key) ?? next(request);
60
- getRequests.set(key, response);
61
- return response;
55
+ policy: {
56
+ name: 'aggressive-cache-get-responses',
57
+ async sendRequest(request, next) {
58
+ if (request.method !== 'GET') return next(request);
59
+ const key = JSON.stringify([request.url, request.body]);
60
+ const response = getRequests.get(key) ?? next(request);
61
+ getRequests.set(key, response);
62
+ return response;
63
+ },
62
64
  },
65
+ position: 'perCall',
63
66
  };
64
67
  };
65
68
 
@@ -94,15 +97,53 @@ export const genErrorFormatterPolicy = (
94
97
  export const genVersionCheckPolicy = (
95
98
  name: string,
96
99
  ignorePath: string,
97
- versionPromise: Promise<string>,
100
+ versionPromise: Promise<string | Error>,
98
101
  geVersion: string,
99
102
  ltVersion: string,
100
103
  ): PipelinePolicy => ({
101
104
  name: 'version-check',
102
105
  async sendRequest(request, next) {
103
106
  if (new URL(request.url).pathname === ignorePath) return next(request);
104
- const args = [await versionPromise, geVersion, ltVersion] as const;
107
+ const version = await versionPromise;
108
+ if (version instanceof Error) throw version;
109
+ const args = [version, geVersion, ltVersion] as const;
105
110
  if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
106
111
  return next(request);
107
112
  },
108
113
  });
114
+
115
+ export const genRetryOnFailurePolicy = (
116
+ retryCount: number,
117
+ retryOverallDelay: number,
118
+ ): AdditionalPolicyConfig => ({
119
+ policy: {
120
+ name: 'retry-on-failure',
121
+ async sendRequest(request, next) {
122
+ const statusesToNotRetry = [200, 400, 403];
123
+
124
+ const intervals = new Array(retryCount).fill(0)
125
+ .map((_, idx) => ((idx + 1) / retryCount) ** 2);
126
+ const intervalSum = intervals.reduce((a, b) => a + b);
127
+ const intervalsInMs = intervals.map((el) => (el / intervalSum) * retryOverallDelay);
128
+
129
+ let error: Error | undefined;
130
+ for (let attempt = 0; attempt <= retryCount; attempt += 1) {
131
+ if (error != null) {
132
+ if (
133
+ !(error instanceof RestError)
134
+ || statusesToNotRetry.includes(error.response?.status ?? 0)
135
+ ) throw error;
136
+ await pause(intervalsInMs[attempt - 1]);
137
+ }
138
+ try {
139
+ return await next(request);
140
+ } catch (e) {
141
+ error = e;
142
+ }
143
+ }
144
+ if (error == null) throw new UnexpectedTsError();
145
+ throw error;
146
+ },
147
+ },
148
+ position: 'perCall',
149
+ });
@@ -1,19 +1,3 @@
1
- /*
2
- * ISC License (ISC)
3
- * Copyright 2018 aeternity developers
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software for any
6
- * purpose with or without fee is hereby granted, provided that the above
7
- * copyright notice and this permission notice appear in all copies.
8
- *
9
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- * PERFORMANCE OF THIS SOFTWARE.
16
- */
17
1
  import BigNumber from 'bignumber.js';
18
2
  import { NoSerializerFoundError, TypeError } from './errors';
19
3
 
@@ -29,7 +13,7 @@ export function toBytes(val?: null | string | number | BigNumber, big = false):
29
13
  // If the value is an int it will be encoded as bytes big endian
30
14
  // Raises ValueError if the input is not an int or string
31
15
 
32
- if (val === undefined || val === null) return Buffer.from([]);
16
+ if (val == null) return Buffer.from([]);
33
17
  if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {
34
18
  if (!BigNumber.isBigNumber(val)) val = new BigNumber(val);
35
19
  if (!val.isInteger()) throw new TypeError(`Unexpected not integer value: ${val.toFixed()}`);