GramJs: Auto-fixes by ESLint
This commit is contained in:
parent
5f4a210d7b
commit
146a0db3c2
@ -1,5 +1,5 @@
|
|||||||
const crypto = require('./crypto/crypto');
|
|
||||||
const BigInt = require('big-integer');
|
const BigInt = require('big-integer');
|
||||||
|
const crypto = require('./crypto/crypto');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* converts a buffer to big int
|
* converts a buffer to big int
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const {
|
|||||||
generateRandomBytes,
|
generateRandomBytes,
|
||||||
} = require('./Helpers');
|
} = require('./Helpers');
|
||||||
const crypto = require('./crypto/crypto');
|
const crypto = require('./crypto/crypto');
|
||||||
|
|
||||||
const SIZE_FOR_HASH = 256;
|
const SIZE_FOR_HASH = 256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,9 +139,9 @@ function isGoodModExpFirst(modexp, prime) {
|
|||||||
const minDiffBitsCount = 2048 - 64;
|
const minDiffBitsCount = 2048 - 64;
|
||||||
const maxModExpSize = 256;
|
const maxModExpSize = 256;
|
||||||
|
|
||||||
return !(diff.lesser(BigInt(0)) || diff.bitLength() < minDiffBitsCount ||
|
return !(diff.lesser(BigInt(0)) || diff.bitLength() < minDiffBitsCount
|
||||||
modexp.bitLength() < minDiffBitsCount ||
|
|| modexp.bitLength() < minDiffBitsCount
|
||||||
Math.floor((modexp.bitLength() + 7) / 8) > maxModExpSize);
|
|| Math.floor((modexp.bitLength() + 7) / 8) > maxModExpSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
function xor(a, b) {
|
function xor(a, b) {
|
||||||
@ -209,7 +210,7 @@ async function computeCheck(request, password) {
|
|||||||
|
|
||||||
const pwHash = await computeHash(algo, password);
|
const pwHash = await computeHash(algo, password);
|
||||||
const p = readBigIntFromBuffer(algo.p, false);
|
const p = readBigIntFromBuffer(algo.p, false);
|
||||||
const g = algo.g;
|
const { g } = algo;
|
||||||
const B = readBigIntFromBuffer(request.srp_B, false);
|
const B = readBigIntFromBuffer(request.srp_B, false);
|
||||||
try {
|
try {
|
||||||
checkPrimeAndGood(algo.p, g);
|
checkPrimeAndGood(algo.p, g);
|
||||||
@ -271,7 +272,7 @@ async function computeCheck(request, password) {
|
|||||||
return new constructors.InputCheckPasswordSRP({
|
return new constructors.InputCheckPasswordSRP({
|
||||||
srpId: request.srpId,
|
srpId: request.srpId,
|
||||||
A: Buffer.from(aForHash),
|
A: Buffer.from(aForHash),
|
||||||
M1: M1,
|
M1,
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -280,4 +281,3 @@ module.exports = {
|
|||||||
computeCheck,
|
computeCheck,
|
||||||
computeDigest,
|
computeDigest,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
const { constructors } = require('./tl');
|
const { constructors } = require('./tl');
|
||||||
|
|
||||||
const USERNAME_RE = new RegExp('@|(?:https?:\\/\\/)?(?:www\\.)?' +
|
const USERNAME_RE = new RegExp('@|(?:https?:\\/\\/)?(?:www\\.)?'
|
||||||
'(?:telegram\\.(?:me|dog)|t\\.me)\\/(@|joinchat\\/)?');
|
+ '(?:telegram\\.(?:me|dog)|t\\.me)\\/(@|joinchat\\/)?');
|
||||||
|
|
||||||
const JPEG_HEADER = Buffer.from('ffd8ffe000104a46494600010100000100010000ffdb004300281c1e231e19282321232d2b28303c64413c37373c7b585d4964918099968f808c8aa0b4e6c3a0aadaad8a8cc8ffcbdaeef5ffffff9bc1fffffffaffe6fdfff8ffdb0043012b2d2d3c353c76414176f8a58ca5f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8ffc00011080000000003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00', 'hex');
|
const JPEG_HEADER = Buffer.from('ffd8ffe000104a46494600010100000100010000ffdb004300281c1e231e19282321232d2b28303c64413c37373c7b585d4964918099968f808c8aa0b4e6c3a0aadaad8a8cc8ffcbdaeef5ffffff9bc1fffffffaffe6fdfff8ffdb0043012b2d2d3c353c76414176f8a58ca5f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8ffc00011080000000003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00', 'hex');
|
||||||
const JPEG_FOOTER = Buffer.from('ffd9', 'hex');
|
const JPEG_FOOTER = Buffer.from('ffd9', 'hex');
|
||||||
|
|
||||||
const TG_JOIN_RE = new RegExp('tg:\\/\\/(join)\\?invite=');
|
const TG_JOIN_RE = new RegExp('tg:\\/\\/(join)\\?invite=');
|
||||||
|
|
||||||
const VALID_USERNAME_RE = new RegExp('^([a-z]((?!__)[\\w\\d]){3,30}[a-z\\d]|gif|vid|' +
|
const VALID_USERNAME_RE = new RegExp('^([a-z]((?!__)[\\w\\d]){3,30}[a-z\\d]|gif|vid|'
|
||||||
'pic|bing|wiki|imdb|bold|vote|like|coub)$');
|
+ 'pic|bing|wiki|imdb|bold|vote|like|coub)$');
|
||||||
|
|
||||||
function _raiseCastFail(entity, target) {
|
function _raiseCastFail(entity, target) {
|
||||||
throw new Error(`Cannot cast ${entity.className} to any kind of ${target}`);
|
throw new Error(`Cannot cast ${entity.className} to any kind of ${target}`);
|
||||||
@ -60,8 +60,8 @@ function getInputPeer(entity, allowSelf = true, checkHash = true) {
|
|||||||
throw new Error('User without accessHash or min info cannot be input');
|
throw new Error('User without accessHash or min info cannot be input');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity instanceof constructors.Chat || entity instanceof constructors.ChatEmpty ||
|
if (entity instanceof constructors.Chat || entity instanceof constructors.ChatEmpty
|
||||||
entity instanceof constructors.ChatForbidden) {
|
|| entity instanceof constructors.ChatForbidden) {
|
||||||
return new constructors.InputPeerChat({ chatId: entity.id });
|
return new constructors.InputPeerChat({ chatId: entity.id });
|
||||||
}
|
}
|
||||||
if (entity instanceof constructors.Channel) {
|
if (entity instanceof constructors.Channel) {
|
||||||
@ -505,7 +505,7 @@ function getMessageId(message) {
|
|||||||
if (message === null || message === undefined) {
|
if (message === null || message === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (typeof message == 'number') {
|
if (typeof message === 'number') {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
if (message.SUBCLASS_OF_ID === 0x790009e3) { // crc32(b'Message')
|
if (message.SUBCLASS_OF_ID === 0x790009e3) { // crc32(b'Message')
|
||||||
|
|||||||
@ -88,7 +88,7 @@ export async function updateTwoFaSettings(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await client.invoke(new Api.account.UpdatePasswordSettings({
|
await client.invoke(new Api.account.UpdatePasswordSettings({
|
||||||
password: password,
|
password,
|
||||||
newSettings: new Api.account.PasswordInputSettings({
|
newSettings: new Api.account.PasswordInputSettings({
|
||||||
newAlgo: pwd.newAlgo,
|
newAlgo: pwd.newAlgo,
|
||||||
newPasswordHash: newPassword ? await computeDigest(pwd.newAlgo, newPassword) : Buffer.alloc(0),
|
newPasswordHash: newPassword ? await computeDigest(pwd.newAlgo, newPassword) : Buffer.alloc(0),
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const os = require('os');
|
||||||
const Logger = require('../extensions/Logger');
|
const Logger = require('../extensions/Logger');
|
||||||
const { sleep } = require('../Helpers');
|
const { sleep } = require('../Helpers');
|
||||||
const errors = require('../errors');
|
const errors = require('../errors');
|
||||||
@ -6,7 +7,6 @@ const Helpers = require('../Helpers');
|
|||||||
const { BinaryWriter } = require('../extensions');
|
const { BinaryWriter } = require('../extensions');
|
||||||
const utils = require('../Utils');
|
const utils = require('../Utils');
|
||||||
const Session = require('../sessions/Abstract');
|
const Session = require('../sessions/Abstract');
|
||||||
const os = require('os');
|
|
||||||
const { LAYER } = require('../tl/AllTLObjects');
|
const { LAYER } = require('../tl/AllTLObjects');
|
||||||
const {
|
const {
|
||||||
constructors,
|
constructors,
|
||||||
@ -69,7 +69,7 @@ class TelegramClient {
|
|||||||
this.apiHash = apiHash;
|
this.apiHash = apiHash;
|
||||||
this._useIPV6 = args.useIPV6;
|
this._useIPV6 = args.useIPV6;
|
||||||
// this._entityCache = new Set()
|
// this._entityCache = new Set()
|
||||||
if (typeof args.baseLogger == 'string') {
|
if (typeof args.baseLogger === 'string') {
|
||||||
this._log = new Logger();
|
this._log = new Logger();
|
||||||
} else {
|
} else {
|
||||||
this._log = args.baseLogger;
|
this._log = args.baseLogger;
|
||||||
@ -294,7 +294,7 @@ class TelegramClient {
|
|||||||
const sender = new MTProtoSender(this.session.getAuthKey(dcId),
|
const sender = new MTProtoSender(this.session.getAuthKey(dcId),
|
||||||
{
|
{
|
||||||
logger: this._log,
|
logger: this._log,
|
||||||
dcId: dcId,
|
dcId,
|
||||||
retries: this._connectionRetries,
|
retries: this._connectionRetries,
|
||||||
delay: this._retryDelay,
|
delay: this._retryDelay,
|
||||||
autoReconnect: this._autoReconnect,
|
autoReconnect: this._autoReconnect,
|
||||||
@ -313,12 +313,11 @@ class TelegramClient {
|
|||||||
));
|
));
|
||||||
if (this.session.dcId !== dcId) {
|
if (this.session.dcId !== dcId) {
|
||||||
this._log.info(`Exporting authorization for data center ${dc.ipAddress}`);
|
this._log.info(`Exporting authorization for data center ${dc.ipAddress}`);
|
||||||
const auth = await this.invoke(new requests.auth.ExportAuthorization({ dcId: dcId }));
|
const auth = await this.invoke(new requests.auth.ExportAuthorization({ dcId }));
|
||||||
const req = this._initWith(new requests.auth.ImportAuthorization({
|
const req = this._initWith(new requests.auth.ImportAuthorization({
|
||||||
id: auth.id,
|
id: auth.id,
|
||||||
bytes: auth.bytes,
|
bytes: auth.bytes,
|
||||||
},
|
}));
|
||||||
));
|
|
||||||
await sender.send(req);
|
await sender.send(req);
|
||||||
}
|
}
|
||||||
sender.dcId = dcId;
|
sender.dcId = dcId;
|
||||||
@ -360,7 +359,7 @@ class TelegramClient {
|
|||||||
date = new Date().getTime();
|
date = new Date().getTime();
|
||||||
media = messageOrMedia;
|
media = messageOrMedia;
|
||||||
}
|
}
|
||||||
if (typeof media == 'string') {
|
if (typeof media === 'string') {
|
||||||
throw new Error('not implemented');
|
throw new Error('not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +423,7 @@ class TelegramClient {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return this.downloadFile(loc, {
|
return this.downloadFile(loc, {
|
||||||
dcId: dcId,
|
dcId,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// TODO this should never raise
|
// TODO this should never raise
|
||||||
@ -592,8 +591,8 @@ class TelegramClient {
|
|||||||
// this._entityCache.add(result)
|
// this._entityCache.add(result)
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof errors.ServerError || e.message === 'RPC_CALL_FAIL' ||
|
if (e instanceof errors.ServerError || e.message === 'RPC_CALL_FAIL'
|
||||||
e.message === 'RPC_MCGET_FAIL') {
|
|| e.message === 'RPC_MCGET_FAIL') {
|
||||||
this._log.warn(`Telegram is having internal issues ${e.constructor.name}`);
|
this._log.warn(`Telegram is having internal issues ${e.constructor.name}`);
|
||||||
await sleep(2000);
|
await sleep(2000);
|
||||||
} else if (e instanceof errors.FloodWaitError || e instanceof errors.FloodTestPhoneWaitError) {
|
} else if (e instanceof errors.FloodWaitError || e instanceof errors.FloodTestPhoneWaitError) {
|
||||||
@ -603,8 +602,8 @@ class TelegramClient {
|
|||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} else if (e instanceof errors.PhoneMigrateError || e instanceof errors.NetworkMigrateError ||
|
} else if (e instanceof errors.PhoneMigrateError || e instanceof errors.NetworkMigrateError
|
||||||
e instanceof errors.UserMigrateError) {
|
|| e instanceof errors.UserMigrateError) {
|
||||||
this._log.info(`Phone migrated to ${e.newDc}`);
|
this._log.info(`Phone migrated to ${e.newDc}`);
|
||||||
const shouldRaise = e instanceof errors.PhoneMigrateError || e instanceof errors.NetworkMigrateError;
|
const shouldRaise = e instanceof errors.PhoneMigrateError || e instanceof errors.NetworkMigrateError;
|
||||||
if (shouldRaise && await checkAuthorization(this)) {
|
if (shouldRaise && await checkAuthorization(this)) {
|
||||||
@ -682,8 +681,8 @@ class TelegramClient {
|
|||||||
_processUpdate(update, others, entities) {
|
_processUpdate(update, others, entities) {
|
||||||
update._entities = entities || [];
|
update._entities = entities || [];
|
||||||
const args = {
|
const args = {
|
||||||
update: update,
|
update,
|
||||||
others: others,
|
others,
|
||||||
};
|
};
|
||||||
this._dispatchUpdate(args);
|
this._dispatchUpdate(args);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export interface UserAuthParams {
|
|||||||
phoneCode: (isCodeViaApp?: boolean) => Promise<string>;
|
phoneCode: (isCodeViaApp?: boolean) => Promise<string>;
|
||||||
password: (hint?: string) => Promise<string>;
|
password: (hint?: string) => Promise<string>;
|
||||||
firstAndLastNames: () => Promise<[string, string?]>;
|
firstAndLastNames: () => Promise<[string, string?]>;
|
||||||
qrCode: (qrCode: { token: Buffer, expires: number }) => Promise<void>;
|
qrCode: (qrCode: { token: Buffer; expires: number }) => Promise<void>;
|
||||||
onError: (err: Error) => void;
|
onError: (err: Error) => void;
|
||||||
forceSMS?: boolean;
|
forceSMS?: boolean;
|
||||||
}
|
}
|
||||||
@ -19,8 +19,8 @@ export interface BotAuthParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ApiCredentials {
|
interface ApiCredentials {
|
||||||
apiId: number,
|
apiId: number;
|
||||||
apiHash: string,
|
apiHash: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QR_CODE_TIMEOUT = 30000;
|
const QR_CODE_TIMEOUT = 30000;
|
||||||
|
|||||||
@ -39,7 +39,9 @@ export async function downloadFile(
|
|||||||
inputLocation: Api.InputFileLocation,
|
inputLocation: Api.InputFileLocation,
|
||||||
fileParams: DownloadFileParams,
|
fileParams: DownloadFileParams,
|
||||||
) {
|
) {
|
||||||
let { partSizeKb, fileSize, workers = 1, end } = fileParams;
|
let {
|
||||||
|
partSizeKb, fileSize, workers = 1, end,
|
||||||
|
} = fileParams;
|
||||||
const { dcId, progressCallback, start = 0 } = fileParams;
|
const { dcId, progressCallback, start = 0 } = fileParams;
|
||||||
|
|
||||||
end = end && end < fileSize ? end : fileSize - 1;
|
end = end && end < fileSize ? end : fileSize - 1;
|
||||||
@ -151,6 +153,7 @@ export async function downloadFile(
|
|||||||
|
|
||||||
class Foreman {
|
class Foreman {
|
||||||
private deferred: Deferred | undefined;
|
private deferred: Deferred | undefined;
|
||||||
|
|
||||||
private activeWorkers = 0;
|
private activeWorkers = 0;
|
||||||
|
|
||||||
constructor(private maxWorkers: number) {
|
constructor(private maxWorkers: number) {
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export async function uploadFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < partCount; i += workers) {
|
for (let i = 0; i < partCount; i += workers) {
|
||||||
let sendingParts = [];
|
const sendingParts = [];
|
||||||
let end = i + workers;
|
let end = i + workers;
|
||||||
if (end > partCount) {
|
if (end > partCount) {
|
||||||
end = partCount;
|
end = partCount;
|
||||||
@ -86,7 +86,6 @@ export async function uploadFile(
|
|||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
}
|
}
|
||||||
})());
|
})());
|
||||||
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
|
|||||||
@ -8,7 +8,6 @@ const BinaryReader = require('../extensions/BinaryReader');
|
|||||||
const { sleep } = require('../Helpers');
|
const { sleep } = require('../Helpers');
|
||||||
|
|
||||||
class AuthKey {
|
class AuthKey {
|
||||||
|
|
||||||
constructor(value, hash) {
|
constructor(value, hash) {
|
||||||
if (!hash || !value) {
|
if (!hash || !value) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class Factorizator {
|
|||||||
*/
|
*/
|
||||||
static gcd(a, b) {
|
static gcd(a, b) {
|
||||||
while (b.neq(BigInt.zero)) {
|
while (b.neq(BigInt.zero)) {
|
||||||
let temp = b;
|
const temp = b;
|
||||||
b = a.remainder(b);
|
b = a.remainder(b);
|
||||||
a = temp;
|
a = temp;
|
||||||
}
|
}
|
||||||
@ -51,9 +51,8 @@ class Factorizator {
|
|||||||
k = BigInt.zero;
|
k = BigInt.zero;
|
||||||
|
|
||||||
while (k.lesser(r) && g.eq(BigInt.one)) {
|
while (k.lesser(r) && g.eq(BigInt.one)) {
|
||||||
|
|
||||||
ys = y;
|
ys = y;
|
||||||
let condition = BigInt.min(m, r.minus(k));
|
const condition = BigInt.min(m, r.minus(k));
|
||||||
for (let i = 0; BigInt(i)
|
for (let i = 0; BigInt(i)
|
||||||
.lesser(condition); i++) {
|
.lesser(condition); i++) {
|
||||||
y = (modExp(y, BigInt(2), pq)).add(c)
|
y = (modExp(y, BigInt(2), pq)).add(c)
|
||||||
@ -85,8 +84,8 @@ class Factorizator {
|
|||||||
const p = g;
|
const p = g;
|
||||||
q = pq.divide(g);
|
q = pq.divide(g);
|
||||||
return p < q ? {
|
return p < q ? {
|
||||||
p: p,
|
p,
|
||||||
q: q,
|
q,
|
||||||
} : {
|
} : {
|
||||||
p: q,
|
p: q,
|
||||||
q: p,
|
q: p,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
|
const { IGE: aes_ige } = require('@cryptography/aes');
|
||||||
const Helpers = require('../Helpers');
|
const Helpers = require('../Helpers');
|
||||||
|
|
||||||
const { IGE: aes_ige } = require('@cryptography/aes');
|
|
||||||
|
|
||||||
class IGENEW {
|
class IGENEW {
|
||||||
constructor(key, iv) {
|
constructor(key, iv) {
|
||||||
@ -28,10 +28,7 @@ class IGENEW {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Helpers.convertToLittle(this.ige.encrypt(plainText));
|
return Helpers.convertToLittle(this.ige.encrypt(plainText));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = IGENEW;
|
module.exports = IGENEW;
|
||||||
|
|||||||
@ -9,21 +9,21 @@ const {
|
|||||||
} = require('../Helpers');
|
} = require('../Helpers');
|
||||||
|
|
||||||
const PUBLIC_KEYS = [{
|
const PUBLIC_KEYS = [{
|
||||||
'fingerprint': [40, 85, 94, 156, 117, 240, 61, 22, 65, 244, 169, 2, 33, 107, 232, 108, 2, 43, 180, 195],
|
fingerprint: [40, 85, 94, 156, 117, 240, 61, 22, 65, 244, 169, 2, 33, 107, 232, 108, 2, 43, 180, 195],
|
||||||
'n': BigInt('24403446649145068056824081744112065346446136066297307473868293895086332508101251964919587745984311372853053253457835208829824428441874946556659953519213382748319518214765985662663680818277989736779506318868003755216402538945900388706898101286548187286716959100102939636333452457308619454821845196109544157601096359148241435922125602449263164512290854366930013825808102403072317738266383237191313714482187326643144603633877219028262697593882410403273959074350849923041765639673335775605842311578109726403165298875058941765362622936097839775380070572921007586266115476975819175319995527916042178582540628652481530373407'),
|
n: BigInt('24403446649145068056824081744112065346446136066297307473868293895086332508101251964919587745984311372853053253457835208829824428441874946556659953519213382748319518214765985662663680818277989736779506318868003755216402538945900388706898101286548187286716959100102939636333452457308619454821845196109544157601096359148241435922125602449263164512290854366930013825808102403072317738266383237191313714482187326643144603633877219028262697593882410403273959074350849923041765639673335775605842311578109726403165298875058941765362622936097839775380070572921007586266115476975819175319995527916042178582540628652481530373407'),
|
||||||
'e': 65537,
|
e: 65537,
|
||||||
}, {
|
}, {
|
||||||
'fingerprint': [140, 171, 9, 34, 146, 246, 166, 50, 10, 170, 229, 247, 155, 114, 28, 177, 29, 106, 153, 154],
|
fingerprint: [140, 171, 9, 34, 146, 246, 166, 50, 10, 170, 229, 247, 155, 114, 28, 177, 29, 106, 153, 154],
|
||||||
'n': BigInt('25081407810410225030931722734886059247598515157516470397242545867550116598436968553551465554653745201634977779380884774534457386795922003815072071558370597290368737862981871277312823942822144802509055492512145589734772907225259038113414940384446493111736999668652848440655603157665903721517224934142301456312994547591626081517162758808439979745328030376796953660042629868902013177751703385501412640560275067171555763725421377065095231095517201241069856888933358280729674273422117201596511978645878544308102076746465468955910659145532699238576978901011112475698963666091510778777356966351191806495199073754705289253783'),
|
n: BigInt('25081407810410225030931722734886059247598515157516470397242545867550116598436968553551465554653745201634977779380884774534457386795922003815072071558370597290368737862981871277312823942822144802509055492512145589734772907225259038113414940384446493111736999668652848440655603157665903721517224934142301456312994547591626081517162758808439979745328030376796953660042629868902013177751703385501412640560275067171555763725421377065095231095517201241069856888933358280729674273422117201596511978645878544308102076746465468955910659145532699238576978901011112475698963666091510778777356966351191806495199073754705289253783'),
|
||||||
'e': 65537,
|
e: 65537,
|
||||||
}, {
|
}, {
|
||||||
'fingerprint': [243, 218, 109, 239, 16, 202, 176, 78, 167, 8, 255, 209, 120, 234, 205, 112, 111, 42, 91, 176],
|
fingerprint: [243, 218, 109, 239, 16, 202, 176, 78, 167, 8, 255, 209, 120, 234, 205, 112, 111, 42, 91, 176],
|
||||||
'n': BigInt('22347337644621997830323797217583448833849627595286505527328214795712874535417149457567295215523199212899872122674023936713124024124676488204889357563104452250187725437815819680799441376434162907889288526863223004380906766451781702435861040049293189979755757428366240570457372226323943522935844086838355728767565415115131238950994049041950699006558441163206523696546297006014416576123345545601004508537089192869558480948139679182328810531942418921113328804749485349441503927570568778905918696883174575510385552845625481490900659718413892216221539684717773483326240872061786759868040623935592404144262688161923519030977'),
|
n: BigInt('22347337644621997830323797217583448833849627595286505527328214795712874535417149457567295215523199212899872122674023936713124024124676488204889357563104452250187725437815819680799441376434162907889288526863223004380906766451781702435861040049293189979755757428366240570457372226323943522935844086838355728767565415115131238950994049041950699006558441163206523696546297006014416576123345545601004508537089192869558480948139679182328810531942418921113328804749485349441503927570568778905918696883174575510385552845625481490900659718413892216221539684717773483326240872061786759868040623935592404144262688161923519030977'),
|
||||||
'e': 65537,
|
e: 65537,
|
||||||
}, {
|
}, {
|
||||||
'fingerprint': [128, 80, 214, 72, 77, 244, 98, 7, 201, 250, 37, 244, 227, 51, 96, 199, 182, 37, 224, 113],
|
fingerprint: [128, 80, 214, 72, 77, 244, 98, 7, 201, 250, 37, 244, 227, 51, 96, 199, 182, 37, 224, 113],
|
||||||
'n': BigInt('24573455207957565047870011785254215390918912369814947541785386299516827003508659346069416840622922416779652050319196701077275060353178142796963682024347858398319926119639265555410256455471016400261630917813337515247954638555325280392998950756512879748873422896798579889820248358636937659872379948616822902110696986481638776226860777480684653756042166610633513404129518040549077551227082262066602286208338952016035637334787564972991208252928951876463555456715923743181359826124083963758009484867346318483872552977652588089928761806897223231500970500186019991032176060579816348322451864584743414550721639495547636008351'),
|
n: BigInt('24573455207957565047870011785254215390918912369814947541785386299516827003508659346069416840622922416779652050319196701077275060353178142796963682024347858398319926119639265555410256455471016400261630917813337515247954638555325280392998950756512879748873422896798579889820248358636937659872379948616822902110696986481638776226860777480684653756042166610633513404129518040549077551227082262066602286208338952016035637334787564972991208252928951876463555456715923743181359826124083963758009484867346318483872552977652588089928761806897223231500970500186019991032176060579816348322451864584743414550721639495547636008351'),
|
||||||
'e': 65537,
|
e: 65537,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const _serverKeys = {};
|
const _serverKeys = {};
|
||||||
|
|||||||
@ -29,7 +29,6 @@ class Counter {
|
|||||||
|
|
||||||
class CTR {
|
class CTR {
|
||||||
constructor(key, counter) {
|
constructor(key, counter) {
|
||||||
|
|
||||||
if (!(counter instanceof Counter)) {
|
if (!(counter instanceof Counter)) {
|
||||||
counter = new Counter(counter);
|
counter = new Counter(counter);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,47 +87,47 @@ class CdnFileTamperedError extends SecurityError {
|
|||||||
class BadMessageError extends Error {
|
class BadMessageError extends Error {
|
||||||
static ErrorMessages = {
|
static ErrorMessages = {
|
||||||
16:
|
16:
|
||||||
'msg_id too low (most likely, client time is wrong it would be worthwhile to ' +
|
'msg_id too low (most likely, client time is wrong it would be worthwhile to '
|
||||||
'synchronize it using msg_id notifications and re-send the original message ' +
|
+ 'synchronize it using msg_id notifications and re-send the original message '
|
||||||
'with the “correct” msg_id or wrap it in a container with a new msg_id if the ' +
|
+ 'with the “correct” msg_id or wrap it in a container with a new msg_id if the '
|
||||||
'original message had waited too long on the client to be transmitted).',
|
+ 'original message had waited too long on the client to be transmitted).',
|
||||||
|
|
||||||
17:
|
17:
|
||||||
'msg_id too high (similar to the previous case, the client time has to be ' +
|
'msg_id too high (similar to the previous case, the client time has to be '
|
||||||
'synchronized, and the message re-sent with the correct msg_id).',
|
+ 'synchronized, and the message re-sent with the correct msg_id).',
|
||||||
|
|
||||||
18:
|
18:
|
||||||
'Incorrect two lower order msg_id bits (the server expects client message msg_id ' +
|
'Incorrect two lower order msg_id bits (the server expects client message msg_id '
|
||||||
'to be divisible by 4).',
|
+ 'to be divisible by 4).',
|
||||||
|
|
||||||
19: 'Container msg_id is the same as msg_id of a previously received message ' + '(this must never happen).',
|
19: 'Container msg_id is the same as msg_id of a previously received message ' + '(this must never happen).',
|
||||||
|
|
||||||
20:
|
20:
|
||||||
'Message too old, and it cannot be verified whether the server has received a ' +
|
'Message too old, and it cannot be verified whether the server has received a '
|
||||||
'message with this msg_id or not.',
|
+ 'message with this msg_id or not.',
|
||||||
|
|
||||||
32:
|
32:
|
||||||
'msg_seqno too low (the server has already received a message with a lower ' +
|
'msg_seqno too low (the server has already received a message with a lower '
|
||||||
'msg_id but with either a higher or an equal and odd seqno).',
|
+ 'msg_id but with either a higher or an equal and odd seqno).',
|
||||||
|
|
||||||
33:
|
33:
|
||||||
'msg_seqno too high (similarly, there is a message with a higher msg_id but with ' +
|
'msg_seqno too high (similarly, there is a message with a higher msg_id but with '
|
||||||
'either a lower or an equal and odd seqno).',
|
+ 'either a lower or an equal and odd seqno).',
|
||||||
|
|
||||||
34: 'An even msg_seqno expected (irrelevant message), but odd received.',
|
34: 'An even msg_seqno expected (irrelevant message), but odd received.',
|
||||||
|
|
||||||
35: 'Odd msg_seqno expected (relevant message), but even received.',
|
35: 'Odd msg_seqno expected (relevant message), but even received.',
|
||||||
|
|
||||||
48:
|
48:
|
||||||
'Incorrect server salt (in this case, the bad_server_salt response is received with ' +
|
'Incorrect server salt (in this case, the bad_server_salt response is received with '
|
||||||
'the correct salt, and the message is to be re-sent with it).',
|
+ 'the correct salt, and the message is to be re-sent with it).',
|
||||||
|
|
||||||
64: 'Invalid container.',
|
64: 'Invalid container.',
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(request, code) {
|
constructor(request, code) {
|
||||||
let errorMessage = BadMessageError.ErrorMessages[code] ||
|
let errorMessage = BadMessageError.ErrorMessages[code]
|
||||||
`Unknown error code (this should not happen): ${code}.`;
|
|| `Unknown error code (this should not happen): ${code}.`;
|
||||||
errorMessage += ` Caused by ${request.className}`;
|
errorMessage += ` Caused by ${request.className}`;
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
this.message = errorMessage;
|
this.message = errorMessage;
|
||||||
|
|||||||
@ -41,6 +41,7 @@ class InvalidDCError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class BadRequestError extends RPCError {
|
class BadRequestError extends RPCError {
|
||||||
code = 400;
|
code = 400;
|
||||||
|
|
||||||
message = 'BAD_REQUEST';
|
message = 'BAD_REQUEST';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ class BadRequestError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class UnauthorizedError extends RPCError {
|
class UnauthorizedError extends RPCError {
|
||||||
code = 401;
|
code = 401;
|
||||||
|
|
||||||
message = 'UNAUTHORIZED';
|
message = 'UNAUTHORIZED';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +61,7 @@ class UnauthorizedError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class ForbiddenError extends RPCError {
|
class ForbiddenError extends RPCError {
|
||||||
code = 403;
|
code = 403;
|
||||||
|
|
||||||
message = 'FORBIDDEN';
|
message = 'FORBIDDEN';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +70,7 @@ class ForbiddenError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class NotFoundError extends RPCError {
|
class NotFoundError extends RPCError {
|
||||||
code = 404;
|
code = 404;
|
||||||
|
|
||||||
message = 'NOT_FOUND';
|
message = 'NOT_FOUND';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +80,7 @@ class NotFoundError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class AuthKeyError extends RPCError {
|
class AuthKeyError extends RPCError {
|
||||||
code = 406;
|
code = 406;
|
||||||
|
|
||||||
message = 'AUTH_KEY';
|
message = 'AUTH_KEY';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +92,7 @@ class AuthKeyError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class FloodError extends RPCError {
|
class FloodError extends RPCError {
|
||||||
code = 420;
|
code = 420;
|
||||||
|
|
||||||
message = 'FLOOD';
|
message = 'FLOOD';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +103,7 @@ class FloodError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class ServerError extends RPCError {
|
class ServerError extends RPCError {
|
||||||
code = 500; // Also witnessed as -500
|
code = 500; // Also witnessed as -500
|
||||||
|
|
||||||
message = 'INTERNAL';
|
message = 'INTERNAL';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +113,7 @@ class ServerError extends RPCError {
|
|||||||
*/
|
*/
|
||||||
class TimedOutError extends RPCError {
|
class TimedOutError extends RPCError {
|
||||||
code = 503; // Only witnessed as -503
|
code = 503; // Only witnessed as -503
|
||||||
|
|
||||||
message = 'Timeout';
|
message = 'Timeout';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,8 @@ const {
|
|||||||
class UserMigrateError extends InvalidDCError {
|
class UserMigrateError extends InvalidDCError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const newDc = Number(args.capture || 0);
|
const newDc = Number(args.capture || 0);
|
||||||
super(`The user whose identity is being used to execute queries is associated with DC ${newDc}` + RPCError._fmtRequest(args.request));
|
super(`The user whose identity is being used to execute queries is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `The user whose identity is being used to execute queries is associated with DC ${newDc}` + RPCError._fmtRequest(args.request);
|
this.message = `The user whose identity is being used to execute queries is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`;
|
||||||
this.newDc = newDc;
|
this.newDc = newDc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,8 +19,8 @@ class UserMigrateError extends InvalidDCError {
|
|||||||
class PhoneMigrateError extends InvalidDCError {
|
class PhoneMigrateError extends InvalidDCError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const newDc = Number(args.capture || 0);
|
const newDc = Number(args.capture || 0);
|
||||||
super(`The phone number a user is trying to use for authorization is associated with DC ${newDc}` + RPCError._fmtRequest(args.request));
|
super(`The phone number a user is trying to use for authorization is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `The phone number a user is trying to use for authorization is associated with DC ${newDc}` + RPCError._fmtRequest(args.request);
|
this.message = `The phone number a user is trying to use for authorization is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`;
|
||||||
this.newDc = newDc;
|
this.newDc = newDc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,8 +28,8 @@ class PhoneMigrateError extends InvalidDCError {
|
|||||||
class SlowModeWaitError extends FloodError {
|
class SlowModeWaitError extends FloodError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const seconds = Number(args.capture || 0);
|
const seconds = Number(args.capture || 0);
|
||||||
super(`A wait of ${seconds} seconds is required before sending another message in this chat` + RPCError._fmtRequest(args.request));
|
super(`A wait of ${seconds} seconds is required before sending another message in this chat${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `A wait of ${seconds} seconds is required before sending another message in this chat` + RPCError._fmtRequest(args.request);
|
this.message = `A wait of ${seconds} seconds is required before sending another message in this chat${RPCError._fmtRequest(args.request)}`;
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,8 +37,8 @@ class SlowModeWaitError extends FloodError {
|
|||||||
class FloodWaitError extends FloodError {
|
class FloodWaitError extends FloodError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const seconds = Number(args.capture || 0);
|
const seconds = Number(args.capture || 0);
|
||||||
super(`A wait of ${seconds} seconds is required` + RPCError._fmtRequest(args.request));
|
super(`A wait of ${seconds} seconds is required${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `A wait of ${seconds} seconds is required` + RPCError._fmtRequest(args.request);
|
this.message = `A wait of ${seconds} seconds is required${RPCError._fmtRequest(args.request)}`;
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,8 +46,8 @@ class FloodWaitError extends FloodError {
|
|||||||
class FloodTestPhoneWaitError extends FloodError {
|
class FloodTestPhoneWaitError extends FloodError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const seconds = Number(args.capture || 0);
|
const seconds = Number(args.capture || 0);
|
||||||
super(`A wait of ${seconds} seconds is required in the test servers` + RPCError._fmtRequest(args.request));
|
super(`A wait of ${seconds} seconds is required in the test servers${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `A wait of ${seconds} seconds is required in the test servers` + RPCError._fmtRequest(args.request);
|
this.message = `A wait of ${seconds} seconds is required in the test servers${RPCError._fmtRequest(args.request)}`;
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,8 +55,8 @@ class FloodTestPhoneWaitError extends FloodError {
|
|||||||
class FileMigrateError extends InvalidDCError {
|
class FileMigrateError extends InvalidDCError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const newDc = Number(args.capture || 0);
|
const newDc = Number(args.capture || 0);
|
||||||
super(`The file to be accessed is currently stored in DC ${newDc}` + RPCError._fmtRequest(args.request));
|
super(`The file to be accessed is currently stored in DC ${newDc}${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `The file to be accessed is currently stored in DC ${newDc}` + RPCError._fmtRequest(args.request);
|
this.message = `The file to be accessed is currently stored in DC ${newDc}${RPCError._fmtRequest(args.request)}`;
|
||||||
this.newDc = newDc;
|
this.newDc = newDc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,8 +64,8 @@ class FileMigrateError extends InvalidDCError {
|
|||||||
class NetworkMigrateError extends InvalidDCError {
|
class NetworkMigrateError extends InvalidDCError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const newDc = Number(args.capture || 0);
|
const newDc = Number(args.capture || 0);
|
||||||
super(`The source IP address is associated with DC ${newDc}` + RPCError._fmtRequest(args.request));
|
super(`The source IP address is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `The source IP address is associated with DC ${newDc}` + RPCError._fmtRequest(args.request);
|
this.message = `The source IP address is associated with DC ${newDc}${RPCError._fmtRequest(args.request)}`;
|
||||||
this.newDc = newDc;
|
this.newDc = newDc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,8 +73,8 @@ class NetworkMigrateError extends InvalidDCError {
|
|||||||
class EmailUnconfirmedError extends BadRequestError {
|
class EmailUnconfirmedError extends BadRequestError {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
const codeLength = Number(args.capture || 0);
|
const codeLength = Number(args.capture || 0);
|
||||||
super(`Email unconfirmed, the length of the code must be ${codeLength}` + RPCError._fmtRequest(args.request));
|
super(`Email unconfirmed, the length of the code must be ${codeLength}${RPCError._fmtRequest(args.request)}`);
|
||||||
this.message = `Email unconfirmed, the length of the code must be ${codeLength}` + RPCError._fmtRequest(args.request);
|
this.message = `Email unconfirmed, the length of the code must be ${codeLength}${RPCError._fmtRequest(args.request)}`;
|
||||||
this.codeLength = codeLength;
|
this.codeLength = codeLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,8 @@ function RPCMessageToError(rpcError, request) {
|
|||||||
if (m) {
|
if (m) {
|
||||||
const capture = m.length === 2 ? parseInt(m[1]) : null;
|
const capture = m.length === 2 ? parseInt(m[1]) : null;
|
||||||
return new Cls({
|
return new Cls({
|
||||||
request: request,
|
request,
|
||||||
capture: capture,
|
capture,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,7 @@ class EventBuilder {
|
|||||||
chats: null,
|
chats: null,
|
||||||
blacklistChats: null,
|
blacklistChats: null,
|
||||||
func: null,
|
func: null,
|
||||||
},
|
}) {
|
||||||
) {
|
|
||||||
this.chats = args.chats;
|
this.chats = args.chats;
|
||||||
this.blacklistChats = Boolean(args.blacklistChats);
|
this.blacklistChats = Boolean(args.blacklistChats);
|
||||||
this.resolved = false;
|
this.resolved = false;
|
||||||
|
|||||||
@ -8,10 +8,10 @@ class Logger {
|
|||||||
_level = level || 'debug';
|
_level = level || 'debug';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isBrowser = typeof process === 'undefined' ||
|
this.isBrowser = typeof process === 'undefined'
|
||||||
process.type === 'renderer' ||
|
|| process.type === 'renderer'
|
||||||
process.browser === true ||
|
|| process.browser === true
|
||||||
process.__nwjs;
|
|| process.__nwjs;
|
||||||
if (!this.isBrowser) {
|
if (!this.isBrowser) {
|
||||||
this.colors = {
|
this.colors = {
|
||||||
start: '\x1b[2m',
|
start: '\x1b[2m',
|
||||||
|
|||||||
@ -80,7 +80,6 @@ class MessagePacker {
|
|||||||
this._log.warn(`Message payload for ${state.request.className || state.request.constructor.name} is too long ${state.data.length} and cannot be sent`);
|
this._log.warn(`Message payload for ${state.request.className || state.request.constructor.name} is too long ${state.data.length} and cannot be sent`);
|
||||||
state.reject('Request Payload is too big');
|
state.reject('Request Payload is too big');
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!batch.length) {
|
if (!batch.length) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const Mutex = require('async-mutex').Mutex;
|
const { Mutex } = require('async-mutex');
|
||||||
|
|
||||||
const mutex = new Mutex();
|
const mutex = new Mutex();
|
||||||
|
|
||||||
const WebSocketClient = require('websocket').w3cwebsocket;
|
const WebSocketClient = require('websocket').w3cwebsocket;
|
||||||
@ -23,7 +24,7 @@ class PromisedWebSockets {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const thisTime = await this.read(number);
|
const thisTime = await this.read(number);
|
||||||
readData = Buffer.concat([readData, thisTime]);
|
readData = Buffer.concat([readData, thisTime]);
|
||||||
number = number - thisTime.length;
|
number -= thisTime.length;
|
||||||
if (!number) {
|
if (!number) {
|
||||||
return readData;
|
return readData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ const BinaryReader = require('./BinaryReader');
|
|||||||
const PromisedWebSockets = require('./PromisedWebSockets');
|
const PromisedWebSockets = require('./PromisedWebSockets');
|
||||||
const MessagePacker = require('./MessagePacker');
|
const MessagePacker = require('./MessagePacker');
|
||||||
const AsyncQueue = require('./AsyncQueue');
|
const AsyncQueue = require('./AsyncQueue');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
BinaryWriter,
|
BinaryWriter,
|
||||||
BinaryReader,
|
BinaryReader,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ async function doAuthentication(sender, log) {
|
|||||||
|
|
||||||
const nonce = Helpers.readBigIntFromBuffer(bytes, false, true);
|
const nonce = Helpers.readBigIntFromBuffer(bytes, false, true);
|
||||||
|
|
||||||
const resPQ = await sender.send(new requests.ReqPqMulti({ nonce: nonce }));
|
const resPQ = await sender.send(new requests.ReqPqMulti({ nonce }));
|
||||||
log.debug('Starting authKey generation step 1');
|
log.debug('Starting authKey generation step 1');
|
||||||
|
|
||||||
if (!(resPQ instanceof constructors.ResPQ)) {
|
if (!(resPQ instanceof constructors.ResPQ)) {
|
||||||
@ -50,11 +50,11 @@ async function doAuthentication(sender, log) {
|
|||||||
|
|
||||||
const pqInnerData = new constructors.PQInnerData({
|
const pqInnerData = new constructors.PQInnerData({
|
||||||
pq: Helpers.getByteArray(pq), // unsigned
|
pq: Helpers.getByteArray(pq), // unsigned
|
||||||
p: p,
|
p,
|
||||||
q: q,
|
q,
|
||||||
nonce: resPQ.nonce,
|
nonce: resPQ.nonce,
|
||||||
serverNonce: resPQ.serverNonce,
|
serverNonce: resPQ.serverNonce,
|
||||||
newNonce: newNonce,
|
newNonce,
|
||||||
});
|
});
|
||||||
|
|
||||||
// sha_digest + data + random_bytes
|
// sha_digest + data + random_bytes
|
||||||
@ -75,8 +75,8 @@ async function doAuthentication(sender, log) {
|
|||||||
new requests.ReqDHParams({
|
new requests.ReqDHParams({
|
||||||
nonce: resPQ.nonce,
|
nonce: resPQ.nonce,
|
||||||
serverNonce: resPQ.serverNonce,
|
serverNonce: resPQ.serverNonce,
|
||||||
p: p,
|
p,
|
||||||
q: q,
|
q,
|
||||||
publicKeyFingerprint: targetFingerprint,
|
publicKeyFingerprint: targetFingerprint,
|
||||||
encryptedData: cipherText,
|
encryptedData: cipherText,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
* This module contains the class used to communicate with Telegram's servers
|
* This module contains the class used to communicate with Telegram's servers
|
||||||
* in plain text, when no authorization key has been created yet.
|
* in plain text, when no authorization key has been created yet.
|
||||||
*/
|
*/
|
||||||
|
const BigInt = require('big-integer');
|
||||||
const Helpers = require('../Helpers');
|
const Helpers = require('../Helpers');
|
||||||
const MTProtoState = require('./MTProtoState');
|
const MTProtoState = require('./MTProtoState');
|
||||||
const BinaryReader = require('../extensions/BinaryReader');
|
const BinaryReader = require('../extensions/BinaryReader');
|
||||||
const { InvalidBufferError } = require('../errors/Common');
|
const { InvalidBufferError } = require('../errors/Common');
|
||||||
const BigInt = require('big-integer');
|
|
||||||
const { toSignedLittleBuffer } = require('../Helpers');
|
const { toSignedLittleBuffer } = require('../Helpers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +29,6 @@ class MTProtoPlainSender {
|
|||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
async send(request) {
|
async send(request) {
|
||||||
|
|
||||||
let body = request.getBytes();
|
let body = request.getBytes();
|
||||||
let msgId = this._state._getNewMsgId();
|
let msgId = this._state._getNewMsgId();
|
||||||
const m = toSignedLittleBuffer(msgId, 8);
|
const m = toSignedLittleBuffer(msgId, 8);
|
||||||
@ -69,7 +68,6 @@ class MTProtoPlainSender {
|
|||||||
*/
|
*/
|
||||||
return reader.tgReadObject();
|
return reader.tgReadObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MTProtoPlainSender;
|
module.exports = MTProtoPlainSender;
|
||||||
|
|||||||
@ -176,7 +176,7 @@ class MTProtoSender {
|
|||||||
if (this._updateCallback && attempt === 0) {
|
if (this._updateCallback && attempt === 0) {
|
||||||
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.disconnected));
|
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.disconnected));
|
||||||
}
|
}
|
||||||
this._log.error('WebSocket connection failed attempt: ' + (attempt + 1));
|
this._log.error(`WebSocket connection failed attempt: ${attempt + 1}`);
|
||||||
await Helpers.sleep(this._delay);
|
await Helpers.sleep(this._delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ class MTProtoSender {
|
|||||||
this._last_acks.push(ack);
|
this._last_acks.push(ack);
|
||||||
this._pending_ack.clear();
|
this._pending_ack.clear();
|
||||||
}
|
}
|
||||||
this._log.debug('Waiting for messages to send...' + this._reconnecting);
|
this._log.debug(`Waiting for messages to send...${this._reconnecting}`);
|
||||||
// TODO Wait for the connection send queue to be empty?
|
// TODO Wait for the connection send queue to be empty?
|
||||||
// This means that while it's not empty we can wait for
|
// This means that while it's not empty we can wait for
|
||||||
// more messages to be added to the send queue.
|
// more messages to be added to the send queue.
|
||||||
@ -332,8 +332,8 @@ class MTProtoSender {
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let data = res.data;
|
let { data } = res;
|
||||||
const batch = res.batch;
|
const { batch } = res;
|
||||||
this._log.debug(`Encrypting ${batch.length} message(s) in ${data.length} bytes for sending`);
|
this._log.debug(`Encrypting ${batch.length} message(s) in ${data.length} bytes for sending`);
|
||||||
|
|
||||||
data = await this._state.encryptMessageData(data);
|
data = await this._state.encryptMessageData(data);
|
||||||
@ -568,7 +568,7 @@ class MTProtoSender {
|
|||||||
this._log.warn(`Note: ${message.obj.className} is not an update, not dispatching it`);
|
this._log.warn(`Note: ${message.obj.className} is not an update, not dispatching it`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._log.debug('Handling update ' + message.obj.className);
|
this._log.debug(`Handling update ${message.obj.className}`);
|
||||||
if (this._updateCallback) {
|
if (this._updateCallback) {
|
||||||
this._updateCallback(message.obj);
|
this._updateCallback(message.obj);
|
||||||
}
|
}
|
||||||
@ -638,7 +638,6 @@ class MTProtoSender {
|
|||||||
// msg_seqno too high never seems to happen but just in case
|
// msg_seqno too high never seems to happen but just in case
|
||||||
this._state._sequence -= 16;
|
this._state._sequence -= 16;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
for (const state of states) {
|
for (const state of states) {
|
||||||
state.reject(new BadMessageError(state.request, badMsg.errorCode));
|
state.reject(new BadMessageError(state.request, badMsg.errorCode));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
|
const BigInt = require('big-integer');
|
||||||
const { readBufferFromBigInt } = require('../../Helpers');
|
const { readBufferFromBigInt } = require('../../Helpers');
|
||||||
const {
|
const {
|
||||||
Connection,
|
Connection,
|
||||||
PacketCodec,
|
PacketCodec,
|
||||||
} = require('./Connection');
|
} = require('./Connection');
|
||||||
const BigInt = require('big-integer');
|
|
||||||
|
|
||||||
class AbridgedPacketCodec extends PacketCodec {
|
class AbridgedPacketCodec extends PacketCodec {
|
||||||
static tag = Buffer.from('ef', 'hex');
|
static tag = Buffer.from('ef', 'hex');
|
||||||
|
|
||||||
static obfuscateTag = Buffer.from('efefefef', 'hex');
|
static obfuscateTag = Buffer.from('efefefef', 'hex');
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|||||||
@ -76,10 +76,10 @@ class ObfuscatedIO {
|
|||||||
|
|
||||||
class ConnectionTCPObfuscated extends ObfuscatedConnection {
|
class ConnectionTCPObfuscated extends ObfuscatedConnection {
|
||||||
ObfuscatedIO = ObfuscatedIO;
|
ObfuscatedIO = ObfuscatedIO;
|
||||||
|
|
||||||
PacketCodecClass = AbridgedPacketCodec;
|
PacketCodecClass = AbridgedPacketCodec;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ConnectionTCPObfuscated,
|
ConnectionTCPObfuscated,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,9 @@ const MTProtoSender = require('./MTProtoSender');
|
|||||||
|
|
||||||
class UpdateConnectionState {
|
class UpdateConnectionState {
|
||||||
static disconnected = -1;
|
static disconnected = -1;
|
||||||
|
|
||||||
static connected = 1;
|
static connected = 1;
|
||||||
|
|
||||||
static broken = 0;
|
static broken = 0;
|
||||||
|
|
||||||
constructor(state) {
|
constructor(state) {
|
||||||
@ -18,6 +20,7 @@ const {
|
|||||||
ConnectionTCPAbridged,
|
ConnectionTCPAbridged,
|
||||||
ConnectionTCPObfuscated,
|
ConnectionTCPObfuscated,
|
||||||
} = require('./connection');
|
} = require('./connection');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Connection,
|
Connection,
|
||||||
ConnectionTCPFull,
|
ConnectionTCPFull,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const StorageSession = require('./StorageSession');
|
|
||||||
const idb = require('idb-keyval');
|
const idb = require('idb-keyval');
|
||||||
|
const StorageSession = require('./StorageSession');
|
||||||
|
|
||||||
const CACHE_NAME = 'GramJs';
|
const CACHE_NAME = 'GramJs';
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
const MemorySession = require('./Memory');
|
const MemorySession = require('./Memory');
|
||||||
const AuthKey = require('../crypto/AuthKey');
|
const AuthKey = require('../crypto/AuthKey');
|
||||||
const BinaryReader = require('../extensions/BinaryReader');
|
const BinaryReader = require('../extensions/BinaryReader');
|
||||||
|
|
||||||
const CURRENT_VERSION = '1';
|
const CURRENT_VERSION = '1';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const api = require('./api');
|
const api = require('./api');
|
||||||
|
|
||||||
const LAYER = 121;
|
const LAYER = 121;
|
||||||
const tlobjects = {};
|
const tlobjects = {};
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class MTProtoRequest {
|
|||||||
|
|
||||||
// These should be overrode
|
// These should be overrode
|
||||||
onSend() {
|
onSend() {
|
||||||
throw Error('Not overload ' + this.constructor.name);
|
throw Error(`Not overload ${this.constructor.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
onResponse(buffer) {
|
onResponse(buffer) {
|
||||||
|
|||||||
@ -223,13 +223,19 @@ function createClasses(classesType, params) {
|
|||||||
|
|
||||||
class VirtualClass {
|
class VirtualClass {
|
||||||
static CONSTRUCTOR_ID = constructorId;
|
static CONSTRUCTOR_ID = constructorId;
|
||||||
|
|
||||||
static SUBCLASS_OF_ID = subclassOfId;
|
static SUBCLASS_OF_ID = subclassOfId;
|
||||||
|
|
||||||
static className = fullName;
|
static className = fullName;
|
||||||
|
|
||||||
static classType = classesType;
|
static classType = classesType;
|
||||||
|
|
||||||
CONSTRUCTOR_ID = constructorId;
|
CONSTRUCTOR_ID = constructorId;
|
||||||
|
|
||||||
SUBCLASS_OF_ID = subclassOfId;
|
SUBCLASS_OF_ID = subclassOfId;
|
||||||
|
|
||||||
className = fullName;
|
className = fullName;
|
||||||
|
|
||||||
classType = classesType;
|
classType = classesType;
|
||||||
|
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
@ -241,7 +247,6 @@ function createClasses(classesType, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fromReader(reader) {
|
static fromReader(reader) {
|
||||||
|
|
||||||
const args = {};
|
const args = {};
|
||||||
|
|
||||||
for (const argName in argsConfig) {
|
for (const argName in argsConfig) {
|
||||||
@ -249,10 +254,10 @@ function createClasses(classesType, params) {
|
|||||||
const arg = argsConfig[argName];
|
const arg = argsConfig[argName];
|
||||||
if (arg.isFlag) {
|
if (arg.isFlag) {
|
||||||
if (arg.type === 'true') {
|
if (arg.type === 'true') {
|
||||||
args[argName] = Boolean(args['flags'] & 1 << arg.flagIndex);
|
args[argName] = Boolean(args.flags & 1 << arg.flagIndex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args['flags'] & 1 << arg.flagIndex) {
|
if (args.flags & 1 << arg.flagIndex) {
|
||||||
args[argName] = getArgFromReader(reader, arg);
|
args[argName] = getArgFromReader(reader, arg);
|
||||||
} else {
|
} else {
|
||||||
args[argName] = null;
|
args[argName] = null;
|
||||||
@ -287,7 +292,7 @@ function createClasses(classesType, params) {
|
|||||||
}
|
}
|
||||||
const l = Buffer.alloc(4);
|
const l = Buffer.alloc(4);
|
||||||
l.writeInt32LE(this[arg].length, 0);
|
l.writeInt32LE(this[arg].length, 0);
|
||||||
buffers.push(l, Buffer.concat(this[arg].map(x => argToBytes(x, argsConfig[arg].type))));
|
buffers.push(l, Buffer.concat(this[arg].map((x) => argToBytes(x, argsConfig[arg].type))));
|
||||||
} else if (argsConfig[arg].flagIndicator) {
|
} else if (argsConfig[arg].flagIndicator) {
|
||||||
if (!Object.values(argsConfig)
|
if (!Object.values(argsConfig)
|
||||||
.some((f) => f.isFlag)) {
|
.some((f) => f.isFlag)) {
|
||||||
@ -319,7 +324,6 @@ function createClasses(classesType, params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return Buffer.concat(buffers);
|
return Buffer.concat(buffers);
|
||||||
}
|
}
|
||||||
@ -332,8 +336,8 @@ function createClasses(classesType, params) {
|
|||||||
const m = result.match(/Vector<(int|long)>/);
|
const m = result.match(/Vector<(int|long)>/);
|
||||||
if (m) {
|
if (m) {
|
||||||
reader.readInt();
|
reader.readInt();
|
||||||
let temp = [];
|
const temp = [];
|
||||||
let len = reader.readInt();
|
const len = reader.readInt();
|
||||||
if (m[1] === 'int') {
|
if (m[1] === 'int') {
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
temp.push(reader.readInt());
|
temp.push(reader.readInt());
|
||||||
@ -387,7 +391,6 @@ function createClasses(classesType, params) {
|
|||||||
classes[namespace] = {};
|
classes[namespace] = {};
|
||||||
}
|
}
|
||||||
classes[namespace][name] = VirtualClass;
|
classes[namespace][name] = VirtualClass;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
classes[name] = VirtualClass;
|
classes[name] = VirtualClass;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
const { serializeBytes } = require('../index');
|
|
||||||
const { inflate } = require('pako/dist/pako_inflate');
|
const { inflate } = require('pako/dist/pako_inflate');
|
||||||
|
const { serializeBytes } = require('../index');
|
||||||
|
|
||||||
// CONTEST const { deflate } = require('pako/dist/pako_deflate')
|
// CONTEST const { deflate } = require('pako/dist/pako_deflate')
|
||||||
|
|
||||||
class GZIPPacked {
|
class GZIPPacked {
|
||||||
static CONSTRUCTOR_ID = 0x3072cfa1;
|
static CONSTRUCTOR_ID = 0x3072cfa1;
|
||||||
|
|
||||||
static classType = 'constructor';
|
static classType = 'constructor';
|
||||||
|
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
|
|||||||
@ -2,7 +2,9 @@ const TLMessage = require('./TLMessage');
|
|||||||
|
|
||||||
class MessageContainer {
|
class MessageContainer {
|
||||||
static CONSTRUCTOR_ID = 0x73f1f8dc;
|
static CONSTRUCTOR_ID = 0x73f1f8dc;
|
||||||
|
|
||||||
static classType = 'constructor';
|
static classType = 'constructor';
|
||||||
|
|
||||||
// Maximum size in bytes for the inner payload of the container.
|
// Maximum size in bytes for the inner payload of the container.
|
||||||
// Telegram will close the connection if the payload is bigger.
|
// Telegram will close the connection if the payload is bigger.
|
||||||
// The overhead of the container itself is subtracted.
|
// The overhead of the container itself is subtracted.
|
||||||
@ -19,7 +21,6 @@ class MessageContainer {
|
|||||||
static MAXIMUM_LENGTH = 100;
|
static MAXIMUM_LENGTH = 100;
|
||||||
|
|
||||||
constructor(messages) {
|
constructor(messages) {
|
||||||
|
|
||||||
this.CONSTRUCTOR_ID = 0x73f1f8dc;
|
this.CONSTRUCTOR_ID = 0x73f1f8dc;
|
||||||
this.messages = messages;
|
this.messages = messages;
|
||||||
this.classType = 'constructor';
|
this.classType = 'constructor';
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const GZIPPacked = require('./GZIPPacked');
|
|||||||
|
|
||||||
class RPCResult {
|
class RPCResult {
|
||||||
static CONSTRUCTOR_ID = 0xf35c6d01;
|
static CONSTRUCTOR_ID = 0xf35c6d01;
|
||||||
|
|
||||||
static classType = 'constructor';
|
static classType = 'constructor';
|
||||||
|
|
||||||
constructor(reqMsgId, body, error) {
|
constructor(reqMsgId, body, error) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
class TLMessage {
|
class TLMessage {
|
||||||
static SIZE_OVERHEAD = 12;
|
static SIZE_OVERHEAD = 12;
|
||||||
|
|
||||||
static classType = 'constructor';
|
static classType = 'constructor';
|
||||||
|
|
||||||
constructor(msgId, seqNo, obj) {
|
constructor(msgId, seqNo, obj) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ const TLMessage = require('./TLMessage');
|
|||||||
const RPCResult = require('./RPCResult');
|
const RPCResult = require('./RPCResult');
|
||||||
const MessageContainer = require('./MessageContainer');
|
const MessageContainer = require('./MessageContainer');
|
||||||
const GZIPPacked = require('./GZIPPacked');
|
const GZIPPacked = require('./GZIPPacked');
|
||||||
|
|
||||||
const coreObjects = {
|
const coreObjects = {
|
||||||
[RPCResult.CONSTRUCTOR_ID]: RPCResult,
|
[RPCResult.CONSTRUCTOR_ID]: RPCResult,
|
||||||
[GZIPPacked.CONSTRUCTOR_ID]: GZIPPacked,
|
[GZIPPacked.CONSTRUCTOR_ID]: GZIPPacked,
|
||||||
|
|||||||
@ -76,12 +76,11 @@ const fromLine = (line, isFunction) => {
|
|||||||
argsConfig: {},
|
argsConfig: {},
|
||||||
subclassOfId: crc32(match[3]),
|
subclassOfId: crc32(match[3]),
|
||||||
result: match[3],
|
result: match[3],
|
||||||
isFunction: isFunction,
|
isFunction,
|
||||||
namespace: null,
|
namespace: null,
|
||||||
};
|
};
|
||||||
if (!currentConfig.constructorId) {
|
if (!currentConfig.constructorId) {
|
||||||
|
const hexId = '';
|
||||||
let hexId = '';
|
|
||||||
let args;
|
let args;
|
||||||
|
|
||||||
if (Object.values(currentConfig.argsConfig).length) {
|
if (Object.values(currentConfig.argsConfig).length) {
|
||||||
@ -143,7 +142,7 @@ function buildArgConfig(name, argType) {
|
|||||||
// less annoying to type. Currently the only type that can
|
// less annoying to type. Currently the only type that can
|
||||||
// be inferred is if the name is 'random_id', to which a
|
// be inferred is if the name is 'random_id', to which a
|
||||||
// random ID will be assigned if left as None (the default)
|
// random ID will be assigned if left as None (the default)
|
||||||
let canBeInferred = name === 'random_id';
|
const canBeInferred = name === 'random_id';
|
||||||
|
|
||||||
// The type can be an indicator that other arguments will be flags
|
// The type can be an indicator that other arguments will be flags
|
||||||
if (argType !== '#') {
|
if (argType !== '#') {
|
||||||
@ -186,8 +185,7 @@ function buildArgConfig(name, argType) {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (/^[a-z]$/.test(currentConfig.type.split('.')
|
if (/^[a-z]$/.test(currentConfig.type.split('.')
|
||||||
.pop()
|
.pop()
|
||||||
.charAt(0),
|
.charAt(0))
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
currentConfig.skipConstructorId = true;
|
currentConfig.skipConstructorId = true;
|
||||||
}
|
}
|
||||||
@ -283,12 +281,11 @@ const parseTl = function* (content, layer, methods = [], ignoreIds = CORE_TYPES)
|
|||||||
for (const obj of objAll) {
|
for (const obj of objAll) {
|
||||||
yield obj;
|
yield obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const findAll = (regex, str, matches = []) => {
|
const findAll = (regex, str, matches = []) => {
|
||||||
if (!regex.flags.includes(`g`)) {
|
if (!regex.flags.includes('g')) {
|
||||||
regex = new RegExp(regex.source, `g`);
|
regex = new RegExp(regex.source, 'g');
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = regex.exec(str);
|
const res = regex.exec(str);
|
||||||
@ -303,7 +300,7 @@ const findAll = (regex, str, matches = []) => {
|
|||||||
|
|
||||||
function serializeBytes(data) {
|
function serializeBytes(data) {
|
||||||
if (!(data instanceof Buffer)) {
|
if (!(data instanceof Buffer)) {
|
||||||
if (typeof data == 'string') {
|
if (typeof data === 'string') {
|
||||||
data = Buffer.from(data);
|
data = Buffer.from(data);
|
||||||
} else {
|
} else {
|
||||||
throw Error(`Bytes or str expected, not ${data.constructor.name}`);
|
throw Error(`Bytes or str expected, not ${data.constructor.name}`);
|
||||||
@ -330,7 +327,6 @@ function serializeBytes(data) {
|
|||||||
.fill(0));
|
.fill(0));
|
||||||
|
|
||||||
return Buffer.concat(r);
|
return Buffer.concat(r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeDate(dt) {
|
function serializeDate(dt) {
|
||||||
@ -341,7 +337,7 @@ function serializeDate(dt) {
|
|||||||
if (dt instanceof Date) {
|
if (dt instanceof Date) {
|
||||||
dt = Math.floor((Date.now() - dt.getTime()) / 1000);
|
dt = Math.floor((Date.now() - dt.getTime()) / 1000);
|
||||||
}
|
}
|
||||||
if (typeof dt == 'number') {
|
if (typeof dt === 'number') {
|
||||||
const t = Buffer.alloc(4);
|
const t = Buffer.alloc(4);
|
||||||
t.writeInt32LE(dt, 0);
|
t.writeInt32LE(dt, 0);
|
||||||
return t;
|
return t;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const {
|
|||||||
serializeBytes,
|
serializeBytes,
|
||||||
serializeDate,
|
serializeDate,
|
||||||
} = require('./generationHelpers');
|
} = require('./generationHelpers');
|
||||||
|
|
||||||
const patched = null;
|
const patched = null;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -18,9 +18,9 @@ function main() {
|
|||||||
const functions = [...apiConfig.functions, ...schemeConfig.functions];
|
const functions = [...apiConfig.functions, ...schemeConfig.functions];
|
||||||
const constructors = [...apiConfig.constructors, ...schemeConfig.constructors];
|
const constructors = [...apiConfig.constructors, ...schemeConfig.constructors];
|
||||||
const generated = templateFn({
|
const generated = templateFn({
|
||||||
types: types,
|
types,
|
||||||
functions: functions,
|
functions,
|
||||||
constructors: constructors,
|
constructors,
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(OUTPUT_FILE, generated);
|
fs.writeFileSync(OUTPUT_FILE, generated);
|
||||||
@ -37,7 +37,7 @@ function extractParams(fileContent) {
|
|||||||
functions.push(def);
|
functions.push(def);
|
||||||
} else {
|
} else {
|
||||||
if (!types[def.result]) {
|
if (!types[def.result]) {
|
||||||
let [namespace, name] = def.result.includes('.') ? def.result.split('.') : [undefined, def.result];
|
const [namespace, name] = def.result.includes('.') ? def.result.split('.') : [undefined, def.result];
|
||||||
|
|
||||||
types[def.result] = {
|
types[def.result] = {
|
||||||
namespace,
|
namespace,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user