steamutils 1.4.77 → 1.4.78

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