2 releases

0.1.1 Jan 25, 2025
0.1.0 Jan 25, 2025

#211 in Authentication

Download history 167/week @ 2025-01-20 50/week @ 2025-01-27 19/week @ 2025-02-03

236 downloads per month

MIT license

36KB
607 lines

Telegram Mini Apps Init Data Parser for Rust

Crates.io Documentation License: MIT Build Status codecov

A Rust library for parsing and validating Telegram Mini Apps init data. This library helps you work with the data passed from Telegram to your Mini App, ensuring its authenticity and integrity.

Features

  • Parse init data from query string format
  • Validate init data signature using bot token
  • Support for third-party bot validation
  • Type-safe data structures
  • Comprehensive error handling
  • 100% test coverage

Installation

Add this to your Cargo.toml:

[dependencies]
init-data-rs = "0.1.1"

Usage

use init_data_rs::{validate, InitData};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let init_data = "query_id=AAHdF6IQAAAAAN0XohDhrOrc&user=%7B%22id%22%3A279058397%7D&auth_date=1662771648&hash=...";
    let bot_token = "YOUR_BOT_TOKEN";

    // Validate and parse init data
    let data: InitData = validate(init_data, bot_token, None)?;

    // Access parsed data
    if let Some(user) = data.user {
        println!("User ID: {}", user.id.0);
    }

    Ok(())
}

Third-party Bot Validation

use init_data_rs::validate_third_party;

let data = validate_third_party(init_data, bot_token, third_party_token, None)?;

Documentation

For detailed documentation, visit docs.rs/init-data-rs.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This is a Rust port of the official Golang implementation.

Dependencies

~2.7–4MB
~77K SLoC