tma_init_data

Function validate

Source
pub fn validate(
    init_data: String,
    bot_token: String,
    exp_in: Duration,
) -> Result<bool, ValidationError>
Expand description

Validates passed init data. This method expects initData to be passed in the exact raw format as it could be found in window.Telegram.WebApp.initData. Returns Ok in case init data is signed correctly, and it is allowed to trust it.

Current code is implementation of algorithmic code described in official docs: https://core.telegram.org/bots/webapps#validating-data-received-via-the-web-app

ยงArguments

  • init_data - init data passed from application
  • token - TWA bot secret token which was used to create init data
  • exp_in - maximum init data lifetime. It is strongly recommended to use this parameter. In case exp duration is None, function does not check if parameters are expired.