From 6673937e2482b36e4c3bdb923498660568039f16 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Thu, 27 Mar 2025 19:03:26 +0100 Subject: [PATCH] Session: Simplify storage (#5775) --- src/api/types/misc.ts | 1 - src/lib/gramjs/sessions/CallbackSession.ts | 15 ++------------- src/lib/gramjs/types.ts | 1 - src/util/sessions.ts | 15 +-------------- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/api/types/misc.ts b/src/api/types/misc.ts index f485043e1..37f1adc61 100644 --- a/src/api/types/misc.ts +++ b/src/api/types/misc.ts @@ -103,7 +103,6 @@ export interface ApiWebSession { export interface ApiSessionData { mainDcId: number; keys: Record; - hashes: Record; isTest?: true; } diff --git a/src/lib/gramjs/sessions/CallbackSession.ts b/src/lib/gramjs/sessions/CallbackSession.ts index 04bf0ff0e..33909147c 100644 --- a/src/lib/gramjs/sessions/CallbackSession.ts +++ b/src/lib/gramjs/sessions/CallbackSession.ts @@ -28,7 +28,6 @@ export default class CallbackSession extends MemorySession { const { mainDcId, keys, - hashes, isTest, } = this._sessionData; const { @@ -45,16 +44,8 @@ export default class CallbackSession extends MemorySession { ? Buffer.from(keys[dcId] as string, 'hex') : Buffer.from(keys[dcId]); - if (hashes[dcId]) { - const hash = typeof hashes[dcId] === 'string' - ? Buffer.from(hashes[dcId] as string, 'hex') - : Buffer.from(hashes[dcId]); - - this._authKeys[dcId] = new AuthKey(key, hash); - } else { - this._authKeys[dcId] = new AuthKey(); - await this._authKeys[dcId].setKey(key); - } + this._authKeys[dcId] = new AuthKey(); + await this._authKeys[dcId].setKey(key); })); } @@ -85,7 +76,6 @@ export default class CallbackSession extends MemorySession { const sessionData: SessionData = { mainDcId: this._dcId, keys: {}, - hashes: {}, isTest: this._isTestServer || undefined, }; @@ -97,7 +87,6 @@ export default class CallbackSession extends MemorySession { if (!authKey?._key) return; sessionData.keys[dcId] = authKey._key.toString('hex'); - sessionData.hashes[dcId] = authKey._hash!.toString('hex'); }); return sessionData; diff --git a/src/lib/gramjs/types.ts b/src/lib/gramjs/types.ts index 50aaf26cc..cc4069bed 100644 --- a/src/lib/gramjs/types.ts +++ b/src/lib/gramjs/types.ts @@ -20,6 +20,5 @@ export type EntityLike = export interface SessionData { mainDcId: number; keys: Record; - hashes: Record; isTest?: true; } diff --git a/src/util/sessions.ts b/src/util/sessions.ts index 4300422b5..d4112593d 100644 --- a/src/util/sessions.ts +++ b/src/util/sessions.ts @@ -28,7 +28,7 @@ export function hasStoredSession() { export function storeSession(sessionData: ApiSessionData, currentUserId?: string) { const { - mainDcId, keys, hashes, isTest, + mainDcId, keys, isTest, } = sessionData; localStorage.setItem(SESSION_USER_KEY, JSON.stringify({ @@ -40,12 +40,6 @@ export function storeSession(sessionData: ApiSessionData, currentUserId?: string Object.keys(keys).map(Number).forEach((dcId) => { localStorage.setItem(`dc${dcId}_auth_key`, JSON.stringify(keys[dcId])); }); - - if (hashes) { - Object.keys(hashes).map(Number).forEach((dcId) => { - localStorage.setItem(`dc${dcId}_hash`, JSON.stringify(hashes[dcId])); - }); - } } export function clearStoredSession() { @@ -72,7 +66,6 @@ export function loadStoredSession(): ApiSessionData | undefined { const mainDcId = Number(userAuth.dcID); const isTest = userAuth.test; const keys: Record = {}; - const hashes: Record = {}; DC_IDS.forEach((dcId) => { try { @@ -80,11 +73,6 @@ export function loadStoredSession(): ApiSessionData | undefined { if (key) { keys[dcId] = JSON.parse(key); } - - const hash = localStorage.getItem(`dc${dcId}_hash`); - if (hash) { - hashes[dcId] = JSON.parse(hash); - } } catch (err) { if (DEBUG) { // eslint-disable-next-line no-console @@ -99,7 +87,6 @@ export function loadStoredSession(): ApiSessionData | undefined { return { mainDcId, keys, - hashes, isTest, }; }