steamutils 1.4.36 → 1.4.38

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