[Dev] GramJs: Bring back eslint, fix some errors
This commit is contained in:
parent
39ce1790d1
commit
3a3505b58e
@ -17,7 +17,8 @@
|
||||
"check": "tsc && stylelint \"**/*.{css,scss}\" && eslint . --ext .ts,.tsx --ignore-pattern src/lib/gramjs",
|
||||
"check:fix": "npm run check -- --fix",
|
||||
"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:playwright": "playwright test",
|
||||
"test:record": "playwright codegen localhost:1235",
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import BigInt from 'big-integer';
|
||||
import { UpdateConnectionState } from '../network';
|
||||
import Request from '../tl/api';
|
||||
import { default as GramJs } from "../tl/api";
|
||||
import Request, { default as GramJs } from '../tl/api';
|
||||
|
||||
type Peer = {
|
||||
peer: GramJs.Chat | GramJs.Channel | GramJs.User;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { default as Api } from '../tl/api';
|
||||
import Api from '../tl/api';
|
||||
import TelegramClient from './TelegramClient';
|
||||
import utils from '../Utils';
|
||||
import { sleep } from '../Helpers';
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
// eslint-disable-next-line import/no-named-default
|
||||
import { default as Api } from '../tl/api';
|
||||
import Api from '../tl/api';
|
||||
import TelegramClient from './TelegramClient';
|
||||
import { getAppropriatedPartSize } from '../Utils';
|
||||
import { sleep, createDeferred } from '../Helpers';
|
||||
import errors from '../errors';
|
||||
|
||||
export interface progressCallback {
|
||||
interface OnProgress {
|
||||
isCanceled?: boolean;
|
||||
acceptsBuffer?: boolean;
|
||||
|
||||
@ -22,7 +21,7 @@ export interface DownloadFileParams {
|
||||
partSizeKb?: number;
|
||||
start?: number;
|
||||
end?: number;
|
||||
progressCallback?: progressCallback;
|
||||
progressCallback?: OnProgress;
|
||||
}
|
||||
|
||||
interface Deferred {
|
||||
@ -36,7 +35,6 @@ const DEFAULT_CHUNK_SIZE = 64; // kb
|
||||
const ONE_MB = 1024 * 1024;
|
||||
const DISCONNECT_SLEEP = 1000;
|
||||
|
||||
|
||||
class Foreman {
|
||||
private deferred: Deferred | undefined;
|
||||
|
||||
@ -124,7 +122,7 @@ export async function downloadFile(
|
||||
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) => {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
|
||||
@ -63,8 +63,9 @@ export async function uploadFile(
|
||||
for (let j = i; j < end; j++) {
|
||||
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) => {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
let sender;
|
||||
try {
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
sha1,
|
||||
} from '../Helpers';
|
||||
|
||||
const PUBLIC_KEYS = [
|
||||
export const SERVER_KEYS = [
|
||||
{
|
||||
fingerprint: bigInt('-3414540481677951611'),
|
||||
n: bigInt(
|
||||
@ -23,23 +23,19 @@ const PUBLIC_KEYS = [
|
||||
{
|
||||
fingerprint: bigInt('-5595554452916591101'),
|
||||
n: bigInt(
|
||||
'2534288944884041556497168959071347320689884775908477905258202659454602246385394058588521595116849196570822' +
|
||||
'26493991806038180742006204637761354248846321625124031637930839216416315647409595294193595958529411668489405859523' +
|
||||
'37613333022396096584117954892216031229237302943701877588456738335398602461675225081791820393153757504952636234951' +
|
||||
'32323782003654358104782690612092797248736680529211579223142368426126233039432475078545094258975175539015664775146' +
|
||||
'07193514399690599495696153028090507215003302390050778898553239175099482557220816446894421272976054225797071426466' +
|
||||
'60768825302832201908302295573257427896031830742328565032949',
|
||||
'2534288944884041556497168959071347320689884775908477905258202659454602246385394058588521595116849196570'
|
||||
+ '8222649399180603818074200620463776135424884632162512403163793083921641631564740959529419359595852941166'
|
||||
+ '8489405859523376133330223960965841179548922160312292373029437018775884567383353986024616752250817918203'
|
||||
+ '9315375750495263623495132323782003654358104782690612092797248736680529211579223142368426126233039432475'
|
||||
+ '0785450942589751755390156647751460719351439969059949569615302809050721500330239005077889855323917509948'
|
||||
+ '255722081644689442127297605422579707142646660768825302832201908302295573257427896031830742328565032949',
|
||||
),
|
||||
e: 65537,
|
||||
},
|
||||
];
|
||||
|
||||
export const _serverKeys = new Map<string, { n: bigInt.BigInteger; e: number }>();
|
||||
|
||||
PUBLIC_KEYS.forEach(({ fingerprint, ...keyInfo }) => {
|
||||
_serverKeys.set(fingerprint.toString(),
|
||||
keyInfo);
|
||||
});
|
||||
].reduce((acc, { fingerprint, ...keyInfo }) => {
|
||||
acc.set(fingerprint.toString(), keyInfo);
|
||||
return acc;
|
||||
}, new Map<string, { n: bigInt.BigInteger; e: number }>());
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export async function encrypt(fingerprint: bigInt.BigInteger, data: Buffer) {
|
||||
const key = _serverKeys.get(fingerprint.toString());
|
||||
const key = SERVER_KEYS.get(fingerprint.toString());
|
||||
if (!key) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import { default as Api } from '../tl/api';
|
||||
import { SecurityError } from '../errors';
|
||||
// eslint-disable-next-line import/no-named-default
|
||||
import { default as MTProtoPlainSender } from './MTProtoPlainSender';
|
||||
import { _serverKeys } from '../crypto/RSA';
|
||||
import { SERVER_KEYS } from '../crypto/RSA';
|
||||
|
||||
const bigInt = require('big-integer');
|
||||
const IGE = require('../crypto/IGE');
|
||||
@ -58,7 +58,7 @@ export async function doAuthentication(sender: MTProtoPlainSender, log: any) {
|
||||
let targetFingerprint;
|
||||
let targetKey;
|
||||
for (const fingerprint of resPQ.serverPublicKeyFingerprints) {
|
||||
targetKey = _serverKeys.get(fingerprint.toString());
|
||||
targetKey = SERVER_KEYS.get(fingerprint.toString());
|
||||
if (targetKey !== undefined) {
|
||||
targetFingerprint = fingerprint;
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user