Skip to content

Commit 827feef

Browse files
authored
#155 refactor: remove server-side validation from SDK (#156)
- Remove validate_init_data module and ValidationKey - Remove verify_init_data_hash from interop - Remove dependencies: hmac-sha256, hex, base64, ed25519-dalek - Update README to recommend init-data-rs for backend validation - Delete validation tests Validation must happen on the server with bot token. Client-side SDK should not handle server responsibilities. Recommend init-data-rs crate for backend validation.
1 parent 52719d2 commit 827feef

File tree

13 files changed

+155
-582
lines changed

13 files changed

+155
-582
lines changed

Cargo.lock

Lines changed: 2 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ web-sys = { version = "0.3", features = [
4242
"Location",
4343
"CssStyleDeclaration",
4444
] }
45-
hmac-sha256 = "1"
46-
hex = "0.4"
4745
percent-encoding = "2"
48-
base64 = "0.22"
49-
ed25519-dalek = "2"
5046
masterror = { workspace = true }
5147
regex = "1"
5248
reqwest = { version = "0.12", default-features = false, features = [

README.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -678,33 +678,25 @@ with the parsed data available in the context.
678678

679679
### Validating initData
680680

681-
Validate the integrity of the `Telegram.WebApp.initData` payload on the server.
682-
The `validate_init_data` module is re-exported at the crate root and can be
683-
used directly or through the `TelegramWebApp::validate_init_data` helper:
681+
**Server-side validation is required.** Use the [`init-data-rs`](https://github.com/escwxyz/init-data-rs) crate for backend validation:
684682

685-
```rust,no_run
686-
use telegram_webapp_sdk::{
687-
validate_init_data::ValidationKey,
688-
TelegramWebApp
689-
};
683+
```rust,ignore
684+
// On your backend server
685+
use init_data_rs::{validate, InitData};
690686
691-
let bot_token = "123456:ABC";
692-
let query = "user=alice&auth_date=1&hash=48f4c0e9d3dd46a5734bf2c5d4df9f4ec52a3cd612f6482a7d2c68e84e702ee2";
693-
TelegramWebApp::validate_init_data(query, ValidationKey::BotToken(bot_token))?;
687+
async fn authenticate(init_data_str: &str, bot_token: &str) -> Result<InitData, Box<dyn std::error::Error>> {
688+
// Validate with optional expiration time (in seconds)
689+
let init_data: InitData = validate(init_data_str, bot_token, Some(3600))?;
690+
Ok(init_data)
691+
}
692+
```
694693

695-
// For Ed25519-signed data
696-
# use ed25519_dalek::{Signer, SigningKey};
697-
# let sk = SigningKey::from_bytes(&[1u8;32]);
698-
# let pk = sk.verifying_key();
699-
# let sig = sk.sign(b"a=1\nb=2");
700-
# let init_data = format!("a=1&b=2&signature={}", base64::encode(sig.to_bytes()));
701-
TelegramWebApp::validate_init_data(
702-
&init_data,
703-
ValidationKey::Ed25519PublicKey(pk.as_bytes())
704-
)?;
694+
**Why server-side only?**
695+
- Bot tokens must never be exposed to client-side code
696+
- Validation requires secret keys that should remain on the server
697+
- This follows industry-standard security practices
705698

706-
# Ok::<(), Box<dyn std::error::Error>>(())
707-
```
699+
See the [init-data-rs documentation](https://docs.rs/init-data-rs) for complete usage examples.
708700

709701
<p align="right"><a href="#readme-top">Back to top</a></p>
710702

demo/dist/demo-d788830ec512cc93.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,22 @@ export function apply_default_theme() {
256256
}
257257
}
258258

259-
function wasm_bindgen__convert__closures_____invoke__h9a03a9b032c64c17(arg0, arg1) {
260-
wasm.wasm_bindgen__convert__closures_____invoke__h9a03a9b032c64c17(arg0, arg1);
261-
}
262-
263259
function wasm_bindgen__convert__closures_____invoke__hde3f86340efe2d67(arg0, arg1, arg2) {
264260
wasm.wasm_bindgen__convert__closures_____invoke__hde3f86340efe2d67(arg0, arg1, arg2);
265261
}
266262

267-
function wasm_bindgen__convert__closures_____invoke__h77889b4a60ffe254(arg0, arg1) {
268-
wasm.wasm_bindgen__convert__closures_____invoke__h77889b4a60ffe254(arg0, arg1);
263+
function wasm_bindgen__convert__closures_____invoke__h9a03a9b032c64c17(arg0, arg1) {
264+
wasm.wasm_bindgen__convert__closures_____invoke__h9a03a9b032c64c17(arg0, arg1);
269265
}
270266

271267
function wasm_bindgen__convert__closures_____invoke__hd9400bcc9f3461f7(arg0, arg1, arg2) {
272268
wasm.wasm_bindgen__convert__closures_____invoke__hd9400bcc9f3461f7(arg0, arg1, arg2);
273269
}
274270

271+
function wasm_bindgen__convert__closures_____invoke__h77889b4a60ffe254(arg0, arg1) {
272+
wasm.wasm_bindgen__convert__closures_____invoke__h77889b4a60ffe254(arg0, arg1);
273+
}
274+
275275
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
276276

277277
async function __wbg_load(module, imports) {
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)