@mtkruto/node 0.0.821 → 0.0.822
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/esm/client/client.d.ts +78 -14
- package/esm/client/client.js +126 -1
- package/esm/tl/2_types.d.ts +48 -48
- package/esm/tl/2_types.js +180 -180
- package/esm/tl/3_functions.d.ts +13 -13
- package/esm/tl/3_functions.js +39 -39
- package/esm/utilities/1_password.d.ts +1 -1
- package/esm/utilities/1_password.js +2 -1
- package/package.json +1 -1
- package/script/client/client.d.ts +78 -14
- package/script/client/client.js +127 -2
- package/script/tl/2_types.d.ts +48 -48
- package/script/tl/2_types.js +180 -180
- package/script/tl/3_functions.d.ts +13 -13
- package/script/tl/3_functions.js +39 -39
- package/script/utilities/1_password.d.ts +1 -1
- package/script/utilities/1_password.js +2 -1
package/esm/tl/3_functions.d.ts
CHANGED
|
@@ -496,7 +496,7 @@ export declare class AccountUpdateProfile extends Function<types.TypeUser> {
|
|
|
496
496
|
protected get [id](): number;
|
|
497
497
|
static get [paramDesc](): ParamDesc;
|
|
498
498
|
protected get [params](): Params;
|
|
499
|
-
constructor(params
|
|
499
|
+
constructor(params?: {
|
|
500
500
|
firstName?: string;
|
|
501
501
|
lastName?: string;
|
|
502
502
|
about?: string;
|
|
@@ -847,7 +847,7 @@ export declare class AccountInitTakeoutSession extends Function<types.AccountTak
|
|
|
847
847
|
protected get [id](): number;
|
|
848
848
|
static get [paramDesc](): ParamDesc;
|
|
849
849
|
protected get [params](): Params;
|
|
850
|
-
constructor(params
|
|
850
|
+
constructor(params?: {
|
|
851
851
|
contacts?: true;
|
|
852
852
|
messageUsers?: true;
|
|
853
853
|
messageChats?: true;
|
|
@@ -862,7 +862,7 @@ export declare class AccountFinishTakeoutSession extends Function<boolean> {
|
|
|
862
862
|
protected get [id](): number;
|
|
863
863
|
static get [paramDesc](): ParamDesc;
|
|
864
864
|
protected get [params](): Params;
|
|
865
|
-
constructor(params
|
|
865
|
+
constructor(params?: {
|
|
866
866
|
success?: true;
|
|
867
867
|
});
|
|
868
868
|
}
|
|
@@ -908,7 +908,7 @@ export declare class AccountGetNotifyExceptions extends Function<types.TypeUpdat
|
|
|
908
908
|
protected get [id](): number;
|
|
909
909
|
static get [paramDesc](): ParamDesc;
|
|
910
910
|
protected get [params](): Params;
|
|
911
|
-
constructor(params
|
|
911
|
+
constructor(params?: {
|
|
912
912
|
compareSound?: true;
|
|
913
913
|
peer?: types.TypeInputNotifyPeer;
|
|
914
914
|
});
|
|
@@ -1054,7 +1054,7 @@ export declare class AccountInstallTheme extends Function<boolean> {
|
|
|
1054
1054
|
protected get [id](): number;
|
|
1055
1055
|
static get [paramDesc](): ParamDesc;
|
|
1056
1056
|
protected get [params](): Params;
|
|
1057
|
-
constructor(params
|
|
1057
|
+
constructor(params?: {
|
|
1058
1058
|
dark?: true;
|
|
1059
1059
|
theme?: types.TypeInputTheme;
|
|
1060
1060
|
format?: string;
|
|
@@ -1088,7 +1088,7 @@ export declare class AccountSetContentSettings extends Function<boolean> {
|
|
|
1088
1088
|
protected get [id](): number;
|
|
1089
1089
|
static get [paramDesc](): ParamDesc;
|
|
1090
1090
|
protected get [params](): Params;
|
|
1091
|
-
constructor(params
|
|
1091
|
+
constructor(params?: {
|
|
1092
1092
|
sensitiveEnabled?: true;
|
|
1093
1093
|
});
|
|
1094
1094
|
}
|
|
@@ -2550,7 +2550,7 @@ export declare class MessagesClearRecentStickers extends Function<boolean> {
|
|
|
2550
2550
|
protected get [id](): number;
|
|
2551
2551
|
static get [paramDesc](): ParamDesc;
|
|
2552
2552
|
protected get [params](): Params;
|
|
2553
|
-
constructor(params
|
|
2553
|
+
constructor(params?: {
|
|
2554
2554
|
attached?: true;
|
|
2555
2555
|
});
|
|
2556
2556
|
}
|
|
@@ -3041,7 +3041,7 @@ export declare class MessagesRequestURLAuth extends Function<types.TypeURLAuthRe
|
|
|
3041
3041
|
protected get [id](): number;
|
|
3042
3042
|
static get [paramDesc](): ParamDesc;
|
|
3043
3043
|
protected get [params](): Params;
|
|
3044
|
-
constructor(params
|
|
3044
|
+
constructor(params?: {
|
|
3045
3045
|
peer?: types.TypeInputPeer;
|
|
3046
3046
|
msgId?: number;
|
|
3047
3047
|
buttonId?: number;
|
|
@@ -3057,7 +3057,7 @@ export declare class MessagesAcceptURLAuth extends Function<types.TypeURLAuthRes
|
|
|
3057
3057
|
protected get [id](): number;
|
|
3058
3058
|
static get [paramDesc](): ParamDesc;
|
|
3059
3059
|
protected get [params](): Params;
|
|
3060
|
-
constructor(params
|
|
3060
|
+
constructor(params?: {
|
|
3061
3061
|
writeAllowed?: true;
|
|
3062
3062
|
peer?: types.TypeInputPeer;
|
|
3063
3063
|
msgId?: number;
|
|
@@ -3269,7 +3269,7 @@ export declare class MessagesDeletePhoneCallHistory extends Function<types.Messa
|
|
|
3269
3269
|
protected get [id](): number;
|
|
3270
3270
|
static get [paramDesc](): ParamDesc;
|
|
3271
3271
|
protected get [params](): Params;
|
|
3272
|
-
constructor(params
|
|
3272
|
+
constructor(params?: {
|
|
3273
3273
|
revoke?: true;
|
|
3274
3274
|
});
|
|
3275
3275
|
}
|
|
@@ -4092,7 +4092,7 @@ export declare class PhotosUploadProfilePhoto extends Function<types.PhotosPhoto
|
|
|
4092
4092
|
protected get [id](): number;
|
|
4093
4093
|
static get [paramDesc](): ParamDesc;
|
|
4094
4094
|
protected get [params](): Params;
|
|
4095
|
-
constructor(params
|
|
4095
|
+
constructor(params?: {
|
|
4096
4096
|
fallback?: true;
|
|
4097
4097
|
bot?: types.TypeInputUser;
|
|
4098
4098
|
file?: types.TypeInputFile;
|
|
@@ -4686,7 +4686,7 @@ export declare class ChannelsGetAdminedPublicChannels extends Function<types.Typ
|
|
|
4686
4686
|
protected get [id](): number;
|
|
4687
4687
|
static get [paramDesc](): ParamDesc;
|
|
4688
4688
|
protected get [params](): Params;
|
|
4689
|
-
constructor(params
|
|
4689
|
+
constructor(params?: {
|
|
4690
4690
|
byLocation?: true;
|
|
4691
4691
|
checkLimit?: true;
|
|
4692
4692
|
});
|
|
@@ -5306,7 +5306,7 @@ export declare class PaymentsClearSavedInfo extends Function<boolean> {
|
|
|
5306
5306
|
protected get [id](): number;
|
|
5307
5307
|
static get [paramDesc](): ParamDesc;
|
|
5308
5308
|
protected get [params](): Params;
|
|
5309
|
-
constructor(params
|
|
5309
|
+
constructor(params?: {
|
|
5310
5310
|
credentials?: true;
|
|
5311
5311
|
info?: true;
|
|
5312
5312
|
});
|
package/esm/tl/3_functions.js
CHANGED
|
@@ -1594,9 +1594,9 @@ export class AccountUpdateProfile extends Function {
|
|
|
1594
1594
|
writable: true,
|
|
1595
1595
|
value: void 0
|
|
1596
1596
|
});
|
|
1597
|
-
this.firstName = params
|
|
1598
|
-
this.lastName = params
|
|
1599
|
-
this.about = params
|
|
1597
|
+
this.firstName = params?.firstName;
|
|
1598
|
+
this.lastName = params?.lastName;
|
|
1599
|
+
this.about = params?.about;
|
|
1600
1600
|
}
|
|
1601
1601
|
}
|
|
1602
1602
|
export class AccountUpdateStatus extends Function {
|
|
@@ -2664,13 +2664,13 @@ export class AccountInitTakeoutSession extends Function {
|
|
|
2664
2664
|
writable: true,
|
|
2665
2665
|
value: void 0
|
|
2666
2666
|
});
|
|
2667
|
-
this.contacts = params
|
|
2668
|
-
this.messageUsers = params
|
|
2669
|
-
this.messageChats = params
|
|
2670
|
-
this.messageMegagroups = params
|
|
2671
|
-
this.messageChannels = params
|
|
2672
|
-
this.files = params
|
|
2673
|
-
this.fileMaxSize = params
|
|
2667
|
+
this.contacts = params?.contacts;
|
|
2668
|
+
this.messageUsers = params?.messageUsers;
|
|
2669
|
+
this.messageChats = params?.messageChats;
|
|
2670
|
+
this.messageMegagroups = params?.messageMegagroups;
|
|
2671
|
+
this.messageChannels = params?.messageChannels;
|
|
2672
|
+
this.files = params?.files;
|
|
2673
|
+
this.fileMaxSize = params?.fileMaxSize;
|
|
2674
2674
|
}
|
|
2675
2675
|
}
|
|
2676
2676
|
export class AccountFinishTakeoutSession extends Function {
|
|
@@ -2697,7 +2697,7 @@ export class AccountFinishTakeoutSession extends Function {
|
|
|
2697
2697
|
writable: true,
|
|
2698
2698
|
value: void 0
|
|
2699
2699
|
});
|
|
2700
|
-
this.success = params
|
|
2700
|
+
this.success = params?.success;
|
|
2701
2701
|
}
|
|
2702
2702
|
}
|
|
2703
2703
|
export class AccountConfirmPasswordEmail extends Function {
|
|
@@ -2824,8 +2824,8 @@ export class AccountGetNotifyExceptions extends Function {
|
|
|
2824
2824
|
writable: true,
|
|
2825
2825
|
value: void 0
|
|
2826
2826
|
});
|
|
2827
|
-
this.compareSound = params
|
|
2828
|
-
this.peer = params
|
|
2827
|
+
this.compareSound = params?.compareSound;
|
|
2828
|
+
this.peer = params?.peer;
|
|
2829
2829
|
}
|
|
2830
2830
|
}
|
|
2831
2831
|
export class AccountGetWallPaper extends Function {
|
|
@@ -3319,10 +3319,10 @@ export class AccountInstallTheme extends Function {
|
|
|
3319
3319
|
writable: true,
|
|
3320
3320
|
value: void 0
|
|
3321
3321
|
});
|
|
3322
|
-
this.dark = params
|
|
3323
|
-
this.theme = params
|
|
3324
|
-
this.format = params
|
|
3325
|
-
this.baseTheme = params
|
|
3322
|
+
this.dark = params?.dark;
|
|
3323
|
+
this.theme = params?.theme;
|
|
3324
|
+
this.format = params?.format;
|
|
3325
|
+
this.baseTheme = params?.baseTheme;
|
|
3326
3326
|
}
|
|
3327
3327
|
}
|
|
3328
3328
|
export class AccountGetTheme extends Function {
|
|
@@ -3417,7 +3417,7 @@ export class AccountSetContentSettings extends Function {
|
|
|
3417
3417
|
writable: true,
|
|
3418
3418
|
value: void 0
|
|
3419
3419
|
});
|
|
3420
|
-
this.sensitiveEnabled = params
|
|
3420
|
+
this.sensitiveEnabled = params?.sensitiveEnabled;
|
|
3421
3421
|
}
|
|
3422
3422
|
}
|
|
3423
3423
|
export class AccountGetContentSettings extends Function {
|
|
@@ -8265,7 +8265,7 @@ export class MessagesClearRecentStickers extends Function {
|
|
|
8265
8265
|
writable: true,
|
|
8266
8266
|
value: void 0
|
|
8267
8267
|
});
|
|
8268
|
-
this.attached = params
|
|
8268
|
+
this.attached = params?.attached;
|
|
8269
8269
|
}
|
|
8270
8270
|
}
|
|
8271
8271
|
export class MessagesGetArchivedStickers extends Function {
|
|
@@ -9887,10 +9887,10 @@ export class MessagesRequestURLAuth extends Function {
|
|
|
9887
9887
|
writable: true,
|
|
9888
9888
|
value: void 0
|
|
9889
9889
|
});
|
|
9890
|
-
this.peer = params
|
|
9891
|
-
this.msgId = params
|
|
9892
|
-
this.buttonId = params
|
|
9893
|
-
this.url = params
|
|
9890
|
+
this.peer = params?.peer;
|
|
9891
|
+
this.msgId = params?.msgId;
|
|
9892
|
+
this.buttonId = params?.buttonId;
|
|
9893
|
+
this.url = params?.url;
|
|
9894
9894
|
}
|
|
9895
9895
|
}
|
|
9896
9896
|
export class MessagesAcceptURLAuth extends Function {
|
|
@@ -9949,11 +9949,11 @@ export class MessagesAcceptURLAuth extends Function {
|
|
|
9949
9949
|
writable: true,
|
|
9950
9950
|
value: void 0
|
|
9951
9951
|
});
|
|
9952
|
-
this.writeAllowed = params
|
|
9953
|
-
this.peer = params
|
|
9954
|
-
this.msgId = params
|
|
9955
|
-
this.buttonId = params
|
|
9956
|
-
this.url = params
|
|
9952
|
+
this.writeAllowed = params?.writeAllowed;
|
|
9953
|
+
this.peer = params?.peer;
|
|
9954
|
+
this.msgId = params?.msgId;
|
|
9955
|
+
this.buttonId = params?.buttonId;
|
|
9956
|
+
this.url = params?.url;
|
|
9957
9957
|
}
|
|
9958
9958
|
}
|
|
9959
9959
|
export class MessagesHidePeerSettingsBar extends Function {
|
|
@@ -10625,7 +10625,7 @@ export class MessagesDeletePhoneCallHistory extends Function {
|
|
|
10625
10625
|
writable: true,
|
|
10626
10626
|
value: void 0
|
|
10627
10627
|
});
|
|
10628
|
-
this.revoke = params
|
|
10628
|
+
this.revoke = params?.revoke;
|
|
10629
10629
|
}
|
|
10630
10630
|
}
|
|
10631
10631
|
export class MessagesCheckHistoryImport extends Function {
|
|
@@ -13388,12 +13388,12 @@ export class PhotosUploadProfilePhoto extends Function {
|
|
|
13388
13388
|
writable: true,
|
|
13389
13389
|
value: void 0
|
|
13390
13390
|
});
|
|
13391
|
-
this.fallback = params
|
|
13392
|
-
this.bot = params
|
|
13393
|
-
this.file = params
|
|
13394
|
-
this.video = params
|
|
13395
|
-
this.videoStartTs = params
|
|
13396
|
-
this.videoEmojiMarkup = params
|
|
13391
|
+
this.fallback = params?.fallback;
|
|
13392
|
+
this.bot = params?.bot;
|
|
13393
|
+
this.file = params?.file;
|
|
13394
|
+
this.video = params?.video;
|
|
13395
|
+
this.videoStartTs = params?.videoStartTs;
|
|
13396
|
+
this.videoEmojiMarkup = params?.videoEmojiMarkup;
|
|
13397
13397
|
}
|
|
13398
13398
|
}
|
|
13399
13399
|
export class PhotosDeletePhotos extends Function {
|
|
@@ -15227,8 +15227,8 @@ export class ChannelsGetAdminedPublicChannels extends Function {
|
|
|
15227
15227
|
writable: true,
|
|
15228
15228
|
value: void 0
|
|
15229
15229
|
});
|
|
15230
|
-
this.byLocation = params
|
|
15231
|
-
this.checkLimit = params
|
|
15230
|
+
this.byLocation = params?.byLocation;
|
|
15231
|
+
this.checkLimit = params?.checkLimit;
|
|
15232
15232
|
}
|
|
15233
15233
|
}
|
|
15234
15234
|
export class ChannelsEditBanned extends Function {
|
|
@@ -17227,8 +17227,8 @@ export class PaymentsClearSavedInfo extends Function {
|
|
|
17227
17227
|
writable: true,
|
|
17228
17228
|
value: void 0
|
|
17229
17229
|
});
|
|
17230
|
-
this.credentials = params
|
|
17231
|
-
this.info = params
|
|
17230
|
+
this.credentials = params?.credentials;
|
|
17231
|
+
this.info = params?.info;
|
|
17232
17232
|
}
|
|
17233
17233
|
}
|
|
17234
17234
|
export class PaymentsGetBankCardData extends Function {
|
|
@@ -8,4 +8,4 @@ export declare function pbkdf2(password: Uint8Array, salt: Uint8Array, iteration
|
|
|
8
8
|
export declare const ph2: (password: Uint8Array, salt1: Uint8Array, salt2: Uint8Array) => Promise<Uint8Array>;
|
|
9
9
|
export declare function isGoodModExpFirst(modexp: bigint, prime: bigint): boolean;
|
|
10
10
|
export declare function pad(bigint: number | bigint | Uint8Array): Uint8Array;
|
|
11
|
-
export declare function checkPassword(
|
|
11
|
+
export declare function checkPassword(password_: string, ap: types.AccountPassword): Promise<types.InputCheckPasswordSRP>;
|
|
@@ -69,7 +69,8 @@ export function pad(bigint) {
|
|
|
69
69
|
return concat(new Uint8Array(256 - bigint.length), bigint);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
export async function checkPassword(
|
|
72
|
+
export async function checkPassword(password_, ap) {
|
|
73
|
+
const password = new TextEncoder().encode(password_);
|
|
73
74
|
const algo = ap.currentAlgo;
|
|
74
75
|
if (!(algo instanceof
|
|
75
76
|
types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
|
package/package.json
CHANGED
|
@@ -4,16 +4,43 @@ import * as functions from "../tl/3_functions.js";
|
|
|
4
4
|
import { ClientAbstract } from "./client_abstract.js";
|
|
5
5
|
import { Session } from "../session/session.js";
|
|
6
6
|
import { DC, TransportProvider } from "../transport/transport_provider.js";
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
last: S;
|
|
10
|
-
}> {
|
|
7
|
+
export declare const restartAuth: unique symbol;
|
|
8
|
+
export interface AuthorizeUserParams<S = string> {
|
|
11
9
|
phone: S | (() => MaybePromise<S>);
|
|
12
10
|
code: S | (() => MaybePromise<S>);
|
|
13
11
|
password: S | (() => MaybePromise<S>);
|
|
14
|
-
names: N | (() => MaybePromise<N>);
|
|
15
12
|
}
|
|
16
13
|
export type UpdatesHandler = null | ((client: Client, update: types.Updates) => MaybePromise<void>);
|
|
14
|
+
export interface ClientParams {
|
|
15
|
+
/**
|
|
16
|
+
* The transport provider to use. Defaults to `defaultTransportProvider`.
|
|
17
|
+
*/
|
|
18
|
+
transportProvider?: TransportProvider;
|
|
19
|
+
/**
|
|
20
|
+
* The app_version parameter to be passed to initConnection when calling `authorize`.
|
|
21
|
+
*/
|
|
22
|
+
appVersion?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The device_version parameter to be passed to initConnection when calling `authorize`.
|
|
25
|
+
*/
|
|
26
|
+
deviceModel?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The lang_code parameter to be passed to initConnection when calling `authorize`.
|
|
29
|
+
*/
|
|
30
|
+
langCode?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The lang_pack parameter to be passed to initConnection when calling `authorize`.
|
|
33
|
+
*/
|
|
34
|
+
langPack?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The system_lang_cde parameter to be passed to initConnection when calling `authorize`.
|
|
37
|
+
*/
|
|
38
|
+
systemLangCode?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The system_version parameter to be passed to initConnection when calling `authorize`.
|
|
41
|
+
*/
|
|
42
|
+
systemVersion?: string;
|
|
43
|
+
}
|
|
17
44
|
export declare class Client extends ClientAbstract {
|
|
18
45
|
readonly session: Session;
|
|
19
46
|
readonly apiId: number;
|
|
@@ -29,22 +56,59 @@ export declare class Client extends ClientAbstract {
|
|
|
29
56
|
readonly langPack: string;
|
|
30
57
|
readonly systemLangCode: string;
|
|
31
58
|
readonly systemVersion: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Constructs the client.
|
|
61
|
+
*
|
|
62
|
+
* @param session The session provider to use. Defaults to in-memory session.
|
|
63
|
+
* @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
|
|
64
|
+
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
|
|
65
|
+
* @param params Other parameters.
|
|
66
|
+
*/
|
|
67
|
+
constructor(session?: Session, apiId?: number, apiHash?: string, params?: ClientParams);
|
|
41
68
|
private shouldLoadSession;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the DC and resets the auth key stored in the session provider
|
|
71
|
+
* if the stored DC was not the same as the `dc` parameter.
|
|
72
|
+
*
|
|
73
|
+
* @param dc The DC to change to.
|
|
74
|
+
*/
|
|
42
75
|
setDc(dc: DC): void;
|
|
76
|
+
/**
|
|
77
|
+
* Loads the session if `setDc` was not called, initializes and connnects
|
|
78
|
+
* a `ClientPlain` to generate auth key if there was none, and connects the client.
|
|
79
|
+
* Before establishing the connection, the session is saved.
|
|
80
|
+
*/
|
|
43
81
|
connect(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
84
|
+
*
|
|
85
|
+
* - Bot token (`string`)
|
|
86
|
+
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
87
|
+
* - User authorization handlers (`AuthorizeUserParams`)
|
|
88
|
+
*
|
|
89
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](2).
|
|
90
|
+
*
|
|
91
|
+
* Notes:
|
|
92
|
+
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
93
|
+
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
94
|
+
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
95
|
+
*
|
|
96
|
+
* [1]: https://core.telegram.org/method/initConnection
|
|
97
|
+
* [2]: https://core.telegram.org/method/updates.getState
|
|
98
|
+
*/
|
|
44
99
|
authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
45
100
|
private receiveLoop;
|
|
46
101
|
private pingLoop;
|
|
102
|
+
/**
|
|
103
|
+
* Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
|
|
104
|
+
* to be connected.
|
|
105
|
+
*
|
|
106
|
+
* @param function_ The function to invoke.
|
|
107
|
+
*/
|
|
47
108
|
invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
|
|
48
109
|
invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Alias for `invoke` with its second parameter being `true`.
|
|
112
|
+
*/
|
|
49
113
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
50
114
|
}
|
package/script/client/client.js
CHANGED
|
@@ -23,11 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Client = void 0;
|
|
26
|
+
exports.Client = exports.restartAuth = void 0;
|
|
27
27
|
const deps_js_1 = require("../deps.js");
|
|
28
28
|
const constants_js_1 = require("../constants.js");
|
|
29
29
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
30
30
|
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
31
|
+
const _1_password_js_1 = require("../utilities/1_password.js");
|
|
31
32
|
const types = __importStar(require("../tl/2_types.js"));
|
|
32
33
|
const functions = __importStar(require("../tl/3_functions.js"));
|
|
33
34
|
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
@@ -37,7 +38,16 @@ const _6_message_container_js_1 = require("../tl/6_message_container.js");
|
|
|
37
38
|
const client_abstract_js_1 = require("./client_abstract.js");
|
|
38
39
|
const client_plain_js_1 = require("./client_plain.js");
|
|
39
40
|
const session_memory_js_1 = require("../session/session_memory.js");
|
|
41
|
+
exports.restartAuth = Symbol();
|
|
40
42
|
class Client extends client_abstract_js_1.ClientAbstract {
|
|
43
|
+
/**
|
|
44
|
+
* Constructs the client.
|
|
45
|
+
*
|
|
46
|
+
* @param session The session provider to use. Defaults to in-memory session.
|
|
47
|
+
* @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
|
|
48
|
+
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
|
|
49
|
+
* @param params Other parameters.
|
|
50
|
+
*/
|
|
41
51
|
constructor(session = new session_memory_js_1.SessionMemory(), apiId = 0, apiHash = "", params) {
|
|
42
52
|
super(params?.transportProvider);
|
|
43
53
|
Object.defineProperty(this, "session", {
|
|
@@ -137,6 +147,12 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
137
147
|
this.systemLangCode = params?.systemLangCode ?? constants_js_1.DEFAULT_SYSTEM_LANG_CODE;
|
|
138
148
|
this.systemVersion = params?.systemVersion ?? constants_js_1.DEFAULT_SYSTEM_VERSION;
|
|
139
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Sets the DC and resets the auth key stored in the session provider
|
|
152
|
+
* if the stored DC was not the same as the `dc` parameter.
|
|
153
|
+
*
|
|
154
|
+
* @param dc The DC to change to.
|
|
155
|
+
*/
|
|
140
156
|
setDc(dc) {
|
|
141
157
|
if (this.session.dc != dc) {
|
|
142
158
|
this.session.dc = dc;
|
|
@@ -147,6 +163,11 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
147
163
|
}
|
|
148
164
|
super.setDc(dc);
|
|
149
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Loads the session if `setDc` was not called, initializes and connnects
|
|
168
|
+
* a `ClientPlain` to generate auth key if there was none, and connects the client.
|
|
169
|
+
* Before establishing the connection, the session is saved.
|
|
170
|
+
*/
|
|
150
171
|
async connect() {
|
|
151
172
|
if (this.shouldLoadSession) {
|
|
152
173
|
await this.session.load();
|
|
@@ -172,6 +193,23 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
172
193
|
this.receiveLoop();
|
|
173
194
|
this.pingLoop();
|
|
174
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
198
|
+
*
|
|
199
|
+
* - Bot token (`string`)
|
|
200
|
+
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
201
|
+
* - User authorization handlers (`AuthorizeUserParams`)
|
|
202
|
+
*
|
|
203
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](2).
|
|
204
|
+
*
|
|
205
|
+
* Notes:
|
|
206
|
+
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
207
|
+
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
208
|
+
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
209
|
+
*
|
|
210
|
+
* [1]: https://core.telegram.org/method/initConnection
|
|
211
|
+
* [2]: https://core.telegram.org/method/updates.getState
|
|
212
|
+
*/
|
|
175
213
|
async authorize(params) {
|
|
176
214
|
if (!this.apiId) {
|
|
177
215
|
throw new Error("apiId not set");
|
|
@@ -201,12 +239,92 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
201
239
|
throw err;
|
|
202
240
|
}
|
|
203
241
|
}
|
|
242
|
+
let signedIn = false;
|
|
243
|
+
let phoneNumber = null;
|
|
204
244
|
try {
|
|
205
245
|
if (params instanceof types.AuthExportedAuthorization) {
|
|
206
246
|
await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
|
|
207
247
|
}
|
|
208
248
|
else if (typeof params == "object") {
|
|
209
|
-
|
|
249
|
+
while (true) {
|
|
250
|
+
if (signedIn) {
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
try {
|
|
254
|
+
try {
|
|
255
|
+
phoneNumber = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
256
|
+
const sentCode = await this.invoke(new functions.AuthSendCode({
|
|
257
|
+
apiId: this.apiId,
|
|
258
|
+
apiHash: this.apiHash,
|
|
259
|
+
phoneNumber,
|
|
260
|
+
settings: new types.CodeSettings(),
|
|
261
|
+
}));
|
|
262
|
+
if (sentCode instanceof types.AuthSentCode) {
|
|
263
|
+
while (true) {
|
|
264
|
+
const phoneCode = typeof params.code === "string" ? params.code : await params.code();
|
|
265
|
+
try {
|
|
266
|
+
const auth = await this.invoke(new functions.AuthSignIn({ phoneNumber, phoneCode, phoneCodeHash: sentCode.phoneCodeHash }));
|
|
267
|
+
if (auth instanceof types.AuthAuthorizationSignUpRequired) {
|
|
268
|
+
throw new Error("Sign up not supported");
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
signedIn = true;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
if (err instanceof types.RPCError && err.errorMessage == "PHONE_CODE_INVALID") {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw new Error(`Handling ${sentCode.constructor.name} not implemented`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
|
|
291
|
+
while (true) {
|
|
292
|
+
const ap = await this.invoke(new functions.AccountGetPassword());
|
|
293
|
+
if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
|
|
294
|
+
try {
|
|
295
|
+
const password = typeof params.password === "string" ? params.password : await params.password();
|
|
296
|
+
const input = await (0, _1_password_js_1.checkPassword)(password, ap);
|
|
297
|
+
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
if (err instanceof types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
throw err;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
if (err == exports.restartAuth) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
210
328
|
}
|
|
211
329
|
else {
|
|
212
330
|
await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
@@ -221,6 +339,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
221
339
|
newDc += "-test";
|
|
222
340
|
}
|
|
223
341
|
await this.reconnect(newDc);
|
|
342
|
+
if (typeof params === "object" && phoneNumber != null) {
|
|
343
|
+
params = Object.assign({}, params);
|
|
344
|
+
params.phone = phoneNumber;
|
|
345
|
+
}
|
|
224
346
|
await this.authorize(params);
|
|
225
347
|
}
|
|
226
348
|
else {
|
|
@@ -344,6 +466,9 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
344
466
|
return result;
|
|
345
467
|
}
|
|
346
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Alias for `invoke` with its second parameter being `true`.
|
|
471
|
+
*/
|
|
347
472
|
send(function_) {
|
|
348
473
|
return this.invoke(function_, true);
|
|
349
474
|
}
|