[Dev] GramJs: Bring back eslint, fix some errors

This commit is contained in:
Alexander Zinchuk 2022-05-03 14:17:18 +01:00
parent 39ce1790d1
commit 3a3505b58e
8 changed files with 24 additions and 30 deletions

View File

@ -17,7 +17,8 @@
"check": "tsc && stylelint \"**/*.{css,scss}\" && eslint . --ext .ts,.tsx --ignore-pattern src/lib/gramjs", "check": "tsc && stylelint \"**/*.{css,scss}\" && eslint . --ext .ts,.tsx --ignore-pattern src/lib/gramjs",
"check:fix": "npm run check -- --fix", "check:fix": "npm run check -- --fix",
"gramjs:tl": "node ./src/lib/gramjs/tl/generateModules.js", "gramjs:tl": "node ./src/lib/gramjs/tl/generateModules.js",
"gramjs:lint:fix": "eslint ./src/lib/gramjs --fix", "gramjs:lint": "eslint src/lib/gramjs --ext .ts,.tsx",
"gramjs:lint:fix": "npm run gramjs:lint -- --fix",
"test": "cross-env APP_ENV=test jest --verbose --forceExit", "test": "cross-env APP_ENV=test jest --verbose --forceExit",
"test:playwright": "playwright test", "test:playwright": "playwright test",
"test:record": "playwright codegen localhost:1235", "test:record": "playwright codegen localhost:1235",

View File

@ -1,5 +1,4 @@
{ {
"root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"plugins": [ "plugins": [
"@typescript-eslint" "@typescript-eslint"

View File

@ -1,7 +1,6 @@
import BigInt from 'big-integer'; import BigInt from 'big-integer';
import { UpdateConnectionState } from '../network'; import { UpdateConnectionState } from '../network';
import Request from '../tl/api'; import Request, { default as GramJs } from '../tl/api';
import { default as GramJs } from "../tl/api";
type Peer = { type Peer = {
peer: GramJs.Chat | GramJs.Channel | GramJs.User; peer: GramJs.Chat | GramJs.Channel | GramJs.User;

View File

@ -1,4 +1,4 @@
import { default as Api } from '../tl/api'; import Api from '../tl/api';
import TelegramClient from './TelegramClient'; import TelegramClient from './TelegramClient';
import utils from '../Utils'; import utils from '../Utils';
import { sleep } from '../Helpers'; import { sleep } from '../Helpers';

View File

@ -1,11 +1,10 @@
// eslint-disable-next-line import/no-named-default import Api from '../tl/api';
import { default as Api } from '../tl/api';
import TelegramClient from './TelegramClient'; import TelegramClient from './TelegramClient';
import { getAppropriatedPartSize } from '../Utils'; import { getAppropriatedPartSize } from '../Utils';
import { sleep, createDeferred } from '../Helpers'; import { sleep, createDeferred } from '../Helpers';
import errors from '../errors'; import errors from '../errors';
export interface progressCallback { interface OnProgress {
isCanceled?: boolean; isCanceled?: boolean;
acceptsBuffer?: boolean; acceptsBuffer?: boolean;
@ -22,7 +21,7 @@ export interface DownloadFileParams {
partSizeKb?: number; partSizeKb?: number;
start?: number; start?: number;
end?: number; end?: number;
progressCallback?: progressCallback; progressCallback?: OnProgress;
} }
interface Deferred { interface Deferred {
@ -36,7 +35,6 @@ const DEFAULT_CHUNK_SIZE = 64; // kb
const ONE_MB = 1024 * 1024; const ONE_MB = 1024 * 1024;
const DISCONNECT_SLEEP = 1000; const DISCONNECT_SLEEP = 1000;
class Foreman { class Foreman {
private deferred: Deferred | undefined; private deferred: Deferred | undefined;
@ -124,7 +122,7 @@ export async function downloadFile(
break; break;
} }
// eslint-disable-next-line no-loop-func // eslint-disable-next-line no-loop-func, @typescript-eslint/no-loop-func
promises.push((async (offsetMemo: number) => { promises.push((async (offsetMemo: number) => {
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {

View File

@ -63,8 +63,9 @@ export async function uploadFile(
for (let j = i; j < end; j++) { for (let j = i; j < end; j++) {
const bytes = buffer.slice(j * partSize, (j + 1) * partSize); const bytes = buffer.slice(j * partSize, (j + 1) * partSize);
// eslint-disable-next-line no-loop-func // eslint-disable-next-line no-loop-func, @typescript-eslint/no-loop-func
sendingParts.push((async (jMemo: number, bytesMemo: Buffer) => { sendingParts.push((async (jMemo: number, bytesMemo: Buffer) => {
// eslint-disable-next-line no-constant-condition
while (true) { while (true) {
let sender; let sender;
try { try {

View File

@ -7,7 +7,7 @@ import {
sha1, sha1,
} from '../Helpers'; } from '../Helpers';
const PUBLIC_KEYS = [ export const SERVER_KEYS = [
{ {
fingerprint: bigInt('-3414540481677951611'), fingerprint: bigInt('-3414540481677951611'),
n: bigInt( n: bigInt(
@ -23,23 +23,19 @@ const PUBLIC_KEYS = [
{ {
fingerprint: bigInt('-5595554452916591101'), fingerprint: bigInt('-5595554452916591101'),
n: bigInt( n: bigInt(
'2534288944884041556497168959071347320689884775908477905258202659454602246385394058588521595116849196570822' + '2534288944884041556497168959071347320689884775908477905258202659454602246385394058588521595116849196570'
'26493991806038180742006204637761354248846321625124031637930839216416315647409595294193595958529411668489405859523' + + '8222649399180603818074200620463776135424884632162512403163793083921641631564740959529419359595852941166'
'37613333022396096584117954892216031229237302943701877588456738335398602461675225081791820393153757504952636234951' + + '8489405859523376133330223960965841179548922160312292373029437018775884567383353986024616752250817918203'
'32323782003654358104782690612092797248736680529211579223142368426126233039432475078545094258975175539015664775146' + + '9315375750495263623495132323782003654358104782690612092797248736680529211579223142368426126233039432475'
'07193514399690599495696153028090507215003302390050778898553239175099482557220816446894421272976054225797071426466' + + '0785450942589751755390156647751460719351439969059949569615302809050721500330239005077889855323917509948'
'60768825302832201908302295573257427896031830742328565032949', + '255722081644689442127297605422579707142646660768825302832201908302295573257427896031830742328565032949',
), ),
e: 65537, e: 65537,
}, },
]; ].reduce((acc, { fingerprint, ...keyInfo }) => {
acc.set(fingerprint.toString(), keyInfo);
export const _serverKeys = new Map<string, { n: bigInt.BigInteger; e: number }>(); return acc;
}, new Map<string, { n: bigInt.BigInteger; e: number }>());
PUBLIC_KEYS.forEach(({ fingerprint, ...keyInfo }) => {
_serverKeys.set(fingerprint.toString(),
keyInfo);
});
/** /**
* Encrypts the given data known the fingerprint to be used * Encrypts the given data known the fingerprint to be used
@ -50,7 +46,7 @@ PUBLIC_KEYS.forEach(({ fingerprint, ...keyInfo }) => {
* @returns {Buffer|*|undefined} the cipher text, or undefined if no key matching this fingerprint is found. * @returns {Buffer|*|undefined} the cipher text, or undefined if no key matching this fingerprint is found.
*/ */
export async function encrypt(fingerprint: bigInt.BigInteger, data: Buffer) { export async function encrypt(fingerprint: bigInt.BigInteger, data: Buffer) {
const key = _serverKeys.get(fingerprint.toString()); const key = SERVER_KEYS.get(fingerprint.toString());
if (!key) { if (!key) {
return undefined; return undefined;
} }

View File

@ -9,7 +9,7 @@ import { default as Api } from '../tl/api';
import { SecurityError } from '../errors'; import { SecurityError } from '../errors';
// eslint-disable-next-line import/no-named-default // eslint-disable-next-line import/no-named-default
import { default as MTProtoPlainSender } from './MTProtoPlainSender'; import { default as MTProtoPlainSender } from './MTProtoPlainSender';
import { _serverKeys } from '../crypto/RSA'; import { SERVER_KEYS } from '../crypto/RSA';
const bigInt = require('big-integer'); const bigInt = require('big-integer');
const IGE = require('../crypto/IGE'); const IGE = require('../crypto/IGE');
@ -58,7 +58,7 @@ export async function doAuthentication(sender: MTProtoPlainSender, log: any) {
let targetFingerprint; let targetFingerprint;
let targetKey; let targetKey;
for (const fingerprint of resPQ.serverPublicKeyFingerprints) { for (const fingerprint of resPQ.serverPublicKeyFingerprints) {
targetKey = _serverKeys.get(fingerprint.toString()); targetKey = SERVER_KEYS.get(fingerprint.toString());
if (targetKey !== undefined) { if (targetKey !== undefined) {
targetFingerprint = fingerprint; targetFingerprint = fingerprint;
break; break;