steamutils 1.4.92 → 1.4.93
Sign up to get free protection for your applications and to get access to all the features.
- package/.idea/codeStyles/Project.xml +0 -1
- package/.idea/gbrowser_project.xml +11 -0
- package/.idea/git_toolbox_blame.xml +6 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.prettierrc.json +3 -3
- package/SteamClient.js +3174 -3174
- package/_steamproto.js +33 -33
- package/axios.js +84 -84
- package/bufferHelpers.js +115 -115
- package/cheerio.js +103 -103
- package/const.js +518 -518
- package/create_proto.js +96 -96
- package/create_remote_file.js +159 -153
- package/full_steamproto.js +34 -34
- package/helpers/protos.js +48 -48
- package/index.js +7776 -7776
- package/package.json +1 -1
- package/protos/csgo/base_gcmessages.proto +553 -553
- package/protos/csgo/base_gcmessages_csgo.proto +547 -547
- package/protos/csgo/c_peer2peer_netmessages.proto +55 -55
- package/protos/csgo/clientmessages.proto +48 -48
- package/protos/csgo/connectionless_netmessages.proto +17 -17
- package/protos/csgo/cs_gameevents.proto +35 -35
- package/protos/csgo/cs_usercmd.proto +34 -34
- package/protos/csgo/cstrike15_usermessages.proto +592 -592
- package/protos/csgo/demo.proto +165 -165
- package/protos/csgo/econ_gcmessages.proto +219 -219
- package/protos/csgo/enums_clientserver.proto +1529 -1529
- package/protos/csgo/fatdemo.proto +125 -125
- package/protos/csgo/gameevents.proto +120 -120
- package/protos/csgo/gcsdk_gcmessages.proto +323 -323
- package/protos/csgo/gcsystemmsgs.proto +243 -243
- package/protos/csgo/netmessages.proto +618 -618
- package/protos/csgo/networkbasetypes.proto +246 -246
- package/protos/csgo/networksystem_protomessages.proto +17 -17
- package/protos/csgo/steamdatagram_messages_auth.proto +65 -65
- package/protos/csgo/steamdatagram_messages_sdr.proto +534 -534
- package/protos/csgo/steammessages_cloud.steamworkssdk.proto +68 -68
- package/protos/csgo/steammessages_gamenetworkingui.proto +61 -61
- package/protos/csgo/steammessages_helprequest.steamworkssdk.proto +22 -22
- package/protos/csgo/steammessages_oauth.steamworkssdk.proto +18 -18
- package/protos/csgo/steammessages_player.steamworkssdk.proto +254 -254
- package/protos/csgo/steammessages_publishedfile.steamworkssdk.proto +233 -233
- package/protos/csgo/steamnetworkingsockets_messages.proto +205 -205
- package/protos/csgo/steamnetworkingsockets_messages_certs.proto +39 -39
- package/protos/csgo/steamnetworkingsockets_messages_udp.proto +75 -75
- package/protos/csgo/te.proto +259 -259
- package/protos/csgo/uifontfile_format.proto +13 -13
- package/protos/csgo/usercmd.proto +39 -39
- package/protos/csgo/usermessages.proto +752 -752
- package/protos/google/protobuf/descriptor.proto +281 -281
- package/protos/steam/clientmetrics.proto +45 -45
- package/protos/steam/content_manifest.proto +62 -62
- package/protos/steam/contenthubs.proto +41 -41
- package/protos/steam/encrypted_app_ticket.proto +10 -10
- package/protos/steam/enums.proto +501 -501
- package/protos/steam/enums_clientserver.proto +1508 -1508
- package/protos/steam/enums_productinfo.proto +14 -14
- package/protos/steam/htmlmessages.proto +1039 -1039
- package/protos/steam/offline_ticket.proto +8 -8
- package/protos/steam/steamdatagram_messages_auth.proto +65 -65
- package/protos/steam/steamdatagram_messages_sdr.proto +533 -533
- package/protos/steam/steammessages_accounthardware.steamclient.proto +167 -167
- package/protos/steam/steammessages_appoverview.proto +204 -204
- package/protos/steam/steammessages_auth.steamclient.proto +375 -375
- package/protos/steam/steammessages_broadcast.steamclient.proto +618 -618
- package/protos/steam/steammessages_chat.steamclient.proto +1070 -1070
- package/protos/steam/steammessages_client_objects.proto +649 -649
- package/protos/steam/steammessages_clientlanp2p.proto +43 -43
- package/protos/steam/steammessages_clientmetrics.steamclient.proto +192 -192
- package/protos/steam/steammessages_clientnotificationtypes.proto +250 -250
- package/protos/steam/steammessages_clientserver.proto +392 -392
- package/protos/steam/steammessages_clientserver_2.proto +771 -771
- package/protos/steam/steammessages_clientserver_appinfo.proto +131 -131
- package/protos/steam/steammessages_clientserver_friends.proto +260 -260
- package/protos/steam/steammessages_clientserver_gameservers.proto +159 -159
- package/protos/steam/steammessages_clientserver_lbs.proto +70 -70
- package/protos/steam/steammessages_clientserver_login.proto +167 -167
- package/protos/steam/steammessages_clientserver_mms.proto +233 -233
- package/protos/steam/steammessages_clientserver_ucm.proto +207 -207
- package/protos/steam/steammessages_clientserver_uds.proto +125 -125
- package/protos/steam/steammessages_clientserver_ufs.proto +45 -45
- package/protos/steam/steammessages_clientserver_userstats.proto +80 -80
- package/protos/steam/steammessages_cloud.steamclient.proto +422 -422
- package/protos/steam/steammessages_contentsystem.steamclient.proto +123 -123
- package/protos/steam/steammessages_credentials.steamclient.proto +96 -96
- package/protos/steam/steammessages_datapublisher.steamclient.proto +102 -102
- package/protos/steam/steammessages_depotbuilder.steamclient.proto +99 -99
- package/protos/steam/steammessages_deviceauth.steamclient.proto +169 -169
- package/protos/steam/steammessages_econ.steamclient.proto +137 -137
- package/protos/steam/steammessages_familygroups.steamclient.proto +441 -441
- package/protos/steam/steammessages_friendmessages.steamclient.proto +141 -141
- package/protos/steam/steammessages_gamenetworking.steamclient.proto +25 -25
- package/protos/steam/steammessages_gamenetworkingui.proto +61 -61
- package/protos/steam/steammessages_gamenotifications.steamclient.proto +131 -131
- package/protos/steam/steammessages_gameservers.steamclient.proto +136 -136
- package/protos/steam/steammessages_hiddevices.proto +157 -157
- package/protos/steam/steammessages_inventory.steamclient.proto +172 -172
- package/protos/steam/steammessages_linkfilter.steamclient.proto +39 -39
- package/protos/steam/steammessages_lobbymatchmaking.steamclient.proto +29 -29
- package/protos/steam/steammessages_market.steamclient.proto +22 -22
- package/protos/steam/steammessages_marketingmessages.steamclient.proto +273 -273
- package/protos/steam/steammessages_offline.steamclient.proto +33 -33
- package/protos/steam/steammessages_parental.steamclient.proto +262 -262
- package/protos/steam/steammessages_parties.steamclient.proto +75 -75
- package/protos/steam/steammessages_partnerapps.steamclient.proto +106 -106
- package/protos/steam/steammessages_player.steamclient.proto +915 -915
- package/protos/steam/steammessages_publishedfile.steamclient.proto +737 -737
- package/protos/steam/steammessages_qms.steamclient.proto +111 -111
- package/protos/steam/steammessages_remoteclient.proto +100 -100
- package/protos/steam/steammessages_remoteclient_discovery.proto +244 -244
- package/protos/steam/steammessages_remoteclient_service.steamclient.proto +31 -31
- package/protos/steam/steammessages_remoteclient_service_messages.proto +217 -217
- package/protos/steam/steammessages_remoteplay.proto +975 -975
- package/protos/steam/steammessages_secrets.steamclient.proto +35 -35
- package/protos/steam/steammessages_shader.steamclient.proto +89 -89
- package/protos/steam/steammessages_site_license.steamclient.proto +103 -103
- package/protos/steam/steammessages_sitelicenseclient.proto +38 -38
- package/protos/steam/steammessages_siteserverui.proto +130 -130
- package/protos/steam/steammessages_steamtv.steamclient.proto +533 -533
- package/protos/steam/steammessages_store.steamclient.proto +404 -404
- package/protos/steam/steammessages_storebrowse.steamclient.proto +457 -457
- package/protos/steam/steammessages_timedtrial.steamclient.proto +40 -40
- package/protos/steam/steammessages_twofactor.steamclient.proto +157 -157
- package/protos/steam/steammessages_unified_test.steamclient.proto +51 -51
- package/protos/steam/steammessages_useraccount.steamclient.proto +211 -211
- package/protos/steam/steammessages_vac.steamclient.proto +37 -37
- package/protos/steam/steammessages_video.steamclient.proto +68 -68
- package/protos/steam/steammessages_virtualcontroller.proto +138 -138
- package/protos/steam/steammessages_workshop.steamclient.proto +19 -19
- package/protos/steam/steamnetworkingsockets_messages.proto +205 -205
- package/protos/steam/steamnetworkingsockets_messages_certs.proto +39 -39
- package/protos/steam/steamnetworkingsockets_messages_udp.proto +75 -75
- package/protos/steam/webuimessages_achievements.proto +29 -29
- package/protos/steam/webuimessages_gamenotes.proto +21 -21
- package/protos/steam/webuimessages_gamescope.proto +57 -57
- package/protos/steam/webuimessages_steamengine.proto +41 -41
- package/protos/steam/webuimessages_steamos.proto +114 -114
- package/protos/steam/webuimessages_storagedevicemanager.proto +110 -110
- package/protos/steam/webuimessages_systemmanager.proto +17 -17
- package/protos/steam/webuimessages_transport.proto +22 -22
- package/protos/steam/webuimessages_transportvalidation.proto +111 -111
- package/protos/webui/common.proto +4024 -4024
- package/protos/webui/service_accountcart.proto +153 -153
- package/protos/webui/service_accountlinking.proto +27 -27
- package/protos/webui/service_accountprivacy.proto +42 -42
- package/protos/webui/service_accountprivateapps.proto +34 -34
- package/protos/webui/service_auction.proto +97 -97
- package/protos/webui/service_authentication.proto +222 -222
- package/protos/webui/service_authenticationsupport.proto +74 -74
- package/protos/webui/service_broadcast.proto +562 -562
- package/protos/webui/service_chat.proto +11 -11
- package/protos/webui/service_chatroom.proto +810 -810
- package/protos/webui/service_chatusability.proto +107 -107
- package/protos/webui/service_checkout.proto +84 -84
- package/protos/webui/service_clan.proto +41 -41
- package/protos/webui/service_clanchatrooms.proto +25 -25
- package/protos/webui/service_clanfaqs.proto +202 -202
- package/protos/webui/service_clientcomm.proto +151 -151
- package/protos/webui/service_clientmetrics.proto +22 -22
- package/protos/webui/service_cloud.proto +222 -222
- package/protos/webui/service_cloudconfigstore.proto +51 -51
- package/protos/webui/service_cloudgaming.proto +30 -30
- package/protos/webui/service_community.proto +365 -365
- package/protos/webui/service_dailydeal.proto +89 -89
- package/protos/webui/service_econ.proto +134 -134
- package/protos/webui/service_embedded.proto +24 -24
- package/protos/webui/service_experimentservice.proto +6 -6
- package/protos/webui/service_familygroups.proto +355 -355
- package/protos/webui/service_fovasvideo.proto +15 -15
- package/protos/webui/service_friendmessages.proto +133 -133
- package/protos/webui/service_friendslist.proto +70 -70
- package/protos/webui/service_gamenotes.proto +15 -15
- package/protos/webui/service_gamerecording.proto +265 -265
- package/protos/webui/service_gamerecordingclip.proto +85 -85
- package/protos/webui/service_gamerecordingdebug.proto +52 -52
- package/protos/webui/service_helprequestlogs.proto +16 -16
- package/protos/webui/service_loyaltyrewards.proto +252 -252
- package/protos/webui/service_marketingmessages.proto +215 -215
- package/protos/webui/service_mobileapp.proto +18 -18
- package/protos/webui/service_mobileauth.proto +24 -24
- package/protos/webui/service_mobiledevice.proto +26 -26
- package/protos/webui/service_mobileperaccount.proto +31 -31
- package/protos/webui/service_news.proto +110 -110
- package/protos/webui/service_parental.proto +258 -258
- package/protos/webui/service_partnermembershipinvite.proto +34 -34
- package/protos/webui/service_partnerstorebrowse.proto +28 -28
- package/protos/webui/service_phone.proto +51 -51
- package/protos/webui/service_physicalgoods.proto +15 -15
- package/protos/webui/service_player.proto +918 -918
- package/protos/webui/service_promotioneventinvites.proto +109 -109
- package/protos/webui/service_promotionplanning.proto +186 -186
- package/protos/webui/service_promotionstats.proto +23 -23
- package/protos/webui/service_publishedfile.proto +714 -714
- package/protos/webui/service_publishing.proto +200 -200
- package/protos/webui/service_quest.proto +127 -127
- package/protos/webui/service_salefeature.proto +373 -373
- package/protos/webui/service_saleitemrewards.proto +54 -54
- package/protos/webui/service_shoppingcart.proto +152 -152
- package/protos/webui/service_steamawards.proto +76 -76
- package/protos/webui/service_steamcharts.proto +75 -75
- package/protos/webui/service_steamengine.proto +36 -36
- package/protos/webui/service_steamlearn.proto +876 -876
- package/protos/webui/service_steamnotification.proto +73 -73
- package/protos/webui/service_steamtv.proto +495 -495
- package/protos/webui/service_steamvrvoicechat.proto +67 -67
- package/protos/webui/service_steamvrwebrtc.proto +48 -48
- package/protos/webui/service_storagedevicemanager.proto +104 -104
- package/protos/webui/service_store.proto +359 -359
- package/protos/webui/service_storeappsimilarity.proto +76 -76
- package/protos/webui/service_storebrowse.proto +103 -103
- package/protos/webui/service_storemarketing.proto +44 -44
- package/protos/webui/service_storequery.proto +103 -103
- package/protos/webui/service_storesales.proto +87 -87
- package/protos/webui/service_storetopsellers.proto +44 -44
- package/protos/webui/service_systemmanager.proto +11 -11
- package/protos/webui/service_test_transporterror.proto +6 -6
- package/protos/webui/service_transportauth.proto +17 -17
- package/protos/webui/service_transportvalidation.proto +69 -69
- package/protos/webui/service_twofactor.proto +170 -170
- package/protos/webui/service_useraccount.proto +142 -142
- package/protos/webui/service_usergameactivity.proto +34 -34
- package/protos/webui/service_usergamenotes.proto +70 -70
- package/protos/webui/service_usernews.proto +68 -68
- package/protos/webui/service_userreviews.proto +97 -97
- package/protos/webui/service_video.proto +50 -50
- package/protos/webui/service_videoclip.proto +62 -62
- package/protos/webui/service_voicechat.proto +139 -139
- package/protos/webui/service_webrtc.proto +52 -52
- package/remote.js +2209 -2203
- package/steamproto.js +1 -1
- package/utils.js +987 -987
- package/.idea/deployment.xml +0 -14
package/utils.js
CHANGED
@@ -1,987 +1,987 @@
|
|
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
|
-
const steamId = arguments[0]?.steamId;
|
699
|
-
try {
|
700
|
-
const { aud } = decodeJwt(accessToken);
|
701
|
-
let platformType = EAuthTokenPlatformType.SteamClient;
|
702
|
-
if (aud.includes("mobile")) {
|
703
|
-
platformType = EAuthTokenPlatformType.MobileApp;
|
704
|
-
} else if (aud.includes("client")) {
|
705
|
-
platformType = EAuthTokenPlatformType.SteamClient;
|
706
|
-
} else if (aud.includes("web")) {
|
707
|
-
platformType = EAuthTokenPlatformType.WebBrowser;
|
708
|
-
}
|
709
|
-
|
710
|
-
const { LoginSession } = await import("steam-session");
|
711
|
-
const session = new LoginSession(platformType);
|
712
|
-
session.refreshToken = refreshToken;
|
713
|
-
await session.refreshAccessToken();
|
714
|
-
const cookie = (await session.getWebCookies())?.join?.(";");
|
715
|
-
return {
|
716
|
-
cookie,
|
717
|
-
accessToken: session.accessToken,
|
718
|
-
accessTokenDecoded: decodeJwt(session.accessToken),
|
719
|
-
};
|
720
|
-
} catch (e) {
|
721
|
-
console.error(`${steamId ? `[${steamId}] ` : ""}renewRefreshToken Error`, e);
|
722
|
-
}
|
723
|
-
}
|
724
|
-
|
725
|
-
export async function approveLogin({ steamId, url, sharedSecret, accessToken, shouldApprove }) {
|
726
|
-
try {
|
727
|
-
const { LoginApprover } = await import("steam-session");
|
728
|
-
const approver = new LoginApprover(accessToken, sharedSecret, {});
|
729
|
-
const sessionInfo = await approver.getAuthSessionInfo(url);
|
730
|
-
sessionInfo.steamId = steamId;
|
731
|
-
|
732
|
-
if (typeof shouldApprove === "function" && !shouldApprove(sessionInfo)) {
|
733
|
-
return;
|
734
|
-
}
|
735
|
-
|
736
|
-
await approver.approveAuthSession({
|
737
|
-
qrChallengeUrl: url,
|
738
|
-
approve: true,
|
739
|
-
});
|
740
|
-
|
741
|
-
return {
|
742
|
-
steamId,
|
743
|
-
sessionInfo,
|
744
|
-
};
|
745
|
-
} catch (error) {
|
746
|
-
console.error(`[${steamId}] approveLogin Error`, error);
|
747
|
-
return {
|
748
|
-
steamId,
|
749
|
-
error,
|
750
|
-
};
|
751
|
-
}
|
752
|
-
}
|
753
|
-
|
754
|
-
export function getBonusXpTimeRefresh() {
|
755
|
-
let resetDay = moment.utc().startOf("isoWeek").add(2, "days").add(1, "hours");
|
756
|
-
while (moment().isAfter(resetDay)) {
|
757
|
-
resetDay = resetDay.add(7, "days");
|
758
|
-
}
|
759
|
-
if (moment().isBefore(resetDay)) {
|
760
|
-
resetDay = resetDay.subtract(7, "days");
|
761
|
-
}
|
762
|
-
return resetDay;
|
763
|
-
}
|
764
|
-
|
765
|
-
export function estimateNextXp(currentXp, xpEarned) {
|
766
|
-
//estimate next xp
|
767
|
-
let bonusTime = 1;
|
768
|
-
if (xpEarned < 4500) {
|
769
|
-
bonusTime = 4;
|
770
|
-
} else if (xpEarned < 7500) {
|
771
|
-
bonusTime = 2;
|
772
|
-
} else if (xpEarned < 11200) {
|
773
|
-
bonusTime = 1;
|
774
|
-
} else {
|
775
|
-
bonusTime = 0.175;
|
776
|
-
}
|
777
|
-
|
778
|
-
const nextXp = 30 * 13 * bonusTime;
|
779
|
-
return nextXp + currentXp;
|
780
|
-
}
|
781
|
-
|
782
|
-
export function formatMarketCurrency(valueInCents, currencyCode = getMarketCurrencyCode(g_rgWalletInfo.wallet_currency), countryCode) {
|
783
|
-
if (!valueInCents && valueInCents !== 0) {
|
784
|
-
return "";
|
785
|
-
}
|
786
|
-
|
787
|
-
let currencyFormat = (valueInCents / 100).toFixed(2);
|
788
|
-
|
789
|
-
if (g_rgCurrencyData[currencyCode]) {
|
790
|
-
const currencyData = g_rgCurrencyData[currencyCode];
|
791
|
-
if (isCurrencyWholeUnits(currencyCode)) {
|
792
|
-
currencyFormat = currencyFormat.replace(".00", "");
|
793
|
-
}
|
794
|
-
|
795
|
-
if (currencyData.strDecimalSymbol !== ".") {
|
796
|
-
currencyFormat = currencyFormat.replace(".", currencyData.strDecimalSymbol);
|
797
|
-
}
|
798
|
-
|
799
|
-
const currencySymbol = getMarketCurrencySymbol(currencyCode);
|
800
|
-
const currencyReturn = isCurrencySymbolBeforeValue(currencyCode) ? currencySymbol + currencyData.strSymbolAndNumberSeparator + currencyFormat : currencyFormat + currencyData.strSymbolAndNumberSeparator + currencySymbol;
|
801
|
-
|
802
|
-
if (currencyCode === "USD" && typeof countryCode != "undefined" && countryCode != "US") {
|
803
|
-
return `${currencyReturn} USD`;
|
804
|
-
} else if (currencyCode === "EUR") {
|
805
|
-
return currencyReturn.replace(",00", ",--");
|
806
|
-
} else {
|
807
|
-
return currencyReturn;
|
808
|
-
}
|
809
|
-
} else {
|
810
|
-
return `${currencyFormat} ${currencyCode}`;
|
811
|
-
}
|
812
|
-
}
|
813
|
-
|
814
|
-
export function getMarketPriceValueAsInt(strAmount) {
|
815
|
-
let nAmount;
|
816
|
-
if (!strAmount) {
|
817
|
-
return 0;
|
818
|
-
}
|
819
|
-
|
820
|
-
// Users may enter either comma or period for the decimal mark and digit group separators.
|
821
|
-
strAmount = strAmount.replace(/,/g, ".");
|
822
|
-
|
823
|
-
// strip the currency symbol, set .-- to .00
|
824
|
-
strAmount = strAmount.replace(getMarketCurrencySymbol(getMarketCurrencyCode(g_rgWalletInfo.wallet_currency)), "").replace(".--", ".00");
|
825
|
-
|
826
|
-
// strip spaces
|
827
|
-
strAmount = strAmount.replace(/ /g, "");
|
828
|
-
|
829
|
-
// Remove all but the last period so that entries like "1,147.6" work
|
830
|
-
if (strAmount.includes(".")) {
|
831
|
-
var splitAmount = strAmount.split(".");
|
832
|
-
var strLastSegment = splitAmount[splitAmount.length - 1];
|
833
|
-
|
834
|
-
if (!isNaN(strLastSegment) && strLastSegment.length == 3 && splitAmount[splitAmount.length - 2] != "0") {
|
835
|
-
// Looks like the user only entered thousands separators. Remove all commas and periods.
|
836
|
-
// Ensures an entry like "1,147" is not treated as "1.147"
|
837
|
-
//
|
838
|
-
// Users may be surprised to find that "1.147" is treated as "1,147". "1.147" is either an error or the user
|
839
|
-
// really did mean one thousand one hundred and forty seven since no currencies can be split into more than
|
840
|
-
// hundredths. If it was an error, the user should notice in the next step of the dialog and can go back and
|
841
|
-
// correct it. If they happen to not notice, it is better that we list the item at a higher price than
|
842
|
-
// intended instead of lower than intended (which we would have done if we accepted the 1.147 value as is).
|
843
|
-
strAmount = splitAmount.join("");
|
844
|
-
} else {
|
845
|
-
strAmount = `${splitAmount.slice(0, -1).join("")}.${strLastSegment}`;
|
846
|
-
}
|
847
|
-
}
|
848
|
-
|
849
|
-
let flAmount = parseFloat(strAmount) * 100;
|
850
|
-
nAmount = Math.floor(isNaN(flAmount) ? 0 : flAmount + 0.000001); // round down
|
851
|
-
|
852
|
-
nAmount = Math.max(nAmount, 0);
|
853
|
-
return nAmount;
|
854
|
-
}
|
855
|
-
|
856
|
-
export function isCurrencyWholeUnits(currencyCode) {
|
857
|
-
return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bWholeUnitsOnly && currencyCode !== "RUB";
|
858
|
-
}
|
859
|
-
|
860
|
-
export function isCurrencySymbolBeforeValue(currencyCode) {
|
861
|
-
return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bSymbolIsPrefix;
|
862
|
-
}
|
863
|
-
|
864
|
-
// Return the symbol to use for a currency
|
865
|
-
export function getMarketCurrencySymbol(currencyCode) {
|
866
|
-
return g_rgCurrencyData[currencyCode]?.strSymbol ?? currencyCode;
|
867
|
-
}
|
868
|
-
|
869
|
-
export function getMarketCurrencyCode(currencyId) {
|
870
|
-
currencyId = parseInt(currencyId);
|
871
|
-
for (const code in g_rgCurrencyData) {
|
872
|
-
if (g_rgCurrencyData[code].eCurrencyCode === currencyId) {
|
873
|
-
return code;
|
874
|
-
}
|
875
|
-
}
|
876
|
-
return "Unknown";
|
877
|
-
}
|
878
|
-
|
879
|
-
export async function loginWithCredentials({ username, password, timeoutMs = 120000, sharedSecret, getMailSteamGuardCodes }) {
|
880
|
-
if (!username) {
|
881
|
-
return {
|
882
|
-
error: "No username",
|
883
|
-
};
|
884
|
-
}
|
885
|
-
|
886
|
-
if (!password) {
|
887
|
-
return {
|
888
|
-
error: "No password",
|
889
|
-
};
|
890
|
-
}
|
891
|
-
|
892
|
-
const { LoginSession } = await import("steam-session");
|
893
|
-
let authenticated = false;
|
894
|
-
return new Promise((resolve) => {
|
895
|
-
const timeout = setTimeout(function () {
|
896
|
-
resolve({
|
897
|
-
error: "Timed out",
|
898
|
-
});
|
899
|
-
}, timeoutMs);
|
900
|
-
|
901
|
-
const session = new LoginSession(EAuthTokenPlatformType.MobileApp);
|
902
|
-
session.on("authenticated", async () => {
|
903
|
-
authenticated = true;
|
904
|
-
const cookie = (await session.getWebCookies())?.join?.(";");
|
905
|
-
return onResolve({
|
906
|
-
cookie,
|
907
|
-
accessToken: session.accessToken,
|
908
|
-
refreshToken: session.refreshToken,
|
909
|
-
accessTokenDecoded: decodeJwt(session.accessToken),
|
910
|
-
});
|
911
|
-
});
|
912
|
-
|
913
|
-
session
|
914
|
-
.startWithCredentials({
|
915
|
-
accountName: username,
|
916
|
-
password: password,
|
917
|
-
steamGuardMachineToken: "",
|
918
|
-
})
|
919
|
-
.then(async function (startResult) {
|
920
|
-
if (!startResult.actionRequired) {
|
921
|
-
return;
|
922
|
-
}
|
923
|
-
|
924
|
-
if (sharedSecret) {
|
925
|
-
let error = null;
|
926
|
-
const maxRetry = 3;
|
927
|
-
for (let i = 0; i < maxRetry; i++) {
|
928
|
-
try {
|
929
|
-
await session.submitSteamGuardCode(SteamTotp.generateAuthCode(sharedSecret));
|
930
|
-
error = null;
|
931
|
-
} catch (e) {
|
932
|
-
error = e;
|
933
|
-
}
|
934
|
-
await sleep(1000);
|
935
|
-
}
|
936
|
-
if (error) {
|
937
|
-
console.error(error);
|
938
|
-
onResolve({ error });
|
939
|
-
}
|
940
|
-
} else {
|
941
|
-
if (startResult.validActions.every((validAction) => validAction.type !== 2)) {
|
942
|
-
console.error(startResult.validActions);
|
943
|
-
return onResolve({
|
944
|
-
error: "validActions",
|
945
|
-
});
|
946
|
-
}
|
947
|
-
|
948
|
-
if (typeof getMailSteamGuardCodes === "function") {
|
949
|
-
const codes = await getMailSteamGuardCodes();
|
950
|
-
if (!Array.isArray(codes) || !codes.length) {
|
951
|
-
return onResolve({
|
952
|
-
error: "Can't find steam guard code",
|
953
|
-
});
|
954
|
-
}
|
955
|
-
|
956
|
-
let error = null;
|
957
|
-
for (const code of codes) {
|
958
|
-
if (!authenticated) {
|
959
|
-
try {
|
960
|
-
await session.submitSteamGuardCode(code);
|
961
|
-
error = null;
|
962
|
-
} catch (e) {
|
963
|
-
error = e;
|
964
|
-
}
|
965
|
-
await sleep(1000);
|
966
|
-
}
|
967
|
-
}
|
968
|
-
if (!authenticated && error) {
|
969
|
-
onResolve(error);
|
970
|
-
}
|
971
|
-
} else {
|
972
|
-
return onResolve({
|
973
|
-
error: "MailCodeError",
|
974
|
-
});
|
975
|
-
}
|
976
|
-
}
|
977
|
-
})
|
978
|
-
.catch(function (e) {
|
979
|
-
return onResolve(e);
|
980
|
-
});
|
981
|
-
|
982
|
-
function onResolve(data) {
|
983
|
-
clearTimeout(timeout);
|
984
|
-
return resolve(data);
|
985
|
-
}
|
986
|
-
});
|
987
|
-
}
|
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
|
+
const steamId = arguments[0]?.steamId;
|
699
|
+
try {
|
700
|
+
const { aud } = decodeJwt(accessToken);
|
701
|
+
let platformType = EAuthTokenPlatformType.SteamClient;
|
702
|
+
if (aud.includes("mobile")) {
|
703
|
+
platformType = EAuthTokenPlatformType.MobileApp;
|
704
|
+
} else if (aud.includes("client")) {
|
705
|
+
platformType = EAuthTokenPlatformType.SteamClient;
|
706
|
+
} else if (aud.includes("web")) {
|
707
|
+
platformType = EAuthTokenPlatformType.WebBrowser;
|
708
|
+
}
|
709
|
+
|
710
|
+
const { LoginSession } = await import("steam-session");
|
711
|
+
const session = new LoginSession(platformType);
|
712
|
+
session.refreshToken = refreshToken;
|
713
|
+
await session.refreshAccessToken();
|
714
|
+
const cookie = (await session.getWebCookies())?.join?.(";");
|
715
|
+
return {
|
716
|
+
cookie,
|
717
|
+
accessToken: session.accessToken,
|
718
|
+
accessTokenDecoded: decodeJwt(session.accessToken),
|
719
|
+
};
|
720
|
+
} catch (e) {
|
721
|
+
console.error(`${steamId ? `[${steamId}] ` : ""}renewRefreshToken Error`, e);
|
722
|
+
}
|
723
|
+
}
|
724
|
+
|
725
|
+
export async function approveLogin({ steamId, url, sharedSecret, accessToken, shouldApprove }) {
|
726
|
+
try {
|
727
|
+
const { LoginApprover } = await import("steam-session");
|
728
|
+
const approver = new LoginApprover(accessToken, sharedSecret, {});
|
729
|
+
const sessionInfo = await approver.getAuthSessionInfo(url);
|
730
|
+
sessionInfo.steamId = steamId;
|
731
|
+
|
732
|
+
if (typeof shouldApprove === "function" && !shouldApprove(sessionInfo)) {
|
733
|
+
return;
|
734
|
+
}
|
735
|
+
|
736
|
+
await approver.approveAuthSession({
|
737
|
+
qrChallengeUrl: url,
|
738
|
+
approve: true,
|
739
|
+
});
|
740
|
+
|
741
|
+
return {
|
742
|
+
steamId,
|
743
|
+
sessionInfo,
|
744
|
+
};
|
745
|
+
} catch (error) {
|
746
|
+
console.error(`[${steamId}] approveLogin Error`, error);
|
747
|
+
return {
|
748
|
+
steamId,
|
749
|
+
error,
|
750
|
+
};
|
751
|
+
}
|
752
|
+
}
|
753
|
+
|
754
|
+
export function getBonusXpTimeRefresh() {
|
755
|
+
let resetDay = moment.utc().startOf("isoWeek").add(2, "days").add(1, "hours");
|
756
|
+
while (moment().isAfter(resetDay)) {
|
757
|
+
resetDay = resetDay.add(7, "days");
|
758
|
+
}
|
759
|
+
if (moment().isBefore(resetDay)) {
|
760
|
+
resetDay = resetDay.subtract(7, "days");
|
761
|
+
}
|
762
|
+
return resetDay;
|
763
|
+
}
|
764
|
+
|
765
|
+
export function estimateNextXp(currentXp, xpEarned) {
|
766
|
+
//estimate next xp
|
767
|
+
let bonusTime = 1;
|
768
|
+
if (xpEarned < 4500) {
|
769
|
+
bonusTime = 4;
|
770
|
+
} else if (xpEarned < 7500) {
|
771
|
+
bonusTime = 2;
|
772
|
+
} else if (xpEarned < 11200) {
|
773
|
+
bonusTime = 1;
|
774
|
+
} else {
|
775
|
+
bonusTime = 0.175;
|
776
|
+
}
|
777
|
+
|
778
|
+
const nextXp = 30 * 13 * bonusTime;
|
779
|
+
return nextXp + currentXp;
|
780
|
+
}
|
781
|
+
|
782
|
+
export function formatMarketCurrency(valueInCents, currencyCode = getMarketCurrencyCode(g_rgWalletInfo.wallet_currency), countryCode) {
|
783
|
+
if (!valueInCents && valueInCents !== 0) {
|
784
|
+
return "";
|
785
|
+
}
|
786
|
+
|
787
|
+
let currencyFormat = (valueInCents / 100).toFixed(2);
|
788
|
+
|
789
|
+
if (g_rgCurrencyData[currencyCode]) {
|
790
|
+
const currencyData = g_rgCurrencyData[currencyCode];
|
791
|
+
if (isCurrencyWholeUnits(currencyCode)) {
|
792
|
+
currencyFormat = currencyFormat.replace(".00", "");
|
793
|
+
}
|
794
|
+
|
795
|
+
if (currencyData.strDecimalSymbol !== ".") {
|
796
|
+
currencyFormat = currencyFormat.replace(".", currencyData.strDecimalSymbol);
|
797
|
+
}
|
798
|
+
|
799
|
+
const currencySymbol = getMarketCurrencySymbol(currencyCode);
|
800
|
+
const currencyReturn = isCurrencySymbolBeforeValue(currencyCode) ? currencySymbol + currencyData.strSymbolAndNumberSeparator + currencyFormat : currencyFormat + currencyData.strSymbolAndNumberSeparator + currencySymbol;
|
801
|
+
|
802
|
+
if (currencyCode === "USD" && typeof countryCode != "undefined" && countryCode != "US") {
|
803
|
+
return `${currencyReturn} USD`;
|
804
|
+
} else if (currencyCode === "EUR") {
|
805
|
+
return currencyReturn.replace(",00", ",--");
|
806
|
+
} else {
|
807
|
+
return currencyReturn;
|
808
|
+
}
|
809
|
+
} else {
|
810
|
+
return `${currencyFormat} ${currencyCode}`;
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
814
|
+
export function getMarketPriceValueAsInt(strAmount) {
|
815
|
+
let nAmount;
|
816
|
+
if (!strAmount) {
|
817
|
+
return 0;
|
818
|
+
}
|
819
|
+
|
820
|
+
// Users may enter either comma or period for the decimal mark and digit group separators.
|
821
|
+
strAmount = strAmount.replace(/,/g, ".");
|
822
|
+
|
823
|
+
// strip the currency symbol, set .-- to .00
|
824
|
+
strAmount = strAmount.replace(getMarketCurrencySymbol(getMarketCurrencyCode(g_rgWalletInfo.wallet_currency)), "").replace(".--", ".00");
|
825
|
+
|
826
|
+
// strip spaces
|
827
|
+
strAmount = strAmount.replace(/ /g, "");
|
828
|
+
|
829
|
+
// Remove all but the last period so that entries like "1,147.6" work
|
830
|
+
if (strAmount.includes(".")) {
|
831
|
+
var splitAmount = strAmount.split(".");
|
832
|
+
var strLastSegment = splitAmount[splitAmount.length - 1];
|
833
|
+
|
834
|
+
if (!isNaN(strLastSegment) && strLastSegment.length == 3 && splitAmount[splitAmount.length - 2] != "0") {
|
835
|
+
// Looks like the user only entered thousands separators. Remove all commas and periods.
|
836
|
+
// Ensures an entry like "1,147" is not treated as "1.147"
|
837
|
+
//
|
838
|
+
// Users may be surprised to find that "1.147" is treated as "1,147". "1.147" is either an error or the user
|
839
|
+
// really did mean one thousand one hundred and forty seven since no currencies can be split into more than
|
840
|
+
// hundredths. If it was an error, the user should notice in the next step of the dialog and can go back and
|
841
|
+
// correct it. If they happen to not notice, it is better that we list the item at a higher price than
|
842
|
+
// intended instead of lower than intended (which we would have done if we accepted the 1.147 value as is).
|
843
|
+
strAmount = splitAmount.join("");
|
844
|
+
} else {
|
845
|
+
strAmount = `${splitAmount.slice(0, -1).join("")}.${strLastSegment}`;
|
846
|
+
}
|
847
|
+
}
|
848
|
+
|
849
|
+
let flAmount = parseFloat(strAmount) * 100;
|
850
|
+
nAmount = Math.floor(isNaN(flAmount) ? 0 : flAmount + 0.000001); // round down
|
851
|
+
|
852
|
+
nAmount = Math.max(nAmount, 0);
|
853
|
+
return nAmount;
|
854
|
+
}
|
855
|
+
|
856
|
+
export function isCurrencyWholeUnits(currencyCode) {
|
857
|
+
return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bWholeUnitsOnly && currencyCode !== "RUB";
|
858
|
+
}
|
859
|
+
|
860
|
+
export function isCurrencySymbolBeforeValue(currencyCode) {
|
861
|
+
return g_rgCurrencyData[currencyCode] && g_rgCurrencyData[currencyCode].bSymbolIsPrefix;
|
862
|
+
}
|
863
|
+
|
864
|
+
// Return the symbol to use for a currency
|
865
|
+
export function getMarketCurrencySymbol(currencyCode) {
|
866
|
+
return g_rgCurrencyData[currencyCode]?.strSymbol ?? currencyCode;
|
867
|
+
}
|
868
|
+
|
869
|
+
export function getMarketCurrencyCode(currencyId) {
|
870
|
+
currencyId = parseInt(currencyId);
|
871
|
+
for (const code in g_rgCurrencyData) {
|
872
|
+
if (g_rgCurrencyData[code].eCurrencyCode === currencyId) {
|
873
|
+
return code;
|
874
|
+
}
|
875
|
+
}
|
876
|
+
return "Unknown";
|
877
|
+
}
|
878
|
+
|
879
|
+
export async function loginWithCredentials({ username, password, timeoutMs = 120000, sharedSecret, getMailSteamGuardCodes }) {
|
880
|
+
if (!username) {
|
881
|
+
return {
|
882
|
+
error: "No username",
|
883
|
+
};
|
884
|
+
}
|
885
|
+
|
886
|
+
if (!password) {
|
887
|
+
return {
|
888
|
+
error: "No password",
|
889
|
+
};
|
890
|
+
}
|
891
|
+
|
892
|
+
const { LoginSession } = await import("steam-session");
|
893
|
+
let authenticated = false;
|
894
|
+
return new Promise((resolve) => {
|
895
|
+
const timeout = setTimeout(function () {
|
896
|
+
resolve({
|
897
|
+
error: "Timed out",
|
898
|
+
});
|
899
|
+
}, timeoutMs);
|
900
|
+
|
901
|
+
const session = new LoginSession(EAuthTokenPlatformType.MobileApp);
|
902
|
+
session.on("authenticated", async () => {
|
903
|
+
authenticated = true;
|
904
|
+
const cookie = (await session.getWebCookies())?.join?.(";");
|
905
|
+
return onResolve({
|
906
|
+
cookie,
|
907
|
+
accessToken: session.accessToken,
|
908
|
+
refreshToken: session.refreshToken,
|
909
|
+
accessTokenDecoded: decodeJwt(session.accessToken),
|
910
|
+
});
|
911
|
+
});
|
912
|
+
|
913
|
+
session
|
914
|
+
.startWithCredentials({
|
915
|
+
accountName: username,
|
916
|
+
password: password,
|
917
|
+
steamGuardMachineToken: "",
|
918
|
+
})
|
919
|
+
.then(async function (startResult) {
|
920
|
+
if (!startResult.actionRequired) {
|
921
|
+
return;
|
922
|
+
}
|
923
|
+
|
924
|
+
if (sharedSecret) {
|
925
|
+
let error = null;
|
926
|
+
const maxRetry = 3;
|
927
|
+
for (let i = 0; i < maxRetry; i++) {
|
928
|
+
try {
|
929
|
+
await session.submitSteamGuardCode(SteamTotp.generateAuthCode(sharedSecret));
|
930
|
+
error = null;
|
931
|
+
} catch (e) {
|
932
|
+
error = e;
|
933
|
+
}
|
934
|
+
await sleep(1000);
|
935
|
+
}
|
936
|
+
if (error) {
|
937
|
+
console.error(error);
|
938
|
+
onResolve({ error });
|
939
|
+
}
|
940
|
+
} else {
|
941
|
+
if (startResult.validActions.every((validAction) => validAction.type !== 2)) {
|
942
|
+
console.error(startResult.validActions);
|
943
|
+
return onResolve({
|
944
|
+
error: "validActions",
|
945
|
+
});
|
946
|
+
}
|
947
|
+
|
948
|
+
if (typeof getMailSteamGuardCodes === "function") {
|
949
|
+
const codes = await getMailSteamGuardCodes();
|
950
|
+
if (!Array.isArray(codes) || !codes.length) {
|
951
|
+
return onResolve({
|
952
|
+
error: "Can't find steam guard code",
|
953
|
+
});
|
954
|
+
}
|
955
|
+
|
956
|
+
let error = null;
|
957
|
+
for (const code of codes) {
|
958
|
+
if (!authenticated) {
|
959
|
+
try {
|
960
|
+
await session.submitSteamGuardCode(code);
|
961
|
+
error = null;
|
962
|
+
} catch (e) {
|
963
|
+
error = e;
|
964
|
+
}
|
965
|
+
await sleep(1000);
|
966
|
+
}
|
967
|
+
}
|
968
|
+
if (!authenticated && error) {
|
969
|
+
onResolve(error);
|
970
|
+
}
|
971
|
+
} else {
|
972
|
+
return onResolve({
|
973
|
+
error: "MailCodeError",
|
974
|
+
});
|
975
|
+
}
|
976
|
+
}
|
977
|
+
})
|
978
|
+
.catch(function (e) {
|
979
|
+
return onResolve(e);
|
980
|
+
});
|
981
|
+
|
982
|
+
function onResolve(data) {
|
983
|
+
clearTimeout(timeout);
|
984
|
+
return resolve(data);
|
985
|
+
}
|
986
|
+
});
|
987
|
+
}
|