mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
add checking of data in web app
This commit is contained in:
parent
d0006bb089
commit
dd7567f43c
@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
import dev.inmo.micro_utils.crypto.CryptoJs
|
||||
|
||||
fun CryptoJs.HmacSHA256(text: String, key: String) = this.asDynamic().HmacSHA256(text, key).unsafeCast<String>()
|
||||
|
||||
fun CryptoJs.hex(text: String) = this.asDynamic().format.Hex(text).unsafeCast<String>()
|
@ -1,5 +1,7 @@
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
import dev.inmo.micro_utils.crypto.CryptoJS
|
||||
|
||||
external class WebApp {
|
||||
val initData: String
|
||||
val initDataUnsafe: WebAppInitData
|
||||
@ -73,3 +75,7 @@ fun WebApp.onMainButtonClicked(eventHandler: EventHandler) = onEvent(EventType.M
|
||||
* @return The callback which should be used in case you want to turn off events handling
|
||||
*/
|
||||
fun WebApp.onViewportChanged(eventHandler: ViewportChangedEventHandler) = onEvent(EventType.ViewportChanged, eventHandler)
|
||||
|
||||
fun WebApp.isInitDataSafe(botToken: String) = CryptoJS.hex(
|
||||
CryptoJS.HmacSHA256(botToken, "WebAppData")
|
||||
) == initDataUnsafe.hash
|
||||
|
Loading…
Reference in New Issue
Block a user