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

⚡ layer

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

Crates.io docs.rs TL Layer License Rust

layer 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 layer?

Most Telegram libraries are thin wrappers around generated code or ports from Python/JavaScript. layer is different — it was built from scratch to understand MTProto at the lowest level, then wrapped in an ergonomic 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 — all as strongly typed Rust enums.
🔧
Raw API Escape Hatch
Call any of 500+ Telegram API methods directly via client.invoke() with full type safety.
🏗️
Auto-Generated Types
All 2,300+ Layer 223 constructors generated at build time from the official TL schema.

Crate overview

CrateDescriptionTypical user
layer-clientHigh-level async client — auth, send, receive, bots✅ You
layer-tl-typesAll Layer 223 constructors, functions, enumsRaw API calls
layer-mtprotoMTProto session, DH, framing, transportLibrary authors
layer-cryptoAES-IGE, RSA, SHA, auth key derivationInternal
layer-tl-genBuild-time Rust code generatorBuild tool
layer-tl-parser.tl schema → AST parserBuild tool

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


Quick install

[dependencies]
layer-client = "0.2.2"
tokio        = { version = "1", features = ["full"] }

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


Acknowledgements

  • Lonami for grammers — the architecture, SRP math, and session design are deeply inspired by this fantastic library.
  • Telegram for the detailed MTProto specification.
  • The Rust async ecosystem: tokio, flate2, getrandom, sha2, and friends.