steamutils 1.3.98 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -48
- package/package.json +1 -1
- package/utils.js +155 -141
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import URL, { fileURLToPath } from "url";
|
|
|
8
8
|
import Url from "url-parse";
|
|
9
9
|
import qs from "qs";
|
|
10
10
|
import xml2js from "xml2js";
|
|
11
|
-
import { console_log, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, sleep } from "./utils.js";
|
|
11
|
+
import { console_log, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
|
12
12
|
import { Header, request } from "./axios.js";
|
|
13
13
|
import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
|
|
14
14
|
import { getJSObjectFronXML } from "./xml2json.js";
|
|
@@ -1328,7 +1328,7 @@ export default class SteamUser {
|
|
|
1328
1328
|
// retry = 1;
|
|
1329
1329
|
// }
|
|
1330
1330
|
|
|
1331
|
-
if (params.method === "POST" && response?.data?.success === 15) {
|
|
1331
|
+
if (params.method === "POST" && (response?.data?.success === 15 || response?.data === false)) {
|
|
1332
1332
|
continue;
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
@@ -5921,9 +5921,10 @@ export default class SteamUser {
|
|
|
5921
5921
|
for (const cookieManager of this._cookies) {
|
|
5922
5922
|
let result = null;
|
|
5923
5923
|
let error = null;
|
|
5924
|
+
let checkLoginResult = null;
|
|
5924
5925
|
|
|
5925
5926
|
try {
|
|
5926
|
-
|
|
5927
|
+
checkLoginResult = await axios.request({
|
|
5927
5928
|
url: "https://store.steampowered.com/account",
|
|
5928
5929
|
headers: {
|
|
5929
5930
|
Cookie: cookieManager.toString(),
|
|
@@ -5933,6 +5934,10 @@ export default class SteamUser {
|
|
|
5933
5934
|
if (checkLoginResult.request?.res?.responseUrl?.startsWith("https://store.steampowered.com/login/")) {
|
|
5934
5935
|
continue;
|
|
5935
5936
|
}
|
|
5937
|
+
|
|
5938
|
+
if (Array.isArray(checkLoginResult?.headers?.["set-cookie"])) {
|
|
5939
|
+
cookieManager.setCookies(checkLoginResult?.headers["set-cookie"]);
|
|
5940
|
+
}
|
|
5936
5941
|
} catch (e) {
|
|
5937
5942
|
error = e;
|
|
5938
5943
|
}
|
|
@@ -7254,44 +7259,14 @@ export default class SteamUser {
|
|
|
7254
7259
|
});
|
|
7255
7260
|
return revokeRefreshTokenResult?.data;
|
|
7256
7261
|
}
|
|
7257
|
-
async revokeAccessToken(accessToken, tokenId, sharedSecret
|
|
7262
|
+
async revokeAccessToken(accessToken, tokenId, sharedSecret) {
|
|
7258
7263
|
const version = 1;
|
|
7259
|
-
|
|
7260
|
-
let signatureData = Buffer.alloc(2 + 8 + 8);
|
|
7264
|
+
const signatureData = Buffer.alloc(2 + 8 + 8);
|
|
7261
7265
|
signatureData.writeUInt16LE(version, 0);
|
|
7262
|
-
signatureData.writeBigUInt64LE(BigInt(
|
|
7266
|
+
signatureData.writeBigUInt64LE(BigInt(tokenId), 2);
|
|
7263
7267
|
signatureData.writeBigUInt64LE(BigInt(this._steamIdUser), 10);
|
|
7264
|
-
const secretAsBuffer = (sharedSecret) => {
|
|
7265
|
-
if (Buffer.isBuffer(sharedSecret)) {
|
|
7266
|
-
return sharedSecret;
|
|
7267
|
-
}
|
|
7268
|
-
|
|
7269
|
-
if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
|
|
7270
|
-
// Looks like it's hex
|
|
7271
|
-
return Buffer.from(sharedSecret, "hex");
|
|
7272
|
-
}
|
|
7273
|
-
|
|
7274
|
-
// It must be base64
|
|
7275
|
-
return Buffer.from(sharedSecret, "base64");
|
|
7276
|
-
};
|
|
7277
|
-
|
|
7278
7268
|
const signature = createHmac("sha256", secretAsBuffer(sharedSecret)).update(signatureData).digest();
|
|
7279
7269
|
|
|
7280
|
-
/*const approver = new LoginApprover(accessToken, sharedSecret, {});
|
|
7281
|
-
const sessionInfo = await approver._handler.sendRequest({
|
|
7282
|
-
apiInterface: "Authentication",
|
|
7283
|
-
apiMethod: "RevokeRefreshToken",
|
|
7284
|
-
apiVersion: 1,
|
|
7285
|
-
data: {
|
|
7286
|
-
token_id: tokenId,
|
|
7287
|
-
steamid: this._steamIdUser,
|
|
7288
|
-
revoke_action: 1,
|
|
7289
|
-
signature: signature.toString(),
|
|
7290
|
-
},
|
|
7291
|
-
accessToken: accessToken,
|
|
7292
|
-
});
|
|
7293
|
-
console.log("sessionInfo", sessionInfo);*/
|
|
7294
|
-
|
|
7295
7270
|
const Protos = helpers([
|
|
7296
7271
|
{
|
|
7297
7272
|
name: "csgo",
|
|
@@ -7311,25 +7286,21 @@ export default class SteamUser {
|
|
|
7311
7286
|
}).toString("base64"),
|
|
7312
7287
|
};
|
|
7313
7288
|
|
|
7314
|
-
|
|
7315
|
-
// access_token: accessToken,
|
|
7316
|
-
// token_id: tokenId,
|
|
7317
|
-
// steamid: this._steamIdUser,
|
|
7318
|
-
// // revoke_action: Protos.csgo.EAuthTokenRevokeAction.k_EAuthTokenRevokePermanent,
|
|
7319
|
-
// revoke_action: 1,
|
|
7320
|
-
// signature: signature,
|
|
7321
|
-
// };
|
|
7322
|
-
|
|
7323
|
-
const revokeRefreshTokenResult = await this._httpRequest({
|
|
7289
|
+
const result = await this._httpRequest({
|
|
7324
7290
|
url: `https://api.steampowered.com/IAuthenticationService/RevokeRefreshToken/v1?${qs.stringify(params)}`,
|
|
7325
7291
|
// responseType: "arraybuffer",
|
|
7326
7292
|
method: "POST",
|
|
7327
|
-
data:
|
|
7293
|
+
data: {
|
|
7294
|
+
token_id: tokenId,
|
|
7295
|
+
steamid: this._steamIdUser,
|
|
7296
|
+
revoke_action: 1,
|
|
7297
|
+
signature: signature,
|
|
7298
|
+
},
|
|
7328
7299
|
headers: {
|
|
7329
7300
|
"Content-Type": "multipart/form-data",
|
|
7330
7301
|
},
|
|
7331
7302
|
});
|
|
7332
|
-
return
|
|
7303
|
+
return result?.data;
|
|
7333
7304
|
}
|
|
7334
7305
|
}
|
|
7335
7306
|
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,141 +1,155 @@
|
|
|
1
|
-
const isBrowser = typeof window !== "undefined";
|
|
2
|
-
|
|
3
|
-
export const sleep = (ms) => {
|
|
4
|
-
return new Promise((resolve) => {
|
|
5
|
-
setTimeout(resolve, ms);
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const sleepRandom = async (startMs, endMs) => {
|
|
10
|
-
return await sleep(Math.random() * (endMs - startMs) + startMs);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* const audioTrack = stream.getAudioTracks()[0]
|
|
15
|
-
* const videoStream = UserMedia.createBlankVideoTrack()
|
|
16
|
-
* videoStream.addTrack(audioTrack)
|
|
17
|
-
* stream = videoStream
|
|
18
|
-
* **/
|
|
19
|
-
export const createBlankVideoTrack = (opts = {}) => {
|
|
20
|
-
const { width = 1920, height = 1080 } = opts;
|
|
21
|
-
|
|
22
|
-
const canvas = Object.assign(document.createElement("canvas"), {
|
|
23
|
-
width,
|
|
24
|
-
height,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
canvas.getContext("2d").fillRect(0, 0, width, height);
|
|
28
|
-
|
|
29
|
-
return canvas.captureStream();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const minDate = new Date(0),
|
|
33
|
-
maxDate = new Date(parseInt("ffffffff", 16) * 1000);
|
|
34
|
-
|
|
35
|
-
export function objectIdFromDate(date) {
|
|
36
|
-
if (date < minDate || date > maxDate) {
|
|
37
|
-
return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
|
|
38
|
-
}
|
|
39
|
-
var pad = "00000000";
|
|
40
|
-
var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
|
|
41
|
-
return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function dateFromObjectId(objectId) {
|
|
45
|
-
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function console_log(...args) {
|
|
49
|
-
const params = [];
|
|
50
|
-
params.push(new Date().toUTCString());
|
|
51
|
-
const errorStack = new Error().stack;
|
|
52
|
-
const fnName = errorStack
|
|
53
|
-
.split("\n")
|
|
54
|
-
.map((e) => e?.trim())
|
|
55
|
-
.filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
|
|
56
|
-
.substr(3);
|
|
57
|
-
params.push(fnName);
|
|
58
|
-
console.log(
|
|
59
|
-
params
|
|
60
|
-
.filter(Boolean)
|
|
61
|
-
.map((p) => `[${p.trim()}]`)
|
|
62
|
-
.join(" "),
|
|
63
|
-
...args,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function removeSpaceKeys(object) {
|
|
68
|
-
//mutate object
|
|
69
|
-
if (!object || Array.isArray(object)) {
|
|
70
|
-
return object;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
Object.entries(object).forEach(([key, value]) => {
|
|
74
|
-
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
75
|
-
if (newKey !== key) {
|
|
76
|
-
delete object[key];
|
|
77
|
-
object[newKey] = value;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return object;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getCleanObject(object) {
|
|
84
|
-
//like removeSpaceKeys but not mutate object
|
|
85
|
-
if (!object || Array.isArray(object)) {
|
|
86
|
-
return object;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const newObject = {};
|
|
90
|
-
Object.entries(object).forEach(([key, value]) => {
|
|
91
|
-
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
92
|
-
newObject[newKey] = value;
|
|
93
|
-
});
|
|
94
|
-
return newObject;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function JSON_parse(data) {
|
|
98
|
-
try {
|
|
99
|
-
return JSON.parse(data);
|
|
100
|
-
} catch (e) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function JSON_stringify(data) {
|
|
106
|
-
try {
|
|
107
|
-
return JSON.stringify(data);
|
|
108
|
-
} catch (e) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function throttle(fn, delay) {
|
|
114
|
-
let canFire = true;
|
|
115
|
-
let queue = [];
|
|
116
|
-
|
|
117
|
-
async function pop() {
|
|
118
|
-
if (queue.length < 1) return;
|
|
119
|
-
|
|
120
|
-
const [that, args] = queue.pop();
|
|
121
|
-
await fn.apply(that, args);
|
|
122
|
-
canFire = false;
|
|
123
|
-
setTimeout(async () => {
|
|
124
|
-
canFire = true;
|
|
125
|
-
await pop();
|
|
126
|
-
}, delay);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function push() {
|
|
130
|
-
queue.push([this, arguments]);
|
|
131
|
-
if (canFire) {
|
|
132
|
-
await pop();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
push.cancel = () => {
|
|
137
|
-
queue = [];
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
return push;
|
|
141
|
-
}
|
|
1
|
+
const isBrowser = typeof window !== "undefined";
|
|
2
|
+
|
|
3
|
+
export const sleep = (ms) => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
setTimeout(resolve, ms);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const sleepRandom = async (startMs, endMs) => {
|
|
10
|
+
return await sleep(Math.random() * (endMs - startMs) + startMs);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* const audioTrack = stream.getAudioTracks()[0]
|
|
15
|
+
* const videoStream = UserMedia.createBlankVideoTrack()
|
|
16
|
+
* videoStream.addTrack(audioTrack)
|
|
17
|
+
* stream = videoStream
|
|
18
|
+
* **/
|
|
19
|
+
export const createBlankVideoTrack = (opts = {}) => {
|
|
20
|
+
const { width = 1920, height = 1080 } = opts;
|
|
21
|
+
|
|
22
|
+
const canvas = Object.assign(document.createElement("canvas"), {
|
|
23
|
+
width,
|
|
24
|
+
height,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
canvas.getContext("2d").fillRect(0, 0, width, height);
|
|
28
|
+
|
|
29
|
+
return canvas.captureStream();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const minDate = new Date(0),
|
|
33
|
+
maxDate = new Date(parseInt("ffffffff", 16) * 1000);
|
|
34
|
+
|
|
35
|
+
export function objectIdFromDate(date) {
|
|
36
|
+
if (date < minDate || date > maxDate) {
|
|
37
|
+
return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
|
|
38
|
+
}
|
|
39
|
+
var pad = "00000000";
|
|
40
|
+
var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
|
|
41
|
+
return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function dateFromObjectId(objectId) {
|
|
45
|
+
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function console_log(...args) {
|
|
49
|
+
const params = [];
|
|
50
|
+
params.push(new Date().toUTCString());
|
|
51
|
+
const errorStack = new Error().stack;
|
|
52
|
+
const fnName = errorStack
|
|
53
|
+
.split("\n")
|
|
54
|
+
.map((e) => e?.trim())
|
|
55
|
+
.filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
|
|
56
|
+
.substr(3);
|
|
57
|
+
params.push(fnName);
|
|
58
|
+
console.log(
|
|
59
|
+
params
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map((p) => `[${p.trim()}]`)
|
|
62
|
+
.join(" "),
|
|
63
|
+
...args,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function removeSpaceKeys(object) {
|
|
68
|
+
//mutate object
|
|
69
|
+
if (!object || Array.isArray(object)) {
|
|
70
|
+
return object;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
74
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
75
|
+
if (newKey !== key) {
|
|
76
|
+
delete object[key];
|
|
77
|
+
object[newKey] = value;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return object;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getCleanObject(object) {
|
|
84
|
+
//like removeSpaceKeys but not mutate object
|
|
85
|
+
if (!object || Array.isArray(object)) {
|
|
86
|
+
return object;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const newObject = {};
|
|
90
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
91
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
92
|
+
newObject[newKey] = value;
|
|
93
|
+
});
|
|
94
|
+
return newObject;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function JSON_parse(data) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(data);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function JSON_stringify(data) {
|
|
106
|
+
try {
|
|
107
|
+
return JSON.stringify(data);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function throttle(fn, delay) {
|
|
114
|
+
let canFire = true;
|
|
115
|
+
let queue = [];
|
|
116
|
+
|
|
117
|
+
async function pop() {
|
|
118
|
+
if (queue.length < 1) return;
|
|
119
|
+
|
|
120
|
+
const [that, args] = queue.pop();
|
|
121
|
+
await fn.apply(that, args);
|
|
122
|
+
canFire = false;
|
|
123
|
+
setTimeout(async () => {
|
|
124
|
+
canFire = true;
|
|
125
|
+
await pop();
|
|
126
|
+
}, delay);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function push() {
|
|
130
|
+
queue.push([this, arguments]);
|
|
131
|
+
if (canFire) {
|
|
132
|
+
await pop();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
push.cancel = () => {
|
|
137
|
+
queue = [];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return push;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const secretAsBuffer = (sharedSecret) => {
|
|
144
|
+
if (Buffer.isBuffer(sharedSecret)) {
|
|
145
|
+
return sharedSecret;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
|
|
149
|
+
// Looks like it's hex
|
|
150
|
+
return Buffer.from(sharedSecret, "hex");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// It must be base64
|
|
154
|
+
return Buffer.from(sharedSecret, "base64");
|
|
155
|
+
};
|