@aeternity/aepp-sdk 10.0.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (424) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -14
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -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 +69 -0
  14. package/es/AeSdkAepp.mjs +175 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +212 -0
  17. package/es/AeSdkBase.mjs +310 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +103 -0
  20. package/es/AeSdkWallet.mjs +322 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +44 -0
  23. package/es/Node.mjs +141 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +65 -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 +25 -0
  29. package/es/account/Memory.mjs +81 -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 +79 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +209 -0
  35. package/es/aens.mjs +332 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -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 +118 -0
  56. package/es/aepp-wallet-communication/schema.mjs +214 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -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 +1061 -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 +4164 -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 +220 -0
  92. package/es/chain.mjs +524 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/{handlers.js → handlers.mjs} +163 -130
  96. package/es/channel/handlers.mjs.map +1 -0
  97. package/es/channel/index.d.ts +634 -0
  98. package/es/channel/index.mjs +978 -0
  99. package/es/channel/index.mjs.map +1 -0
  100. package/es/channel/internal.d.ts +100 -0
  101. package/es/channel/internal.mjs +328 -0
  102. package/es/channel/internal.mjs.map +1 -0
  103. package/es/contract/Compiler.d.ts +17 -0
  104. package/es/contract/Compiler.mjs +67 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +125 -0
  107. package/es/contract/aci.mjs +496 -0
  108. package/es/contract/aci.mjs.map +1 -0
  109. package/es/contract/ga.d.ts +68 -0
  110. package/es/contract/ga.mjs +190 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +68 -0
  113. package/es/contract/methods.mjs +101 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/index.d.ts +32 -0
  116. package/es/index.mjs +49 -0
  117. package/es/index.mjs.map +1 -0
  118. package/es/oracle.d.ts +154 -0
  119. package/es/oracle.mjs +288 -0
  120. package/es/oracle.mjs.map +1 -0
  121. package/es/spend.d.ts +61 -0
  122. package/es/spend.mjs +122 -0
  123. package/es/spend.mjs.map +1 -0
  124. package/es/tx/builder/constants.d.ts +41 -0
  125. package/es/tx/builder/constants.mjs +100 -0
  126. package/es/tx/builder/constants.mjs.map +1 -0
  127. package/es/tx/builder/field-types.d.ts +62 -0
  128. package/es/tx/builder/field-types.mjs +126 -0
  129. package/es/tx/builder/field-types.mjs.map +1 -0
  130. package/es/tx/builder/helpers.d.ts +131 -0
  131. package/es/tx/builder/helpers.mjs +223 -0
  132. package/es/tx/builder/helpers.mjs.map +1 -0
  133. package/es/tx/builder/index.d.ts +75 -0
  134. package/es/tx/builder/index.mjs +424 -0
  135. package/es/tx/builder/index.mjs.map +1 -0
  136. package/es/tx/builder/schema.d.ts +350 -0
  137. package/es/tx/builder/schema.mjs +320 -0
  138. package/es/tx/builder/schema.mjs.map +1 -0
  139. package/es/tx/index.d.ts +63 -0
  140. package/es/tx/index.mjs +209 -0
  141. package/es/tx/index.mjs.map +1 -0
  142. package/es/tx/min-fee.d.ts +20 -0
  143. package/es/tx/min-fee.mjs +148 -0
  144. package/es/tx/min-fee.mjs.map +1 -0
  145. package/es/tx/validator.d.ts +19 -0
  146. package/es/tx/validator.mjs +240 -0
  147. package/es/tx/validator.mjs.map +1 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  149. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  151. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  152. package/es/typings/bip32-path/index.d.mjs +2 -0
  153. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  154. package/es/typings/blakejs/index.d.mjs +2 -0
  155. package/es/typings/blakejs/index.d.mjs.map +1 -0
  156. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  157. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  158. package/es/utils/amount-formatter.d.ts +42 -0
  159. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
  160. package/es/utils/amount-formatter.mjs.map +1 -0
  161. package/es/utils/autorest.d.ts +6 -0
  162. package/es/utils/autorest.mjs +97 -0
  163. package/es/utils/autorest.mjs.map +1 -0
  164. package/es/utils/bignumber.d.ts +13 -0
  165. package/es/utils/bignumber.mjs +23 -0
  166. package/es/utils/bignumber.mjs.map +1 -0
  167. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  168. package/es/utils/{bytes.js → bytes.mjs} +26 -22
  169. package/es/utils/bytes.mjs.map +1 -0
  170. package/es/utils/crypto.d.ts +103 -0
  171. package/es/utils/crypto.mjs +221 -0
  172. package/es/utils/crypto.mjs.map +1 -0
  173. package/es/utils/encoder.d.ts +26 -0
  174. package/es/utils/encoder.mjs +102 -0
  175. package/es/utils/encoder.mjs.map +1 -0
  176. package/es/utils/errors.d.ts +481 -0
  177. package/es/utils/errors.mjs +882 -0
  178. package/es/utils/errors.mjs.map +1 -0
  179. package/es/utils/hd-wallet.d.ts +34 -0
  180. package/es/utils/hd-wallet.mjs +122 -0
  181. package/es/utils/hd-wallet.mjs.map +1 -0
  182. package/es/utils/json-big.d.ts +5 -0
  183. package/es/utils/json-big.mjs +41 -0
  184. package/es/utils/json-big.mjs.map +1 -0
  185. package/es/utils/keystore.d.ts +51 -0
  186. package/es/utils/keystore.mjs +145 -0
  187. package/es/utils/keystore.mjs.map +1 -0
  188. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  189. package/es/utils/{mptree.js → mptree.mjs} +33 -25
  190. package/es/utils/mptree.mjs.map +1 -0
  191. package/es/utils/other.d.ts +14 -0
  192. package/es/utils/other.mjs +28 -0
  193. package/es/utils/other.mjs.map +1 -0
  194. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  195. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  196. package/es/utils/semver-satisfies.mjs.map +1 -0
  197. package/es/utils/string.d.ts +24 -0
  198. package/es/utils/{string.js → string.mjs} +9 -11
  199. package/es/utils/string.mjs.map +1 -0
  200. package/package.json +67 -64
  201. package/src/AeSdk.ts +65 -0
  202. package/src/AeSdkAepp.ts +167 -0
  203. package/src/AeSdkBase.ts +320 -0
  204. package/src/AeSdkWallet.ts +332 -0
  205. package/src/Node.ts +167 -0
  206. package/src/account/Base.ts +114 -0
  207. package/src/account/Memory.ts +83 -0
  208. package/src/account/Rpc.ts +67 -0
  209. package/src/aens.ts +391 -0
  210. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  211. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  212. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  213. package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
  214. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  215. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  216. package/src/aepp-wallet-communication/schema.ts +181 -0
  217. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  218. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  219. package/src/apis/compiler/compiler.ts +585 -0
  220. package/src/apis/compiler/index.ts +2 -0
  221. package/src/apis/compiler/models/index.ts +301 -0
  222. package/src/apis/compiler/models/mappers.ts +583 -0
  223. package/src/apis/compiler/models/parameters.ts +93 -0
  224. package/src/apis/node/code-model-v4.yaml +10046 -0
  225. package/src/apis/node/index.ts +2 -0
  226. package/src/apis/node/models/index.ts +1253 -0
  227. package/src/apis/node/models/mappers.ts +4278 -0
  228. package/src/apis/node/models/parameters.ts +188 -0
  229. package/src/apis/node/node.ts +1299 -0
  230. package/src/chain.ts +444 -0
  231. package/src/channel/{handlers.js → handlers.ts} +238 -143
  232. package/src/channel/index.ts +991 -0
  233. package/src/channel/internal.ts +345 -0
  234. package/src/contract/Compiler.ts +66 -0
  235. package/src/contract/aci.ts +529 -0
  236. package/src/contract/ga.ts +178 -0
  237. package/src/contract/methods.ts +118 -0
  238. package/src/index.ts +51 -0
  239. package/src/oracle.ts +342 -0
  240. package/src/spend.ts +152 -0
  241. package/src/tx/builder/constants.ts +96 -0
  242. package/src/tx/builder/field-types.ts +111 -0
  243. package/src/tx/builder/helpers.ts +253 -0
  244. package/src/tx/builder/index.ts +394 -0
  245. package/src/tx/builder/schema.ts +771 -0
  246. package/src/tx/index.ts +199 -0
  247. package/src/tx/min-fee.ts +136 -0
  248. package/src/tx/validator.ts +226 -0
  249. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  250. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  251. package/src/typings/bip32-path/index.d.ts +33 -0
  252. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  253. package/src/utils/amount-formatter.ts +29 -41
  254. package/src/utils/autorest.ts +90 -0
  255. package/src/utils/bignumber.ts +9 -19
  256. package/src/utils/bytes.ts +15 -16
  257. package/src/utils/crypto.ts +217 -0
  258. package/src/utils/encoder.ts +98 -0
  259. package/src/utils/errors.ts +817 -0
  260. package/src/utils/hd-wallet.ts +134 -0
  261. package/src/utils/json-big.ts +26 -0
  262. package/src/utils/keystore.ts +179 -0
  263. package/src/utils/mptree.ts +26 -20
  264. package/src/utils/other.ts +28 -43
  265. package/src/utils/string.ts +8 -10
  266. package/CHANGELOG.md +0 -1603
  267. package/es/account/base.js +0 -169
  268. package/es/account/base.js.map +0 -1
  269. package/es/account/memory.js +0 -84
  270. package/es/account/memory.js.map +0 -1
  271. package/es/account/multiple.js +0 -178
  272. package/es/account/multiple.js.map +0 -1
  273. package/es/ae/aens.js +0 -408
  274. package/es/ae/aens.js.map +0 -1
  275. package/es/ae/aepp.js +0 -45
  276. package/es/ae/aepp.js.map +0 -1
  277. package/es/ae/contract.js +0 -312
  278. package/es/ae/contract.js.map +0 -1
  279. package/es/ae/index.js +0 -206
  280. package/es/ae/index.js.map +0 -1
  281. package/es/ae/oracle.js +0 -322
  282. package/es/ae/oracle.js.map +0 -1
  283. package/es/ae/universal.js +0 -45
  284. package/es/ae/universal.js.map +0 -1
  285. package/es/ae/wallet.js +0 -50
  286. package/es/ae/wallet.js.map +0 -1
  287. package/es/amount-formatter.d.ts +0 -58
  288. package/es/bignumber.d.ts +0 -24
  289. package/es/chain/index.js +0 -256
  290. package/es/chain/index.js.map +0 -1
  291. package/es/chain/node.js +0 -394
  292. package/es/chain/node.js.map +0 -1
  293. package/es/channel/handlers.js.map +0 -1
  294. package/es/channel/index.js +0 -980
  295. package/es/channel/index.js.map +0 -1
  296. package/es/channel/internal.js +0 -266
  297. package/es/channel/internal.js.map +0 -1
  298. package/es/contract/aci/helpers.js +0 -298
  299. package/es/contract/aci/helpers.js.map +0 -1
  300. package/es/contract/aci/index.js +0 -361
  301. package/es/contract/aci/index.js.map +0 -1
  302. package/es/contract/aci/transformation.js +0 -66
  303. package/es/contract/aci/transformation.js.map +0 -1
  304. package/es/contract/compiler.js +0 -244
  305. package/es/contract/compiler.js.map +0 -1
  306. package/es/contract/ga/helpers.js +0 -22
  307. package/es/contract/ga/helpers.js.map +0 -1
  308. package/es/contract/ga/index.js +0 -170
  309. package/es/contract/ga/index.js.map +0 -1
  310. package/es/contract/index.js +0 -162
  311. package/es/contract/index.js.map +0 -1
  312. package/es/crypto-ts.d.ts +0 -9
  313. package/es/index.js +0 -57
  314. package/es/index.js.map +0 -1
  315. package/es/node-pool/index.js +0 -187
  316. package/es/node-pool/index.js.map +0 -1
  317. package/es/node.js +0 -132
  318. package/es/node.js.map +0 -1
  319. package/es/other.d.ts +0 -31
  320. package/es/string.d.ts +0 -26
  321. package/es/tx/builder/helpers.js +0 -305
  322. package/es/tx/builder/helpers.js.map +0 -1
  323. package/es/tx/builder/index.js +0 -595
  324. package/es/tx/builder/index.js.map +0 -1
  325. package/es/tx/builder/schema.js +0 -814
  326. package/es/tx/builder/schema.js.map +0 -1
  327. package/es/tx/index.js +0 -300
  328. package/es/tx/index.js.map +0 -1
  329. package/es/tx/tx-object.js +0 -276
  330. package/es/tx/tx-object.js.map +0 -1
  331. package/es/tx/tx.js +0 -937
  332. package/es/tx/tx.js.map +0 -1
  333. package/es/tx/validator.js +0 -208
  334. package/es/tx/validator.js.map +0 -1
  335. package/es/typings/blakejs/index.d.js +0 -2
  336. package/es/typings/blakejs/index.d.js.map +0 -1
  337. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
  338. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  339. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
  340. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  341. package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
  342. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  343. package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
  344. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  345. package/es/utils/aepp-wallet-communication/helpers.js +0 -103
  346. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  347. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
  348. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  349. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
  350. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  351. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
  352. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  353. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  354. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  355. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
  356. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  357. package/es/utils/amount-formatter.js.map +0 -1
  358. package/es/utils/async-init.js +0 -67
  359. package/es/utils/async-init.js.map +0 -1
  360. package/es/utils/bignumber.js +0 -28
  361. package/es/utils/bignumber.js.map +0 -1
  362. package/es/utils/bytes.js.map +0 -1
  363. package/es/utils/crypto-ts.js.map +0 -1
  364. package/es/utils/crypto.js +0 -304
  365. package/es/utils/crypto.js.map +0 -1
  366. package/es/utils/hd-wallet.js +0 -112
  367. package/es/utils/hd-wallet.js.map +0 -1
  368. package/es/utils/json-big.js +0 -45
  369. package/es/utils/json-big.js.map +0 -1
  370. package/es/utils/keystore.js +0 -228
  371. package/es/utils/keystore.js.map +0 -1
  372. package/es/utils/mptree.js.map +0 -1
  373. package/es/utils/other.js +0 -43
  374. package/es/utils/other.js.map +0 -1
  375. package/es/utils/semver-satisfies.js.map +0 -1
  376. package/es/utils/string.js.map +0 -1
  377. package/es/utils/swagger.js +0 -132
  378. package/es/utils/swagger.js.map +0 -1
  379. package/src/account/base.js +0 -153
  380. package/src/account/memory.js +0 -78
  381. package/src/account/multiple.js +0 -154
  382. package/src/ae/aens.js +0 -366
  383. package/src/ae/aepp.js +0 -45
  384. package/src/ae/contract.js +0 -285
  385. package/src/ae/index.js +0 -167
  386. package/src/ae/oracle.js +0 -296
  387. package/src/ae/universal.js +0 -47
  388. package/src/ae/wallet.js +0 -50
  389. package/src/chain/index.js +0 -250
  390. package/src/chain/node.js +0 -293
  391. package/src/channel/index.js +0 -898
  392. package/src/channel/internal.js +0 -231
  393. package/src/contract/aci/index.js +0 -317
  394. package/src/contract/aci/transformation.js +0 -72
  395. package/src/contract/compiler.js +0 -195
  396. package/src/contract/ga/helpers.js +0 -17
  397. package/src/contract/ga/index.js +0 -147
  398. package/src/contract/index.js +0 -163
  399. package/src/index.js +0 -90
  400. package/src/node-pool/index.js +0 -171
  401. package/src/node.js +0 -118
  402. package/src/tx/builder/helpers.js +0 -325
  403. package/src/tx/builder/index.js +0 -460
  404. package/src/tx/builder/schema.js +0 -1211
  405. package/src/tx/index.js +0 -301
  406. package/src/tx/tx-object.js +0 -186
  407. package/src/tx/tx.js +0 -622
  408. package/src/tx/validator.js +0 -161
  409. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
  410. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
  411. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  412. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
  413. package/src/utils/aepp-wallet-communication/helpers.js +0 -70
  414. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
  415. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
  416. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
  417. package/src/utils/aepp-wallet-communication/schema.js +0 -108
  418. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
  419. package/src/utils/async-init.js +0 -41
  420. package/src/utils/crypto.js +0 -312
  421. package/src/utils/hd-wallet.js +0 -115
  422. package/src/utils/json-big.js +0 -26
  423. package/src/utils/keystore.js +0 -223
  424. package/src/utils/swagger.js +0 -133
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.mjs","names":["verify","hash","encode","decode","BigNumber","PROTOCOL_VM_ABI","TX_TYPE","unpackTx","calculateMinFee","UnsupportedProtocolError","concatBuffers","isKeyOfObject","validators","encodedTx","signatures","account","nodeNetworkId","parentTxTypes","undefined","length","prefix","from","payingFor","join","txWithNetworkId","rlpEncoded","txHashWithNetworkId","decodedPub","id","message","key","checkedKeys","tx","node","txType","verifyTransaction","fee","minFee","params","vsn","VSN","lte","toString","ttl","height","amount","nameFee","cost","plus","minus","balance","toFixed","nonce","gaMeta","validNonce","ctVersion","abiVersion","consensusProtocolVersion","protocol","txProtocol","Object","entries","some","value","JSON","stringify","contractId","contractCall","active","getContract","error","response","parsedBody","reason","getSenderAddress","map","filter","a","replace","transaction","address","signed","Promise","all","getAccountByPubkey","catch","then","acc","getCurrentKeyBlockHeight","getNodeInfo","v","flat"],"sources":["../../src/tx/validator.ts"],"sourcesContent":["import { verify, hash } from '../utils/crypto'\nimport { encode, decode } from './builder/helpers'\nimport BigNumber from 'bignumber.js'\nimport {\n PROTOCOL_VM_ABI, RawTxObject, TxSchema, TxParamsCommon, TX_TYPE, TxTypeSchemas, CtVersion\n} from './builder/schema'\nimport { TxUnpacked, unpackTx } from './builder'\nimport calculateMinFee from './min-fee'\nimport { UnsupportedProtocolError } from '../utils/errors'\nimport { concatBuffers, isKeyOfObject } from '../utils/other'\nimport { EncodedData } from '../utils/encoder'\nimport Node from '../Node'\n\ninterface Account {\n balance: bigint\n id: EncodedData<'ak'>\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[TX_TYPE.signed]\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?: EncodedData<'ct'>\n },\n options: {\n account?: Account\n nodeNetworkId: string\n parentTxTypes: TX_TYPE[]\n node: Node\n txType: TX_TYPE\n height: number\n consensusProtocolVersion: number\n }\n) => ValidatorResult[] | Promise<ValidatorResult[]>\n\nconst validators: Validator[] = [\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(TX_TYPE.payingFor) ? ['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 await verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, 'tx'),\n node,\n [...parentTxTypes, txType]\n )\n },\n (tx: any, { txType }) => {\n if (tx.fee === undefined) return []\n const minFee = calculateMinFee(txType, { params: tx, vsn: tx.VSN })\n if (minFee.lte(tx.fee)) return []\n return [{\n message: `Fee ${tx.fee as string} is too low, minimum fee for this transaction is ${minFee.toString()}`,\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 (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 === TX_TYPE.payingFor ? (tx.tx.encodedTx.tx).fee : 0)\n .minus(parentTxTypes.includes(TX_TYPE.payingFor) ? 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(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 ({ 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 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 contractId = contractId as EncodedData<'ct'>\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\nconst getSenderAddress = (\n tx: TxParamsCommon | RawTxObject<TxSchema>\n): EncodedData<'ak'> | 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 EncodedData<'ak'> | 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 * @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: EncodedData<'tx' | 'pi'>,\n node: Node,\n parentTxTypes: TX_TYPE[] = []\n): Promise<ValidatorResult[]> {\n const { tx, txType } = unpackTx<TX_TYPE.signed>(transaction)\n const address = getSenderAddress(tx) ??\n (txType === TX_TYPE.signed ? 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 EncodedData<'ak'> })),\n node.getCurrentKeyBlockHeight(),\n node.getNodeInfo()\n ])\n\n return (await Promise.all(\n validators.map(v => v(\n tx as any,\n { txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes }\n ))\n )).flat()\n}\n"],"mappings":";;;;;SAASA,M,EAAQC,I;SACRC,M,EAAQC,M;AACjB,OAAOC,SAAP,MAAsB,cAAtB;SAEEC,e,EAAwDC,O;SAErCC,Q;OACdC,e;SACEC,wB;SACAC,a,EAAeC,a;AA2CxB,MAAMC,UAAuB,GAAG,CAC9B,iBAA0E;EAAA,IAAzE;IAAEC,SAAF;IAAaC;EAAb,CAAyE;EAAA,IAA9C;IAAEC,OAAF;IAAWC,aAAX;IAA0BC;EAA1B,CAA8C;EACxE,IAAI,CAACJ,SAAD,aAAC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AC3D;EAAlB,CAAL,CAHT,CAHuF,EAO3FK,IAAI,CAACuD,wBAAL,EAP2F,EAQ3FvD,IAAI,CAACwD,WAAL,EAR2F,CAAZ,CAAjF;EAWA,OAAO,CAAC,MAAMP,OAAO,CAACC,GAAR,CACZvE,UAAU,CAAC+D,GAAX,CAAee,CAAC,IAAIA,CAAC,CACnB1D,EADmB,EAEnB;IAAEE,MAAF;IAAUD,IAAV;IAAgBlB,OAAhB;IAAyB6B,MAAzB;IAAiCa,wBAAjC;IAA2DzC,aAA3D;IAA0EC;EAA1E,CAFmB,CAArB,CADY,CAAP,EAKJ0E,IALI,EAAP;AAMD"}
@@ -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__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 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":""}
@@ -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/blakejs/index.d.ts"],"sourcesContent":["declare module 'blakejs' {\n interface Context {\n b: Uint8Array\n h: Uint32Array\n t: number\n c: number\n outlen: number\n }\n\n export type Data = Buffer | Uint8Array | string\n\n type Key = Uint8Array | null\n\n export const blake2b: (data: Data, key?: Key, outlen?: number) => Uint8Array\n\n export const blake2bFinal: (context: Context) => Uint8Array\n\n export const blake2bHex: (data: Data, key?: Key, outlen?: number) => string\n\n export const blake2bInit: (outlen?: number, key?: Key) => Context\n\n export const blake2bUpdate: (context: Context, data: Data) => void\n\n export const blake2s: (data: Data, key?: Key, outlen?: number) => Uint8Array\n\n export const blake2sFinal: (context: Context) => Uint8Array\n\n export const blake2sHex: (data: Data, key?: Key, outlen?: number) => string\n\n export const blake2sInit: (outlen?: number, key?: Key) => Context\n\n export const blake2sUpdate: (context: Context, data: Data) => void\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 to AE
13
+ * @param value - amount to convert
14
+ * @param options - options
15
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
16
+ */
17
+ export declare const toAe: (value: string | number | BigNumber, { denomination }?: {
18
+ denomination?: AE_AMOUNT_FORMATS | undefined;
19
+ }) => string;
20
+ /**
21
+ * Convert amount to aettos
22
+ * @param value - amount to convert
23
+ * @param options - options
24
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
25
+ */
26
+ export declare const toAettos: (value: string | number | BigNumber, { denomination }?: {
27
+ denomination?: AE_AMOUNT_FORMATS | undefined;
28
+ }) => string;
29
+ /**
30
+ * Convert amount from one to other denomination
31
+ * @param value - amount to convert
32
+ * @param options - options
33
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
34
+ * @param options.targetDenomination - target denomination,
35
+ * can be ['ae', 'aettos']
36
+ */
37
+ export declare const formatAmount: (value: string | number | bigint | BigNumber, { denomination, targetDenomination }: {
38
+ denomination?: AE_AMOUNT_FORMATS | undefined;
39
+ targetDenomination?: AE_AMOUNT_FORMATS | undefined;
40
+ }) => string;
41
+ declare const _default: (rawValue: string | number | BigNumber) => string;
42
+ export default _default;
@@ -14,32 +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
- import { isBigNumber } from './bignumber';
25
- /**
26
- * AE amount formats
27
- */
28
-
29
- export const AE_AMOUNT_FORMATS = {
30
- AE: 'ae',
31
- MILI_AE: 'miliAE',
32
- MICRO_AE: 'microAE',
33
- NANO_AE: 'nanoAE',
34
- PICO_AE: 'picoAE',
35
- FEMTO_AE: 'femtoAE',
36
- AETTOS: 'aettos'
37
- };
18
+ import { isBigNumber } from "./bignumber.mjs";
19
+ import { ArgumentError } from "./errors.mjs";
20
+ export let AE_AMOUNT_FORMATS;
38
21
  /**
39
22
  * DENOMINATION_MAGNITUDE
40
23
  */
41
24
 
42
- 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 = {
43
36
  [AE_AMOUNT_FORMATS.AE]: 0,
44
37
  [AE_AMOUNT_FORMATS.MILI_AE]: -3,
45
38
  [AE_AMOUNT_FORMATS.MICRO_AE]: -6,
@@ -50,10 +43,9 @@ export const DENOMINATION_MAGNITUDE = {
50
43
  };
51
44
  /**
52
45
  * Convert amount to AE
53
- * @param {String|Number|BigNumber} value amount to convert
54
- * @param {Object} [options={}] options
55
- * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
56
- * @return {String}
46
+ * @param value - amount to convert
47
+ * @param options - options
48
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
57
49
  */
58
50
 
59
51
  export const toAe = function (value) {
@@ -67,10 +59,9 @@ export const toAe = function (value) {
67
59
  };
68
60
  /**
69
61
  * Convert amount to aettos
70
- * @param {String|Number|BigNumber} value amount to convert
71
- * @param {Object} [options={}] options
72
- * @param {String} [options.denomination='ae'] denomination of amount, can be ['ae', 'aettos']
73
- * @return {String}
62
+ * @param value - amount to convert
63
+ * @param options - options
64
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
74
65
  */
75
66
 
76
67
  export const toAettos = function (value) {
@@ -83,23 +74,20 @@ export const toAettos = function (value) {
83
74
  };
84
75
  /**
85
76
  * Convert amount from one to other denomination
86
- * @param {String|Number|BigNumber} value amount to convert
87
- * @param {Object} [options={}] options
88
- * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
89
- * @param {String} [options.targetDenomination='aettos'] target denomination, can be ['ae', 'aettos']
90
- * @return {String}
77
+ * @param value - amount to convert
78
+ * @param options - options
79
+ * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
80
+ * @param options.targetDenomination - target denomination,
81
+ * can be ['ae', 'aettos']
91
82
  */
92
83
 
93
- export const formatAmount = function (value) {
84
+ export const formatAmount = (value, _ref) => {
94
85
  let {
95
86
  denomination = AE_AMOUNT_FORMATS.AETTOS,
96
87
  targetDenomination = AE_AMOUNT_FORMATS.AETTOS
97
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
98
- const denominations = Object.values(AE_AMOUNT_FORMATS);
99
- if (!denominations.includes(denomination)) throw new Error(`Invalid denomination: ${denomination}`);
100
- if (!denominations.includes(targetDenomination)) throw new Error(`Invalid target denomination: ${targetDenomination}`);
101
- if (!isBigNumber(value)) throw new Error(`Value ${value === null || value === void 0 ? void 0 : value.toString()} is not type of number`);
102
- return new BigNumber(value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
88
+ } = _ref;
89
+ if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);
90
+ return new BigNumber(typeof value === 'bigint' ? value.toString() : value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
103
91
  };
104
92
  const prefixes = [{
105
93
  name: 'exa',
@@ -117,11 +105,17 @@ const prefixes = [{
117
105
 
118
106
  const getNearestPrefix = exponent => prefixes.reduce((p, n) => Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p);
119
107
 
120
- const getLowerBoundPrefix = exponent => prefixes.find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];
108
+ const getLowerBoundPrefix = exponent => {
109
+ var _prefixes$find;
110
+
111
+ return (_prefixes$find = prefixes.find(p => p.magnitude <= exponent)) !== null && _prefixes$find !== void 0 ? _prefixes$find : prefixes[prefixes.length - 1];
112
+ };
121
113
 
122
114
  export default (rawValue => {
115
+ var _value$e;
116
+
123
117
  const value = new BigNumber(rawValue);
124
- const exp = value.e ?? 0;
118
+ const exp = (_value$e = value.e) !== null && _value$e !== void 0 ? _value$e : 0;
125
119
  const {
126
120
  name,
127
121
  magnitude
@@ -129,4 +123,4 @@ export default (rawValue => {
129
123
  const v = value.shiftedBy(-magnitude).precision(9 + Math.min(exp - magnitude, 0)).toFixed();
130
124
  return `${v}${name !== '' ? ' ' : ''}${name}`;
131
125
  });
132
- //# sourceMappingURL=amount-formatter.js.map
126
+ //# sourceMappingURL=amount-formatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount-formatter.mjs","names":["BigNumber","isBigNumber","ArgumentError","AE_AMOUNT_FORMATS","DENOMINATION_MAGNITUDE","AE","MILI_AE","MICRO_AE","NANO_AE","PICO_AE","FEMTO_AE","AETTOS","toAe","value","denomination","formatAmount","targetDenomination","toAettos","toString","shiftedBy","toFixed","prefixes","name","magnitude","getNearestPrefix","exponent","reduce","p","n","Math","abs","getLowerBoundPrefix","find","length","rawValue","exp","e","v","precision","min"],"sources":["../../src/utils/amount-formatter.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport BigNumber from 'bignumber.js'\nimport { isBigNumber } from './bignumber'\nimport { ArgumentError } from './errors'\n\nexport enum AE_AMOUNT_FORMATS {\n AE = 'ae',\n MILI_AE = 'miliAE',\n MICRO_AE = 'microAE',\n NANO_AE = 'nanoAE',\n PICO_AE = 'picoAE',\n FEMTO_AE = 'femtoAE',\n AETTOS = 'aettos'\n}\n\n/**\n * DENOMINATION_MAGNITUDE\n */\nconst DENOMINATION_MAGNITUDE = {\n [AE_AMOUNT_FORMATS.AE]: 0,\n [AE_AMOUNT_FORMATS.MILI_AE]: -3,\n [AE_AMOUNT_FORMATS.MICRO_AE]: -6,\n [AE_AMOUNT_FORMATS.NANO_AE]: -9,\n [AE_AMOUNT_FORMATS.PICO_AE]: -12,\n [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,\n [AE_AMOUNT_FORMATS.AETTOS]: -18\n} as const\n\n/**\n * Convert amount to AE\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAe = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {}\n): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })\n\n/**\n * Convert amount to aettos\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n */\nexport const toAettos = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {}\n): string => formatAmount(value, { denomination })\n\n/**\n * Convert amount from one to other denomination\n * @param value - amount to convert\n * @param options - options\n * @param options.denomination - denomination of amount, can be ['ae', 'aettos']\n * @param options.targetDenomination - target denomination,\n * can be ['ae', 'aettos']\n */\nexport const formatAmount = (\n value: string | number | bigint | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:\n { denomination?: AE_AMOUNT_FORMATS, targetDenomination?: AE_AMOUNT_FORMATS }\n): string => {\n if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value)\n\n return new BigNumber(typeof value === 'bigint' ? value.toString() : value)\n .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])\n .toFixed()\n}\n\ninterface Prefix {\n name: string\n magnitude: number\n}\n\nconst prefixes: Prefix[] = [\n { name: 'exa', magnitude: 18 },\n { name: 'giga', magnitude: 9 },\n { name: '', magnitude: 0 },\n { name: 'pico', magnitude: -12 }\n]\n\nconst getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (\n Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p))\n\nconst getLowerBoundPrefix = (exponent: number): Prefix => prefixes\n .find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1]\n\nexport default (rawValue: string | number | BigNumber): string => {\n const value: BigNumber = new BigNumber(rawValue)\n\n const exp = value.e ?? 0\n const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp)\n const v = value\n .shiftedBy(-magnitude)\n .precision(9 + Math.min(exp - magnitude, 0))\n .toFixed()\n return `${v}${name !== '' ? ' ' : ''}${name}`\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,W;SACAC,a;AAET,WAAYC,iBAAZ;AAUA;AACA;AACA;;WAZYA,iB;EAAAA,iB;EAAAA,iB;EAAAA,iB;EAAAA,iB;EAAAA,iB;EAAAA,iB;EAAAA,iB;GAAAA,iB,KAAAA,iB;;AAaZ,MAAMC,sBAAsB,GAAG;EAC7B,CAACD,iBAAiB,CAACE,EAAnB,GAAwB,CADK;EAE7B,CAACF,iBAAiB,CAACG,OAAnB,GAA6B,CAAC,CAFD;EAG7B,CAACH,iBAAiB,CAACI,QAAnB,GAA8B,CAAC,CAHF;EAI7B,CAACJ,iBAAiB,CAACK,OAAnB,GAA6B,CAAC,CAJD;EAK7B,CAACL,iBAAiB,CAACM,OAAnB,GAA6B,CAAC,EALD;EAM7B,CAACN,iBAAiB,CAACO,QAAnB,GAA8B,CAAC,EANF;EAO7B,CAACP,iBAAiB,CAACQ,MAAnB,GAA4B,CAAC;AAPA,CAA/B;AAUA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,IAAI,GAAG,UAClBC,KADkB;EAAA,IAElB;IAAEC,YAAY,GAAGX,iBAAiB,CAACQ;EAAnC,CAFkB,uEAEkE,EAFlE;EAAA,OAGPI,YAAY,CAACF,KAAD,EAAQ;IAAEC,YAAF;IAAgBE,kBAAkB,EAAEb,iBAAiB,CAACE;EAAtD,CAAR,CAHL;AAAA,CAAb;AAKP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMY,QAAQ,GAAG,UACtBJ,KADsB;EAAA,IAEtB;IAAEC,YAAY,GAA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ADrB,CAAvD;;AAGA,MAAMI,mBAAmB,GAAIN,QAAD;EAAA;;EAAA,yBAA8BJ,QAAQ,CAC/DW,IADuD,CAClDL,CAAC,IAAIA,CAAC,CAACJ,SAAF,IAAeE,QAD8B,CAA9B,2DACaJ,QAAQ,CAACA,QAAQ,CAACY,MAAT,GAAkB,CAAnB,CADrB;AAAA,CAA5B;;AAGA,gBAAgBC,QAAD,IAAmD;EAAA;;EAChE,MAAMrB,KAAgB,GAAG,IAAIb,SAAJ,CAAckC,QAAd,CAAzB;EAEA,MAAMC,GAAG,eAAGtB,KAAK,CAACuB,CAAT,+CAAc,CAAvB;EACA,MAAM;IAAEd,IAAF;IAAQC;EAAR,IAAsB,CAACY,GAAG,GAAG,CAAN,GAAUX,gBAAV,GAA6BO,mBAA9B,EAAmDI,GAAnD,CAA5B;EACA,MAAME,CAAC,GAAGxB,KAAK,CACZM,SADO,CACG,CAACI,SADJ,EAEPe,SAFO,CAEG,IAAIT,IAAI,CAACU,GAAL,CAASJ,GAAG,GAAGZ,SAAf,EAA0B,CAA1B,CAFP,EAGPH,OAHO,EAAV;EAIA,OAAQ,GAAEiB,CAAE,GAAEf,IAAI,KAAK,EAAT,GAAc,GAAd,GAAoB,EAAG,GAAEA,IAAK,EAA5C;AACD,CAVD"}
@@ -0,0 +1,6 @@
1
+ import { PipelinePolicy } from '@azure/core-rest-pipeline';
2
+ import { AdditionalPolicyConfig } from '@azure/core-client';
3
+ export declare const genRequestQueuesPolicy: () => AdditionalPolicyConfig;
4
+ export declare const genCombineGetRequestsPolicy: () => AdditionalPolicyConfig;
5
+ export declare const genErrorFormatterPolicy: (getMessage: (b: any) => string) => AdditionalPolicyConfig;
6
+ export declare const genVersionCheckPolicy: (name: string, ignorePath: string, versionPromise: Promise<string>, geVersion: string, ltVersion: string) => PipelinePolicy;
@@ -0,0 +1,97 @@
1
+ import { RestError } from '@azure/core-rest-pipeline';
2
+ import { pause } from "./other.mjs";
3
+ import semverSatisfies from "./semver-satisfies.mjs";
4
+ import { UnsupportedVersionError } from "./errors.mjs";
5
+ export const genRequestQueuesPolicy = () => {
6
+ const requestQueues = new Map();
7
+ return {
8
+ policy: {
9
+ name: 'request-queues',
10
+
11
+ async sendRequest(request, next) {
12
+ var _requestQueues$get;
13
+
14
+ const key = request.headers.get('__queue');
15
+ request.headers.delete('__queue');
16
+
17
+ const getResponse = async () => await next(request);
18
+
19
+ if (key == null) return await getResponse();
20
+ const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse); // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
21
+ // gap to ensure that node won't reject the nonce
22
+
23
+ requestQueues.set(key, req.then(async () => await pause(750)));
24
+ return await req;
25
+ }
26
+
27
+ },
28
+ position: 'perCall'
29
+ };
30
+ };
31
+ export const genCombineGetRequestsPolicy = () => {
32
+ const pendingGetRequests = new Map();
33
+ return {
34
+ policy: {
35
+ name: 'combine-requests',
36
+
37
+ async sendRequest(request, next) {
38
+ var _pendingGetRequests$g;
39
+
40
+ if (request.method !== 'GET') return await next(request);
41
+ const key = JSON.stringify([request.url, request.body]);
42
+ const response = (_pendingGetRequests$g = pendingGetRequests.get(key)) !== null && _pendingGetRequests$g !== void 0 ? _pendingGetRequests$g : next(request);
43
+ pendingGetRequests.set(key, response);
44
+
45
+ try {
46
+ return await response;
47
+ } finally {
48
+ pendingGetRequests.delete(key);
49
+ }
50
+ }
51
+
52
+ },
53
+ position: 'perCall'
54
+ };
55
+ };
56
+ export const genErrorFormatterPolicy = getMessage => ({
57
+ policy: {
58
+ name: 'error-formatter',
59
+
60
+ async sendRequest(request, next) {
61
+ try {
62
+ return await next(request);
63
+ } catch (error) {
64
+ var _error$response;
65
+
66
+ if (!(error instanceof RestError) || error.request == null) throw error;
67
+ if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.bodyAsText) == null) throw error;
68
+ let body;
69
+
70
+ try {
71
+ body = JSON.parse(error.response.bodyAsText);
72
+ } catch (e) {
73
+ throw error;
74
+ }
75
+
76
+ error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
77
+ const message = getMessage(body);
78
+ if (message !== '') error.message += `:${message}`;
79
+ throw error;
80
+ }
81
+ }
82
+
83
+ },
84
+ position: 'perCall'
85
+ });
86
+ export const genVersionCheckPolicy = (name, ignorePath, versionPromise, geVersion, ltVersion) => ({
87
+ name: 'version-check',
88
+
89
+ async sendRequest(request, next) {
90
+ if (new URL(request.url).pathname === ignorePath) return await next(request);
91
+ const args = [await versionPromise, geVersion, ltVersion];
92
+ if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
93
+ return await next(request);
94
+ }
95
+
96
+ });
97
+ //# sourceMappingURL=autorest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autorest.mjs","names":["RestError","pause","semverSatisfies","UnsupportedVersionError","genRequestQueuesPolicy","requestQueues","Map","policy","name","sendRequest","request","next","key","headers","get","delete","getResponse","req","Promise","resolve","then","set","position","genCombineGetRequestsPolicy","pendingGetRequests","method","JSON","stringify","url","body","response","genErrorFormatterPolicy","getMessage","error","bodyAsText","parse","e","message","URL","pathname","slice","genVersionCheckPolicy","ignorePath","versionPromise","geVersion","ltVersion","args"],"sources":["../../src/utils/autorest.ts"],"sourcesContent":["import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline'\nimport { AdditionalPolicyConfig } from '@azure/core-client'\nimport { pause } from './other'\nimport semverSatisfies from './semver-satisfies'\nimport { UnsupportedVersionError } from './errors'\n\nexport const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {\n const requestQueues = new Map<string, Promise<unknown>>()\n\n return {\n policy: {\n name: 'request-queues',\n async sendRequest (request, next) {\n const key = request.headers.get('__queue')\n request.headers.delete('__queue')\n const getResponse = async (): Promise<PipelineResponse> => await next(request)\n if (key == null) return await getResponse()\n const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse)\n // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803\n // gap to ensure that node won't reject the nonce\n requestQueues.set(key, req.then(async () => await pause(750)))\n return await req\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {\n const pendingGetRequests = new Map<string, Promise<PipelineResponse>>()\n\n return {\n policy: {\n name: 'combine-requests',\n async sendRequest (request, next) {\n if (request.method !== 'GET') return await next(request)\n const key = JSON.stringify([request.url, request.body])\n const response = pendingGetRequests.get(key) ?? next(request)\n pendingGetRequests.set(key, response)\n try {\n return await response\n } finally {\n pendingGetRequests.delete(key)\n }\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genErrorFormatterPolicy = (\n getMessage: (b: any) => string\n): AdditionalPolicyConfig => ({\n policy: {\n name: 'error-formatter',\n async sendRequest (request, next) {\n try {\n return await next(request)\n } catch (error) {\n if (!(error instanceof RestError) || error.request == null) throw error\n if (error.response?.bodyAsText == null) throw error\n\n let body\n try {\n body = JSON.parse(error.response.bodyAsText)\n } catch (e) {\n throw error\n }\n error.message = `${new URL(error.request.url).pathname.slice(1)} error`\n const message = getMessage(body)\n if (message !== '') error.message += `:${message}`\n throw error\n }\n }\n },\n position: 'perCall'\n})\n\nexport const genVersionCheckPolicy = (\n name: string, ignorePath: string,\n versionPromise: Promise<string>, geVersion: string, ltVersion: string\n): PipelinePolicy => ({\n name: 'version-check',\n async sendRequest (request, next) {\n if (new URL(request.url).pathname === ignorePath) return await next(request)\n const args = [await versionPromise, geVersion, ltVersion] as const\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args)\n return await next(request)\n }\n})\n"],"mappings":"AAAA,SAASA,SAAT,QAA4D,2BAA5D;SAESC,K;OACFC,e;SACEC,uB;AAET,OAAO,MAAMC,sBAAsB,GAAG,MAA8B;EAClE,MAAMC,aAAa,GAAG,IAAIC,GAAJ,EAAtB;EAEA,OAAO;IACLC,MAAM,EAAE;MACNC,IAAI,EAAE,gBADA;;MAEN,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hC;AA4BP,OAAO,MAAMmB,qBAAqB,GAAG,CACnCjC,IADmC,EACrBkC,UADqB,EAEnCC,cAFmC,EAEFC,SAFE,EAEiBC,SAFjB,MAGf;EACpBrC,IAAI,EAAE,eADc;;EAEpB,MAAMC,WAAN,CAAmBC,OAAnB,EAA4BC,IAA5B,EAAkC;IAChC,IAAI,IAAI2B,GAAJ,CAAQ5B,OAAO,CAACkB,GAAhB,EAAqBW,QAArB,KAAkCG,UAAtC,EAAkD,OAAO,MAAM/B,IAAI,CAACD,OAAD,CAAjB;IAClD,MAAMoC,IAAI,GAAG,CAAC,MAAMH,cAAP,EAAuBC,SAAvB,EAAkCC,SAAlC,CAAb;IACA,IAAI,CAAC3C,eAAe,CAAC,GAAG4C,IAAJ,CAApB,EAA+B,MAAM,IAAI3C,uBAAJ,CAA4BK,IAA5B,EAAkC,GAAGsC,IAArC,CAAN;IAC/B,OAAO,MAAMnC,IAAI,CAACD,OAAD,CAAjB;EACD;;AAPmB,CAHe,CAA9B"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Big Number Helpers
3
+ */
4
+ import BigNumber from 'bignumber.js';
5
+ /**
6
+ * Check if value is BigNumber, Number, BigInt or number string representation
7
+ * @param number - number to check
8
+ */
9
+ export declare const isBigNumber: (number: string | number | bigint | BigNumber) => boolean;
10
+ /**
11
+ * BigNumber ceil operation
12
+ */
13
+ export declare const ceil: (bigNumber: BigNumber) => BigNumber;
@@ -0,0 +1,23 @@
1
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
+
3
+ /**
4
+ * Big Number Helpers
5
+ */
6
+ import BigNumber from 'bignumber.js';
7
+ /**
8
+ * Check if value is BigNumber, Number, BigInt or number string representation
9
+ * @param number - number to check
10
+ */
11
+
12
+ export const isBigNumber = number => {
13
+ var _context;
14
+
15
+ if (typeof number === 'bigint') return true;
16
+ return _includesInstanceProperty(_context = ['number', 'object', 'string']).call(_context, typeof number) && (!isNaN(number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
17
+ };
18
+ /**
19
+ * BigNumber ceil operation
20
+ */
21
+
22
+ export const ceil = bigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL);
23
+ //# sourceMappingURL=bignumber.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bignumber.mjs","names":["BigNumber","isBigNumber","number","isNaN","Number","isInteger","ceil","bigNumber","integerValue","ROUND_CEIL"],"sources":["../../src/utils/bignumber.ts"],"sourcesContent":["/**\n * Big Number Helpers\n */\nimport BigNumber from 'bignumber.js'\n\n/**\n * Check if value is BigNumber, Number, BigInt or number string representation\n * @param number - number to check\n */\nexport const isBigNumber = (number: string | number | bigint | BigNumber): boolean => {\n if (typeof number === 'bigint') return true\n return ['number', 'object', 'string'].includes(typeof number) &&\n (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))\n}\n\n/**\n * BigNumber ceil operation\n */\nexport const ceil = (bigNumber: BigNumber): BigNumber => bigNumber\n .integerValue(BigNumber.ROUND_CEIL)\n"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,MAAD,IAA2D;EAAA;;EACpF,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC,OAAO,IAAP;EAChC,OAAO,sCAAC,QAAD,EAAW,QAAX,EAAqB,QAArB,kBAAwC,OAAOA,MAA/C,MACJ,CAACC,KAAK,CAACD,MAAD,CAAN,IAA4BE,MAAM,CAACC,SAAP,CAAiBH,MAAjB,CAA5B,IAAwDF,SAAS,CAACC,WAAV,CAAsBC,MAAtB,CADpD,CAAP;AAED,CAJM;AAMP;AACA;AACA;;AACA,OAAO,MAAMI,IAAI,GAAIC,SAAD,IAAqCA,SAAS,CAC/DC,YADsD,CACzCR,SAAS,CAACS,UAD+B,CAAlD"}
@@ -1,29 +1,26 @@
1
1
  /// <reference types="node" />
2
2
  import BigNumber from 'bignumber.js';
3
- /**
4
- * Bytes module
5
- * @module @aeternity/aepp-sdk/es/utils/bytes
6
- * @example import { Crypto } from '@aeternity/aepp-sdk'
7
- */
8
3
  /**
9
4
  * Convert bignumber to byte array
10
- * @param {BigNumber} x bignumber instance
11
- * @return Buffer
5
+ * @param x - bignumber instance
6
+ * @returns Buffer
12
7
  */
13
8
  export declare function bigNumberToByteArray(x: BigNumber): Buffer;
14
9
  /**
15
10
  * Convert string, number, or BigNumber to byte array
16
- * @param {null|string|number|BigNumber} val
17
- * @param {boolean} big enables force conversion to BigNumber
18
- * @return Buffer
11
+ * @param val - value to convert
12
+ * @param big - enables force conversion to BigNumber
13
+ * @returns Buffer
19
14
  */
20
15
  export declare function toBytes(val?: null | string | number | BigNumber, big?: boolean): Buffer;
21
16
  /**
22
17
  * Convert a string to a Buffer. If encoding is not specified, hex-encoding
23
18
  * will be used if the input is valid hex. If the input is valid base64 but
24
19
  * not valid hex, base64 will be used. Otherwise, utf8 will be used.
25
- * @param {string} str String to be converted.
26
- * @param {string} [enc] Encoding of the input string.
27
- * @return {buffer} Buffer containing the input data.
20
+ * @param str - String to be converted.
21
+ * @param enc - Encoding of the input string.
22
+ * @returns Buffer containing the input data.
28
23
  */
29
24
  export declare function str2buf(str: string, enc?: BufferEncoding): Buffer;
25
+ export declare const bytesToHex: (b: Uint8Array) => string;
26
+ export declare const hexToBytes: (s: string) => Uint8Array;
@@ -1,3 +1,8 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
1
6
  /*
2
7
  * ISC License (ISC)
3
8
  * Copyright 2018 aeternity developers
@@ -15,30 +20,25 @@
15
20
  * PERFORMANCE OF THIS SOFTWARE.
16
21
  */
17
22
  import BigNumber from 'bignumber.js';
18
- import { isBase64, isHex } from './string';
19
- /**
20
- * Bytes module
21
- * @module @aeternity/aepp-sdk/es/utils/bytes
22
- * @example import { Crypto } from '@aeternity/aepp-sdk'
23
- */
24
-
23
+ import { NoSerializerFoundError, TypeError } from "./errors.mjs";
24
+ import { isBase64, isHex } from "./string.mjs";
25
25
  /**
26
26
  * Convert bignumber to byte array
27
- * @param {BigNumber} x bignumber instance
28
- * @return Buffer
27
+ * @param x - bignumber instance
28
+ * @returns Buffer
29
29
  */
30
30
 
31
31
  export function bigNumberToByteArray(x) {
32
- if (!x.isInteger()) throw new Error(`Unexpected not integer value: ${x.toFixed()}`);
32
+ if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`);
33
33
  let hexString = x.toString(16);
34
34
  if (hexString.length % 2 === 1) hexString = '0' + hexString;
35
- return Buffer.from(hexString, 'hex');
35
+ return _Buffer.from(hexString, 'hex');
36
36
  }
37
37
  /**
38
38
  * Convert string, number, or BigNumber to byte array
39
- * @param {null|string|number|BigNumber} val
40
- * @param {boolean} big enables force conversion to BigNumber
41
- * @return Buffer
39
+ * @param val - value to convert
40
+ * @param big - enables force conversion to BigNumber
41
+ * @returns Buffer
42
42
  */
43
43
 
44
44
  export function toBytes(val) {
@@ -46,7 +46,7 @@ export function toBytes(val) {
46
46
  // Encode a value to bytes.
47
47
  // If the value is an int it will be encoded as bytes big endian
48
48
  // Raises ValueError if the input is not an int or string
49
- if (val === undefined || val === null) return Buffer.from([]);
49
+ if (val === undefined || val === null) return _Buffer.from([]);
50
50
 
51
51
  if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {
52
52
  if (!BigNumber.isBigNumber(val)) val = new BigNumber(val);
@@ -54,21 +54,25 @@ export function toBytes(val) {
54
54
  }
55
55
 
56
56
  if (typeof val === 'string') {
57
- return Buffer.from(val);
57
+ return _Buffer.from(val);
58
58
  }
59
59
 
60
- throw new Error('Byte serialization not supported');
60
+ throw new NoSerializerFoundError();
61
61
  }
62
62
  /**
63
63
  * Convert a string to a Buffer. If encoding is not specified, hex-encoding
64
64
  * will be used if the input is valid hex. If the input is valid base64 but
65
65
  * not valid hex, base64 will be used. Otherwise, utf8 will be used.
66
- * @param {string} str String to be converted.
67
- * @param {string} [enc] Encoding of the input string.
68
- * @return {buffer} Buffer containing the input data.
66
+ * @param str - String to be converted.
67
+ * @param enc - Encoding of the input string.
68
+ * @returns Buffer containing the input data.
69
69
  */
70
70
 
71
71
  export function str2buf(str, enc) {
72
- return Buffer.from(str, enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined));
72
+ var _ref;
73
+
74
+ return _Buffer.from(str, (_ref = enc !== null && enc !== void 0 ? enc : isHex(str) ? 'hex' : undefined) !== null && _ref !== void 0 ? _ref : isBase64(str) ? 'base64' : undefined);
73
75
  }
74
- //# sourceMappingURL=bytes.js.map
76
+ export const bytesToHex = b => _Buffer.from(b).toString('hex');
77
+ export const hexToBytes = s => _Buffer.from(s, 'hex');
78
+ //# sourceMappingURL=bytes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.mjs","names":["BigNumber","NoSerializerFoundError","TypeError","isBase64","isHex","bigNumberToByteArray","x","isInteger","toFixed","hexString","toString","length","from","toBytes","val","big","undefined","Number","isBigNumber","str2buf","str","enc","bytesToHex","b","hexToBytes","s"],"sources":["../../src/utils/bytes.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport BigNumber from 'bignumber.js'\nimport { NoSerializerFoundError, TypeError } from './errors'\nimport { isBase64, isHex } from './string'\n\n/**\n * Convert bignumber to byte array\n * @param x - bignumber instance\n * @returns Buffer\n */\nexport function bigNumberToByteArray (x: BigNumber): Buffer {\n if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)\n let hexString = x.toString(16)\n if (hexString.length % 2 === 1) hexString = '0' + hexString\n return Buffer.from(hexString, 'hex')\n}\n\n/**\n * Convert string, number, or BigNumber to byte array\n * @param val - value to convert\n * @param big - enables force conversion to BigNumber\n * @returns Buffer\n */\nexport function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {\n // Encode a value to bytes.\n // If the value is an int it will be encoded as bytes big endian\n // Raises ValueError if the input is not an int or string\n\n if (val === undefined || val === null) return Buffer.from([])\n if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {\n if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)\n return bigNumberToByteArray(val)\n }\n if (typeof val === 'string') {\n return Buffer.from(val)\n }\n throw new NoSerializerFoundError()\n}\n\n/**\n * Convert a string to a Buffer. If encoding is not specified, hex-encoding\n * will be used if the input is valid hex. If the input is valid base64 but\n * not valid hex, base64 will be used. Otherwise, utf8 will be used.\n * @param str - String to be converted.\n * @param enc - Encoding of the input string.\n * @returns Buffer containing the input data.\n */\nexport function str2buf (str: string, enc?: BufferEncoding): Buffer {\n return Buffer.from(\n str,\n enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)\n )\n}\n\nexport const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString('hex')\n\nexport const hexToBytes = (s: string): Uint8Array => Buffer.from(s, 'hex')\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,M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