@aeternity/aepp-sdk 11.0.1 → 12.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (444) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -22
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +2 -1
  6. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +20765 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/AeSdk.d.ts +37 -0
  11. package/es/AeSdk.mjs +81 -0
  12. package/es/AeSdk.mjs.map +1 -0
  13. package/es/AeSdkAepp.d.ts +70 -0
  14. package/es/AeSdkAepp.mjs +176 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +213 -0
  17. package/es/AeSdkBase.mjs +314 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +104 -0
  20. package/es/AeSdkWallet.mjs +326 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +41 -0
  23. package/es/Node.mjs +147 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +68 -0
  26. package/es/account/Base.mjs +123 -0
  27. package/es/account/Base.mjs.map +1 -0
  28. package/es/account/Memory.d.ts +26 -0
  29. package/es/account/Memory.mjs +103 -0
  30. package/es/account/Memory.mjs.map +1 -0
  31. package/es/account/Rpc.d.ts +27 -0
  32. package/es/account/Rpc.mjs +80 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +222 -0
  35. package/es/aens.mjs +338 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +33 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +73 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +58 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +146 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +11 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +16 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  54. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  55. package/es/aepp-wallet-communication/schema.d.ts +105 -46
  56. package/es/aepp-wallet-communication/schema.mjs +251 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +25 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +62 -0
  60. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  61. package/es/apis/compiler/compiler.d.ts +92 -0
  62. package/es/apis/compiler/compiler.mjs +576 -0
  63. package/es/apis/compiler/compiler.mjs.map +1 -0
  64. package/es/apis/compiler/index.d.ts +2 -0
  65. package/es/apis/compiler/index.mjs +3 -0
  66. package/es/apis/compiler/index.mjs.map +1 -0
  67. package/es/apis/compiler/models/index.d.ts +248 -0
  68. package/es/apis/compiler/models/index.mjs +48 -0
  69. package/es/apis/compiler/models/index.mjs.map +1 -0
  70. package/es/apis/compiler/models/mappers.d.ts +23 -0
  71. package/es/apis/compiler/models/mappers.mjs +585 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  73. package/es/apis/compiler/models/parameters.d.ts +13 -0
  74. package/es/apis/compiler/models/parameters.mjs +71 -0
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  76. package/es/apis/node/index.d.ts +2 -0
  77. package/es/apis/node/index.mjs +3 -0
  78. package/es/apis/node/index.mjs.map +1 -0
  79. package/es/apis/node/models/index.d.ts +1065 -0
  80. package/es/apis/node/models/index.mjs +2 -0
  81. package/es/apis/node/models/index.mjs.map +1 -0
  82. package/es/apis/node/models/mappers.d.ts +95 -0
  83. package/es/apis/node/models/mappers.mjs +4166 -0
  84. package/es/apis/node/models/mappers.mjs.map +1 -0
  85. package/es/apis/node/models/parameters.d.ts +17 -0
  86. package/es/apis/node/models/parameters.mjs +165 -0
  87. package/es/apis/node/models/parameters.mjs.map +1 -0
  88. package/es/apis/node/node.d.ts +215 -0
  89. package/es/apis/node/node.mjs +1165 -0
  90. package/es/apis/node/node.mjs.map +1 -0
  91. package/es/chain.d.ts +248 -0
  92. package/es/chain.mjs +560 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/handlers.mjs +164 -131
  96. package/es/channel/handlers.mjs.map +1 -1
  97. package/es/channel/index.d.ts +625 -0
  98. package/es/channel/index.mjs +897 -902
  99. package/es/channel/index.mjs.map +1 -1
  100. package/es/channel/internal.d.ts +101 -0
  101. package/es/channel/internal.mjs +136 -85
  102. package/es/channel/internal.mjs.map +1 -1
  103. package/es/contract/Compiler.d.ts +18 -0
  104. package/es/contract/Compiler.mjs +68 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +127 -0
  107. package/es/contract/aci.mjs +225 -193
  108. package/es/contract/aci.mjs.map +1 -1
  109. package/es/contract/ga.d.ts +69 -0
  110. package/es/contract/ga.mjs +195 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +71 -0
  113. package/es/contract/methods.mjs +104 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/deprecated/index.d.ts +143 -0
  116. package/es/deprecated/index.mjs +162 -0
  117. package/es/deprecated/index.mjs.map +1 -0
  118. package/es/deprecated/methods.d.ts +18 -0
  119. package/es/deprecated/methods.mjs +26 -0
  120. package/es/deprecated/methods.mjs.map +1 -0
  121. package/es/index.d.ts +35 -0
  122. package/es/index.mjs +35 -40
  123. package/es/index.mjs.map +1 -1
  124. package/es/oracle.d.ts +161 -0
  125. package/es/oracle.mjs +306 -0
  126. package/es/oracle.mjs.map +1 -0
  127. package/es/spend.d.ts +62 -0
  128. package/es/spend.mjs +111 -0
  129. package/es/spend.mjs.map +1 -0
  130. package/es/tx/builder/address.d.ts +25 -0
  131. package/es/tx/builder/address.mjs +45 -0
  132. package/es/tx/builder/address.mjs.map +1 -0
  133. package/es/tx/builder/constants.d.ts +70 -0
  134. package/es/tx/builder/constants.mjs +61 -47
  135. package/es/tx/builder/constants.mjs.map +1 -1
  136. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  137. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  138. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  139. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  140. package/es/tx/builder/field-types/deposit.mjs +19 -0
  141. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  142. package/es/tx/builder/field-types/fee.d.ts +25 -0
  143. package/es/tx/builder/field-types/fee.mjs +150 -0
  144. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  145. package/es/tx/builder/field-types/field.d.ts +6 -0
  146. package/es/tx/builder/field-types/field.mjs +15 -0
  147. package/es/tx/builder/field-types/field.mjs.map +1 -0
  148. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  149. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  150. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  151. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  152. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  153. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  154. package/es/tx/builder/field-types/index.d.ts +70 -0
  155. package/es/tx/builder/field-types/index.mjs +25 -0
  156. package/es/tx/builder/field-types/index.mjs.map +1 -0
  157. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  158. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  159. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  160. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  161. package/es/tx/builder/field-types/name-id.mjs +19 -0
  162. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  163. package/es/tx/builder/field-types/name.d.ts +13 -0
  164. package/es/tx/builder/field-types/name.mjs +18 -0
  165. package/es/tx/builder/field-types/name.mjs.map +1 -0
  166. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  167. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  168. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  169. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  170. package/es/tx/builder/field-types/u-int.mjs +14 -0
  171. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  172. package/es/tx/builder/helpers.d.ts +125 -0
  173. package/es/tx/builder/helpers.mjs +94 -198
  174. package/es/tx/builder/helpers.mjs.map +1 -1
  175. package/es/tx/builder/index.d.ts +88 -0
  176. package/es/tx/builder/index.mjs +167 -358
  177. package/es/tx/builder/index.mjs.map +1 -1
  178. package/es/tx/builder/schema.d.ts +1201 -0
  179. package/es/tx/builder/schema.mjs +175 -561
  180. package/es/tx/builder/schema.mjs.map +1 -1
  181. package/es/tx/index.d.ts +64 -0
  182. package/es/tx/index.mjs +151 -265
  183. package/es/tx/index.mjs.map +1 -1
  184. package/es/tx/validator.d.ts +20 -0
  185. package/es/tx/validator.mjs +104 -124
  186. package/es/tx/validator.mjs.map +1 -1
  187. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  188. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  189. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  190. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  191. package/es/typings/bip32-path/index.d.mjs +2 -0
  192. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  193. package/es/typings/blakejs/index.d.mjs.map +1 -1
  194. package/es/typings/sha-js/index.d.mjs +2 -0
  195. package/es/typings/sha-js/index.d.mjs.map +1 -0
  196. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  197. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  198. package/es/utils/amount-formatter.d.ts +42 -0
  199. package/es/utils/amount-formatter.mjs +36 -49
  200. package/es/utils/amount-formatter.mjs.map +1 -1
  201. package/es/utils/autorest.d.ts +6 -0
  202. package/es/utils/autorest.mjs +97 -0
  203. package/es/utils/autorest.mjs.map +1 -0
  204. package/es/utils/bignumber.d.ts +13 -0
  205. package/es/utils/bignumber.mjs +11 -8
  206. package/es/utils/bignumber.mjs.map +1 -1
  207. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  208. package/es/utils/bytes.mjs +11 -15
  209. package/es/utils/bytes.mjs.map +1 -1
  210. package/es/utils/crypto.d.ts +88 -0
  211. package/es/utils/crypto.mjs +64 -98
  212. package/es/utils/crypto.mjs.map +1 -1
  213. package/es/utils/encoder-types.d.ts +61 -0
  214. package/es/utils/encoder-types.mjs +36 -0
  215. package/es/utils/encoder-types.mjs.map +1 -0
  216. package/es/utils/encoder.d.ts +25 -0
  217. package/es/utils/encoder.mjs +71 -59
  218. package/es/utils/encoder.mjs.map +1 -1
  219. package/es/{errors.d.ts → utils/errors.d.ts} +246 -59
  220. package/es/utils/errors.mjs +313 -136
  221. package/es/utils/errors.mjs.map +1 -1
  222. package/es/utils/hd-wallet.d.ts +50 -0
  223. package/es/utils/hd-wallet.mjs +86 -45
  224. package/es/utils/hd-wallet.mjs.map +1 -1
  225. package/es/utils/json-big.d.ts +5 -0
  226. package/es/utils/json-big.mjs +12 -16
  227. package/es/utils/json-big.mjs.map +1 -1
  228. package/es/utils/keystore.d.ts +51 -0
  229. package/es/utils/keystore.mjs +101 -194
  230. package/es/utils/keystore.mjs.map +1 -1
  231. package/es/{mptree.d.ts → utils/mptree.d.ts} +6 -9
  232. package/es/utils/mptree.mjs +22 -18
  233. package/es/utils/mptree.mjs.map +1 -1
  234. package/es/utils/other.d.ts +20 -0
  235. package/es/utils/other.mjs +32 -35
  236. package/es/utils/other.mjs.map +1 -1
  237. package/es/utils/semver-satisfies.d.ts +1 -0
  238. package/es/utils/semver-satisfies.mjs +2 -2
  239. package/es/utils/semver-satisfies.mjs.map +1 -1
  240. package/es/utils/string.d.ts +24 -0
  241. package/es/utils/string.mjs +8 -10
  242. package/es/utils/string.mjs.map +1 -1
  243. package/package.json +55 -43
  244. package/src/AeSdk.ts +68 -0
  245. package/src/AeSdkAepp.ts +176 -0
  246. package/src/AeSdkBase.ts +338 -0
  247. package/src/AeSdkWallet.ts +348 -0
  248. package/src/Node.ts +173 -0
  249. package/src/account/Base.ts +124 -0
  250. package/src/account/Memory.ts +98 -0
  251. package/src/account/Rpc.ts +69 -0
  252. package/src/aens.ts +407 -0
  253. package/src/aepp-wallet-communication/connection/Browser.ts +71 -0
  254. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +59 -0
  255. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +122 -0
  256. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +18 -18
  257. package/src/aepp-wallet-communication/rpc/RpcClient.ts +143 -0
  258. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  259. package/src/aepp-wallet-communication/schema.ts +224 -0
  260. package/src/aepp-wallet-communication/wallet-detector.ts +72 -0
  261. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  262. package/src/apis/compiler/compiler.ts +585 -0
  263. package/src/apis/compiler/index.ts +2 -0
  264. package/src/apis/compiler/models/index.ts +301 -0
  265. package/src/apis/compiler/models/mappers.ts +583 -0
  266. package/src/apis/compiler/models/parameters.ts +93 -0
  267. package/src/apis/node/code-model-v4.yaml +10080 -0
  268. package/src/apis/node/index.ts +2 -0
  269. package/src/apis/node/models/index.ts +1257 -0
  270. package/src/apis/node/models/mappers.ts +4280 -0
  271. package/src/apis/node/models/parameters.ts +188 -0
  272. package/src/apis/node/node.ts +1299 -0
  273. package/src/chain.ts +502 -0
  274. package/src/channel/handlers.ts +817 -0
  275. package/src/channel/index.ts +1025 -0
  276. package/src/channel/internal.ts +361 -0
  277. package/src/contract/Compiler.ts +67 -0
  278. package/src/contract/aci.ts +538 -0
  279. package/src/contract/ga.ts +199 -0
  280. package/src/contract/methods.ts +123 -0
  281. package/src/deprecated/index.ts +172 -0
  282. package/src/deprecated/methods.ts +25 -0
  283. package/src/index.ts +56 -0
  284. package/src/oracle.ts +364 -0
  285. package/src/spend.ts +164 -0
  286. package/src/tx/builder/address.ts +50 -0
  287. package/src/tx/builder/constants.ts +126 -0
  288. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  289. package/src/tx/builder/field-types/deposit.ts +21 -0
  290. package/src/tx/builder/field-types/fee.ts +143 -0
  291. package/src/tx/builder/field-types/field.ts +9 -0
  292. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  293. package/src/tx/builder/field-types/gas-price.ts +16 -0
  294. package/src/tx/builder/field-types/index.ts +45 -0
  295. package/src/tx/builder/field-types/name-fee.ts +32 -0
  296. package/src/tx/builder/field-types/name-id.ts +20 -0
  297. package/src/tx/builder/field-types/name.ts +18 -0
  298. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  299. package/src/tx/builder/field-types/u-int.ts +16 -0
  300. package/src/tx/builder/helpers.ts +248 -0
  301. package/src/tx/builder/index.ts +400 -0
  302. package/src/tx/builder/schema.ts +727 -0
  303. package/src/tx/index.ts +192 -0
  304. package/src/tx/validator.ts +230 -0
  305. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  306. package/src/typings/@aeternity__uuid/index.d.ts +5 -0
  307. package/src/typings/bip32-path/index.d.ts +33 -0
  308. package/src/typings/blakejs/index.d.ts +4 -32
  309. package/src/typings/sha-js/index.d.ts +5 -0
  310. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  311. package/src/utils/amount-formatter.ts +56 -69
  312. package/src/utils/autorest.ts +93 -0
  313. package/src/utils/bignumber.ts +11 -12
  314. package/src/utils/bytes.ts +29 -31
  315. package/src/utils/crypto.ts +205 -0
  316. package/src/utils/encoder-types.ts +63 -0
  317. package/src/utils/encoder.ts +116 -71
  318. package/src/utils/errors.ts +482 -366
  319. package/src/utils/hd-wallet.ts +166 -0
  320. package/src/utils/json-big.ts +27 -0
  321. package/src/utils/keystore.ts +182 -0
  322. package/src/utils/mptree.ts +64 -61
  323. package/src/utils/other.ts +34 -41
  324. package/src/utils/semver-satisfies.ts +15 -11
  325. package/src/utils/string.ts +18 -20
  326. package/es/account/base.mjs +0 -179
  327. package/es/account/base.mjs.map +0 -1
  328. package/es/account/memory.mjs +0 -99
  329. package/es/account/memory.mjs.map +0 -1
  330. package/es/account/multiple.mjs +0 -179
  331. package/es/account/multiple.mjs.map +0 -1
  332. package/es/ae/aens.mjs +0 -404
  333. package/es/ae/aens.mjs.map +0 -1
  334. package/es/ae/aepp.mjs +0 -45
  335. package/es/ae/aepp.mjs.map +0 -1
  336. package/es/ae/contract.mjs +0 -159
  337. package/es/ae/contract.mjs.map +0 -1
  338. package/es/ae/index.mjs +0 -207
  339. package/es/ae/index.mjs.map +0 -1
  340. package/es/ae/oracle.mjs +0 -339
  341. package/es/ae/oracle.mjs.map +0 -1
  342. package/es/ae/universal.mjs +0 -45
  343. package/es/ae/universal.mjs.map +0 -1
  344. package/es/ae/wallet.mjs +0 -50
  345. package/es/ae/wallet.mjs.map +0 -1
  346. package/es/amount-formatter.d.ts +0 -58
  347. package/es/bignumber.d.ts +0 -18
  348. package/es/chain/index.mjs +0 -272
  349. package/es/chain/index.mjs.map +0 -1
  350. package/es/chain/node.mjs +0 -442
  351. package/es/chain/node.mjs.map +0 -1
  352. package/es/contract/compiler.mjs +0 -115
  353. package/es/contract/compiler.mjs.map +0 -1
  354. package/es/contract/ga/helpers.mjs +0 -30
  355. package/es/contract/ga/helpers.mjs.map +0 -1
  356. package/es/contract/ga/index.mjs +0 -178
  357. package/es/contract/ga/index.mjs.map +0 -1
  358. package/es/crypto-ts.d.ts +0 -9
  359. package/es/encoder.d.ts +0 -26
  360. package/es/node-pool/index.mjs +0 -188
  361. package/es/node-pool/index.mjs.map +0 -1
  362. package/es/node.mjs +0 -133
  363. package/es/node.mjs.map +0 -1
  364. package/es/other.d.ts +0 -31
  365. package/es/semver-satisfies.d.ts +0 -1
  366. package/es/string.d.ts +0 -26
  367. package/es/tx/builder/field-types.mjs +0 -74
  368. package/es/tx/builder/field-types.mjs.map +0 -1
  369. package/es/tx/tx-object.mjs +0 -283
  370. package/es/tx/tx-object.mjs.map +0 -1
  371. package/es/tx/tx.mjs +0 -938
  372. package/es/tx/tx.mjs.map +0 -1
  373. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  374. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  375. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  376. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  377. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  378. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  379. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  380. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  381. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  382. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  383. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  384. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  385. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  386. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  387. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  388. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  389. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  390. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  391. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  392. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  393. package/es/utils/async-init.mjs +0 -64
  394. package/es/utils/async-init.mjs.map +0 -1
  395. package/es/utils/crypto-ts.mjs.map +0 -1
  396. package/es/utils/swagger.mjs +0 -164
  397. package/es/utils/swagger.mjs.map +0 -1
  398. package/src/account/base.js +0 -153
  399. package/src/account/memory.js +0 -83
  400. package/src/account/multiple.js +0 -162
  401. package/src/ae/aens.js +0 -361
  402. package/src/ae/aepp.js +0 -45
  403. package/src/ae/contract.js +0 -148
  404. package/src/ae/index.js +0 -168
  405. package/src/ae/oracle.js +0 -311
  406. package/src/ae/universal.js +0 -47
  407. package/src/ae/wallet.js +0 -50
  408. package/src/chain/index.js +0 -269
  409. package/src/chain/node.js +0 -320
  410. package/src/channel/handlers.js +0 -673
  411. package/src/channel/index.js +0 -903
  412. package/src/channel/internal.js +0 -236
  413. package/src/contract/aci.js +0 -376
  414. package/src/contract/compiler.js +0 -100
  415. package/src/contract/ga/helpers.js +0 -19
  416. package/src/contract/ga/index.js +0 -150
  417. package/src/index.js +0 -89
  418. package/src/node-pool/index.js +0 -172
  419. package/src/node.js +0 -116
  420. package/src/tx/builder/constants.js +0 -100
  421. package/src/tx/builder/field-types.js +0 -61
  422. package/src/tx/builder/helpers.js +0 -334
  423. package/src/tx/builder/index.js +0 -465
  424. package/src/tx/builder/schema.js +0 -1100
  425. package/src/tx/index.js +0 -301
  426. package/src/tx/tx-object.js +0 -187
  427. package/src/tx/tx.js +0 -631
  428. package/src/tx/validator.js +0 -181
  429. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  430. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  431. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  432. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  433. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  434. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  435. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  436. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  437. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  438. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  439. package/src/utils/async-init.js +0 -45
  440. package/src/utils/crypto.js +0 -219
  441. package/src/utils/hd-wallet.js +0 -100
  442. package/src/utils/json-big.js +0 -26
  443. package/src/utils/keystore.js +0 -219
  444. package/src/utils/swagger.js +0 -156
@@ -1,47 +1,90 @@
1
1
  import _buffer from "buffer";
2
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
3
  const {
3
4
  Buffer: _Buffer
4
5
  } = _buffer;
5
- import { verify, hash } from "../utils/crypto.mjs";
6
- import { encode, decode } from "./builder/helpers.mjs";
7
6
  import BigNumber from 'bignumber.js';
8
- import { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from "./builder/schema.mjs";
9
- import { calculateFee, unpackTx } from "./builder/index.mjs";
7
+ import { hash, verify } from "../utils/crypto.mjs";
8
+ import { PROTOCOL_VM_ABI } from "./builder/schema.mjs";
9
+ import { Tag } from "./builder/constants.mjs";
10
+ import { unpackTx } from "./builder/index.mjs";
10
11
  import { UnsupportedProtocolError } from "../utils/errors.mjs";
12
+ import { concatBuffers, isKeyOfObject } from "../utils/other.mjs";
13
+ import { decode, encode, Encoding } from "../utils/encoder.mjs";
14
+ const validators = [];
15
+
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];
11
17
  /**
12
- * Transaction validator
13
- * @module @aeternity/aepp-sdk/es/tx/validator
14
- * @export verifyTransaction
15
- * @example import { verifyTransaction } from '@aeternity/aepp-sdk'
18
+ * Transaction Validator
19
+ * This function validates some of transaction properties,
20
+ * to make sure it can be posted it to the chain
21
+ * @category transaction builder
22
+ * @param transaction - Base64Check-encoded transaction
23
+ * @param node - Node to validate transaction against
24
+ * @param parentTxTypes - Types of parent transactions
25
+ * @returns Array with verification errors
26
+ * @example const errors = await verifyTransaction(transaction, node)
16
27
  */
17
28
 
18
- const validators = [(_ref, _ref2) => {
29
+
30
+ export default async function verifyTransaction(transaction, node) {
31
+ var _getSenderAddress;
32
+
33
+ let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
34
+ const {
35
+ tx,
36
+ txType
37
+ } = unpackTx(transaction);
38
+ const address = (_getSenderAddress = getSenderAddress(tx)) !== null && _getSenderAddress !== void 0 ? _getSenderAddress : txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined;
39
+ const [account, {
40
+ height
41
+ }, {
42
+ consensusProtocolVersion,
43
+ 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,
50
+ id: acc.id
51
+ })), node.getCurrentKeyBlockHeight(), node.getNodeInfo()]);
52
+ return (await Promise.all(validators.map(v => v(tx, {
53
+ txType,
54
+ node,
55
+ account,
56
+ height,
57
+ consensusProtocolVersion,
58
+ nodeNetworkId,
59
+ parentTxTypes
60
+ })))).flat();
61
+ }
62
+ validators.push((_ref, _ref2) => {
19
63
  let {
20
64
  encodedTx,
21
65
  signatures
22
66
  } = _ref;
23
67
  let {
24
68
  account,
25
- node,
69
+ nodeNetworkId,
26
70
  parentTxTypes
27
71
  } = _ref2;
28
72
  if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : signatures) === undefined) return [];
73
+ if (account == null) return [];
29
74
  if (signatures.length !== 1) return []; // TODO: Support multisignature?
30
75
 
31
- const prefix = _Buffer.from([node.nodeNetworkId, ...(parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : [])].join('-'));
32
-
33
- const txWithNetworkId = _Buffer.concat([prefix, encodedTx.rlpEncoded]);
76
+ const prefix = _Buffer.from([nodeNetworkId, ...(_includesInstanceProperty(parentTxTypes).call(parentTxTypes, Tag.PayingForTx) ? ['inner_tx'] : [])].join('-'));
34
77
 
35
- const txHashWithNetworkId = _Buffer.concat([prefix, hash(encodedTx.rlpEncoded)]);
36
-
37
- const decodedPub = decode(account.id, 'ak');
78
+ const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);
79
+ const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);
80
+ const decodedPub = decode(account.id);
38
81
  if (verify(txWithNetworkId, signatures[0], decodedPub) || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
39
82
  return [{
40
83
  message: 'Signature cannot be verified, please ensure that you transaction have' + ' the correct prefix and the correct private key for the sender address',
41
84
  key: 'InvalidSignature',
42
85
  checkedKeys: ['encodedTx', 'signatures']
43
86
  }];
44
- }, (_ref3, _ref4) => {
87
+ }, async (_ref3, _ref4) => {
45
88
  let {
46
89
  encodedTx,
47
90
  tx
@@ -52,31 +95,14 @@ const validators = [(_ref, _ref2) => {
52
95
  txType
53
96
  } = _ref4;
54
97
  if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx) === undefined) return [];
55
- return verifyTransaction(encode((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx).rlpEncoded, 'tx'), node, [...parentTxTypes, txType]);
56
- }, (tx, _ref5) => {
57
- let {
58
- txType
59
- } = _ref5;
60
- if (tx.fee === undefined) return [];
61
- const minFee = calculateFee(0, txType, {
62
- gas: +tx.gas || 0,
63
- params: tx,
64
- showWarning: false,
65
- vsn: tx.VSN
66
- });
67
- if (new BigNumber(minFee).lte(tx.fee)) return [];
68
- return [{
69
- message: `Fee ${tx.fee} is too low, minimum fee for this transaction is ${minFee}`,
70
- key: 'InsufficientFee',
71
- checkedKeys: ['fee']
72
- }];
73
- }, (_ref6, _ref7) => {
98
+ return verifyTransaction(encode((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx).rlpEncoded, Encoding.Transaction), node, [...parentTxTypes, txType]);
99
+ }, (_ref5, _ref6) => {
74
100
  let {
75
101
  ttl
76
- } = _ref6;
102
+ } = _ref5;
77
103
  let {
78
104
  height
79
- } = _ref7;
105
+ } = _ref6;
80
106
  if (ttl === undefined) return [];
81
107
  ttl = +ttl;
82
108
  if (ttl === 0 || ttl >= height) return [];
@@ -85,37 +111,39 @@ const validators = [(_ref, _ref2) => {
85
111
  key: 'ExpiredTTL',
86
112
  checkedKeys: ['ttl']
87
113
  }];
88
- }, (_ref8, _ref9) => {
89
- var _ref10;
114
+ }, (_ref7, _ref8) => {
115
+ var _ref9, _fee;
90
116
 
91
117
  let {
92
118
  amount,
93
119
  fee,
94
120
  nameFee,
95
121
  tx
96
- } = _ref8;
122
+ } = _ref7;
97
123
  let {
98
124
  account,
99
125
  parentTxTypes,
100
126
  txType
101
- } = _ref9;
102
- if (((_ref10 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref10 !== void 0 ? _ref10 : nameFee) === undefined) return [];
103
- const cost = new BigNumber(fee).plus(nameFee || 0).plus(amount || 0).plus(txType === TX_TYPE.payingFor ? tx.tx.encodedTx.tx.fee : 0).minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0);
104
- if (cost.lte(account.balance)) return [];
127
+ } = _ref8;
128
+ if (account == null) return [];
129
+ if (((_ref9 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref9 !== void 0 ? _ref9 : nameFee) === undefined) return [];
130
+ (_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);
132
+ if (cost.lte(account.balance.toString())) return [];
105
133
  return [{
106
- message: `Account balance ${account.balance} is not enough to execute the transaction that costs ${cost.toFixed()}`,
134
+ message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,
107
135
  key: 'InsufficientBalance',
108
136
  checkedKeys: ['amount', 'fee', 'nameFee']
109
137
  }];
110
- }, (_ref11, _ref12) => {
138
+ }, (_ref10, _ref11) => {
111
139
  let {
112
140
  nonce
113
- } = _ref11;
141
+ } = _ref10;
114
142
  let {
115
143
  account,
116
144
  parentTxTypes
117
- } = _ref12;
118
- if (nonce === undefined || parentTxTypes.includes(TX_TYPE.gaMeta)) return [];
145
+ } = _ref11;
146
+ if (nonce == null || account == null || _includesInstanceProperty(parentTxTypes).call(parentTxTypes, Tag.GaMetaTx)) return [];
119
147
  nonce = +nonce;
120
148
  const validNonce = account.nonce + 1;
121
149
  if (nonce === validNonce) return [];
@@ -128,41 +156,33 @@ const validators = [(_ref, _ref2) => {
128
156
  }),
129
157
  checkedKeys: ['nonce']
130
158
  }];
131
- }, _ref13 => {
132
- let {
133
- gasPrice
134
- } = _ref13;
135
- if (gasPrice === undefined) return [];
136
- if (gasPrice >= MIN_GAS_PRICE) return [];
137
- return [{
138
- message: `Gas price ${gasPrice} must be bigger then ${MIN_GAS_PRICE}`,
139
- key: 'MinGasPrice',
140
- checkedKeys: ['gasPrice']
141
- }];
142
- }, (_ref14, _ref15) => {
159
+ }, (_ref12, _ref13) => {
143
160
  let {
144
161
  ctVersion,
145
162
  abiVersion
146
- } = _ref14;
163
+ } = _ref12;
147
164
  let {
148
165
  txType,
149
- node
150
- } = _ref15;
151
- const {
152
166
  consensusProtocolVersion
153
- } = node.getNodeInfo();
154
- const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
155
- if (!protocol) throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`); // If not contract create tx
167
+ } = _ref13;
168
+
169
+ if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
170
+ throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);
171
+ }
156
172
 
157
- if (!ctVersion) ctVersion = {
173
+ const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]; // If not contract create tx
174
+
175
+ if (ctVersion == null) ctVersion = {
158
176
  abiVersion
159
177
  };
160
178
  const txProtocol = protocol[txType];
161
- if (!txProtocol) return [];
179
+ if (txProtocol == null) return [];
180
+
181
+ if (Object.entries(ctVersion).some(_ref14 => {
182
+ var _context;
162
183
 
163
- if (Object.entries(ctVersion).some(_ref16 => {
164
- let [key, value] = _ref16;
165
- return !txProtocol[key].includes(+value);
184
+ let [key, value] = _ref14;
185
+ return !_includesInstanceProperty(_context = txProtocol[key]).call(_context, +value);
166
186
  })) {
167
187
  return [{
168
188
  message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,
@@ -172,20 +192,21 @@ const validators = [(_ref, _ref2) => {
172
192
  }
173
193
 
174
194
  return [];
175
- }, async (_ref17, _ref18) => {
195
+ }, async (_ref15, _ref16) => {
176
196
  let {
177
197
  contractId
178
- } = _ref17;
198
+ } = _ref15;
179
199
  let {
180
200
  txType,
181
201
  node
182
- } = _ref18;
183
- if (TX_TYPE.contractCall !== txType) return [];
202
+ } = _ref16;
203
+ if (Tag.ContractCallTx !== txType) return [];
204
+ contractId = contractId;
184
205
 
185
206
  try {
186
207
  const {
187
208
  active
188
- } = await node.api.getContract(contractId);
209
+ } = await node.getContract(contractId);
189
210
  if (active) return [];
190
211
  return [{
191
212
  message: `Contract ${contractId} is not active`,
@@ -193,55 +214,14 @@ const validators = [(_ref, _ref2) => {
193
214
  checkedKeys: ['contractId']
194
215
  }];
195
216
  } catch (error) {
196
- var _error$response, _error$response$body;
217
+ var _error$response, _error$response$parse;
197
218
 
198
- if (!((_error$response = error.response) !== null && _error$response !== void 0 && (_error$response$body = _error$response.body) !== null && _error$response$body !== void 0 && _error$response$body.reason)) throw error;
219
+ 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;
199
220
  return [{
200
- message: error.response.body.reason,
221
+ message: error.response.parsedBody.reason,
201
222
  key: 'ContractNotFound',
202
223
  checkedKeys: ['contractId']
203
224
  }];
204
225
  }
205
- }];
206
-
207
- const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'].map(key => tx[key]).filter(a => a).map(a => a.replace(/^ok_/, 'ak_'))[0];
208
- /**
209
- * Transaction Validator
210
- * This function validates some of transaction properties,
211
- * to make sure it can be posted it to the chain
212
- * @function
213
- * @alias module:@aeternity/aepp-sdk/es/tx/validator
214
- * @rtype (tx: String, node) => void
215
- * @param {String} transaction Base64Check-encoded transaction
216
- * @param {Object} node Node to validate transaction against
217
- * @param {String[]} [parentTxTypes] Types of parent transactions
218
- * @return {Promise<Object[]>} Array with verification errors
219
- * @example const errors = await verifyTransaction(transaction, node)
220
- */
221
-
222
-
223
- export default async function verifyTransaction(transaction, node) {
224
- var _getSenderAddress;
225
-
226
- let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
227
- const {
228
- tx,
229
- txType
230
- } = unpackTx(transaction);
231
- const address = (_getSenderAddress = getSenderAddress(tx)) !== null && _getSenderAddress !== void 0 ? _getSenderAddress : txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null;
232
- const [account, {
233
- height
234
- }] = await Promise.all([address && node.api.getAccountByPubkey(address).catch(() => ({
235
- id: address,
236
- balance: new BigNumber(0),
237
- nonce: 0
238
- })), node.api.getCurrentKeyBlockHeight()]);
239
- return (await Promise.all(validators.map(v => v(tx, {
240
- txType,
241
- node,
242
- account,
243
- height,
244
- parentTxTypes
245
- })))).flat();
246
- }
226
+ });
247
227
  //# sourceMappingURL=validator.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tx/validator.js"],"names":["verify","hash","encode","decode","BigNumber","MIN_GAS_PRICE","PROTOCOL_VM_ABI","TX_TYPE","calculateFee","unpackTx","UnsupportedProtocolError","validators","encodedTx","signatures","account","node","parentTxTypes","undefined","length","prefix","from","nodeNetworkId","includes","payingFor","join","txWithNetworkId","concat","rlpEncoded","txHashWithNetworkId","decodedPub","id","message","key","checkedKeys","tx","txType","verifyTransaction","fee","minFee","gas","params","showWarning","vsn","VSN","lte","ttl","height","amount","nameFee","cost","plus","minus","balance","toFixed","nonce","gaMeta","validNonce","gasPrice","ctVersion","abiVersion","consensusProtocolVersion","getNodeInfo","protocol","txProtocol","Object","entries","some","value","JSON","stringify","contractId","contractCall","active","api","getContract","error","response","body","reason","getSenderAddress","map","filter","a","replace","transaction","address","signed","Promise","all","getAccountByPubkey","catch","getCurrentKeyBlockHeight","v","flat"],"mappings":";;;;SAASA,M,EAAQC,I;SACRC,M,EAAQC,M;AAEjB,OAAOC,SAAP,MAAsB,cAAtB;SACSC,a,EAAeC,e,EAAiBC,O;SAChCC,Y,EAAcC,Q;SACdC,wB;AAET;AACA;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,eAAe,eAAe/C,iBAAf,CAAkCgD,WAAlC,EAA+CrE,IAA/C,EAAyE;AAAA;;AAAA,MAApBC,aAAoB,uEAAJ,EAAI;AACtF,QAAM;AAAEkB,IAAAA,EAAF;AAAMC,IAAAA;AAAN,MAAiB1B,QAAQ,CAAC2E,WAAD,CAA/B;AAEA,QAAMC,OAAO,wBAAGN,gBAAgB,CAAC7C,EAAD,CAAnB,iEACVC,MAAM,KAAK5B,OAAO,CAAC+E,MAAnB,GAA4BP,gBAAgB,CAAC7C,EAAE,CAACtB,SAAH,CAAasB,EAAd,CAA5C,GAAgE,IADnE;AAEA,QAAM,CAACpB,OAAD,EAAU;AAAEgC,IAAAA;AAAF,GAAV,IAAwB,MAAMyC,OAAO,CAACC,GAAR,CAAY,CAC9CH,OAAO,IAAItE,IAAI,CAAC0D,GAAL,CAASgB,kBAAT,CAA4BJ,OAA5B,EAAqCK,KAArC,CAA2C,OAAO;AAC3D5D,IAAAA,EAAE,EAAEuD,OADuD;AAE3DjC,IAAAA,OAAO,EAAE,IAAIhD,SAAJ,CAAc,CAAd,CAFkD;AAG3DkD,IAAAA,KAAK,EAAE;AAHoD,GAAP,CAA3C,CADmC,EAM9CvC,IAAI,CAAC0D,GAAL,CAASkB,wBAAT,EAN8C,CAAZ,CAApC;AASA,SAAO,CAAC,MAAMJ,OAAO,CAACC,GAAR,CACZ7E,UAAU,CAACqE,GAAX,CAAeY,CAAC,IAAIA,CAAC,CAAC1D,EAAD,EAAK;AAAEC,IAAAA,MAAF;AAAUpB,IAAAA,IAAV;AAAgBD,IAAAA,OAAhB;AAAyBgC,IAAAA,MAAzB;AAAiC9B,IAAAA;AAAjC,GAAL,CAArB,CADY,CAAP,EAEL6E,IAFK,EAAP;AAGD","sourcesContent":["import { verify, hash } from '../utils/crypto'\nimport { encode, decode } from './builder/helpers'\n\nimport BigNumber from 'bignumber.js'\nimport { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from './builder/schema'\nimport { calculateFee, unpackTx } from './builder'\nimport { UnsupportedProtocolError } from '../utils/errors'\n\n/**\n * Transaction validator\n * @module @aeternity/aepp-sdk/es/tx/validator\n * @export verifyTransaction\n * @example import { verifyTransaction } from '@aeternity/aepp-sdk'\n */\n\nconst validators = [\n ({ encodedTx, signatures }, { account, node, parentTxTypes }) => {\n if ((encodedTx ?? signatures) === undefined) return []\n if (signatures.length !== 1) return [] // TODO: Support multisignature?\n const prefix = Buffer.from([\n node.nodeNetworkId,\n ...parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : []\n ].join('-'))\n const txWithNetworkId = Buffer.concat([prefix, encodedTx.rlpEncoded])\n const txHashWithNetworkId = Buffer.concat([prefix, hash(encodedTx.rlpEncoded)])\n const decodedPub = decode(account.id, 'ak')\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 ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {\n if ((encodedTx ?? tx) === undefined) return []\n return verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, 'tx'),\n node,\n [...parentTxTypes, txType]\n )\n },\n (tx, { txType }) => {\n if (tx.fee === undefined) return []\n const minFee = calculateFee(0, txType, {\n gas: +tx.gas || 0, params: tx, showWarning: false, vsn: tx.VSN\n })\n if (new BigNumber(minFee).lte(tx.fee)) return []\n return [{\n message: `Fee ${tx.fee} is too low, minimum fee for this transaction is ${minFee}`,\n key: 'InsufficientFee',\n checkedKeys: ['fee']\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 ({ amount, fee, nameFee, tx }, { account, parentTxTypes, txType }) => {\n if ((amount ?? fee ?? nameFee) === undefined) return []\n const cost = new BigNumber(fee).plus(nameFee || 0).plus(amount || 0)\n .plus(txType === TX_TYPE.payingFor ? tx.tx.encodedTx.tx.fee : 0)\n .minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0)\n if (cost.lte(account.balance)) return []\n return [{\n message: `Account balance ${account.balance} 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 === undefined || parentTxTypes.includes(TX_TYPE.gaMeta)) 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 ({ gasPrice }) => {\n if (gasPrice === undefined) return []\n if (gasPrice >= MIN_GAS_PRICE) return []\n return [{\n message: `Gas price ${gasPrice} must be bigger then ${MIN_GAS_PRICE}`,\n key: 'MinGasPrice',\n checkedKeys: ['gasPrice']\n }]\n },\n ({ ctVersion, abiVersion }, { txType, node }) => {\n const { consensusProtocolVersion } = node.getNodeInfo()\n const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]\n if (!protocol) throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`)\n // If not contract create tx\n if (!ctVersion) ctVersion = { abiVersion }\n const txProtocol = protocol[txType]\n if (!txProtocol) return []\n if (Object.entries(ctVersion).some(([key, value]) => !txProtocol[key].includes(+value))) {\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 (TX_TYPE.contractCall !== txType) return []\n try {\n const { active } = await node.api.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?.body?.reason) throw error\n return [{\n message: error.response.body.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId']\n }]\n }\n }\n]\n\nconst getSenderAddress = tx => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'\n]\n .map(key => tx[key])\n .filter(a => a)\n .map(a => a.replace(/^ok_/, 'ak_'))[0]\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 * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/validator\n * @rtype (tx: String, node) => void\n * @param {String} transaction Base64Check-encoded transaction\n * @param {Object} node Node to validate transaction against\n * @param {String[]} [parentTxTypes] Types of parent transactions\n * @return {Promise<Object[]>} Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction (transaction, node, parentTxTypes = []) {\n const { tx, txType } = unpackTx(transaction)\n\n const address = getSenderAddress(tx) ??\n (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null)\n const [account, { height }] = await Promise.all([\n address && node.api.getAccountByPubkey(address).catch(() => ({\n id: address,\n balance: new BigNumber(0),\n nonce: 0\n })),\n node.api.getCurrentKeyBlockHeight()\n ])\n\n return (await Promise.all(\n validators.map(v => v(tx, { txType, node, account, height, parentTxTypes })))\n ).flat()\n}\n"],"file":"validator.mjs"}
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,UAFuC,EAE3B,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"file":"index.d.mjs","names":[],"sources":["../../../src/typings/@aeternity__argon2-browser/index.d.ts"],"sourcesContent":["declare module '@aeternity/argon2-browser/dist/argon2-bundled.min.js' {\n export * from 'argon2-browser';\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.d.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/@aeternity__uuid/index.d.ts"],"sourcesContent":["declare module '@aeternity/uuid' {\n // Already depends on @types/uuid\n // eslint-disable-next-line import/no-extraneous-dependencies\n export * from 'uuid';\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.d.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/bip32-path/index.d.ts"],"sourcesContent":["// TODO: remove after solving https://github.com/axic/bip32-path/issues/5\n\ndeclare module 'bip32-path' {\n interface BipPath {\n toPathArray: () => number[];\n /**\n * returns a text encoded path. Set to noRoot to true to omit the m/ prefix.\n * Set oldStyle true to use h instead of ' for marking hardened nodes.\n */\n toString: (noRoot: boolean, oldStyle: boolean) => string;\n\n /**\n * returns true if the input is a valid path string\n */\n validateString: (path: string) => boolean;\n\n /**\n * returns true if the input is a valid binary path array\n */\n validatePathArray: (path: string) => boolean;\n }\n\n /**\n * creates an instance from a path written as text.\n * Set reqRoot to true if the m/ prefix is mandatory.\n */\n export const fromString: (text: string, reqRoot?: boolean) => BipPath;\n\n /**\n * creates an instance from a binary path array\n */\n export const fromPathArray: (path: string) => BipPath;\n}\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.d.mjs"}
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/blakejs/index.d.ts"],"sourcesContent":["declare module 'blakejs/blake2b.js' {\n export {\n Blake2bCTX, blake2bInit, blake2bUpdate, blake2bFinal, blake2b, blake2bHex,\n } from 'blakejs';\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.d.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/sha-js/index.d.ts"],"sourcesContent":["declare module 'sha.js/sha256.js' {\n import { sha256 } from 'sha.js';\n\n export default sha256;\n}\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.d.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mjs","names":[],"sources":["../../../src/typings/tweetnacl-auth/index.d.ts"],"sourcesContent":["// TODO: remove after solving https://github.com/dchest/tweetnacl-auth-js/issues/3\n\ndeclare module 'tweetnacl-auth' {\n /**\n * Authenticates the given message with the secret key.\n * (In other words, returns HMAC-SHA-512-256 of the message under the key.)\n */\n export default function (message: Uint8Array, key: Uint8Array): Uint8Array;\n\n /**\n * Returns HMAC-SHA-512 (without truncation) of the message under the key\n */\n export const full: (message: Uint8Array, key: Uint8Array) => Uint8Array;\n}\n"],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import BigNumber from 'bignumber.js';
2
+ export declare enum AE_AMOUNT_FORMATS {
3
+ AE = "ae",
4
+ MILI_AE = "miliAE",
5
+ MICRO_AE = "microAE",
6
+ NANO_AE = "nanoAE",
7
+ PICO_AE = "picoAE",
8
+ FEMTO_AE = "femtoAE",
9
+ AETTOS = "aettos"
10
+ }
11
+ /**
12
+ * Convert amount from one to other denomination
13
+ * @param value - amount to convert
14
+ * @param options - options
15
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
16
+ * @param options.targetDenomination - target denomination,
17
+ * can be ['ae', 'aettos']
18
+ */
19
+ export declare const formatAmount: (value: string | number | bigint | BigNumber, { denomination, targetDenomination }: {
20
+ denomination?: AE_AMOUNT_FORMATS | undefined;
21
+ targetDenomination?: AE_AMOUNT_FORMATS | undefined;
22
+ }) => string;
23
+ /**
24
+ * Convert amount to AE
25
+ * @param value - amount to convert
26
+ * @param options - options
27
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
28
+ */
29
+ export declare const toAe: (value: string | number | BigNumber, { denomination }?: {
30
+ denomination?: AE_AMOUNT_FORMATS | undefined;
31
+ }) => string;
32
+ /**
33
+ * Convert amount to aettos
34
+ * @param value - amount to convert
35
+ * @param options - options
36
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
37
+ */
38
+ export declare const toAettos: (value: string | number | BigNumber, { denomination }?: {
39
+ denomination?: AE_AMOUNT_FORMATS | undefined;
40
+ }) => string;
41
+ declare const _default: (rawValue: string | number | BigNumber) => string;
42
+ export default _default;
@@ -14,33 +14,25 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
-
18
- /**
19
- * Amount Formatter
20
- * @module @aeternity/aepp-sdk/es/utils/amount-formatter
21
- * @example import { AmountFormatter } from '@aeternity/aepp-sdk'
22
- */
23
17
  import BigNumber from 'bignumber.js';
24
18
  import { isBigNumber } from "./bignumber.mjs";
25
- import { ArgumentError, InvalidDenominationError } from "./errors.mjs";
26
- /**
27
- * AE amount formats
28
- */
29
-
30
- export const AE_AMOUNT_FORMATS = {
31
- AE: 'ae',
32
- MILI_AE: 'miliAE',
33
- MICRO_AE: 'microAE',
34
- NANO_AE: 'nanoAE',
35
- PICO_AE: 'picoAE',
36
- FEMTO_AE: 'femtoAE',
37
- AETTOS: 'aettos'
38
- };
19
+ import { ArgumentError } from "./errors.mjs";
20
+ export let AE_AMOUNT_FORMATS;
39
21
  /**
40
22
  * DENOMINATION_MAGNITUDE
41
23
  */
42
24
 
43
- export const DENOMINATION_MAGNITUDE = {
25
+ (function (AE_AMOUNT_FORMATS) {
26
+ AE_AMOUNT_FORMATS["AE"] = "ae";
27
+ AE_AMOUNT_FORMATS["MILI_AE"] = "miliAE";
28
+ AE_AMOUNT_FORMATS["MICRO_AE"] = "microAE";
29
+ AE_AMOUNT_FORMATS["NANO_AE"] = "nanoAE";
30
+ AE_AMOUNT_FORMATS["PICO_AE"] = "picoAE";
31
+ AE_AMOUNT_FORMATS["FEMTO_AE"] = "femtoAE";
32
+ AE_AMOUNT_FORMATS["AETTOS"] = "aettos";
33
+ })(AE_AMOUNT_FORMATS || (AE_AMOUNT_FORMATS = {}));
34
+
35
+ const DENOMINATION_MAGNITUDE = {
44
36
  [AE_AMOUNT_FORMATS.AE]: 0,
45
37
  [AE_AMOUNT_FORMATS.MILI_AE]: -3,
46
38
  [AE_AMOUNT_FORMATS.MICRO_AE]: -6,
@@ -49,12 +41,28 @@ export const DENOMINATION_MAGNITUDE = {
49
41
  [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,
50
42
  [AE_AMOUNT_FORMATS.AETTOS]: -18
51
43
  };
44
+ /**
45
+ * Convert amount from one to other denomination
46
+ * @param value - amount to convert
47
+ * @param options - options
48
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
49
+ * @param options.targetDenomination - target denomination,
50
+ * can be ['ae', 'aettos']
51
+ */
52
+
53
+ export const formatAmount = (value, _ref) => {
54
+ let {
55
+ denomination = AE_AMOUNT_FORMATS.AETTOS,
56
+ targetDenomination = AE_AMOUNT_FORMATS.AETTOS
57
+ } = _ref;
58
+ if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);
59
+ return new BigNumber(typeof value === 'bigint' ? value.toString() : value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
60
+ };
52
61
  /**
53
62
  * Convert amount to AE
54
- * @param {String|Number|BigNumber} value amount to convert
55
- * @param {Object} [options={}] options
56
- * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
57
- * @return {String}
63
+ * @param value - amount to convert
64
+ * @param options - options
65
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
58
66
  */
59
67
 
60
68
  export const toAe = function (value) {
@@ -68,10 +76,9 @@ export const toAe = function (value) {
68
76
  };
69
77
  /**
70
78
  * Convert amount to aettos
71
- * @param {String|Number|BigNumber} value amount to convert
72
- * @param {Object} [options={}] options
73
- * @param {String} [options.denomination='ae'] denomination of amount, can be ['ae', 'aettos']
74
- * @return {String}
79
+ * @param value - amount to convert
80
+ * @param options - options
81
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
75
82
  */
76
83
 
77
84
  export const toAettos = function (value) {
@@ -82,26 +89,6 @@ export const toAettos = function (value) {
82
89
  denomination
83
90
  });
84
91
  };
85
- /**
86
- * Convert amount from one to other denomination
87
- * @param {String|Number|BigNumber} value amount to convert
88
- * @param {Object} [options={}] options
89
- * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
90
- * @param {String} [options.targetDenomination='aettos'] target denomination, can be ['ae', 'aettos']
91
- * @return {String}
92
- */
93
-
94
- export const formatAmount = function (value) {
95
- let {
96
- denomination = AE_AMOUNT_FORMATS.AETTOS,
97
- targetDenomination = AE_AMOUNT_FORMATS.AETTOS
98
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
99
- const denominations = Object.values(AE_AMOUNT_FORMATS);
100
- if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`);
101
- if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`);
102
- if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value);
103
- return new BigNumber(value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
104
- };
105
92
  const prefixes = [{
106
93
  name: 'exa',
107
94
  magnitude: 18