Skip to content

serejaris/telegram-skills / skills/tg-miniapp-launch-auth

tg-miniapp-launch-auth

Verified

Use when choosing how a Telegram Mini App opens (keyboard, inline or menu button, main app, direct link, startapp, join request) or when a server must trust a Mini App user: validating initData by HMAC or Ed25519, signature in the check string, auth_date, isVersionAtLeast gating, origin protection, test environment and debugging.

FileKindSize
SKILL.mdskill md10.0 KB
references/testing-debug.mdmarkdown2.3 KB
scripts/init_data.pyscript2.9 KB
tests/test_ed25519.pyscript1.2 KB
tests/test_init_data.pyscript5.7 KB
tests/vectors.pyscript1.1 KB

tests/test_ed25519.py

View on GitHub
import importlib.util
from pathlib import Path
import unittest

from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey

from vectors import BOT_ID, PUBLIC_KEY, SIGNED_INIT_DATA

SPEC = importlib.util.spec_from_file_location(
    'init_data', Path(__file__).parents[1] / 'scripts/init_data.py')
init_data = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(init_data)


class Ed25519Verification(unittest.TestCase):
    def setUp(self):
        self.key = Ed25519PublicKey.from_public_bytes(bytes.fromhex(PUBLIC_KEY))
        self.message, self.signature = init_data.third_party_payload(SIGNED_INIT_DATA, BOT_ID)

    def test_payload_verifies_with_the_test_key(self):
        self.key.verify(self.signature, self.message)

    def test_changed_message_is_rejected(self):
        with self.assertRaises(InvalidSignature):
            self.key.verify(self.signature, self.message + b'x')

    def test_other_bot_id_is_rejected(self):
        message, signature = init_data.third_party_payload(SIGNED_INIT_DATA, BOT_ID + 1)
        with self.assertRaises(InvalidSignature):
            self.key.verify(signature, message)


if __name__ == '__main__':
    unittest.main()
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall