rubjs 2.8.9 → 2.9.0
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/package.json +1 -1
- package/rubjs/client.d.ts +6 -2
- package/rubjs/client.js +1 -1
- package/rubjs/session/index.d.ts +6 -1
- package/rubjs/session/index.js +12 -4
package/package.json
CHANGED
package/rubjs/client.d.ts
CHANGED
@@ -11,6 +11,10 @@ interface Platform {
|
|
11
11
|
}
|
12
12
|
type TypeUpdate = "show_activities" | "chat_updates" | "message_updates" | "show_notifications";
|
13
13
|
type PlatformType = "Web" | "Android";
|
14
|
+
interface SessionType {
|
15
|
+
iv: string;
|
16
|
+
encryptedData: string;
|
17
|
+
}
|
14
18
|
declare class Client extends Methods {
|
15
19
|
defaultPlatform: Platform;
|
16
20
|
apiVersion: string;
|
@@ -21,7 +25,7 @@ declare class Client extends Methods {
|
|
21
25
|
timeout: number;
|
22
26
|
network: Network;
|
23
27
|
privateKey: string | null;
|
24
|
-
sessionFile: string;
|
28
|
+
sessionFile: string | SessionType;
|
25
29
|
platform: PlatformType;
|
26
30
|
userGuid: string | null;
|
27
31
|
sessionDb: SessionManager;
|
@@ -32,6 +36,6 @@ declare class Client extends Methods {
|
|
32
36
|
updateType: TypeUpdate;
|
33
37
|
}[];
|
34
38
|
voiceChatClient: VoiceChatClient;
|
35
|
-
constructor(sessionFile: string, timeout?: number, platform?: PlatformType);
|
39
|
+
constructor(sessionFile: string | SessionType, timeout?: number, platform?: PlatformType);
|
36
40
|
}
|
37
41
|
export default Client;
|
package/rubjs/client.js
CHANGED
@@ -28,8 +28,8 @@ class Client extends methods_1.default {
|
|
28
28
|
this.timeout = timeout !== null && timeout !== void 0 ? timeout : 0;
|
29
29
|
this.eventHandlers = [];
|
30
30
|
this.platform = platform;
|
31
|
-
this.sessionDb = new session_1.default(sessionFile);
|
32
31
|
this.network = new network_1.default(this);
|
32
|
+
this.sessionDb = new session_1.default(sessionFile);
|
33
33
|
this.auth = null;
|
34
34
|
this.privateKey = null;
|
35
35
|
this.eventHandlers = [];
|
package/rubjs/session/index.d.ts
CHANGED
@@ -5,11 +5,16 @@ interface SessionData {
|
|
5
5
|
agent: string;
|
6
6
|
private_key: string;
|
7
7
|
}
|
8
|
+
interface SessionType {
|
9
|
+
iv: string;
|
10
|
+
encryptedData: string;
|
11
|
+
}
|
8
12
|
declare class SessionManager {
|
9
13
|
private secretKey;
|
10
14
|
private filename;
|
11
15
|
private iv;
|
12
|
-
|
16
|
+
private sessionData;
|
17
|
+
constructor(filename: string | SessionType);
|
13
18
|
private encrypt;
|
14
19
|
private decrypt;
|
15
20
|
saveSession(sessionData: SessionData): void;
|
package/rubjs/session/index.js
CHANGED
@@ -9,7 +9,9 @@ class SessionManager {
|
|
9
9
|
constructor(filename) {
|
10
10
|
this.secretKey = "12345678901234567890123456789012";
|
11
11
|
this.iv = crypto_1.default.randomBytes(16);
|
12
|
-
this.filename =
|
12
|
+
this.filename =
|
13
|
+
typeof filename === "string" ? `${filename}.json` : `${Date.now()}.json`;
|
14
|
+
this.sessionData = typeof filename !== "string" && filename;
|
13
15
|
}
|
14
16
|
encrypt(sessionData) {
|
15
17
|
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", Buffer.from(this.secretKey), this.iv);
|
@@ -33,7 +35,7 @@ class SessionManager {
|
|
33
35
|
}
|
34
36
|
getSession() {
|
35
37
|
try {
|
36
|
-
if (!fs_1.default.existsSync(this.filename)) {
|
38
|
+
if (!this.sessionData && !fs_1.default.existsSync(this.filename)) {
|
37
39
|
const defaultSessionData = {
|
38
40
|
phone: "",
|
39
41
|
auth: "",
|
@@ -44,8 +46,14 @@ class SessionManager {
|
|
44
46
|
this.saveSession(defaultSessionData);
|
45
47
|
return defaultSessionData;
|
46
48
|
}
|
47
|
-
|
48
|
-
|
49
|
+
let parsedData;
|
50
|
+
if (this.sessionData) {
|
51
|
+
parsedData = this.sessionData;
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
const rawData = fs_1.default.readFileSync(this.filename, "utf8");
|
55
|
+
parsedData = JSON.parse(rawData);
|
56
|
+
}
|
49
57
|
return this.decrypt(parsedData.encryptedData, Buffer.from(parsedData.iv, "hex"));
|
50
58
|
}
|
51
59
|
catch (error) {
|