@armatofik/tgsnake-core 1.0.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/COPYING +674 -0
- package/COPYING.lesser +165 -0
- package/README.md +88 -0
- package/lib/package.json +46 -0
- package/lib/src/Logger.d.ts +3 -0
- package/lib/src/Logger.js +9 -0
- package/lib/src/Queue.d.ts +19 -0
- package/lib/src/Queue.js +52 -0
- package/lib/src/Timeout.d.ts +9 -0
- package/lib/src/Timeout.js +44 -0
- package/lib/src/Version.node.d.ts +4 -0
- package/lib/src/Version.node.js +26 -0
- package/lib/src/client/Auth.d.ts +40 -0
- package/lib/src/client/Auth.js +317 -0
- package/lib/src/client/Client.d.ts +83 -0
- package/lib/src/client/Client.js +461 -0
- package/lib/src/client/Session.d.ts +9 -0
- package/lib/src/client/Session.js +132 -0
- package/lib/src/client/index.d.ts +3 -0
- package/lib/src/client/index.js +39 -0
- package/lib/src/connection/TCP/TCPAbridged.d.ts +9 -0
- package/lib/src/connection/TCP/TCPAbridged.js +47 -0
- package/lib/src/connection/TCP/TCPAbridgedO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPAbridgedO.js +140 -0
- package/lib/src/connection/TCP/TCPFull.d.ts +10 -0
- package/lib/src/connection/TCP/TCPFull.js +43 -0
- package/lib/src/connection/TCP/TCPIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPIntermediate.js +31 -0
- package/lib/src/connection/TCP/TCPIntermediateO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPIntermediateO.js +123 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.js +38 -0
- package/lib/src/connection/TCP/index.d.ts +7 -0
- package/lib/src/connection/TCP/index.js +17 -0
- package/lib/src/connection/TCP/tcp.d.ts +17 -0
- package/lib/src/connection/TCP/tcp.js +98 -0
- package/lib/src/connection/WebSocket.d.ts +21 -0
- package/lib/src/connection/WebSocket.js +279 -0
- package/lib/src/connection/connection.d.ts +53 -0
- package/lib/src/connection/connection.js +189 -0
- package/lib/src/connection/index.d.ts +4 -0
- package/lib/src/connection/index.js +41 -0
- package/lib/src/crypto/Aes.d.ts +10 -0
- package/lib/src/crypto/Aes.js +135 -0
- package/lib/src/crypto/Mtproto.d.ts +5 -0
- package/lib/src/crypto/Mtproto.js +123 -0
- package/lib/src/crypto/Password.d.ts +5 -0
- package/lib/src/crypto/Password.js +92 -0
- package/lib/src/crypto/Prime.d.ts +4 -0
- package/lib/src/crypto/Prime.js +64 -0
- package/lib/src/crypto/RSA.d.ts +7 -0
- package/lib/src/crypto/RSA.js +99 -0
- package/lib/src/crypto/SecretChat.d.ts +5 -0
- package/lib/src/crypto/SecretChat.js +136 -0
- package/lib/src/crypto/index.d.ts +6 -0
- package/lib/src/crypto/index.js +42 -0
- package/lib/src/errors/Base.d.ts +9 -0
- package/lib/src/errors/Base.js +50 -0
- package/lib/src/errors/Client.d.ts +21 -0
- package/lib/src/errors/Client.js +29 -0
- package/lib/src/errors/File.d.ts +13 -0
- package/lib/src/errors/File.js +30 -0
- package/lib/src/errors/RpcError.d.ts +22 -0
- package/lib/src/errors/RpcError.js +120 -0
- package/lib/src/errors/SecretChat.d.ts +13 -0
- package/lib/src/errors/SecretChat.js +30 -0
- package/lib/src/errors/WebSocket.d.ts +13 -0
- package/lib/src/errors/WebSocket.js +30 -0
- package/lib/src/errors/exceptions/All.d.ts +774 -0
- package/lib/src/errors/exceptions/All.js +778 -0
- package/lib/src/errors/exceptions/BadRequest400.d.ts +2345 -0
- package/lib/src/errors/exceptions/BadRequest400.js +2945 -0
- package/lib/src/errors/exceptions/Flood420.d.ts +37 -0
- package/lib/src/errors/exceptions/Flood420.js +49 -0
- package/lib/src/errors/exceptions/Forbidden403.d.ts +205 -0
- package/lib/src/errors/exceptions/Forbidden403.js +260 -0
- package/lib/src/errors/exceptions/InternalServerError500.d.ts +221 -0
- package/lib/src/errors/exceptions/InternalServerError500.js +280 -0
- package/lib/src/errors/exceptions/NotAcceptable406.d.ts +117 -0
- package/lib/src/errors/exceptions/NotAcceptable406.js +149 -0
- package/lib/src/errors/exceptions/NotFound404.d.ts +9 -0
- package/lib/src/errors/exceptions/NotFound404.js +14 -0
- package/lib/src/errors/exceptions/SeeOther303.d.ts +25 -0
- package/lib/src/errors/exceptions/SeeOther303.js +34 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.d.ts +17 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.js +24 -0
- package/lib/src/errors/exceptions/Unauthorized401.d.ts +41 -0
- package/lib/src/errors/exceptions/Unauthorized401.js +54 -0
- package/lib/src/errors/exceptions/index.d.ts +10 -0
- package/lib/src/errors/exceptions/index.js +48 -0
- package/lib/src/errors/index.d.ts +31 -0
- package/lib/src/errors/index.js +111 -0
- package/lib/src/file/Download.d.ts +11 -0
- package/lib/src/file/Download.js +118 -0
- package/lib/src/file/File.d.ts +20 -0
- package/lib/src/file/File.js +82 -0
- package/lib/src/file/Upload.d.ts +19 -0
- package/lib/src/file/Upload.js +250 -0
- package/lib/src/file/index.d.ts +3 -0
- package/lib/src/file/index.js +11 -0
- package/lib/src/helpers.d.ts +34 -0
- package/lib/src/helpers.js +358 -0
- package/lib/src/index.d.ts +16 -0
- package/lib/src/index.js +56 -0
- package/lib/src/platform.node.d.ts +36 -0
- package/lib/src/platform.node.js +109 -0
- package/lib/src/raw/All.d.ts +2400 -0
- package/lib/src/raw/All.js +2403 -0
- package/lib/src/raw/Raw.d.ts +29195 -0
- package/lib/src/raw/Raw.js +97277 -0
- package/lib/src/raw/core/BytesIO.d.ts +33 -0
- package/lib/src/raw/core/BytesIO.js +145 -0
- package/lib/src/raw/core/GzipPacked.d.ts +10 -0
- package/lib/src/raw/core/GzipPacked.js +60 -0
- package/lib/src/raw/core/Message.d.ts +13 -0
- package/lib/src/raw/core/Message.js +81 -0
- package/lib/src/raw/core/MsgContainer.d.ts +11 -0
- package/lib/src/raw/core/MsgContainer.js +69 -0
- package/lib/src/raw/core/TLObject.d.ts +19 -0
- package/lib/src/raw/core/TLObject.js +108 -0
- package/lib/src/raw/core/UpdateSecretChat.d.ts +40 -0
- package/lib/src/raw/core/UpdateSecretChat.js +88 -0
- package/lib/src/raw/core/index.d.ts +8 -0
- package/lib/src/raw/core/index.js +52 -0
- package/lib/src/raw/core/primitive/Bool.d.ts +20 -0
- package/lib/src/raw/core/primitive/Bool.js +41 -0
- package/lib/src/raw/core/primitive/Bytes.d.ts +7 -0
- package/lib/src/raw/core/primitive/Bytes.js +41 -0
- package/lib/src/raw/core/primitive/Double.d.ts +7 -0
- package/lib/src/raw/core/primitive/Double.js +24 -0
- package/lib/src/raw/core/primitive/Float.d.ts +7 -0
- package/lib/src/raw/core/primitive/Float.js +24 -0
- package/lib/src/raw/core/primitive/Int.d.ts +23 -0
- package/lib/src/raw/core/primitive/Int.js +122 -0
- package/lib/src/raw/core/primitive/String.d.ts +7 -0
- package/lib/src/raw/core/primitive/String.js +15 -0
- package/lib/src/raw/core/primitive/Vector.d.ts +9 -0
- package/lib/src/raw/core/primitive/Vector.js +50 -0
- package/lib/src/raw/core/primitive/index.d.ts +7 -0
- package/lib/src/raw/core/primitive/index.js +22 -0
- package/lib/src/raw/index.d.ts +3 -0
- package/lib/src/raw/index.js +17 -0
- package/lib/src/session/Auth.d.ts +15 -0
- package/lib/src/session/Auth.js +254 -0
- package/lib/src/session/Session.d.ts +58 -0
- package/lib/src/session/Session.js +571 -0
- package/lib/src/session/index.d.ts +7 -0
- package/lib/src/session/index.js +49 -0
- package/lib/src/session/internals/DataCenter.d.ts +42 -0
- package/lib/src/session/internals/DataCenter.js +80 -0
- package/lib/src/session/internals/MsgFactory.d.ts +3 -0
- package/lib/src/session/internals/MsgFactory.js +23 -0
- package/lib/src/session/internals/MsgId.d.ts +9 -0
- package/lib/src/session/internals/MsgId.js +24 -0
- package/lib/src/session/internals/SeqNo.d.ts +6 -0
- package/lib/src/session/internals/SeqNo.js +18 -0
- package/lib/src/session/secretChats/SecretChat.d.ts +29 -0
- package/lib/src/session/secretChats/SecretChat.js +527 -0
- package/lib/src/session/secretChats/index.d.ts +1 -0
- package/lib/src/session/secretChats/index.js +5 -0
- package/lib/src/storage/Abstract.d.ts +68 -0
- package/lib/src/storage/Abstract.js +6 -0
- package/lib/src/storage/SecretChat.d.ts +42 -0
- package/lib/src/storage/SecretChat.js +99 -0
- package/lib/src/storage/Session.d.ts +63 -0
- package/lib/src/storage/Session.js +245 -0
- package/lib/src/storage/StringSession.d.ts +4 -0
- package/lib/src/storage/StringSession.js +77 -0
- package/lib/src/storage/index.d.ts +4 -0
- package/lib/src/storage/index.js +12 -0
- package/package.json +46 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.siginBot = siginBot;
|
|
37
|
+
exports.siginUser = siginUser;
|
|
38
|
+
exports.sendCode = sendCode;
|
|
39
|
+
exports.sigin = sigin;
|
|
40
|
+
exports.recoverPassword = recoverPassword;
|
|
41
|
+
exports.sendRecoveryCode = sendRecoveryCode;
|
|
42
|
+
exports.checkPassword = checkPassword;
|
|
43
|
+
exports.acceptTOS = acceptTOS;
|
|
44
|
+
exports.getPasswordHint = getPasswordHint;
|
|
45
|
+
exports.signup = signup;
|
|
46
|
+
exports.getMe = getMe;
|
|
47
|
+
const index_js_1 = require("../raw/index.js");
|
|
48
|
+
const index_js_2 = require("../session/index.js");
|
|
49
|
+
const Password_js_1 = require("../crypto/Password.js");
|
|
50
|
+
const Logger_js_1 = require("../Logger.js");
|
|
51
|
+
const Errors = __importStar(require("../errors/index.js"));
|
|
52
|
+
async function siginBot(botToken) {
|
|
53
|
+
while (true) {
|
|
54
|
+
let user;
|
|
55
|
+
try {
|
|
56
|
+
user = await this.invoke(new index_js_1.Raw.auth.ImportBotAuthorization({
|
|
57
|
+
botAuthToken: botToken,
|
|
58
|
+
apiId: this._apiId,
|
|
59
|
+
apiHash: this._apiHash,
|
|
60
|
+
flags: 0,
|
|
61
|
+
}), 0);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof Errors.Exceptions.SeeOther.UserMigrate) {
|
|
65
|
+
error;
|
|
66
|
+
await this._session.stop();
|
|
67
|
+
const [ip, port] = await index_js_2.DataCenter.DataCenter(error.value, this._testMode, this._ipv6, false);
|
|
68
|
+
const auth = new index_js_2.Auth(error.value, this._testMode, this._ipv6);
|
|
69
|
+
this._storage.setAddress(error.value, ip, port, this._testMode);
|
|
70
|
+
this._storage.setApiId(this._apiId);
|
|
71
|
+
this._storage.setAuthKey(await auth.create(), this._storage.dcId);
|
|
72
|
+
this._session = new index_js_2.Session(this, this._storage.dcId, this._storage.authKey, this._storage.testMode);
|
|
73
|
+
await this._session.start();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (user && 'user' in user) {
|
|
81
|
+
await this._storage.setUserId(user.user.id);
|
|
82
|
+
await this._storage.setIsBot(true);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (user && 'user' in user) {
|
|
86
|
+
return user.user;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function siginUser(auth) {
|
|
91
|
+
let _phoneNumber;
|
|
92
|
+
let _sendCode;
|
|
93
|
+
let _signedIn;
|
|
94
|
+
let _signedUp;
|
|
95
|
+
while (true) {
|
|
96
|
+
try {
|
|
97
|
+
_phoneNumber = await auth.phoneNumber();
|
|
98
|
+
_sendCode = await sendCode.call(this, _phoneNumber);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof Errors.Exceptions.BadRequest.BadRequest) {
|
|
103
|
+
Logger_js_1.Logger.error(error);
|
|
104
|
+
if (auth.authError) {
|
|
105
|
+
await auth.authError(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
Logger_js_1.Logger.info('[101] The confirmation code has been sent.');
|
|
114
|
+
while (true) {
|
|
115
|
+
const code = await auth.code();
|
|
116
|
+
try {
|
|
117
|
+
_signedIn = await sigin.call(this, _phoneNumber, _sendCode.phoneCodeHash, code);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof Errors.Exceptions.BadRequest.BadRequest) {
|
|
122
|
+
Logger_js_1.Logger.error(error);
|
|
123
|
+
if (auth.authError) {
|
|
124
|
+
await auth.authError(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (error instanceof Errors.Exceptions.Unauthorized.SessionPasswordNeeded) {
|
|
128
|
+
let trying = 1;
|
|
129
|
+
while (true) {
|
|
130
|
+
try {
|
|
131
|
+
if (trying <= 3) {
|
|
132
|
+
if (!auth.password) {
|
|
133
|
+
throw new Error('2FA password required');
|
|
134
|
+
}
|
|
135
|
+
return await checkPassword.call(this, await auth.password(await getPasswordHint.call(this)));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
Logger_js_1.Logger.info('[102] Look you are forgotten the password');
|
|
139
|
+
if (auth.recoveryCode) {
|
|
140
|
+
const emailPattern = await sendRecoveryCode.call(this);
|
|
141
|
+
Logger_js_1.Logger.info(`[103] The recovery code has been sent to ${emailPattern}`);
|
|
142
|
+
while (true) {
|
|
143
|
+
const recoveryCode = await auth.recoveryCode();
|
|
144
|
+
try {
|
|
145
|
+
return await recoverPassword.call(this, recoveryCode);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error instanceof Errors.Exceptions.BadRequest.BadRequest) {
|
|
149
|
+
Logger_js_1.Logger.error(error);
|
|
150
|
+
if (auth.authError) {
|
|
151
|
+
await auth.authError(error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (error instanceof Errors.Exceptions.BadRequest.BadRequest) {
|
|
167
|
+
Logger_js_1.Logger.error(error);
|
|
168
|
+
if (auth.authError) {
|
|
169
|
+
await auth.authError(error);
|
|
170
|
+
}
|
|
171
|
+
trying++;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (_signedIn && _signedIn instanceof index_js_1.Raw.User) {
|
|
185
|
+
return _signedIn;
|
|
186
|
+
}
|
|
187
|
+
while (true) {
|
|
188
|
+
try {
|
|
189
|
+
_signedUp = await signup.call(this, _phoneNumber, _sendCode.phoneCodeHash, auth.firstname ? await auth.firstname() : String(Date.now()), auth.lastname ? await auth.lastname() : '');
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error instanceof Errors.Exceptions.BadRequest.BadRequest) {
|
|
194
|
+
Logger_js_1.Logger.error(error);
|
|
195
|
+
if (auth.authError) {
|
|
196
|
+
await auth.authError(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (_signedIn instanceof index_js_1.Raw.help.TermsOfService) {
|
|
205
|
+
Logger_js_1.Logger.info(`\n${_signedIn.text}\n`);
|
|
206
|
+
await acceptTOS.call(this, _signedIn.id.data);
|
|
207
|
+
}
|
|
208
|
+
return _signedUp;
|
|
209
|
+
}
|
|
210
|
+
async function sendCode(phoneNumber) {
|
|
211
|
+
phoneNumber = phoneNumber.replace(/\+/g, '').trim();
|
|
212
|
+
while (true) {
|
|
213
|
+
try {
|
|
214
|
+
const r = await this.invoke(new index_js_1.Raw.auth.SendCode({
|
|
215
|
+
phoneNumber: phoneNumber,
|
|
216
|
+
apiId: this._apiId,
|
|
217
|
+
apiHash: this._apiHash,
|
|
218
|
+
settings: new index_js_1.Raw.CodeSettings({}),
|
|
219
|
+
}), 0);
|
|
220
|
+
return r;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (error instanceof Errors.Exceptions.SeeOther.NetworkMigrate ||
|
|
224
|
+
error instanceof Errors.Exceptions.SeeOther.PhoneMigrate) {
|
|
225
|
+
await this._session.stop();
|
|
226
|
+
const [ip, port] = await index_js_2.DataCenter.DataCenter(error.value, this._testMode, this._ipv6, false);
|
|
227
|
+
const auth = new index_js_2.Auth(error.value, this._testMode, this._ipv6);
|
|
228
|
+
this._storage.setAddress(error.value, ip, port, this._testMode);
|
|
229
|
+
this._storage.setApiId(this._apiId);
|
|
230
|
+
this._storage.setAuthKey(await auth.create(), this._storage.dcId);
|
|
231
|
+
this._session = new index_js_2.Session(this, this._storage.dcId, this._storage.authKey, this._storage.testMode);
|
|
232
|
+
await this._session.start();
|
|
233
|
+
}
|
|
234
|
+
else if (error instanceof Errors.ClientError.ClientDisconnected) {
|
|
235
|
+
await this.connect();
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function sigin(phoneNumber, phoneCodeHash, phoneCode) {
|
|
244
|
+
const r = await this.invoke(new index_js_1.Raw.auth.SignIn({
|
|
245
|
+
phoneNumber: phoneNumber.replace(/\+/g, '').trim(),
|
|
246
|
+
phoneCodeHash,
|
|
247
|
+
phoneCode,
|
|
248
|
+
}), 0);
|
|
249
|
+
if (r instanceof index_js_1.Raw.auth.AuthorizationSignUpRequired) {
|
|
250
|
+
if (r.termsOfService) {
|
|
251
|
+
return r.termsOfService;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
await this._storage.setUserId(r.user.id);
|
|
257
|
+
await this._storage.setIsBot(false);
|
|
258
|
+
return r.user;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function recoverPassword(code) {
|
|
262
|
+
const r = await this.invoke(new index_js_1.Raw.auth.RecoverPassword({
|
|
263
|
+
code: code,
|
|
264
|
+
}), 0);
|
|
265
|
+
if ('user' in r) {
|
|
266
|
+
await this._storage.setUserId(r.user.id);
|
|
267
|
+
await this._storage.setIsBot(false);
|
|
268
|
+
return r.user;
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
async function sendRecoveryCode() {
|
|
273
|
+
const r = await this.invoke(new index_js_1.Raw.auth.RequestPasswordRecovery(), 0);
|
|
274
|
+
return r.emailPattern;
|
|
275
|
+
}
|
|
276
|
+
async function checkPassword(password) {
|
|
277
|
+
const r = await this.invoke(new index_js_1.Raw.auth.CheckPassword({
|
|
278
|
+
password: (0, Password_js_1.computePasswordCheck)(await this.invoke(new index_js_1.Raw.account.GetPassword(), 0), password),
|
|
279
|
+
}), 0);
|
|
280
|
+
if ('user' in r) {
|
|
281
|
+
await this._storage.setUserId(r.user.id);
|
|
282
|
+
await this._storage.setIsBot(false);
|
|
283
|
+
return r.user;
|
|
284
|
+
}
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
async function acceptTOS(id) {
|
|
288
|
+
const r = await this.invoke(new index_js_1.Raw.help.AcceptTermsOfService({
|
|
289
|
+
id: new index_js_1.Raw.DataJSON({
|
|
290
|
+
data: id,
|
|
291
|
+
}),
|
|
292
|
+
}));
|
|
293
|
+
return Boolean(r);
|
|
294
|
+
}
|
|
295
|
+
async function getPasswordHint() {
|
|
296
|
+
const r = await this.invoke(new index_js_1.Raw.account.GetPassword(), 0);
|
|
297
|
+
return r.hint ?? '';
|
|
298
|
+
}
|
|
299
|
+
async function signup(phoneNumber, phoneCodeHash, firstname, lastname = '') {
|
|
300
|
+
const r = await this.invoke(new index_js_1.Raw.auth.SignUp({
|
|
301
|
+
phoneNumber: phoneNumber.replace(/\+/g, '').trim(),
|
|
302
|
+
phoneCodeHash,
|
|
303
|
+
firstName: firstname,
|
|
304
|
+
lastName: lastname,
|
|
305
|
+
}));
|
|
306
|
+
if ('user' in r) {
|
|
307
|
+
await this._storage.setUserId(r.user.id);
|
|
308
|
+
await this._storage.setIsBot(false);
|
|
309
|
+
return r.user;
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
async function getMe() {
|
|
314
|
+
return await this.invoke(new index_js_1.Raw.users.GetFullUser({
|
|
315
|
+
id: new index_js_1.Raw.InputUserSelf(),
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Semaphore, Buffer } from '../platform.node.js';
|
|
2
|
+
import { Raw } from '../raw/index.js';
|
|
3
|
+
import { AbstractSession } from '../storage/index.js';
|
|
4
|
+
import { SecretChat } from '../session/secretChats/index.js';
|
|
5
|
+
import { TCP } from '../connection/connection.js';
|
|
6
|
+
import * as _Auth from './Auth.js';
|
|
7
|
+
import * as Files from '../file/index.js';
|
|
8
|
+
import type { ProxyInterface } from '../connection/connection.js';
|
|
9
|
+
import type { Session } from '../session/index.js';
|
|
10
|
+
export interface ClientOptions {
|
|
11
|
+
proxy?: ProxyInterface;
|
|
12
|
+
testMode?: boolean;
|
|
13
|
+
ipv6?: boolean;
|
|
14
|
+
deviceModel?: string;
|
|
15
|
+
systemVersion?: string;
|
|
16
|
+
appVersion?: string;
|
|
17
|
+
systemLangCode?: string;
|
|
18
|
+
langCode?: string;
|
|
19
|
+
sleepTreshold?: number;
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
isCdn?: boolean;
|
|
22
|
+
noUpdates?: boolean;
|
|
23
|
+
takeout?: boolean;
|
|
24
|
+
tcp?: TCP;
|
|
25
|
+
local?: boolean;
|
|
26
|
+
maxConcurrentTransmissions?: number;
|
|
27
|
+
maxReconnectRetries?: number;
|
|
28
|
+
defaultDCId?: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class Client {
|
|
31
|
+
_apiId: number;
|
|
32
|
+
_apiHash: string;
|
|
33
|
+
_storage: AbstractSession;
|
|
34
|
+
_testMode: boolean;
|
|
35
|
+
_proxy?: ProxyInterface;
|
|
36
|
+
_ipv6: boolean;
|
|
37
|
+
_deviceModel: string;
|
|
38
|
+
_systemVersion: string;
|
|
39
|
+
_appVersion: string;
|
|
40
|
+
_systemLangCode: string;
|
|
41
|
+
_langCode: string;
|
|
42
|
+
_maxRetries: number;
|
|
43
|
+
_isCdn: boolean;
|
|
44
|
+
_sleepTreshold: number;
|
|
45
|
+
_takeout: boolean;
|
|
46
|
+
_noUpdates: boolean;
|
|
47
|
+
_takeoutId: bigint;
|
|
48
|
+
_dcId: string;
|
|
49
|
+
_defaultDcId: number;
|
|
50
|
+
_session: Session;
|
|
51
|
+
_isConnected: boolean;
|
|
52
|
+
_connectionMode: number;
|
|
53
|
+
_local: boolean;
|
|
54
|
+
_secretChat: SecretChat;
|
|
55
|
+
_getFileSemaphore: Semaphore;
|
|
56
|
+
_saveFileSemaphore: Semaphore;
|
|
57
|
+
_maxReconnectRetries: number;
|
|
58
|
+
_me?: Raw.users.UserFull;
|
|
59
|
+
private _handler;
|
|
60
|
+
constructor(session: AbstractSession, apiHash: string, apiId: number, clientOptions?: ClientOptions);
|
|
61
|
+
exportSession(): Promise<string>;
|
|
62
|
+
invoke<T extends Raw.TypesTLRequest>(query: T, retries?: number, timeout?: number, sleepTreshold?: number): Promise<T['__response__']>;
|
|
63
|
+
logout(): Promise<void>;
|
|
64
|
+
start(auth?: _Auth.SigInBot | _Auth.SigInUser): Promise<Raw.users.UserFull>;
|
|
65
|
+
connect(): Promise<void>;
|
|
66
|
+
handleUpdate(update: Raw.TypeUpdates): Promise<Raw.TypeUpdates>;
|
|
67
|
+
private _handleSecretChatUpdate;
|
|
68
|
+
addHandler(callback: {
|
|
69
|
+
(update: Raw.TypeUpdates): void;
|
|
70
|
+
}): undefined;
|
|
71
|
+
fetchPeers(peers: Array<Raw.TypeUser | Raw.TypeChat>): Promise<boolean>;
|
|
72
|
+
resolvePeer(peerId: bigint | string): Promise<Raw.InputPeerUser | Raw.InputPeerChat | Raw.InputPeerChannel | Raw.InputUserSelf>;
|
|
73
|
+
startSecretChat(chatId: bigint | string): Promise<Raw.TypeEncryptedChat>;
|
|
74
|
+
destroySecretChat(chatId: number): Promise<boolean>;
|
|
75
|
+
saveFile({ source, fileName, fileId, filePart, progress, }: Files.SaveFileParams): Promise<Raw.InputFile | Raw.InputFileBig | undefined>;
|
|
76
|
+
saveFileStream({ source, fileName, progress, }: Files.SaveFileStreamParams): Promise<Raw.InputFile | Raw.InputFileBig | undefined>;
|
|
77
|
+
downloadStream({ file, dcId, limit, offset }: Files.DownloadParam): Files.File;
|
|
78
|
+
download({ file, dcId, limit, offset }: Files.DownloadParam): Promise<Buffer>;
|
|
79
|
+
toJSON(): {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
toString(): string;
|
|
83
|
+
}
|