mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
fix of #591
This commit is contained in:
parent
78a00f0efb
commit
497974e45c
@ -2,6 +2,9 @@
|
||||
|
||||
## 1.1.2
|
||||
|
||||
* `Core`:
|
||||
* Rename of `TelegramAPIUrlsKeeper#checkWebAppLink` -> `TelegramAPIUrlsKeeper#checkWebAppData` (fix of [#591](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/591))
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* `Versions`:
|
||||
|
@ -50,7 +50,7 @@ class TelegramAPIUrlsKeeper(
|
||||
* @param rawData Data from [dev.inmo.tgbotapi.webapps.WebApp.initData]
|
||||
* @param hash Data from [dev.inmo.tgbotapi.webapps.WebApp.initDataUnsafe] from the field [dev.inmo.tgbotapi.webapps.WebAppInitData.hash]
|
||||
*/
|
||||
fun checkWebAppLink(rawData: String, hash: String): Boolean {
|
||||
fun checkWebAppData(rawData: String, hash: String): Boolean {
|
||||
val preparedData = rawData
|
||||
.decodeURLQueryComponent()
|
||||
.split("&")
|
||||
@ -60,4 +60,11 @@ class TelegramAPIUrlsKeeper(
|
||||
|
||||
return HMAC.hmacSHA256(webAppDataSecretKeyHash.bytes, preparedData.toByteArray()).hexLower == hash.lowercase()
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rawData Data from [dev.inmo.tgbotapi.webapps.WebApp.initData]
|
||||
* @param hash Data from [dev.inmo.tgbotapi.webapps.WebApp.initDataUnsafe] from the field [dev.inmo.tgbotapi.webapps.WebAppInitData.hash]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("checkWebAppData"))
|
||||
inline fun checkWebAppLink(rawData: String, hash: String) = checkWebAppData(rawData, hash)
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
import dev.inmo.micro_utils.crypto.CryptoJS
|
||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
|
||||
external class WebApp {
|
||||
@ -77,7 +76,7 @@ fun WebApp.onMainButtonClicked(eventHandler: EventHandler) = onEvent(EventType.M
|
||||
*/
|
||||
fun WebApp.onViewportChanged(eventHandler: ViewportChangedEventHandler) = onEvent(EventType.ViewportChanged, eventHandler)
|
||||
|
||||
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppLink(
|
||||
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
||||
initData,
|
||||
initDataUnsafe.hash
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user