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.
- 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
Add this to your Cargo.toml:
[dependencies]
init-data-rs = "0.1.2"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);
}
Ok(())
}use init_data_rs::validate_third_party;
let data = validate_third_party(init_data, bot_id, None)?;For detailed documentation, visit docs.rs/init-data-rs.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This is a Rust port of the official Golang implementation.