Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

⚑ ferogram

A modular, production-grade async Rust implementation of the Telegram MTProto protocol

Crates.io docs.rs TL Layer License Rust

ferogram is a hand-written, bottom-up implementation of Telegram MTProto in pure Rust. Every component: from the .tl schema parser, to AES-IGE encryption, to the Diffie-Hellman key exchange, to the typed async update stream: is owned and understood by this project.

No black boxes. No magic. Just Rust, all the way down.


Why ferogram?

Most Telegram libraries are thin wrappers around generated code or ports from Python/JavaScript. ferogram is different: it was built from scratch to understand MTProto at the lowest level, then exposed through a straightforward high-level API.

πŸ¦€
Pure Rust
No FFI, no unsafe blocks. Fully async with Tokio. Works on Android (Termux), Linux, macOS, Windows.
⚑
Full MTProto 2.0
Complete DH handshake, AES-IGE encryption, salt tracking, DC migration: all handled automatically.
πŸ”
User + Bot Auth
Phone login with 2FA SRP, bot token login, session persistence across restarts.
πŸ“‘
Typed Update Stream
NewMessage, MessageEdited, CallbackQuery, InlineQuery, ChatAction, UserStatus: all strongly typed.
πŸ”§
Raw API Escape Hatch
Call any of 500+ Telegram API methods directly via client.invoke() with full type safety.
πŸ—οΈ
Auto-Generated Types
All 2,329 Layer 224 constructors generated at build time from the official TL schema.

Crate overview

CrateDescriptionTypical user
ferogramHigh-level async client: auth, send, receive, botsβœ… You
ferogram-tl-typesAll Layer 224 constructors, functions, enumsRaw API calls
ferogram-mtprotoMTProto session, DH, framing, transportLibrary authors
ferogram-cryptoAES-IGE, RSA, SHA, auth key derivationInternal
ferogram-tl-genBuild-time Rust code generatorBuild tool
ferogram-tl-parser.tl schema β†’ AST parserBuild tool

TIP: Most users only ever import ferogram. The other crates are either used internally or for advanced raw API calls.


Quick install

[dependencies]
ferogram = "0.1.1"
tokio        = { version = "1", features = ["full"] }

Then head to Installation for credentials setup, or jump straight to:


Initial Release v0.1.0

Proxy & Transport

  • MTProxy support: connect via t.me/proxy / tg://proxy links or manual host/port/secret config
  • PaddedIntermediate transport (0xDD secrets): randomized padding to mimic official Telegram traffic
  • FakeTLS transport (0xEE secrets): TLS-like framing to make MTProto traffic resemble HTTPS
  • SOCKS5 proxy support in Config with optional username/password authentication
  • IPv6 connectivity for Telegram DCs and proxy connections

Session & Client

  • Multiple session backend support with new Config helpers and builder methods for MTProxy

Protocol Fixes

  • Auth key generation fixed: now uses correct PQInnerDataDc constructor including the DC id: resolves auth failures on many DCs
  • Incoming message validation: rolling buffer of last 500 server msg_ids + Β±300 s timestamp window to prevent replay attacks
  • dh_gen_retry handling: step 3 now retries with cached params, up to 5 attempts (matching Telegram Desktop)
  • MTProxy routing bug fixed: connections now correctly route through the proxy host instead of going directly to Telegram DCs
  • Channel difference sync: initial getChannelDifference starts at limit 100, subsequent calls increase to 1000

See the full CHANGELOG.


Author

Developed by Ankit Chaubey out of curiosity to explore.

Crates.io docs.rs License TL Layer Telegram

ferogram is developed as part of exploration, learning, and experimentation with the Telegram MTProto protocol. Use it at your own risk. Its future and stability are not yet guaranteed.


Terms of Service

Ensure your usage complies with Telegram’s Terms of Service and API Terms of Service. Misuse of the Telegram API, including spam, mass scraping, or automation of normal user accounts, may result in account limitations or permanent bans.