steamutils 1.5.4 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. package/.idea/codeStyles/Project.xml +0 -1
  2. package/.idea/gbrowser_project.xml +11 -0
  3. package/.idea/git_toolbox_blame.xml +6 -0
  4. package/.idea/git_toolbox_prj.xml +15 -0
  5. package/.prettierrc.json +3 -3
  6. package/SteamClient.js +3184 -3184
  7. package/_steamproto.js +39 -39
  8. package/axios.js +84 -84
  9. package/bufferHelpers.js +115 -115
  10. package/cheerio.js +103 -103
  11. package/const.js +518 -518
  12. package/create_proto.js +96 -96
  13. package/create_remote_file.js +153 -153
  14. package/full_steamproto.js +39 -39
  15. package/helpers/protos.js +48 -48
  16. package/index.js +7930 -7930
  17. package/package.json +1 -1
  18. package/protos/csgo/base_gcmessages.proto +553 -553
  19. package/protos/csgo/base_gcmessages_csgo.proto +547 -547
  20. package/protos/csgo/c_peer2peer_netmessages.proto +55 -55
  21. package/protos/csgo/clientmessages.proto +48 -48
  22. package/protos/csgo/connectionless_netmessages.proto +17 -17
  23. package/protos/csgo/cs_gameevents.proto +35 -35
  24. package/protos/csgo/cs_usercmd.proto +34 -34
  25. package/protos/csgo/cstrike15_usermessages.proto +592 -592
  26. package/protos/csgo/demo.proto +165 -165
  27. package/protos/csgo/econ_gcmessages.proto +219 -219
  28. package/protos/csgo/enums_clientserver.proto +1529 -1529
  29. package/protos/csgo/fatdemo.proto +125 -125
  30. package/protos/csgo/gameevents.proto +120 -120
  31. package/protos/csgo/gcsdk_gcmessages.proto +323 -323
  32. package/protos/csgo/gcsystemmsgs.proto +243 -243
  33. package/protos/csgo/netmessages.proto +618 -618
  34. package/protos/csgo/networkbasetypes.proto +246 -246
  35. package/protos/csgo/networksystem_protomessages.proto +17 -17
  36. package/protos/csgo/steamdatagram_messages_auth.proto +65 -65
  37. package/protos/csgo/steamdatagram_messages_sdr.proto +534 -534
  38. package/protos/csgo/steammessages_cloud.steamworkssdk.proto +68 -68
  39. package/protos/csgo/steammessages_gamenetworkingui.proto +61 -61
  40. package/protos/csgo/steammessages_helprequest.steamworkssdk.proto +22 -22
  41. package/protos/csgo/steammessages_oauth.steamworkssdk.proto +18 -18
  42. package/protos/csgo/steammessages_player.steamworkssdk.proto +254 -254
  43. package/protos/csgo/steammessages_publishedfile.steamworkssdk.proto +233 -233
  44. package/protos/csgo/steamnetworkingsockets_messages.proto +205 -205
  45. package/protos/csgo/steamnetworkingsockets_messages_certs.proto +39 -39
  46. package/protos/csgo/steamnetworkingsockets_messages_udp.proto +75 -75
  47. package/protos/csgo/te.proto +259 -259
  48. package/protos/csgo/uifontfile_format.proto +13 -13
  49. package/protos/csgo/usercmd.proto +39 -39
  50. package/protos/csgo/usermessages.proto +752 -752
  51. package/protos/google/protobuf/descriptor.proto +281 -281
  52. package/protos/steam/clientmetrics.proto +45 -45
  53. package/protos/steam/content_manifest.proto +62 -62
  54. package/protos/steam/contenthubs.proto +41 -41
  55. package/protos/steam/encrypted_app_ticket.proto +10 -10
  56. package/protos/steam/enums.proto +501 -501
  57. package/protos/steam/enums_clientserver.proto +1508 -1508
  58. package/protos/steam/enums_productinfo.proto +14 -14
  59. package/protos/steam/htmlmessages.proto +1039 -1039
  60. package/protos/steam/offline_ticket.proto +8 -8
  61. package/protos/steam/steamdatagram_messages_auth.proto +65 -65
  62. package/protos/steam/steamdatagram_messages_sdr.proto +533 -533
  63. package/protos/steam/steammessages_accounthardware.steamclient.proto +167 -167
  64. package/protos/steam/steammessages_appoverview.proto +204 -204
  65. package/protos/steam/steammessages_auth.steamclient.proto +375 -375
  66. package/protos/steam/steammessages_broadcast.steamclient.proto +618 -618
  67. package/protos/steam/steammessages_chat.steamclient.proto +1070 -1070
  68. package/protos/steam/steammessages_client_objects.proto +649 -649
  69. package/protos/steam/steammessages_clientlanp2p.proto +43 -43
  70. package/protos/steam/steammessages_clientmetrics.steamclient.proto +192 -192
  71. package/protos/steam/steammessages_clientnotificationtypes.proto +250 -250
  72. package/protos/steam/steammessages_clientserver.proto +392 -392
  73. package/protos/steam/steammessages_clientserver_2.proto +771 -771
  74. package/protos/steam/steammessages_clientserver_appinfo.proto +131 -131
  75. package/protos/steam/steammessages_clientserver_friends.proto +260 -260
  76. package/protos/steam/steammessages_clientserver_gameservers.proto +159 -159
  77. package/protos/steam/steammessages_clientserver_lbs.proto +70 -70
  78. package/protos/steam/steammessages_clientserver_login.proto +167 -167
  79. package/protos/steam/steammessages_clientserver_mms.proto +233 -233
  80. package/protos/steam/steammessages_clientserver_ucm.proto +207 -207
  81. package/protos/steam/steammessages_clientserver_uds.proto +125 -125
  82. package/protos/steam/steammessages_clientserver_ufs.proto +45 -45
  83. package/protos/steam/steammessages_clientserver_userstats.proto +80 -80
  84. package/protos/steam/steammessages_cloud.steamclient.proto +422 -422
  85. package/protos/steam/steammessages_contentsystem.steamclient.proto +123 -123
  86. package/protos/steam/steammessages_credentials.steamclient.proto +96 -96
  87. package/protos/steam/steammessages_datapublisher.steamclient.proto +102 -102
  88. package/protos/steam/steammessages_depotbuilder.steamclient.proto +99 -99
  89. package/protos/steam/steammessages_deviceauth.steamclient.proto +169 -169
  90. package/protos/steam/steammessages_econ.steamclient.proto +137 -137
  91. package/protos/steam/steammessages_familygroups.steamclient.proto +441 -441
  92. package/protos/steam/steammessages_friendmessages.steamclient.proto +141 -141
  93. package/protos/steam/steammessages_gamenetworking.steamclient.proto +25 -25
  94. package/protos/steam/steammessages_gamenetworkingui.proto +61 -61
  95. package/protos/steam/steammessages_gamenotifications.steamclient.proto +131 -131
  96. package/protos/steam/steammessages_gameservers.steamclient.proto +136 -136
  97. package/protos/steam/steammessages_hiddevices.proto +157 -157
  98. package/protos/steam/steammessages_inventory.steamclient.proto +172 -172
  99. package/protos/steam/steammessages_linkfilter.steamclient.proto +39 -39
  100. package/protos/steam/steammessages_lobbymatchmaking.steamclient.proto +29 -29
  101. package/protos/steam/steammessages_market.steamclient.proto +22 -22
  102. package/protos/steam/steammessages_marketingmessages.steamclient.proto +273 -273
  103. package/protos/steam/steammessages_offline.steamclient.proto +33 -33
  104. package/protos/steam/steammessages_parental.steamclient.proto +262 -262
  105. package/protos/steam/steammessages_parties.steamclient.proto +75 -75
  106. package/protos/steam/steammessages_partnerapps.steamclient.proto +106 -106
  107. package/protos/steam/steammessages_player.steamclient.proto +915 -915
  108. package/protos/steam/steammessages_publishedfile.steamclient.proto +737 -737
  109. package/protos/steam/steammessages_qms.steamclient.proto +111 -111
  110. package/protos/steam/steammessages_remoteclient.proto +100 -100
  111. package/protos/steam/steammessages_remoteclient_discovery.proto +244 -244
  112. package/protos/steam/steammessages_remoteclient_service.steamclient.proto +31 -31
  113. package/protos/steam/steammessages_remoteclient_service_messages.proto +217 -217
  114. package/protos/steam/steammessages_remoteplay.proto +975 -975
  115. package/protos/steam/steammessages_secrets.steamclient.proto +35 -35
  116. package/protos/steam/steammessages_shader.steamclient.proto +89 -89
  117. package/protos/steam/steammessages_site_license.steamclient.proto +103 -103
  118. package/protos/steam/steammessages_sitelicenseclient.proto +38 -38
  119. package/protos/steam/steammessages_siteserverui.proto +130 -130
  120. package/protos/steam/steammessages_steamtv.steamclient.proto +533 -533
  121. package/protos/steam/steammessages_store.steamclient.proto +404 -404
  122. package/protos/steam/steammessages_storebrowse.steamclient.proto +457 -457
  123. package/protos/steam/steammessages_timedtrial.steamclient.proto +40 -40
  124. package/protos/steam/steammessages_twofactor.steamclient.proto +157 -157
  125. package/protos/steam/steammessages_unified_test.steamclient.proto +51 -51
  126. package/protos/steam/steammessages_useraccount.steamclient.proto +211 -211
  127. package/protos/steam/steammessages_vac.steamclient.proto +37 -37
  128. package/protos/steam/steammessages_video.steamclient.proto +68 -68
  129. package/protos/steam/steammessages_virtualcontroller.proto +138 -138
  130. package/protos/steam/steammessages_workshop.steamclient.proto +19 -19
  131. package/protos/steam/steamnetworkingsockets_messages.proto +205 -205
  132. package/protos/steam/steamnetworkingsockets_messages_certs.proto +39 -39
  133. package/protos/steam/steamnetworkingsockets_messages_udp.proto +75 -75
  134. package/protos/steam/webuimessages_achievements.proto +29 -29
  135. package/protos/steam/webuimessages_gamenotes.proto +21 -21
  136. package/protos/steam/webuimessages_gamescope.proto +57 -57
  137. package/protos/steam/webuimessages_steamengine.proto +41 -41
  138. package/protos/steam/webuimessages_steamos.proto +114 -114
  139. package/protos/steam/webuimessages_storagedevicemanager.proto +110 -110
  140. package/protos/steam/webuimessages_systemmanager.proto +17 -17
  141. package/protos/steam/webuimessages_transport.proto +22 -22
  142. package/protos/steam/webuimessages_transportvalidation.proto +111 -111
  143. package/protos/webui/common.proto +4024 -4024
  144. package/protos/webui/service_accountcart.proto +153 -153
  145. package/protos/webui/service_accountlinking.proto +27 -27
  146. package/protos/webui/service_accountprivacy.proto +42 -42
  147. package/protos/webui/service_accountprivateapps.proto +34 -34
  148. package/protos/webui/service_auction.proto +97 -97
  149. package/protos/webui/service_authentication.proto +222 -222
  150. package/protos/webui/service_authenticationsupport.proto +74 -74
  151. package/protos/webui/service_broadcast.proto +562 -562
  152. package/protos/webui/service_chat.proto +11 -11
  153. package/protos/webui/service_chatroom.proto +810 -810
  154. package/protos/webui/service_chatusability.proto +107 -107
  155. package/protos/webui/service_checkout.proto +84 -84
  156. package/protos/webui/service_clan.proto +41 -41
  157. package/protos/webui/service_clanchatrooms.proto +25 -25
  158. package/protos/webui/service_clanfaqs.proto +202 -202
  159. package/protos/webui/service_clientcomm.proto +151 -151
  160. package/protos/webui/service_clientmetrics.proto +22 -22
  161. package/protos/webui/service_cloud.proto +222 -222
  162. package/protos/webui/service_cloudconfigstore.proto +51 -51
  163. package/protos/webui/service_cloudgaming.proto +30 -30
  164. package/protos/webui/service_community.proto +365 -365
  165. package/protos/webui/service_dailydeal.proto +89 -89
  166. package/protos/webui/service_econ.proto +134 -134
  167. package/protos/webui/service_embedded.proto +24 -24
  168. package/protos/webui/service_experimentservice.proto +6 -6
  169. package/protos/webui/service_familygroups.proto +355 -355
  170. package/protos/webui/service_fovasvideo.proto +15 -15
  171. package/protos/webui/service_friendmessages.proto +133 -133
  172. package/protos/webui/service_friendslist.proto +70 -70
  173. package/protos/webui/service_gamenotes.proto +15 -15
  174. package/protos/webui/service_gamerecording.proto +265 -265
  175. package/protos/webui/service_gamerecordingclip.proto +85 -85
  176. package/protos/webui/service_gamerecordingdebug.proto +52 -52
  177. package/protos/webui/service_helprequestlogs.proto +16 -16
  178. package/protos/webui/service_loyaltyrewards.proto +252 -252
  179. package/protos/webui/service_marketingmessages.proto +215 -215
  180. package/protos/webui/service_mobileapp.proto +18 -18
  181. package/protos/webui/service_mobileauth.proto +24 -24
  182. package/protos/webui/service_mobiledevice.proto +26 -26
  183. package/protos/webui/service_mobileperaccount.proto +31 -31
  184. package/protos/webui/service_news.proto +110 -110
  185. package/protos/webui/service_parental.proto +258 -258
  186. package/protos/webui/service_partnermembershipinvite.proto +34 -34
  187. package/protos/webui/service_partnerstorebrowse.proto +28 -28
  188. package/protos/webui/service_phone.proto +51 -51
  189. package/protos/webui/service_physicalgoods.proto +15 -15
  190. package/protos/webui/service_player.proto +918 -918
  191. package/protos/webui/service_promotioneventinvites.proto +109 -109
  192. package/protos/webui/service_promotionplanning.proto +186 -186
  193. package/protos/webui/service_promotionstats.proto +23 -23
  194. package/protos/webui/service_publishedfile.proto +714 -714
  195. package/protos/webui/service_publishing.proto +200 -200
  196. package/protos/webui/service_quest.proto +127 -127
  197. package/protos/webui/service_salefeature.proto +373 -373
  198. package/protos/webui/service_saleitemrewards.proto +54 -54
  199. package/protos/webui/service_shoppingcart.proto +152 -152
  200. package/protos/webui/service_steamawards.proto +76 -76
  201. package/protos/webui/service_steamcharts.proto +75 -75
  202. package/protos/webui/service_steamengine.proto +36 -36
  203. package/protos/webui/service_steamlearn.proto +876 -876
  204. package/protos/webui/service_steamnotification.proto +73 -73
  205. package/protos/webui/service_steamtv.proto +495 -495
  206. package/protos/webui/service_steamvrvoicechat.proto +67 -67
  207. package/protos/webui/service_steamvrwebrtc.proto +48 -48
  208. package/protos/webui/service_storagedevicemanager.proto +104 -104
  209. package/protos/webui/service_store.proto +359 -359
  210. package/protos/webui/service_storeappsimilarity.proto +76 -76
  211. package/protos/webui/service_storebrowse.proto +103 -103
  212. package/protos/webui/service_storemarketing.proto +44 -44
  213. package/protos/webui/service_storequery.proto +103 -103
  214. package/protos/webui/service_storesales.proto +87 -87
  215. package/protos/webui/service_storetopsellers.proto +44 -44
  216. package/protos/webui/service_systemmanager.proto +11 -11
  217. package/protos/webui/service_test_transporterror.proto +6 -6
  218. package/protos/webui/service_transportauth.proto +17 -17
  219. package/protos/webui/service_transportvalidation.proto +69 -69
  220. package/protos/webui/service_twofactor.proto +170 -170
  221. package/protos/webui/service_useraccount.proto +142 -142
  222. package/protos/webui/service_usergameactivity.proto +34 -34
  223. package/protos/webui/service_usergamenotes.proto +70 -70
  224. package/protos/webui/service_usernews.proto +68 -68
  225. package/protos/webui/service_userreviews.proto +97 -97
  226. package/protos/webui/service_video.proto +50 -50
  227. package/protos/webui/service_videoclip.proto +62 -62
  228. package/protos/webui/service_voicechat.proto +139 -139
  229. package/protos/webui/service_webrtc.proto +52 -52
  230. package/remote.js +2240 -2240
  231. package/steamproto.js +146 -146
  232. package/utils.js +1084 -1050
  233. package/.idea/deployment.xml +0 -14
package/utils.js CHANGED
@@ -1,1050 +1,1084 @@
1
- import moment from "moment";
2
- import SteamTotp from "steam-totp";
3
- import { EAuthTokenPlatformType } from "./const.js";
4
- import fs from "fs";
5
- import axios from "axios";
6
-
7
- const isBrowser = typeof window !== "undefined";
8
- const g_rgCurrencyData = {
9
- USD: {
10
- strCode: "USD",
11
- eCurrencyCode: 1,
12
- strSymbol: "$",
13
- bSymbolIsPrefix: true,
14
- bWholeUnitsOnly: false,
15
- strDecimalSymbol: ".",
16
- strThousandsSeparator: ",",
17
- strSymbolAndNumberSeparator: "",
18
- },
19
- GBP: {
20
- strCode: "GBP",
21
- eCurrencyCode: 2,
22
- strSymbol: "\u00a3",
23
- bSymbolIsPrefix: true,
24
- bWholeUnitsOnly: false,
25
- strDecimalSymbol: ".",
26
- strThousandsSeparator: ",",
27
- strSymbolAndNumberSeparator: "",
28
- },
29
- EUR: {
30
- strCode: "EUR",
31
- eCurrencyCode: 3,
32
- strSymbol: "\u20ac",
33
- bSymbolIsPrefix: false,
34
- bWholeUnitsOnly: false,
35
- strDecimalSymbol: ",",
36
- strThousandsSeparator: " ",
37
- strSymbolAndNumberSeparator: "",
38
- },
39
- CHF: {
40
- strCode: "CHF",
41
- eCurrencyCode: 4,
42
- strSymbol: "CHF",
43
- bSymbolIsPrefix: true,
44
- bWholeUnitsOnly: false,
45
- strDecimalSymbol: ".",
46
- strThousandsSeparator: " ",
47
- strSymbolAndNumberSeparator: " ",
48
- },
49
- RUB: {
50
- strCode: "RUB",
51
- eCurrencyCode: 5,
52
- strSymbol: "p\u0443\u0431.",
53
- bSymbolIsPrefix: false,
54
- bWholeUnitsOnly: true,
55
- strDecimalSymbol: ",",
56
- strThousandsSeparator: "",
57
- strSymbolAndNumberSeparator: " ",
58
- },
59
- BRL: {
60
- strCode: "BRL",
61
- eCurrencyCode: 7,
62
- strSymbol: "R$",
63
- bSymbolIsPrefix: true,
64
- bWholeUnitsOnly: false,
65
- strDecimalSymbol: ",",
66
- strThousandsSeparator: ".",
67
- strSymbolAndNumberSeparator: " ",
68
- },
69
- JPY: {
70
- strCode: "JPY",
71
- eCurrencyCode: 8,
72
- strSymbol: "\u00a5",
73
- bSymbolIsPrefix: true,
74
- bWholeUnitsOnly: true,
75
- strDecimalSymbol: ".",
76
- strThousandsSeparator: ",",
77
- strSymbolAndNumberSeparator: " ",
78
- },
79
- NOK: {
80
- strCode: "NOK",
81
- eCurrencyCode: 9,
82
- strSymbol: "kr",
83
- bSymbolIsPrefix: false,
84
- bWholeUnitsOnly: false,
85
- strDecimalSymbol: ",",
86
- strThousandsSeparator: ".",
87
- strSymbolAndNumberSeparator: " ",
88
- },
89
- IDR: {
90
- strCode: "IDR",
91
- eCurrencyCode: 10,
92
- strSymbol: "Rp",
93
- bSymbolIsPrefix: true,
94
- bWholeUnitsOnly: true,
95
- strDecimalSymbol: ".",
96
- strThousandsSeparator: " ",
97
- strSymbolAndNumberSeparator: " ",
98
- },
99
- MYR: {
100
- strCode: "MYR",
101
- eCurrencyCode: 11,
102
- strSymbol: "RM",
103
- bSymbolIsPrefix: true,
104
- bWholeUnitsOnly: false,
105
- strDecimalSymbol: ".",
106
- strThousandsSeparator: ",",
107
- strSymbolAndNumberSeparator: "",
108
- },
109
- PHP: {
110
- strCode: "PHP",
111
- eCurrencyCode: 12,
112
- strSymbol: "P",
113
- bSymbolIsPrefix: true,
114
- bWholeUnitsOnly: false,
115
- strDecimalSymbol: ".",
116
- strThousandsSeparator: ",",
117
- strSymbolAndNumberSeparator: "",
118
- },
119
- SGD: {
120
- strCode: "SGD",
121
- eCurrencyCode: 13,
122
- strSymbol: "S$",
123
- bSymbolIsPrefix: true,
124
- bWholeUnitsOnly: false,
125
- strDecimalSymbol: ".",
126
- strThousandsSeparator: ",",
127
- strSymbolAndNumberSeparator: "",
128
- },
129
- THB: {
130
- strCode: "THB",
131
- eCurrencyCode: 14,
132
- strSymbol: "\u0e3f",
133
- bSymbolIsPrefix: true,
134
- bWholeUnitsOnly: false,
135
- strDecimalSymbol: ".",
136
- strThousandsSeparator: ",",
137
- strSymbolAndNumberSeparator: "",
138
- },
139
- VND: {
140
- strCode: "VND",
141
- eCurrencyCode: 15,
142
- strSymbol: "\u20ab",
143
- bSymbolIsPrefix: false,
144
- bWholeUnitsOnly: true,
145
- strDecimalSymbol: ",",
146
- strThousandsSeparator: ".",
147
- strSymbolAndNumberSeparator: "",
148
- },
149
- KRW: {
150
- strCode: "KRW",
151
- eCurrencyCode: 16,
152
- strSymbol: "\u20a9",
153
- bSymbolIsPrefix: true,
154
- bWholeUnitsOnly: true,
155
- strDecimalSymbol: ".",
156
- strThousandsSeparator: ",",
157
- strSymbolAndNumberSeparator: " ",
158
- },
159
- TRY: {
160
- strCode: "TRY",
161
- eCurrencyCode: 17,
162
- strSymbol: "TL",
163
- bSymbolIsPrefix: false,
164
- bWholeUnitsOnly: false,
165
- strDecimalSymbol: ",",
166
- strThousandsSeparator: ".",
167
- strSymbolAndNumberSeparator: " ",
168
- },
169
- UAH: {
170
- strCode: "UAH",
171
- eCurrencyCode: 18,
172
- strSymbol: "\u20b4",
173
- bSymbolIsPrefix: false,
174
- bWholeUnitsOnly: true,
175
- strDecimalSymbol: ",",
176
- strThousandsSeparator: " ",
177
- strSymbolAndNumberSeparator: "",
178
- },
179
- MXN: {
180
- strCode: "MXN",
181
- eCurrencyCode: 19,
182
- strSymbol: "Mex$",
183
- bSymbolIsPrefix: true,
184
- bWholeUnitsOnly: false,
185
- strDecimalSymbol: ".",
186
- strThousandsSeparator: ",",
187
- strSymbolAndNumberSeparator: " ",
188
- },
189
- CAD: {
190
- strCode: "CAD",
191
- eCurrencyCode: 20,
192
- strSymbol: "CDN$",
193
- bSymbolIsPrefix: true,
194
- bWholeUnitsOnly: false,
195
- strDecimalSymbol: ".",
196
- strThousandsSeparator: ",",
197
- strSymbolAndNumberSeparator: " ",
198
- },
199
- AUD: {
200
- strCode: "AUD",
201
- eCurrencyCode: 21,
202
- strSymbol: "A$",
203
- bSymbolIsPrefix: true,
204
- bWholeUnitsOnly: false,
205
- strDecimalSymbol: ".",
206
- strThousandsSeparator: ",",
207
- strSymbolAndNumberSeparator: " ",
208
- },
209
- NZD: {
210
- strCode: "NZD",
211
- eCurrencyCode: 22,
212
- strSymbol: "NZ$",
213
- bSymbolIsPrefix: true,
214
- bWholeUnitsOnly: false,
215
- strDecimalSymbol: ".",
216
- strThousandsSeparator: ",",
217
- strSymbolAndNumberSeparator: " ",
218
- },
219
- PLN: {
220
- strCode: "PLN",
221
- eCurrencyCode: 6,
222
- strSymbol: "z\u0142",
223
- bSymbolIsPrefix: false,
224
- bWholeUnitsOnly: false,
225
- strDecimalSymbol: ",",
226
- strThousandsSeparator: " ",
227
- strSymbolAndNumberSeparator: "",
228
- },
229
- CNY: {
230
- strCode: "CNY",
231
- eCurrencyCode: 23,
232
- strSymbol: "\u00a5",
233
- bSymbolIsPrefix: true,
234
- bWholeUnitsOnly: false,
235
- strDecimalSymbol: ".",
236
- strThousandsSeparator: ",",
237
- strSymbolAndNumberSeparator: " ",
238
- },
239
- INR: {
240
- strCode: "INR",
241
- eCurrencyCode: 24,
242
- strSymbol: "\u20b9",
243
- bSymbolIsPrefix: true,
244
- bWholeUnitsOnly: true,
245
- strDecimalSymbol: ".",
246
- strThousandsSeparator: ",",
247
- strSymbolAndNumberSeparator: " ",
248
- },
249
- CLP: {
250
- strCode: "CLP",
251
- eCurrencyCode: 25,
252
- strSymbol: "CLP$",
253
- bSymbolIsPrefix: true,
254
- bWholeUnitsOnly: true,
255
- strDecimalSymbol: ",",
256
- strThousandsSeparator: ".",
257
- strSymbolAndNumberSeparator: " ",
258
- },
259
- PEN: {
260
- strCode: "PEN",
261
- eCurrencyCode: 26,
262
- strSymbol: "S/.",
263
- bSymbolIsPrefix: true,
264
- bWholeUnitsOnly: false,
265
- strDecimalSymbol: ".",
266
- strThousandsSeparator: ",",
267
- strSymbolAndNumberSeparator: "",
268
- },
269
- COP: {
270
- strCode: "COP",
271
- eCurrencyCode: 27,
272
- strSymbol: "COL$",
273
- bSymbolIsPrefix: true,
274
- bWholeUnitsOnly: true,
275
- strDecimalSymbol: ",",
276
- strThousandsSeparator: ".",
277
- strSymbolAndNumberSeparator: " ",
278
- },
279
- ZAR: {
280
- strCode: "ZAR",
281
- eCurrencyCode: 28,
282
- strSymbol: "R",
283
- bSymbolIsPrefix: true,
284
- bWholeUnitsOnly: false,
285
- strDecimalSymbol: ".",
286
- strThousandsSeparator: " ",
287
- strSymbolAndNumberSeparator: " ",
288
- },
289
- HKD: {
290
- strCode: "HKD",
291
- eCurrencyCode: 29,
292
- strSymbol: "HK$",
293
- bSymbolIsPrefix: true,
294
- bWholeUnitsOnly: false,
295
- strDecimalSymbol: ".",
296
- strThousandsSeparator: ",",
297
- strSymbolAndNumberSeparator: " ",
298
- },
299
- TWD: {
300
- strCode: "TWD",
301
- eCurrencyCode: 30,
302
- strSymbol: "NT$",
303
- bSymbolIsPrefix: true,
304
- bWholeUnitsOnly: true,
305
- strDecimalSymbol: ".",
306
- strThousandsSeparator: ",",
307
- strSymbolAndNumberSeparator: " ",
308
- },
309
- SAR: {
310
- strCode: "SAR",
311
- eCurrencyCode: 31,
312
- strSymbol: "SR",
313
- bSymbolIsPrefix: false,
314
- bWholeUnitsOnly: false,
315
- strDecimalSymbol: ".",
316
- strThousandsSeparator: ",",
317
- strSymbolAndNumberSeparator: " ",
318
- },
319
- AED: {
320
- strCode: "AED",
321
- eCurrencyCode: 32,
322
- strSymbol: "AED",
323
- bSymbolIsPrefix: false,
324
- bWholeUnitsOnly: false,
325
- strDecimalSymbol: ".",
326
- strThousandsSeparator: ",",
327
- strSymbolAndNumberSeparator: " ",
328
- },
329
- SEK: {
330
- strCode: "SEK",
331
- eCurrencyCode: 33,
332
- strSymbol: "kr",
333
- bSymbolIsPrefix: false,
334
- bWholeUnitsOnly: false,
335
- strDecimalSymbol: ".",
336
- strThousandsSeparator: ",",
337
- strSymbolAndNumberSeparator: " ",
338
- },
339
- ARS: {
340
- strCode: "ARS",
341
- eCurrencyCode: 34,
342
- strSymbol: "ARS$",
343
- bSymbolIsPrefix: true,
344
- bWholeUnitsOnly: false,
345
- strDecimalSymbol: ",",
346
- strThousandsSeparator: ".",
347
- strSymbolAndNumberSeparator: " ",
348
- },
349
- ILS: {
350
- strCode: "ILS",
351
- eCurrencyCode: 35,
352
- strSymbol: "\u20aa",
353
- bSymbolIsPrefix: true,
354
- bWholeUnitsOnly: false,
355
- strDecimalSymbol: ".",
356
- strThousandsSeparator: ",",
357
- strSymbolAndNumberSeparator: "",
358
- },
359
- BYN: {
360
- strCode: "BYN",
361
- eCurrencyCode: 36,
362
- strSymbol: "Br",
363
- bSymbolIsPrefix: true,
364
- bWholeUnitsOnly: false,
365
- strDecimalSymbol: ".",
366
- strThousandsSeparator: ",",
367
- strSymbolAndNumberSeparator: "",
368
- },
369
- KZT: {
370
- strCode: "KZT",
371
- eCurrencyCode: 37,
372
- strSymbol: "\u20b8",
373
- bSymbolIsPrefix: false,
374
- bWholeUnitsOnly: true,
375
- strDecimalSymbol: ",",
376
- strThousandsSeparator: " ",
377
- strSymbolAndNumberSeparator: "",
378
- },
379
- KWD: {
380
- strCode: "KWD",
381
- eCurrencyCode: 38,
382
- strSymbol: "KD",
383
- bSymbolIsPrefix: false,
384
- bWholeUnitsOnly: false,
385
- strDecimalSymbol: ".",
386
- strThousandsSeparator: ",",
387
- strSymbolAndNumberSeparator: " ",
388
- },
389
- QAR: {
390
- strCode: "QAR",
391
- eCurrencyCode: 39,
392
- strSymbol: "QR",
393
- bSymbolIsPrefix: false,
394
- bWholeUnitsOnly: false,
395
- strDecimalSymbol: ".",
396
- strThousandsSeparator: ",",
397
- strSymbolAndNumberSeparator: " ",
398
- },
399
- CRC: {
400
- strCode: "CRC",
401
- eCurrencyCode: 40,
402
- strSymbol: "\u20a1",
403
- bSymbolIsPrefix: true,
404
- bWholeUnitsOnly: true,
405
- strDecimalSymbol: ",",
406
- strThousandsSeparator: ".",
407
- strSymbolAndNumberSeparator: "",
408
- },
409
- UYU: {
410
- strCode: "UYU",
411
- eCurrencyCode: 41,
412
- strSymbol: "$U",
413
- bSymbolIsPrefix: true,
414
- bWholeUnitsOnly: true,
415
- strDecimalSymbol: ",",
416
- strThousandsSeparator: ".",
417
- strSymbolAndNumberSeparator: "",
418
- },
419
- BGN: {
420
- strCode: "BGN",
421
- eCurrencyCode: 42,
422
- strSymbol: "\u043b\u0432",
423
- bSymbolIsPrefix: false,
424
- bWholeUnitsOnly: false,
425
- strDecimalSymbol: ".",
426
- strThousandsSeparator: ",",
427
- strSymbolAndNumberSeparator: " ",
428
- },
429
- HRK: {
430
- strCode: "HRK",
431
- eCurrencyCode: 43,
432
- strSymbol: "kn",
433
- bSymbolIsPrefix: false,
434
- bWholeUnitsOnly: false,
435
- strDecimalSymbol: ".",
436
- strThousandsSeparator: ",",
437
- strSymbolAndNumberSeparator: " ",
438
- },
439
- CZK: {
440
- strCode: "CZK",
441
- eCurrencyCode: 44,
442
- strSymbol: "K\u010d",
443
- bSymbolIsPrefix: false,
444
- bWholeUnitsOnly: false,
445
- strDecimalSymbol: ".",
446
- strThousandsSeparator: ",",
447
- strSymbolAndNumberSeparator: " ",
448
- },
449
- DKK: {
450
- strCode: "DKK",
451
- eCurrencyCode: 45,
452
- strSymbol: "kr.",
453
- bSymbolIsPrefix: false,
454
- bWholeUnitsOnly: false,
455
- strDecimalSymbol: ".",
456
- strThousandsSeparator: ",",
457
- strSymbolAndNumberSeparator: " ",
458
- },
459
- HUF: {
460
- strCode: "HUF",
461
- eCurrencyCode: 46,
462
- strSymbol: "Ft",
463
- bSymbolIsPrefix: false,
464
- bWholeUnitsOnly: false,
465
- strDecimalSymbol: ".",
466
- strThousandsSeparator: ",",
467
- strSymbolAndNumberSeparator: " ",
468
- },
469
- RON: {
470
- strCode: "RON",
471
- eCurrencyCode: 47,
472
- strSymbol: "lei",
473
- bSymbolIsPrefix: false,
474
- bWholeUnitsOnly: false,
475
- strDecimalSymbol: ".",
476
- strThousandsSeparator: ",",
477
- strSymbolAndNumberSeparator: " ",
478
- },
479
- RMB: {
480
- strCode: "RMB",
481
- eCurrencyCode: 9000,
482
- strSymbol: "\u5200\u5e01",
483
- bSymbolIsPrefix: false,
484
- bWholeUnitsOnly: true,
485
- strDecimalSymbol: ".",
486
- strThousandsSeparator: "",
487
- strSymbolAndNumberSeparator: " ",
488
- },
489
- NXP: {
490
- strCode: "NXP",
491
- eCurrencyCode: 9001,
492
- strSymbol: "\uc6d0",
493
- bSymbolIsPrefix: false,
494
- bWholeUnitsOnly: true,
495
- strDecimalSymbol: ".",
496
- strThousandsSeparator: ",",
497
- strSymbolAndNumberSeparator: "",
498
- },
499
- };
500
- const g_rgWalletInfo = {
501
- wallet_currency: 15,
502
- wallet_country: "VN",
503
- wallet_state: "",
504
- wallet_fee: "1",
505
- wallet_fee_minimum: "1",
506
- wallet_fee_percent: "0.05",
507
- wallet_publisher_fee_percent_default: "0.10",
508
- wallet_fee_base: "0",
509
- wallet_balance: "6540490",
510
- wallet_delayed_balance: "0",
511
- wallet_max_balance: "4500000000",
512
- wallet_trade_max_balance: "4049999616",
513
- success: 1,
514
- rwgrsn: -2,
515
- };
516
-
517
- export const sleep = (ms) => {
518
- return new Promise((resolve) => {
519
- setTimeout(resolve, ms);
520
- });
521
- };
522
-
523
- export const sleepRandom = async (startMs, endMs) => {
524
- return await sleep(Math.random() * (endMs - startMs) + startMs);
525
- };
526
-
527
- /**
528
- * const audioTrack = stream.getAudioTracks()[0]
529
- * const videoStream = UserMedia.createBlankVideoTrack()
530
- * videoStream.addTrack(audioTrack)
531
- * stream = videoStream
532
- * **/
533
- export const createBlankVideoTrack = (opts = {}) => {
534
- const { width = 1920, height = 1080 } = opts;
535
-
536
- const canvas = Object.assign(document.createElement("canvas"), {
537
- width,
538
- height,
539
- });
540
-
541
- canvas.getContext("2d").fillRect(0, 0, width, height);
542
-
543
- return canvas.captureStream();
544
- };
545
-
546
- const minDate = new Date(0),
547
- maxDate = new Date(parseInt("ffffffff", 16) * 1000);
548
-
549
- export function objectIdFromDate(date) {
550
- if (date < minDate || date > maxDate) {
551
- return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
552
- }
553
- var pad = "00000000";
554
- var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
555
- return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
556
- }
557
-
558
- export function dateFromObjectId(objectId) {
559
- return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
560
- }
561
-
562
- export function console_log(...args) {
563
- const params = [];
564
- params.push(new Date().toUTCString());
565
- const errorStack = new Error().stack;
566
- const fnName = errorStack
567
- .split("\n")
568
- .map((e) => e?.trim())
569
- .filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
570
- .substr(3);
571
- params.push(fnName);
572
- console.log(
573
- params
574
- .filter(Boolean)
575
- .map((p) => `[${p.trim()}]`)
576
- .join(" "),
577
- ...args,
578
- );
579
- }
580
-
581
- export function removeSpaceKeys(object) {
582
- //mutate object
583
- if (!object || Array.isArray(object)) {
584
- return object;
585
- }
586
-
587
- Object.entries(object).forEach(([key, value]) => {
588
- const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
589
- if (newKey !== key) {
590
- delete object[key];
591
- object[newKey] = value;
592
- }
593
- });
594
- return object;
595
- }
596
-
597
- export function getCleanObject(object) {
598
- //like removeSpaceKeys but not mutate object
599
- if (!object || Array.isArray(object)) {
600
- return object;
601
- }
602
-
603
- const newObject = {};
604
- Object.entries(object).forEach(([key, value]) => {
605
- const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
606
- newObject[newKey] = value;
607
- });
608
- return newObject;
609
- }
610
-
611
- export function JSON_parse(data) {
612
- try {
613
- return JSON.parse(data);
614
- } catch (e) {
615
- return null;
616
- }
617
- }
618
-
619
- export function JSON_stringify(data) {
620
- try {
621
- return JSON.stringify(data);
622
- } catch (e) {
623
- return null;
624
- }
625
- }
626
-
627
- export async function throttle(fn, delay) {
628
- let canFire = true;
629
- let queue = [];
630
-
631
- async function pop() {
632
- if (queue.length < 1) return;
633
-
634
- const [that, args] = queue.pop();
635
- await fn.apply(that, args);
636
- canFire = false;
637
- setTimeout(async () => {
638
- canFire = true;
639
- await pop();
640
- }, delay);
641
- }
642
-
643
- async function push() {
644
- queue.push([this, arguments]);
645
- if (canFire) {
646
- await pop();
647
- }
648
- }
649
-
650
- push.cancel = () => {
651
- queue = [];
652
- };
653
-
654
- return push;
655
- }
656
-
657
- export const secretAsBuffer = (sharedSecret) => {
658
- if (Buffer.isBuffer(sharedSecret)) {
659
- return sharedSecret;
660
- }
661
-
662
- if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
663
- // Looks like it's hex
664
- return Buffer.from(sharedSecret, "hex");
665
- }
666
-
667
- // It must be base64
668
- return Buffer.from(sharedSecret, "base64");
669
- };
670
-
671
- export function decodeLoginQrUrl(qrUrl) {
672
- if (!qrUrl || typeof qrUrl !== "string") {
673
- return null;
674
- }
675
- const match = qrUrl.match(/^https?:\/\/s\.team\/q\/(\d+)\/(\d+)(\?|$)/);
676
- if (!match) {
677
- console.log("Invalid QR code URL");
678
- return null;
679
- }
680
-
681
- return { clientId: match[2], version: parseInt(match[1], 10) };
682
- }
683
-
684
- export function decodeJwt(jwt) {
685
- try {
686
- const parts = jwt.split(".");
687
- if (parts.length !== 3) {
688
- console.err("decodeJwt Error", new Error("Invalid JWT"));
689
- return;
690
- }
691
-
692
- const standardBase64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
693
- return JSON.parse(Buffer.from(standardBase64, "base64").toString("utf8"));
694
- } catch (e) {
695
- console.error("decodeJwt Error", e);
696
- }
697
- }
698
-
699
- export async function renewRefreshToken({ refreshToken, accessToken }) {
700
- const steamId = arguments[0]?.steamId;
701
- try {
702
- const { aud } = decodeJwt(accessToken);
703
- let platformType = EAuthTokenPlatformType.SteamClient;
704
- if (aud.includes("mobile")) {
705
- platformType = EAuthTokenPlatformType.MobileApp;
706
- } else if (aud.includes("client")) {
707
- platformType = EAuthTokenPlatformType.SteamClient;
708
- } else if (aud.includes("web")) {
709
- platformType = EAuthTokenPlatformType.WebBrowser;
710
- }
711
-
712
- const { LoginSession } = await import("steam-session");
713
- const session = new LoginSession(platformType);
714
- session.refreshToken = refreshToken;
715
- await session.refreshAccessToken();
716
- const cookie = (await session.getWebCookies())?.join?.(";");
717
- return {
718
- cookie,
719
- accessToken: session.accessToken,
720
- accessTokenDecoded: decodeJwt(session.accessToken),
721
- };
722
- } catch (e) {
723
- console.error(`${steamId ? `[${steamId}] ` : ""}renewRefreshToken Error`, e);
724
- }
725
- }
726
-
727
- export async function approveLogin({ steamId, url, sharedSecret, accessToken, shouldApprove }) {
728
- try {
729
- const { LoginApprover } = await import("steam-session");
730
- const approver = new LoginApprover(accessToken, sharedSecret, {});
731
- const sessionInfo = await approver.getAuthSessionInfo(url);
732
- sessionInfo.steamId = steamId;
733
-
734
- if (typeof shouldApprove === "function" && !shouldApprove(sessionInfo)) {
735
- return;
736
- }
737
-
738
- await approver.approveAuthSession({
739
- qrChallengeUrl: url,
740
- approve: true,
741
- });
742
-
743
- return {
744
- steamId,
745
- sessionInfo,
746
- };
747
- } catch (error) {
748
- console.error(`[${steamId}] approveLogin Error`, error);
749
- return {
750
- steamId,
751
- error,
752
- };
753
- }
754
- }
755
-
756
- export function getBonusXpTimeRefresh() {
757
- let resetDay = moment.utc().startOf("isoWeek").add(2, "days").add(1, "hours");
758
- while (moment().isAfter(resetDay)) {
759
- resetDay = resetDay.add(7, "days");
760
- }
761
- if (moment().isBefore(resetDay)) {
762
- resetDay = resetDay.subtract(7, "days");
763
- }
764
- return resetDay;
765
- }
766
-
767
- export function estimateNextXp(currentXp, xpEarned) {
768
- //estimate next xp
769
- let bonusTime = 1;
770
- if (xpEarned < 4500) {
771
- bonusTime = 4;
772
- } else if (xpEarned < 7500) {
773
- bonusTime = 2;
774
- } else if (xpEarned < 11200) {
775
- bonusTime = 1;
776
- } else {
777
- bonusTime = 0.175;
778
- }
779
-
780
- const nextXp = 30 * 13 * bonusTime;
781
- return nextXp + currentXp;
782
- }
783
-
784
- export function formatMarketCurrency(valueInCents, currencyCode = getMarketCurrencyCode(g_rgWalletInfo.wallet_currency), countryCode) {
785
- if (!valueInCents && valueInCents !== 0) {
786
- return "";
787
- }
788
-
789
- let currencyFormat = (valueInCents / 100).toFixed(2);
790
-
791
- if (g_rgCurrencyData[currencyCode]) {
792
- const currencyData = g_rgCurrencyData[currencyCode];
793
- if (isCurrencyWholeUnits(currencyCode)) {
794
- currencyFormat = currencyFormat.replace(".00", "");
795
- }
796
-
797
- if (currencyData.strDecimalSymbol !== ".") {
798
- currencyFormat = currencyFormat.replace(".", currencyData.strDecimalSymbol);
799
- }
800
-
801
- const currencySymbol = getMarketCurrencySymbol(currencyCode);
802
- const currencyReturn = isCurrencySymbolBeforeValue(currencyCode) ? currencySymbol + currencyData.strSymbolAndNumberSeparator + currencyFormat : currencyFormat + currencyData.strSymbolAndNumberSeparator + currencySymbol;
803
-
804
- if (currencyCode === "USD" && typeof countryCode != "undefined" && countryCode != "US") {
805
- return `${currencyReturn} USD`;
806
- } else if (currencyCode === "EUR") {
807
- return currencyReturn.replace(",00", ",--");
808
- } else {
809
- return currencyReturn;
810
- }
811
- } else {
812
- return `${currencyFormat} ${currencyCode}`;
813
- }
814
- }
815
-
816
- export function getMarketPriceValueAsInt(strAmount) {
817
- let nAmount;
818
- if (!strAmount) {
819
- return 0;
820
- }
821
-
822
- // Users may enter either comma or period for the decimal mark and digit group separators.
823
- strAmount = strAmount.replace(/,/g, ".");
824
-
825
- // strip the currency symbol, set .-- to .00
826
- strAmount = strAmount.replace(getMarketCurrencySymbol(getMarketCurrencyCode(g_rgWalletInfo.wallet_currency)), "").replace(".--", ".00");
827
-
828
- // strip spaces
829
- strAmount = strAmount.replace(/ /g, "");
830
-
831
- // Remove all but the last period so that entries like "1,147.6" work
832
- if (strAmount.includes(".")) {
833
- var splitAmount = strAmount.split(".");
834
- var strLastSegment = splitAmount[splitAmount.length - 1];
835
-
836
- if (!isNaN(strLastSegment) && strLastSegment.length == 3 && splitAmount[splitAmount.length - 2] != "0") {
837
- // Looks like the user only entered thousands separators. Remove all commas and periods.
838
- // Ensures an entry like "1,147" is not treated as "1.147"
839
- //
840
- // Users may be surprised to find that "1.147" is treated as "1,147". "1.147" is either an error or the user
841
- // really did mean one thousand one hundred and forty seven since no currencies can be split into more than
842
- // hundredths. If it was an error, the user should notice in the next step of the dialog and can go back and
843
- // correct it. If they happen to not notice, it is better that we list the item at a higher price than
844
- // intended instead of lower than intended (which we would have done if we accepted the 1.147 value as is).
845
- strAmount = splitAmount.join("");
846
- } else {
847
- strAmount = `${splitAmount.slice(0, -1).join("")}.${strLastSegment}`;
848
- }
849
- }
850
-
851
- let flAmount = parseFloat(strAmount) * 100;
852
- nAmount = Math.floor(isNaN(flAmount) ? 0 : flAmount + 0.000001); // round down
853
-
854
- nAmount = Math.max(nAmount, 0);
855
- return nAmount;
856
- }
857
-
858
- export function isCurrencyWholeUnits(currencyCode) {
859
- return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bWholeUnitsOnly && currencyCode !== "RUB";
860
- }
861
-
862
- export function isCurrencySymbolBeforeValue(currencyCode) {
863
- return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bSymbolIsPrefix;
864
- }
865
-
866
- // Return the symbol to use for a currency
867
- export function getMarketCurrencySymbol(currencyCode) {
868
- return g_rgCurrencyData[currencyCode]?.strSymbol ?? currencyCode;
869
- }
870
-
871
- export function getMarketCurrencyCode(currencyId) {
872
- currencyId = parseInt(currencyId);
873
- for (const code in g_rgCurrencyData) {
874
- if (g_rgCurrencyData[code].eCurrencyCode === currencyId) {
875
- return code;
876
- }
877
- }
878
- return "Unknown";
879
- }
880
-
881
- export async function loginWithCredentials({ username, password, timeoutMs = 120000, sharedSecret, getMailSteamGuardCodes }) {
882
- if (!username) {
883
- return {
884
- error: "No username",
885
- };
886
- }
887
-
888
- if (!password) {
889
- return {
890
- error: "No password",
891
- };
892
- }
893
-
894
- const { LoginSession } = await import("steam-session");
895
- let authenticated = false;
896
- return new Promise((resolve) => {
897
- const timeout = setTimeout(function () {
898
- resolve({
899
- error: "Timed out",
900
- });
901
- }, timeoutMs);
902
-
903
- const session = new LoginSession(EAuthTokenPlatformType.MobileApp);
904
- session.on("authenticated", async () => {
905
- authenticated = true;
906
- const cookie = (await session.getWebCookies())?.join?.(";");
907
- return onResolve({
908
- cookie,
909
- accessToken: session.accessToken,
910
- refreshToken: session.refreshToken,
911
- accessTokenDecoded: decodeJwt(session.accessToken),
912
- });
913
- });
914
-
915
- session
916
- .startWithCredentials({
917
- accountName: username,
918
- password: password,
919
- steamGuardMachineToken: "",
920
- })
921
- .then(async function (startResult) {
922
- if (!startResult.actionRequired) {
923
- return;
924
- }
925
-
926
- if (sharedSecret) {
927
- let error = null;
928
- const maxRetry = 3;
929
- for (let i = 0; i < maxRetry; i++) {
930
- try {
931
- await session.submitSteamGuardCode(SteamTotp.generateAuthCode(sharedSecret));
932
- error = null;
933
- } catch (e) {
934
- error = e;
935
- }
936
- await sleep(1000);
937
- }
938
- if (error) {
939
- console.error(error);
940
- onResolve({ error });
941
- }
942
- } else {
943
- if (startResult.validActions.every((validAction) => validAction.type !== 2)) {
944
- console.error(startResult.validActions);
945
- return onResolve({
946
- error: "validActions",
947
- });
948
- }
949
-
950
- if (typeof getMailSteamGuardCodes === "function") {
951
- const codes = await getMailSteamGuardCodes();
952
- if (!Array.isArray(codes) || !codes.length) {
953
- return onResolve({
954
- error: "Can't find steam guard code",
955
- });
956
- }
957
-
958
- let error = null;
959
- for (const code of codes) {
960
- if (!authenticated) {
961
- try {
962
- await session.submitSteamGuardCode(code);
963
- error = null;
964
- } catch (e) {
965
- error = e;
966
- }
967
- await sleep(1000);
968
- }
969
- }
970
- if (!authenticated && error) {
971
- onResolve(error);
972
- }
973
- } else {
974
- return onResolve({
975
- error: "MailCodeError",
976
- });
977
- }
978
- }
979
- })
980
- .catch(function (e) {
981
- return onResolve(e);
982
- });
983
-
984
- function onResolve(data) {
985
- clearTimeout(timeout);
986
- return resolve(data);
987
- }
988
- });
989
- }
990
-
991
- export function calculateAccountXP(currentXp, xpEarnedThisWeek, xpEarned, nextXp) {
992
- return (
993
- (() => {
994
- if (typeof nextXp !== "number" || !Number.isFinite(nextXp)) {
995
- return;
996
- }
997
-
998
- currentXp = currentXp || 0;
999
- if (currentXp === nextXp) {
1000
- return;
1001
- }
1002
-
1003
- const update = { currentXp: nextXp };
1004
- if (nextXp < currentXp) {
1005
- update.xpExceed = Date.now();
1006
- }
1007
- const resetDay = getBonusXpTimeRefresh().format("YYYY-MM-DD");
1008
- const isWeekReset = xpEarnedThisWeek !== resetDay;
1009
- let xpEarnedThisRank = nextXp - currentXp;
1010
- if (xpEarnedThisRank < 0) {
1011
- xpEarnedThisRank += 5000;
1012
- }
1013
- if (isWeekReset) {
1014
- update.xpEarnedThisWeek = resetDay;
1015
- update.xpEarned = xpEarnedThisRank;
1016
- } else {
1017
- update.xpEarned = (xpEarned || 0) + xpEarnedThisRank;
1018
- if (xpEarnedThisRank === 0) {
1019
- return;
1020
- }
1021
- }
1022
-
1023
- return update;
1024
- })() || {}
1025
- );
1026
- }
1027
-
1028
- export async function downloadImage(url, filePath) {
1029
- let response = null;
1030
- try {
1031
- response = await axios.get(url, {
1032
- responseType: "arraybuffer",
1033
- });
1034
- } catch (e) {
1035
- /* empty */
1036
- }
1037
-
1038
- if (!response || !response.data) {
1039
- return;
1040
- }
1041
-
1042
- return new Promise((resolve) => {
1043
- fs.writeFile(filePath, response.data, (err) => {
1044
- if (err) {
1045
- resolve();
1046
- }
1047
- resolve(filePath);
1048
- });
1049
- });
1050
- }
1
+ import moment from "moment";
2
+ import SteamTotp from "steam-totp";
3
+ import { EAuthTokenPlatformType } from "./const.js";
4
+ import fs from "fs";
5
+ import axios from "axios";
6
+ import readline from "readline";
7
+
8
+ const isBrowser = typeof window !== "undefined";
9
+ const g_rgCurrencyData = {
10
+ USD: {
11
+ strCode: "USD",
12
+ eCurrencyCode: 1,
13
+ strSymbol: "$",
14
+ bSymbolIsPrefix: true,
15
+ bWholeUnitsOnly: false,
16
+ strDecimalSymbol: ".",
17
+ strThousandsSeparator: ",",
18
+ strSymbolAndNumberSeparator: "",
19
+ },
20
+ GBP: {
21
+ strCode: "GBP",
22
+ eCurrencyCode: 2,
23
+ strSymbol: "\u00a3",
24
+ bSymbolIsPrefix: true,
25
+ bWholeUnitsOnly: false,
26
+ strDecimalSymbol: ".",
27
+ strThousandsSeparator: ",",
28
+ strSymbolAndNumberSeparator: "",
29
+ },
30
+ EUR: {
31
+ strCode: "EUR",
32
+ eCurrencyCode: 3,
33
+ strSymbol: "\u20ac",
34
+ bSymbolIsPrefix: false,
35
+ bWholeUnitsOnly: false,
36
+ strDecimalSymbol: ",",
37
+ strThousandsSeparator: " ",
38
+ strSymbolAndNumberSeparator: "",
39
+ },
40
+ CHF: {
41
+ strCode: "CHF",
42
+ eCurrencyCode: 4,
43
+ strSymbol: "CHF",
44
+ bSymbolIsPrefix: true,
45
+ bWholeUnitsOnly: false,
46
+ strDecimalSymbol: ".",
47
+ strThousandsSeparator: " ",
48
+ strSymbolAndNumberSeparator: " ",
49
+ },
50
+ RUB: {
51
+ strCode: "RUB",
52
+ eCurrencyCode: 5,
53
+ strSymbol: "p\u0443\u0431.",
54
+ bSymbolIsPrefix: false,
55
+ bWholeUnitsOnly: true,
56
+ strDecimalSymbol: ",",
57
+ strThousandsSeparator: "",
58
+ strSymbolAndNumberSeparator: " ",
59
+ },
60
+ BRL: {
61
+ strCode: "BRL",
62
+ eCurrencyCode: 7,
63
+ strSymbol: "R$",
64
+ bSymbolIsPrefix: true,
65
+ bWholeUnitsOnly: false,
66
+ strDecimalSymbol: ",",
67
+ strThousandsSeparator: ".",
68
+ strSymbolAndNumberSeparator: " ",
69
+ },
70
+ JPY: {
71
+ strCode: "JPY",
72
+ eCurrencyCode: 8,
73
+ strSymbol: "\u00a5",
74
+ bSymbolIsPrefix: true,
75
+ bWholeUnitsOnly: true,
76
+ strDecimalSymbol: ".",
77
+ strThousandsSeparator: ",",
78
+ strSymbolAndNumberSeparator: " ",
79
+ },
80
+ NOK: {
81
+ strCode: "NOK",
82
+ eCurrencyCode: 9,
83
+ strSymbol: "kr",
84
+ bSymbolIsPrefix: false,
85
+ bWholeUnitsOnly: false,
86
+ strDecimalSymbol: ",",
87
+ strThousandsSeparator: ".",
88
+ strSymbolAndNumberSeparator: " ",
89
+ },
90
+ IDR: {
91
+ strCode: "IDR",
92
+ eCurrencyCode: 10,
93
+ strSymbol: "Rp",
94
+ bSymbolIsPrefix: true,
95
+ bWholeUnitsOnly: true,
96
+ strDecimalSymbol: ".",
97
+ strThousandsSeparator: " ",
98
+ strSymbolAndNumberSeparator: " ",
99
+ },
100
+ MYR: {
101
+ strCode: "MYR",
102
+ eCurrencyCode: 11,
103
+ strSymbol: "RM",
104
+ bSymbolIsPrefix: true,
105
+ bWholeUnitsOnly: false,
106
+ strDecimalSymbol: ".",
107
+ strThousandsSeparator: ",",
108
+ strSymbolAndNumberSeparator: "",
109
+ },
110
+ PHP: {
111
+ strCode: "PHP",
112
+ eCurrencyCode: 12,
113
+ strSymbol: "P",
114
+ bSymbolIsPrefix: true,
115
+ bWholeUnitsOnly: false,
116
+ strDecimalSymbol: ".",
117
+ strThousandsSeparator: ",",
118
+ strSymbolAndNumberSeparator: "",
119
+ },
120
+ SGD: {
121
+ strCode: "SGD",
122
+ eCurrencyCode: 13,
123
+ strSymbol: "S$",
124
+ bSymbolIsPrefix: true,
125
+ bWholeUnitsOnly: false,
126
+ strDecimalSymbol: ".",
127
+ strThousandsSeparator: ",",
128
+ strSymbolAndNumberSeparator: "",
129
+ },
130
+ THB: {
131
+ strCode: "THB",
132
+ eCurrencyCode: 14,
133
+ strSymbol: "\u0e3f",
134
+ bSymbolIsPrefix: true,
135
+ bWholeUnitsOnly: false,
136
+ strDecimalSymbol: ".",
137
+ strThousandsSeparator: ",",
138
+ strSymbolAndNumberSeparator: "",
139
+ },
140
+ VND: {
141
+ strCode: "VND",
142
+ eCurrencyCode: 15,
143
+ strSymbol: "\u20ab",
144
+ bSymbolIsPrefix: false,
145
+ bWholeUnitsOnly: true,
146
+ strDecimalSymbol: ",",
147
+ strThousandsSeparator: ".",
148
+ strSymbolAndNumberSeparator: "",
149
+ },
150
+ KRW: {
151
+ strCode: "KRW",
152
+ eCurrencyCode: 16,
153
+ strSymbol: "\u20a9",
154
+ bSymbolIsPrefix: true,
155
+ bWholeUnitsOnly: true,
156
+ strDecimalSymbol: ".",
157
+ strThousandsSeparator: ",",
158
+ strSymbolAndNumberSeparator: " ",
159
+ },
160
+ TRY: {
161
+ strCode: "TRY",
162
+ eCurrencyCode: 17,
163
+ strSymbol: "TL",
164
+ bSymbolIsPrefix: false,
165
+ bWholeUnitsOnly: false,
166
+ strDecimalSymbol: ",",
167
+ strThousandsSeparator: ".",
168
+ strSymbolAndNumberSeparator: " ",
169
+ },
170
+ UAH: {
171
+ strCode: "UAH",
172
+ eCurrencyCode: 18,
173
+ strSymbol: "\u20b4",
174
+ bSymbolIsPrefix: false,
175
+ bWholeUnitsOnly: true,
176
+ strDecimalSymbol: ",",
177
+ strThousandsSeparator: " ",
178
+ strSymbolAndNumberSeparator: "",
179
+ },
180
+ MXN: {
181
+ strCode: "MXN",
182
+ eCurrencyCode: 19,
183
+ strSymbol: "Mex$",
184
+ bSymbolIsPrefix: true,
185
+ bWholeUnitsOnly: false,
186
+ strDecimalSymbol: ".",
187
+ strThousandsSeparator: ",",
188
+ strSymbolAndNumberSeparator: " ",
189
+ },
190
+ CAD: {
191
+ strCode: "CAD",
192
+ eCurrencyCode: 20,
193
+ strSymbol: "CDN$",
194
+ bSymbolIsPrefix: true,
195
+ bWholeUnitsOnly: false,
196
+ strDecimalSymbol: ".",
197
+ strThousandsSeparator: ",",
198
+ strSymbolAndNumberSeparator: " ",
199
+ },
200
+ AUD: {
201
+ strCode: "AUD",
202
+ eCurrencyCode: 21,
203
+ strSymbol: "A$",
204
+ bSymbolIsPrefix: true,
205
+ bWholeUnitsOnly: false,
206
+ strDecimalSymbol: ".",
207
+ strThousandsSeparator: ",",
208
+ strSymbolAndNumberSeparator: " ",
209
+ },
210
+ NZD: {
211
+ strCode: "NZD",
212
+ eCurrencyCode: 22,
213
+ strSymbol: "NZ$",
214
+ bSymbolIsPrefix: true,
215
+ bWholeUnitsOnly: false,
216
+ strDecimalSymbol: ".",
217
+ strThousandsSeparator: ",",
218
+ strSymbolAndNumberSeparator: " ",
219
+ },
220
+ PLN: {
221
+ strCode: "PLN",
222
+ eCurrencyCode: 6,
223
+ strSymbol: "z\u0142",
224
+ bSymbolIsPrefix: false,
225
+ bWholeUnitsOnly: false,
226
+ strDecimalSymbol: ",",
227
+ strThousandsSeparator: " ",
228
+ strSymbolAndNumberSeparator: "",
229
+ },
230
+ CNY: {
231
+ strCode: "CNY",
232
+ eCurrencyCode: 23,
233
+ strSymbol: "\u00a5",
234
+ bSymbolIsPrefix: true,
235
+ bWholeUnitsOnly: false,
236
+ strDecimalSymbol: ".",
237
+ strThousandsSeparator: ",",
238
+ strSymbolAndNumberSeparator: " ",
239
+ },
240
+ INR: {
241
+ strCode: "INR",
242
+ eCurrencyCode: 24,
243
+ strSymbol: "\u20b9",
244
+ bSymbolIsPrefix: true,
245
+ bWholeUnitsOnly: true,
246
+ strDecimalSymbol: ".",
247
+ strThousandsSeparator: ",",
248
+ strSymbolAndNumberSeparator: " ",
249
+ },
250
+ CLP: {
251
+ strCode: "CLP",
252
+ eCurrencyCode: 25,
253
+ strSymbol: "CLP$",
254
+ bSymbolIsPrefix: true,
255
+ bWholeUnitsOnly: true,
256
+ strDecimalSymbol: ",",
257
+ strThousandsSeparator: ".",
258
+ strSymbolAndNumberSeparator: " ",
259
+ },
260
+ PEN: {
261
+ strCode: "PEN",
262
+ eCurrencyCode: 26,
263
+ strSymbol: "S/.",
264
+ bSymbolIsPrefix: true,
265
+ bWholeUnitsOnly: false,
266
+ strDecimalSymbol: ".",
267
+ strThousandsSeparator: ",",
268
+ strSymbolAndNumberSeparator: "",
269
+ },
270
+ COP: {
271
+ strCode: "COP",
272
+ eCurrencyCode: 27,
273
+ strSymbol: "COL$",
274
+ bSymbolIsPrefix: true,
275
+ bWholeUnitsOnly: true,
276
+ strDecimalSymbol: ",",
277
+ strThousandsSeparator: ".",
278
+ strSymbolAndNumberSeparator: " ",
279
+ },
280
+ ZAR: {
281
+ strCode: "ZAR",
282
+ eCurrencyCode: 28,
283
+ strSymbol: "R",
284
+ bSymbolIsPrefix: true,
285
+ bWholeUnitsOnly: false,
286
+ strDecimalSymbol: ".",
287
+ strThousandsSeparator: " ",
288
+ strSymbolAndNumberSeparator: " ",
289
+ },
290
+ HKD: {
291
+ strCode: "HKD",
292
+ eCurrencyCode: 29,
293
+ strSymbol: "HK$",
294
+ bSymbolIsPrefix: true,
295
+ bWholeUnitsOnly: false,
296
+ strDecimalSymbol: ".",
297
+ strThousandsSeparator: ",",
298
+ strSymbolAndNumberSeparator: " ",
299
+ },
300
+ TWD: {
301
+ strCode: "TWD",
302
+ eCurrencyCode: 30,
303
+ strSymbol: "NT$",
304
+ bSymbolIsPrefix: true,
305
+ bWholeUnitsOnly: true,
306
+ strDecimalSymbol: ".",
307
+ strThousandsSeparator: ",",
308
+ strSymbolAndNumberSeparator: " ",
309
+ },
310
+ SAR: {
311
+ strCode: "SAR",
312
+ eCurrencyCode: 31,
313
+ strSymbol: "SR",
314
+ bSymbolIsPrefix: false,
315
+ bWholeUnitsOnly: false,
316
+ strDecimalSymbol: ".",
317
+ strThousandsSeparator: ",",
318
+ strSymbolAndNumberSeparator: " ",
319
+ },
320
+ AED: {
321
+ strCode: "AED",
322
+ eCurrencyCode: 32,
323
+ strSymbol: "AED",
324
+ bSymbolIsPrefix: false,
325
+ bWholeUnitsOnly: false,
326
+ strDecimalSymbol: ".",
327
+ strThousandsSeparator: ",",
328
+ strSymbolAndNumberSeparator: " ",
329
+ },
330
+ SEK: {
331
+ strCode: "SEK",
332
+ eCurrencyCode: 33,
333
+ strSymbol: "kr",
334
+ bSymbolIsPrefix: false,
335
+ bWholeUnitsOnly: false,
336
+ strDecimalSymbol: ".",
337
+ strThousandsSeparator: ",",
338
+ strSymbolAndNumberSeparator: " ",
339
+ },
340
+ ARS: {
341
+ strCode: "ARS",
342
+ eCurrencyCode: 34,
343
+ strSymbol: "ARS$",
344
+ bSymbolIsPrefix: true,
345
+ bWholeUnitsOnly: false,
346
+ strDecimalSymbol: ",",
347
+ strThousandsSeparator: ".",
348
+ strSymbolAndNumberSeparator: " ",
349
+ },
350
+ ILS: {
351
+ strCode: "ILS",
352
+ eCurrencyCode: 35,
353
+ strSymbol: "\u20aa",
354
+ bSymbolIsPrefix: true,
355
+ bWholeUnitsOnly: false,
356
+ strDecimalSymbol: ".",
357
+ strThousandsSeparator: ",",
358
+ strSymbolAndNumberSeparator: "",
359
+ },
360
+ BYN: {
361
+ strCode: "BYN",
362
+ eCurrencyCode: 36,
363
+ strSymbol: "Br",
364
+ bSymbolIsPrefix: true,
365
+ bWholeUnitsOnly: false,
366
+ strDecimalSymbol: ".",
367
+ strThousandsSeparator: ",",
368
+ strSymbolAndNumberSeparator: "",
369
+ },
370
+ KZT: {
371
+ strCode: "KZT",
372
+ eCurrencyCode: 37,
373
+ strSymbol: "\u20b8",
374
+ bSymbolIsPrefix: false,
375
+ bWholeUnitsOnly: true,
376
+ strDecimalSymbol: ",",
377
+ strThousandsSeparator: " ",
378
+ strSymbolAndNumberSeparator: "",
379
+ },
380
+ KWD: {
381
+ strCode: "KWD",
382
+ eCurrencyCode: 38,
383
+ strSymbol: "KD",
384
+ bSymbolIsPrefix: false,
385
+ bWholeUnitsOnly: false,
386
+ strDecimalSymbol: ".",
387
+ strThousandsSeparator: ",",
388
+ strSymbolAndNumberSeparator: " ",
389
+ },
390
+ QAR: {
391
+ strCode: "QAR",
392
+ eCurrencyCode: 39,
393
+ strSymbol: "QR",
394
+ bSymbolIsPrefix: false,
395
+ bWholeUnitsOnly: false,
396
+ strDecimalSymbol: ".",
397
+ strThousandsSeparator: ",",
398
+ strSymbolAndNumberSeparator: " ",
399
+ },
400
+ CRC: {
401
+ strCode: "CRC",
402
+ eCurrencyCode: 40,
403
+ strSymbol: "\u20a1",
404
+ bSymbolIsPrefix: true,
405
+ bWholeUnitsOnly: true,
406
+ strDecimalSymbol: ",",
407
+ strThousandsSeparator: ".",
408
+ strSymbolAndNumberSeparator: "",
409
+ },
410
+ UYU: {
411
+ strCode: "UYU",
412
+ eCurrencyCode: 41,
413
+ strSymbol: "$U",
414
+ bSymbolIsPrefix: true,
415
+ bWholeUnitsOnly: true,
416
+ strDecimalSymbol: ",",
417
+ strThousandsSeparator: ".",
418
+ strSymbolAndNumberSeparator: "",
419
+ },
420
+ BGN: {
421
+ strCode: "BGN",
422
+ eCurrencyCode: 42,
423
+ strSymbol: "\u043b\u0432",
424
+ bSymbolIsPrefix: false,
425
+ bWholeUnitsOnly: false,
426
+ strDecimalSymbol: ".",
427
+ strThousandsSeparator: ",",
428
+ strSymbolAndNumberSeparator: " ",
429
+ },
430
+ HRK: {
431
+ strCode: "HRK",
432
+ eCurrencyCode: 43,
433
+ strSymbol: "kn",
434
+ bSymbolIsPrefix: false,
435
+ bWholeUnitsOnly: false,
436
+ strDecimalSymbol: ".",
437
+ strThousandsSeparator: ",",
438
+ strSymbolAndNumberSeparator: " ",
439
+ },
440
+ CZK: {
441
+ strCode: "CZK",
442
+ eCurrencyCode: 44,
443
+ strSymbol: "K\u010d",
444
+ bSymbolIsPrefix: false,
445
+ bWholeUnitsOnly: false,
446
+ strDecimalSymbol: ".",
447
+ strThousandsSeparator: ",",
448
+ strSymbolAndNumberSeparator: " ",
449
+ },
450
+ DKK: {
451
+ strCode: "DKK",
452
+ eCurrencyCode: 45,
453
+ strSymbol: "kr.",
454
+ bSymbolIsPrefix: false,
455
+ bWholeUnitsOnly: false,
456
+ strDecimalSymbol: ".",
457
+ strThousandsSeparator: ",",
458
+ strSymbolAndNumberSeparator: " ",
459
+ },
460
+ HUF: {
461
+ strCode: "HUF",
462
+ eCurrencyCode: 46,
463
+ strSymbol: "Ft",
464
+ bSymbolIsPrefix: false,
465
+ bWholeUnitsOnly: false,
466
+ strDecimalSymbol: ".",
467
+ strThousandsSeparator: ",",
468
+ strSymbolAndNumberSeparator: " ",
469
+ },
470
+ RON: {
471
+ strCode: "RON",
472
+ eCurrencyCode: 47,
473
+ strSymbol: "lei",
474
+ bSymbolIsPrefix: false,
475
+ bWholeUnitsOnly: false,
476
+ strDecimalSymbol: ".",
477
+ strThousandsSeparator: ",",
478
+ strSymbolAndNumberSeparator: " ",
479
+ },
480
+ RMB: {
481
+ strCode: "RMB",
482
+ eCurrencyCode: 9000,
483
+ strSymbol: "\u5200\u5e01",
484
+ bSymbolIsPrefix: false,
485
+ bWholeUnitsOnly: true,
486
+ strDecimalSymbol: ".",
487
+ strThousandsSeparator: "",
488
+ strSymbolAndNumberSeparator: " ",
489
+ },
490
+ NXP: {
491
+ strCode: "NXP",
492
+ eCurrencyCode: 9001,
493
+ strSymbol: "\uc6d0",
494
+ bSymbolIsPrefix: false,
495
+ bWholeUnitsOnly: true,
496
+ strDecimalSymbol: ".",
497
+ strThousandsSeparator: ",",
498
+ strSymbolAndNumberSeparator: "",
499
+ },
500
+ };
501
+ const g_rgWalletInfo = {
502
+ wallet_currency: 15,
503
+ wallet_country: "VN",
504
+ wallet_state: "",
505
+ wallet_fee: "1",
506
+ wallet_fee_minimum: "1",
507
+ wallet_fee_percent: "0.05",
508
+ wallet_publisher_fee_percent_default: "0.10",
509
+ wallet_fee_base: "0",
510
+ wallet_balance: "6540490",
511
+ wallet_delayed_balance: "0",
512
+ wallet_max_balance: "4500000000",
513
+ wallet_trade_max_balance: "4049999616",
514
+ success: 1,
515
+ rwgrsn: -2,
516
+ };
517
+
518
+ export const sleep = (ms) => {
519
+ return new Promise((resolve) => {
520
+ setTimeout(resolve, ms);
521
+ });
522
+ };
523
+
524
+ export const sleepRandom = async (startMs, endMs) => {
525
+ return await sleep(Math.random() * (endMs - startMs) + startMs);
526
+ };
527
+
528
+ /**
529
+ * const audioTrack = stream.getAudioTracks()[0]
530
+ * const videoStream = UserMedia.createBlankVideoTrack()
531
+ * videoStream.addTrack(audioTrack)
532
+ * stream = videoStream
533
+ * **/
534
+ export const createBlankVideoTrack = (opts = {}) => {
535
+ const { width = 1920, height = 1080 } = opts;
536
+
537
+ const canvas = Object.assign(document.createElement("canvas"), {
538
+ width,
539
+ height,
540
+ });
541
+
542
+ canvas.getContext("2d").fillRect(0, 0, width, height);
543
+
544
+ return canvas.captureStream();
545
+ };
546
+
547
+ const minDate = new Date(0),
548
+ maxDate = new Date(parseInt("ffffffff", 16) * 1000);
549
+
550
+ export function objectIdFromDate(date) {
551
+ if (date < minDate || date > maxDate) {
552
+ return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
553
+ }
554
+ var pad = "00000000";
555
+ var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
556
+ return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
557
+ }
558
+
559
+ export function dateFromObjectId(objectId) {
560
+ return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
561
+ }
562
+
563
+ export function console_log(...args) {
564
+ const params = [];
565
+ params.push(new Date().toUTCString());
566
+ const errorStack = new Error().stack;
567
+ const fnName = errorStack
568
+ .split("\n")
569
+ .map((e) => e?.trim())
570
+ .filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
571
+ .substr(3);
572
+ params.push(fnName);
573
+ console.log(
574
+ params
575
+ .filter(Boolean)
576
+ .map((p) => `[${p.trim()}]`)
577
+ .join(" "),
578
+ ...args,
579
+ );
580
+ }
581
+
582
+ export function removeSpaceKeys(object) {
583
+ //mutate object
584
+ if (!object || Array.isArray(object)) {
585
+ return object;
586
+ }
587
+
588
+ Object.entries(object).forEach(([key, value]) => {
589
+ const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
590
+ if (newKey !== key) {
591
+ delete object[key];
592
+ object[newKey] = value;
593
+ }
594
+ });
595
+ return object;
596
+ }
597
+
598
+ export function getCleanObject(object) {
599
+ //like removeSpaceKeys but not mutate object
600
+ if (!object || Array.isArray(object)) {
601
+ return object;
602
+ }
603
+
604
+ const newObject = {};
605
+ Object.entries(object).forEach(([key, value]) => {
606
+ const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
607
+ newObject[newKey] = value;
608
+ });
609
+ return newObject;
610
+ }
611
+
612
+ export function JSON_parse(data) {
613
+ try {
614
+ return JSON.parse(data);
615
+ } catch (e) {
616
+ return null;
617
+ }
618
+ }
619
+
620
+ export function JSON_stringify(data) {
621
+ try {
622
+ return JSON.stringify(data);
623
+ } catch (e) {
624
+ return null;
625
+ }
626
+ }
627
+
628
+ export async function throttle(fn, delay) {
629
+ let canFire = true;
630
+ let queue = [];
631
+
632
+ async function pop() {
633
+ if (queue.length < 1) return;
634
+
635
+ const [that, args] = queue.pop();
636
+ await fn.apply(that, args);
637
+ canFire = false;
638
+ setTimeout(async () => {
639
+ canFire = true;
640
+ await pop();
641
+ }, delay);
642
+ }
643
+
644
+ async function push() {
645
+ queue.push([this, arguments]);
646
+ if (canFire) {
647
+ await pop();
648
+ }
649
+ }
650
+
651
+ push.cancel = () => {
652
+ queue = [];
653
+ };
654
+
655
+ return push;
656
+ }
657
+
658
+ export const secretAsBuffer = (sharedSecret) => {
659
+ if (Buffer.isBuffer(sharedSecret)) {
660
+ return sharedSecret;
661
+ }
662
+
663
+ if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
664
+ // Looks like it's hex
665
+ return Buffer.from(sharedSecret, "hex");
666
+ }
667
+
668
+ // It must be base64
669
+ return Buffer.from(sharedSecret, "base64");
670
+ };
671
+
672
+ export function decodeLoginQrUrl(qrUrl) {
673
+ if (!qrUrl || typeof qrUrl !== "string") {
674
+ return null;
675
+ }
676
+ const match = qrUrl.match(/^https?:\/\/s\.team\/q\/(\d+)\/(\d+)(\?|$)/);
677
+ if (!match) {
678
+ console.log("Invalid QR code URL");
679
+ return null;
680
+ }
681
+
682
+ return { clientId: match[2], version: parseInt(match[1], 10) };
683
+ }
684
+
685
+ export function decodeJwt(jwt) {
686
+ try {
687
+ const parts = jwt.split(".");
688
+ if (parts.length !== 3) {
689
+ console.err("decodeJwt Error", new Error("Invalid JWT"));
690
+ return;
691
+ }
692
+
693
+ const standardBase64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
694
+ return JSON.parse(Buffer.from(standardBase64, "base64").toString("utf8"));
695
+ } catch (e) {
696
+ console.error("decodeJwt Error", e);
697
+ }
698
+ }
699
+
700
+ export async function renewRefreshToken({ refreshToken, accessToken }) {
701
+ const steamId = arguments[0]?.steamId;
702
+ try {
703
+ const { aud } = decodeJwt(accessToken);
704
+ let platformType = EAuthTokenPlatformType.SteamClient;
705
+ if (aud.includes("mobile")) {
706
+ platformType = EAuthTokenPlatformType.MobileApp;
707
+ } else if (aud.includes("client")) {
708
+ platformType = EAuthTokenPlatformType.SteamClient;
709
+ } else if (aud.includes("web")) {
710
+ platformType = EAuthTokenPlatformType.WebBrowser;
711
+ }
712
+
713
+ const { LoginSession } = await import("steam-session");
714
+ const session = new LoginSession(platformType);
715
+ session.refreshToken = refreshToken;
716
+ await session.refreshAccessToken();
717
+ const cookie = (await session.getWebCookies())?.join?.(";");
718
+ return {
719
+ cookie,
720
+ accessToken: session.accessToken,
721
+ accessTokenDecoded: decodeJwt(session.accessToken),
722
+ };
723
+ } catch (e) {
724
+ console.error(`${steamId ? `[${steamId}] ` : ""}renewRefreshToken Error`, e);
725
+ }
726
+ }
727
+
728
+ export async function approveLogin({ steamId, url, sharedSecret, accessToken, shouldApprove }) {
729
+ try {
730
+ const { LoginApprover } = await import("steam-session");
731
+ const approver = new LoginApprover(accessToken, sharedSecret, {});
732
+ const sessionInfo = await approver.getAuthSessionInfo(url);
733
+ sessionInfo.steamId = steamId;
734
+
735
+ if (typeof shouldApprove === "function" && !shouldApprove(sessionInfo)) {
736
+ return;
737
+ }
738
+
739
+ await approver.approveAuthSession({
740
+ qrChallengeUrl: url,
741
+ approve: true,
742
+ });
743
+
744
+ return {
745
+ steamId,
746
+ sessionInfo,
747
+ };
748
+ } catch (error) {
749
+ console.error(`[${steamId}] approveLogin Error`, error);
750
+ return {
751
+ steamId,
752
+ error,
753
+ };
754
+ }
755
+ }
756
+
757
+ export function getBonusXpTimeRefresh() {
758
+ let resetDay = moment.utc().startOf("isoWeek").add(2, "days").add(1, "hours");
759
+ while (moment().isAfter(resetDay)) {
760
+ resetDay = resetDay.add(7, "days");
761
+ }
762
+ if (moment().isBefore(resetDay)) {
763
+ resetDay = resetDay.subtract(7, "days");
764
+ }
765
+ return resetDay;
766
+ }
767
+
768
+ export function estimateNextXp(currentXp, xpEarned) {
769
+ //estimate next xp
770
+ let bonusTime = 1;
771
+ if (xpEarned < 4500) {
772
+ bonusTime = 4;
773
+ } else if (xpEarned < 7500) {
774
+ bonusTime = 2;
775
+ } else if (xpEarned < 11200) {
776
+ bonusTime = 1;
777
+ } else {
778
+ bonusTime = 0.175;
779
+ }
780
+
781
+ const nextXp = 30 * 13 * bonusTime;
782
+ return nextXp + currentXp;
783
+ }
784
+
785
+ export function formatMarketCurrency(valueInCents, currencyCode = getMarketCurrencyCode(g_rgWalletInfo.wallet_currency), countryCode) {
786
+ if (!valueInCents && valueInCents !== 0) {
787
+ return "";
788
+ }
789
+
790
+ let currencyFormat = (valueInCents / 100).toFixed(2);
791
+
792
+ if (g_rgCurrencyData[currencyCode]) {
793
+ const currencyData = g_rgCurrencyData[currencyCode];
794
+ if (isCurrencyWholeUnits(currencyCode)) {
795
+ currencyFormat = currencyFormat.replace(".00", "");
796
+ }
797
+
798
+ if (currencyData.strDecimalSymbol !== ".") {
799
+ currencyFormat = currencyFormat.replace(".", currencyData.strDecimalSymbol);
800
+ }
801
+
802
+ const currencySymbol = getMarketCurrencySymbol(currencyCode);
803
+ const currencyReturn = isCurrencySymbolBeforeValue(currencyCode) ? currencySymbol + currencyData.strSymbolAndNumberSeparator + currencyFormat : currencyFormat + currencyData.strSymbolAndNumberSeparator + currencySymbol;
804
+
805
+ if (currencyCode === "USD" && typeof countryCode != "undefined" && countryCode != "US") {
806
+ return `${currencyReturn} USD`;
807
+ } else if (currencyCode === "EUR") {
808
+ return currencyReturn.replace(",00", ",--");
809
+ } else {
810
+ return currencyReturn;
811
+ }
812
+ } else {
813
+ return `${currencyFormat} ${currencyCode}`;
814
+ }
815
+ }
816
+
817
+ export function getMarketPriceValueAsInt(strAmount) {
818
+ let nAmount;
819
+ if (!strAmount) {
820
+ return 0;
821
+ }
822
+
823
+ // Users may enter either comma or period for the decimal mark and digit group separators.
824
+ strAmount = strAmount.replace(/,/g, ".");
825
+
826
+ // strip the currency symbol, set .-- to .00
827
+ strAmount = strAmount.replace(getMarketCurrencySymbol(getMarketCurrencyCode(g_rgWalletInfo.wallet_currency)), "").replace(".--", ".00");
828
+
829
+ // strip spaces
830
+ strAmount = strAmount.replace(/ /g, "");
831
+
832
+ // Remove all but the last period so that entries like "1,147.6" work
833
+ if (strAmount.includes(".")) {
834
+ var splitAmount = strAmount.split(".");
835
+ var strLastSegment = splitAmount[splitAmount.length - 1];
836
+
837
+ if (!isNaN(strLastSegment) && strLastSegment.length == 3 && splitAmount[splitAmount.length - 2] != "0") {
838
+ // Looks like the user only entered thousands separators. Remove all commas and periods.
839
+ // Ensures an entry like "1,147" is not treated as "1.147"
840
+ //
841
+ // Users may be surprised to find that "1.147" is treated as "1,147". "1.147" is either an error or the user
842
+ // really did mean one thousand one hundred and forty seven since no currencies can be split into more than
843
+ // hundredths. If it was an error, the user should notice in the next step of the dialog and can go back and
844
+ // correct it. If they happen to not notice, it is better that we list the item at a higher price than
845
+ // intended instead of lower than intended (which we would have done if we accepted the 1.147 value as is).
846
+ strAmount = splitAmount.join("");
847
+ } else {
848
+ strAmount = `${splitAmount.slice(0, -1).join("")}.${strLastSegment}`;
849
+ }
850
+ }
851
+
852
+ let flAmount = parseFloat(strAmount) * 100;
853
+ nAmount = Math.floor(isNaN(flAmount) ? 0 : flAmount + 0.000001); // round down
854
+
855
+ nAmount = Math.max(nAmount, 0);
856
+ return nAmount;
857
+ }
858
+
859
+ export function isCurrencyWholeUnits(currencyCode) {
860
+ return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bWholeUnitsOnly && currencyCode !== "RUB";
861
+ }
862
+
863
+ export function isCurrencySymbolBeforeValue(currencyCode) {
864
+ return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bSymbolIsPrefix;
865
+ }
866
+
867
+ // Return the symbol to use for a currency
868
+ export function getMarketCurrencySymbol(currencyCode) {
869
+ return g_rgCurrencyData[currencyCode]?.strSymbol ?? currencyCode;
870
+ }
871
+
872
+ export function getMarketCurrencyCode(currencyId) {
873
+ currencyId = parseInt(currencyId);
874
+ for (const code in g_rgCurrencyData) {
875
+ if (g_rgCurrencyData[code].eCurrencyCode === currencyId) {
876
+ return code;
877
+ }
878
+ }
879
+ return "Unknown";
880
+ }
881
+
882
+ export async function loginWithCredentials({ username, password, timeoutMs = 120000, sharedSecret, getMailSteamGuardCodes }) {
883
+ if (!username) {
884
+ return {
885
+ error: "No username",
886
+ };
887
+ }
888
+
889
+ if (!password) {
890
+ return {
891
+ error: "No password",
892
+ };
893
+ }
894
+
895
+ const { LoginSession } = await import("steam-session");
896
+ let authenticated = false;
897
+ return new Promise((resolve) => {
898
+ const timeout = setTimeout(function () {
899
+ resolve({
900
+ error: "Timed out",
901
+ });
902
+ }, timeoutMs);
903
+
904
+ const session = new LoginSession(EAuthTokenPlatformType.MobileApp);
905
+ session.on("authenticated", async () => {
906
+ authenticated = true;
907
+ const cookie = (await session.getWebCookies())?.join?.(";");
908
+ return onResolve({
909
+ cookie,
910
+ accessToken: session.accessToken,
911
+ refreshToken: session.refreshToken,
912
+ accessTokenDecoded: decodeJwt(session.accessToken),
913
+ });
914
+ });
915
+
916
+ session
917
+ .startWithCredentials({
918
+ accountName: username,
919
+ password: password,
920
+ steamGuardMachineToken: "",
921
+ })
922
+ .then(async function (startResult) {
923
+ if (!startResult.actionRequired) {
924
+ return;
925
+ }
926
+
927
+ if (sharedSecret) {
928
+ let error = null;
929
+ const maxRetry = 3;
930
+ for (let i = 0; i < maxRetry; i++) {
931
+ try {
932
+ await session.submitSteamGuardCode(SteamTotp.generateAuthCode(sharedSecret));
933
+ error = null;
934
+ } catch (e) {
935
+ error = e;
936
+ }
937
+ await sleep(1000);
938
+ }
939
+ if (error) {
940
+ console.error(error);
941
+ onResolve({ error });
942
+ }
943
+ } else {
944
+ if (startResult.validActions.every((validAction) => validAction.type !== 2)) {
945
+ console.error(startResult.validActions);
946
+ return onResolve({
947
+ error: "validActions",
948
+ });
949
+ }
950
+
951
+ if (typeof getMailSteamGuardCodes === "function") {
952
+ const codes = await getMailSteamGuardCodes();
953
+ if (!Array.isArray(codes) || !codes.length) {
954
+ return onResolve({
955
+ error: "Can't find steam guard code",
956
+ });
957
+ }
958
+
959
+ let error = null;
960
+ for (const code of codes) {
961
+ if (!authenticated) {
962
+ try {
963
+ await session.submitSteamGuardCode(code);
964
+ error = null;
965
+ } catch (e) {
966
+ error = e;
967
+ }
968
+ await sleep(1000);
969
+ }
970
+ }
971
+ if (!authenticated && error) {
972
+ onResolve(error);
973
+ }
974
+ } else {
975
+ return onResolve({
976
+ error: "MailCodeError",
977
+ });
978
+ }
979
+ }
980
+ })
981
+ .catch(function (e) {
982
+ return onResolve(e);
983
+ });
984
+
985
+ function onResolve(data) {
986
+ clearTimeout(timeout);
987
+ return resolve(data);
988
+ }
989
+ });
990
+ }
991
+
992
+ export function calculateAccountXP(currentXp, xpEarnedThisWeek, xpEarned, nextXp) {
993
+ return (
994
+ (() => {
995
+ if (typeof nextXp !== "number" || !Number.isFinite(nextXp)) {
996
+ return;
997
+ }
998
+
999
+ currentXp = currentXp || 0;
1000
+ if (currentXp === nextXp) {
1001
+ return;
1002
+ }
1003
+
1004
+ const update = { currentXp: nextXp };
1005
+ if (nextXp < currentXp) {
1006
+ update.xpExceed = Date.now();
1007
+ }
1008
+ const resetDay = getBonusXpTimeRefresh().format("YYYY-MM-DD");
1009
+ const isWeekReset = xpEarnedThisWeek !== resetDay;
1010
+ let xpEarnedThisRank = nextXp - currentXp;
1011
+ if (xpEarnedThisRank < 0) {
1012
+ xpEarnedThisRank += 5000;
1013
+ }
1014
+ if (isWeekReset) {
1015
+ update.xpEarnedThisWeek = resetDay;
1016
+ update.xpEarned = xpEarnedThisRank;
1017
+ } else {
1018
+ update.xpEarned = (xpEarned || 0) + xpEarnedThisRank;
1019
+ if (xpEarnedThisRank === 0) {
1020
+ return;
1021
+ }
1022
+ }
1023
+
1024
+ return update;
1025
+ })() || {}
1026
+ );
1027
+ }
1028
+
1029
+ export async function downloadImage(url, filePath) {
1030
+ let response = null;
1031
+ try {
1032
+ response = await axios.get(url, {
1033
+ responseType: "arraybuffer",
1034
+ });
1035
+ } catch (e) {
1036
+ /* empty */
1037
+ }
1038
+
1039
+ if (!response || !response.data) {
1040
+ return;
1041
+ }
1042
+
1043
+ return new Promise((resolve) => {
1044
+ fs.writeFile(filePath, response.data, (err) => {
1045
+ if (err) {
1046
+ resolve();
1047
+ }
1048
+ resolve(filePath);
1049
+ });
1050
+ });
1051
+ }
1052
+
1053
+ //from large text file
1054
+ export function readRandomLine(filePath) {
1055
+ return new Promise((resolve, reject) => {
1056
+ const rl = readline.createInterface({
1057
+ input: fs.createReadStream(filePath),
1058
+ crlfDelay: Infinity,
1059
+ });
1060
+
1061
+ let resultLine = null;
1062
+ let lineNumber = 0;
1063
+
1064
+ rl.on("line", (line) => {
1065
+ lineNumber += 1;
1066
+ // Choose this line with probability 1 / lineNumber
1067
+ if (Math.random() < 1 / lineNumber) {
1068
+ resultLine = line;
1069
+ }
1070
+ });
1071
+
1072
+ rl.on("close", () => {
1073
+ if (resultLine !== null) {
1074
+ resolve(resultLine);
1075
+ } else {
1076
+ reject(new Error("File is empty"));
1077
+ }
1078
+ });
1079
+
1080
+ rl.on("error", (err) => {
1081
+ reject(err);
1082
+ });
1083
+ });
1084
+ }