init-data-py 0.2.4__tar.gz → 0.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {init_data_py-0.2.4 → init_data_py-0.2.5}/PKG-INFO +2 -3
- {init_data_py-0.2.4 → init_data_py-0.2.5}/pyproject.toml +1 -1
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/__init__.py +1 -1
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/init_data.py +8 -4
- {init_data_py-0.2.4 → init_data_py-0.2.5}/tests/test_validate.py +6 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/.github/workflows/publish.yml +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/.gitignore +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/.python-version +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/LICENCE +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/README.md +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/requirements-dev.lock +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/requirements.lock +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/errors/__init__.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/errors/errors.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/types/__init__.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/types/chat.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/types/object.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/src/init_data_py/types/user.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/tests/__init__.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/tests/test_parse.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/tests/test_sign.py +0 -0
- {init_data_py-0.2.4 → init_data_py-0.2.5}/tests/test_to_query_string.py +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: init-data-py
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: A Python library that provides tools for using and validating Telegram web app init data.
|
|
5
5
|
Author-email: nimaxin <nimaxin@proton.me>
|
|
6
|
-
License
|
|
7
|
-
License-File: LICENCE
|
|
6
|
+
License: MIT
|
|
8
7
|
Requires-Python: >=3.8
|
|
9
8
|
Description-Content-Type: text/markdown
|
|
10
9
|
|
|
@@ -140,7 +140,9 @@ class InitData:
|
|
|
140
140
|
`InitData`:
|
|
141
141
|
This current updated init data by setting the `auth_date` and generated signature (`hash`) attributes.
|
|
142
142
|
"""
|
|
143
|
-
self.auth_date =
|
|
143
|
+
self.auth_date = (
|
|
144
|
+
auth_date if auth_date is not None else int(time.time())
|
|
145
|
+
)
|
|
144
146
|
self.hash = self.calculate_hash(bot_token)
|
|
145
147
|
|
|
146
148
|
return self
|
|
@@ -162,9 +164,11 @@ class InitData:
|
|
|
162
164
|
init_data = self.to_dict(nested=False)
|
|
163
165
|
init_data.pop("hash", None)
|
|
164
166
|
sorted_attrs = sorted(init_data.items())
|
|
165
|
-
data_check_string =
|
|
166
|
-
f"{k}={v}" for k, v in sorted_attrs
|
|
167
|
-
|
|
167
|
+
data_check_string = (
|
|
168
|
+
"\n".join(f"{k}={v}" for k, v in sorted_attrs)
|
|
169
|
+
.replace("/", "\/")
|
|
170
|
+
.encode()
|
|
171
|
+
)
|
|
168
172
|
secret_key = hmac.new(
|
|
169
173
|
b"WebAppData", bot_token.encode(), hashlib.sha256
|
|
170
174
|
).digest()
|
|
@@ -29,6 +29,12 @@ class TestValidateInitData(unittest.TestCase):
|
|
|
29
29
|
init_data = InitData.parse(query_string)
|
|
30
30
|
self.assertTrue(init_data.validate(bot_token))
|
|
31
31
|
|
|
32
|
+
def test_escape_character(self):
|
|
33
|
+
query_string = "query_id=AAF03wc0AgAAAHTfBzTtHPDB&user=%7B%22id%22%3A5167898484%2C%22first_name%22%3A%22xin%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22pvnimaxin%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%2C%22photo_url%22%3A%22https%3A%5C%2F%5C%2Ft.me%5C%2Fi%5C%2Fuserpic%5C%2F320%5C%2FYpcdHFmoxukmQ537mOZhe-Woot_k2xrmbdAIrGK1zFgIVth6Wzacz7P2nGNCcp9j.svg%22%7D&auth_date=1731441609&hash=f4bac82fe8f20abdc03126af489751752e830227b58241ec2f9dd67913909ee0"
|
|
34
|
+
bot_token = "7244657541:AAFMjYH4kc3U9zG0GWnxYfW-QKICVzDwvEw"
|
|
35
|
+
init_data = InitData.parse(query_string)
|
|
36
|
+
self.assertTrue(init_data.validate(bot_token))
|
|
37
|
+
|
|
32
38
|
def test_valid_init_data(self):
|
|
33
39
|
self.assertTrue(self.init_data.validate(self.bot_token))
|
|
34
40
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|