Metadata-Version: 2.4
Name: teleuz
Version: 0.3.1
Summary: Pure-Python asyncio Telegram MTProto client library
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: cryptography>=41.0.0
Requires-Dist: rsa>=4.9

# TeleUz

Pure-Python asyncio Telegram client implementing MTProto from scratch.

No Telethon, Pyrogram, TDLib, or MadelineProto — only `cryptography` and `rsa` for crypto primitives.

## Installation

```bash
pip install -e .
```

## Quick start

```python
import asyncio
from teleuz import Client

async def main():
    client = Client(
        api_id=12345,
        api_hash="YOUR_API_HASH",
        session_path="my.session",
    )

    await client.connect()
    await client.login(phone="+123456789")

    message_id = await client.send_message(
        user_id=123456789,
        message="Hello from TeleUz",
    )
    print(f"Sent message id: {message_id}")

    await client.disconnect()

asyncio.run(main())
```

## Interactive login test

Telethon uslubidagi prompt bilan tekshirish:

```bash
python teleuz_test_login.py
```

Skript quyidagilarni ketma-ket so'raydi:
- API ID
- API hash
- telefon raqam
- SMS/Telegram kod
- agar kerak bo'lsa 2FA parol

Va keyin `8296599550` ID ga `TeleUz orqali yuborildi` xabarini yuborishga urinadi.

## Architecture

```
teleuz/
├── client.py           # High-level async client
├── session.py          # JSON session persistence
├── transport/
│   └── abridged.py     # MTProto abridged TCP transport
├── mtproto/
│   ├── auth.py         # req_pq_multi
│   ├── requests.py     # Handshake request builders
│   ├── respq.py        # resPQ parser
│   ├── dh_exchange.py  # DH key exchange (req_DH_params, set_client_DH_params)
│   ├── message.py      # Unencrypted message framing
│   └── encrypted.py    # MTProto 2.0 AES-IGE encryption
├── crypto/
│   ├── aes_ige.py      # AES-IGE mode
│   ├── dh.py           # Diffie-Hellman
│   ├── factorization.py# Pollard's rho for pq factorization
│   ├── kdf.py          # MTProto 2.0 key derivation
│   ├── keys.py         # Telegram RSA public keys
│   └── nonce.py        # Nonce generation
└── tl/
    ├── primitives.py   # TL serializers (int32, bytes, vectors)
    ├── schema.py       # API method serializers
    └── parser.py       # Response deserializers
```

## Protocol flow

1. **Transport** — TCP connect, send `0xef` (abridged mode)
2. **Handshake** — `req_pq_multi` → `resPQ` → factorize pq → `req_DH_params` → `server_DH_params_ok` → `set_client_DH_params` → `dh_gen_ok`
3. **Auth key** — 256-byte shared secret saved to session file
4. **Encrypted RPC** — AES-IGE encrypted `auth.sendCode` / `auth.signIn` / `messages.sendMessage`

## Session file

Sessions are stored as JSON (`teleuz.session` by default):

- `auth_key` — 256-byte MTProto authorization key
- `server_salt` — 8-byte server salt
- `user_id` — logged-in user ID
- `access_hashes` — cached peer access hashes for messaging
