Consistency and login
The pure pieces of the client flows: what the seven consistency checks expect and how their
report reads, the session table, the QR login URL, the 2FA SRP check and the post-login sequence.
opentele2/mtcute runs the flows themselves on an mtcute client.
Consistency checks
function consistencyChecks(): Array<string>
function consistencyExpectations(profile: ApiProfile, versions?: Versions | null): ConsistencyExpectations
function consistencyReport(outcomes: Array<CheckOutcome>): ConsistencyReport
function consistencySummary(results: Array<CheckResult>): string
function layerResult(libraryLayer: number, advertisedLayer?: number | null): CheckResult
interface CheckOutcome { passed?: boolean; detail?: string; raised?: string }
interface CheckResult { name: string; passed: boolean; detail: string }
interface ConsistencyReport {
checks: Array<CheckResult>
allPassed: boolean
summary: string
warning?: string
}
interface ConsistencyExpectations {
apiId: number
officialApiId: boolean
langPack: string
langPackSkipped: boolean
advertisedLayer: number
layerTolerance: number
appVersion: string
versionIssues: Array<Issue>
appVersionCurrent: boolean
}
const CONSISTENCY_WARNING_PREFIX: string| Function | Description |
|---|---|
consistencyChecks() | The names of the seven checks in run order: get_config, nearest_dc, current_session, layer_match, lang_pack, app_update, terms_of_service. |
consistency | What the checks expect from a session with profile: an official apiId for current_session, the lang pack lang_pack asks about (skipped when empty), the layer and tolerance of layer_match, and whether the app version is current. |
consistency | The report from one outcome per check, in consistencyChecks() order; an outcome with raised fails with the checkException detail. Throws ERR_INVALID_ARG_VALUE unless there is one outcome per check. |
consistency | A count line, then one [OK] name: detail or [FAIL] name: detail line per check. |
layer | The layer_match result: passes within LAYER_TOLERANCE of advertisedLayer (default LAYER). |
warning of the report is CONSISTENCY_WARNING_PREFIX followed by the summary, absent when every
check passed. The detail builders getConfigDetail, getConfigError, nearestDcDetail,
nearestDcError, currentSessionDetail, layerDetail, langPackDetail, langPackError,
appUpdateDetail, appUpdateError, checkError and checkException, and the constants
CURRENT_SESSION_MISSING, LANG_PACK_EMPTY, NO_APP_UPDATE and TERMS_OF_SERVICE_OK, give
each check’s detail text.
Session admin
function sessionRow(authorization: RawAuthorization): SessionRow
function formatSessions(rows: Array<SessionRow>): string
function formatTable(headers: Array<string>, rows: Array<Array<string>>, addSplit?: Array<number> | null): string
function isOfficialApiId(apiId: number): boolean
const SESSION_COLUMNS: string[]
const OFFICIAL_API_IDS: number[]
interface SessionRow {
current?: boolean
deviceModel: string
platform: string
systemVersion: string
apiId: number
appName: string
appVersion: string
officialApp?: boolean
}| Function | Description |
|---|---|
session | The fields PrintSessions shows of an authorization as a client library returns it (RawAuthorization); an absent current or officialApp is false. |
formatSessions(rows) | The table PrintSessions prints, without a trailing newline; the header alone for no rows. |
format | The PrettyTable layout: columns as wide as their longest cell plus two, text centred, a splitter before every row index in addSplit. |
SESSION_COLUMNS | The column labels of the session table. |
The TerminateSession and PrintSessions messages are FRESH_RESET_FORBIDDEN, HASH_INVALID
and SESSIONS_UNAVAILABLE.
Login
function qrLoginUrl(token: Uint8Array): string
function srpCheck(params: SrpParams, password: string, exponents?: Array<Uint8Array> | null): Promise<SrpCheck>
function srpInputs(srpId?: bigint | null, srpB?: Uint8Array | null): SrpInputs
function postLoginSteps(langPack?: string | null): Array<PostLoginStep>
function randomDelayMs(minMs: number, maxMs: number): number
function qrAttemptTimeoutWarning(attemptNumber: number, errorType?: string | null): string
function qrAttemptRetryWarning(attemptNumber: number): string
function unsupportedPasswordAlgorithm(algorithm: string): string
function flowErrorClasses(): Record<string, string>
interface SrpParams { srpId: bigint; g: number; p: Uint8Array; salt1: Uint8Array; salt2: Uint8Array; srpB: Uint8Array }
interface SrpCheck { srpId: bigint; a: Buffer; m1: Buffer }
interface SrpInputs { srpId: bigint; srpB: Buffer }
interface PostLoginStep { request: string; delayMs?: [number, number] }| Function | Description |
|---|---|
qrLoginUrl(token) | tg://login?token= and the auth.exportLoginToken token in URL-safe base64 without padding. |
srp | The inputCheckPasswordSRP values for the 2FA password, as Telethon’s compute_check; rejects with OT_, OT_SRP_BAD_B or OT_SRP_NO_GOOD_RANDOM. exponents replays recorded secret exponents. |
srpInputs(srpId, srpB) | The srpId and srpB taken from an account.Password: both as given when both are present, else 0 and empty, which srpCheck rejects with OT_SRP_BAD_B. |
post | The requests an official client sends after login, in order, each with the sleep range before it; langpack.getLanguages only for a non-empty lang pack. |
random | A uniform random whole number of ms in minMs..=maxMs from the OS random source; throws OT_INVALID_INPUT when minMs > maxMs. |
qr, qrAttemptRetryWarning | The warnings of a timed-out and a retried QR login attempt. |
unsupported | The error text for a 2FA algorithm other than SRP_ALGORITHM. |
flowErrorClasses() | The Python exception class name of every flow error code, by OT_ code. |
The constants of the flows: QR_LOGIN_URL_PREFIX, QR_LOGIN_ATTEMPTS (5),
QR_EXPIRE_SAFETY_SECONDS, QR_LOGIN_TIMEOUT, QR_TIMEOUT_ERROR_TYPE, SRP_ALGORITHM,
SRP_NUMBER_SIZE, NO_PASSWORD_PROVIDED, SIGN_UP_REQUIRED, USER_ID_UNRESOLVED,
EXISTING_SESSION_KEPT, EXISTING_SESSION_REPLACED, POST_LOGIN_APP_UPDATE_SOURCE,
POST_LOGIN_COUNTRIES_LANG_CODE, and the RPC error names the flows match:
RPC_AUTH_TOKEN_ALREADY_ACCEPTED, RPC_AUTH_TOKEN_EXPIRED, RPC_AUTH_TOKEN_INVALID,
RPC_FRESH_RESET_AUTHORISATION_FORBIDDEN, RPC_HASH_INVALID, RPC_PASSWORD_HASH_INVALID and
RPC_SESSION_PASSWORD_NEEDED.