pub fn validate(
init_data: &str,
token: &str,
expires_in: Option<u64>,
) -> Result<InitData, InitDataError>
Expand description
Validates the authenticity and integrity of Telegram Mini Apps init data.
This function performs several checks:
- Validates the format of the init data
- Extracts and verifies the hash
- Checks the data hasn’t expired
- Parses the data into a strongly-typed structure
§Arguments
init_data
- Raw init data string from Telegram Mini Apptoken
- Bot token used for validationexpires_in
- Optional expiration time in seconds (defaults to 24 hours), set to 0 to disable expiration check
§Returns
Ok(InitData)
- Parsed and validated init dataErr(InitDataError)
- Various validation or parsing errors
§Example
use init_data_rs::validate;
let init_data = "query_id=123&auth_date=1662771648&hash=...";
let result = validate(init_data, "BOT_TOKEN", None);
§Errors
See init_data_rs::parse
for possible errors
§Panics
This function panics if SystemTime::now
returns a date less than UNIX_EPOCH
.
Meaning the function should panic only if the device time is really, REALLY bad.