@mtkruto/node 0.0.822 → 0.0.823

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.
@@ -204,6 +204,36 @@ export class Client extends ClientAbstract {
204
204
  systemLangCode: this.systemLangCode,
205
205
  systemVersion: this.systemVersion,
206
206
  }));
207
+ const handlePassword = async (err) => {
208
+ params = params;
209
+ if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
210
+ while (true) {
211
+ const ap = await this.invoke(new functions.AccountGetPassword());
212
+ if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
213
+ try {
214
+ const password = typeof params.password === "string" ? params.password : await params.password();
215
+ const input = await checkPassword(password, ap);
216
+ await this.invoke(new functions.AuthCheckPassword({ password: input }));
217
+ break;
218
+ }
219
+ catch (err) {
220
+ if (err instanceof types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
221
+ continue;
222
+ }
223
+ else {
224
+ throw err;
225
+ }
226
+ }
227
+ }
228
+ else {
229
+ throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
230
+ }
231
+ }
232
+ }
233
+ else {
234
+ throw err;
235
+ }
236
+ };
207
237
  try {
208
238
  await this.invoke(new functions.UpdatesGetState());
209
239
  return;
@@ -261,33 +291,7 @@ export class Client extends ClientAbstract {
261
291
  }
262
292
  }
263
293
  catch (err) {
264
- if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
265
- while (true) {
266
- const ap = await this.invoke(new functions.AccountGetPassword());
267
- if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
268
- try {
269
- const password = typeof params.password === "string" ? params.password : await params.password();
270
- const input = await checkPassword(password, ap);
271
- await this.invoke(new functions.AuthCheckPassword({ password: input }));
272
- break;
273
- }
274
- catch (err) {
275
- if (err instanceof types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
276
- continue;
277
- }
278
- else {
279
- throw err;
280
- }
281
- }
282
- }
283
- else {
284
- throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
285
- }
286
- }
287
- }
288
- else {
289
- throw err;
290
- }
294
+ await handlePassword(err);
291
295
  }
292
296
  }
293
297
  catch (err) {
@@ -320,7 +324,7 @@ export class Client extends ClientAbstract {
320
324
  await this.authorize(params);
321
325
  }
322
326
  else {
323
- throw err;
327
+ await handlePassword(err);
324
328
  }
325
329
  }
326
330
  else {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.822",
5
+ "version": "0.0.823",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -230,6 +230,36 @@ class Client extends client_abstract_js_1.ClientAbstract {
230
230
  systemLangCode: this.systemLangCode,
231
231
  systemVersion: this.systemVersion,
232
232
  }));
233
+ const handlePassword = async (err) => {
234
+ params = params;
235
+ if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
236
+ while (true) {
237
+ const ap = await this.invoke(new functions.AccountGetPassword());
238
+ if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
239
+ try {
240
+ const password = typeof params.password === "string" ? params.password : await params.password();
241
+ const input = await (0, _1_password_js_1.checkPassword)(password, ap);
242
+ await this.invoke(new functions.AuthCheckPassword({ password: input }));
243
+ break;
244
+ }
245
+ catch (err) {
246
+ if (err instanceof types.RPCError && err.errorMessage == "PASSWORD_HASH_INVALID") {
247
+ continue;
248
+ }
249
+ else {
250
+ throw err;
251
+ }
252
+ }
253
+ }
254
+ else {
255
+ throw new Error(`Handling ${ap.currentAlgo?.constructor.name} not implemented`);
256
+ }
257
+ }
258
+ }
259
+ else {
260
+ throw err;
261
+ }
262
+ };
233
263
  try {
234
264
  await this.invoke(new functions.UpdatesGetState());
235
265
  return;
@@ -287,33 +317,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
287
317
  }
288
318
  }
289
319
  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
- }
320
+ await handlePassword(err);
317
321
  }
318
322
  }
319
323
  catch (err) {
@@ -346,7 +350,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
346
350
  await this.authorize(params);
347
351
  }
348
352
  else {
349
- throw err;
353
+ await handlePassword(err);
350
354
  }
351
355
  }
352
356
  else {