steamutils 1.5.4 → 1.5.5

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 +1050 -1050
  233. package/.idea/deployment.xml +0 -14
package/utils.js CHANGED
@@ -1,1050 +1,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
-
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
+
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
+ }