kron-otp 1.0.0__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.
kron_otp-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vib Tools (vibtoolshq)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: kron-otp
3
+ Version: 1.0.0
4
+ Summary: Lightweight TOTP generation and verification for Python.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/vibtoolshq/KronOTP
7
+ Project-URL: Repository, https://github.com/vibtoolshq/KronOTP
8
+ Project-URL: Issues, https://github.com/vibtoolshq/KronOTP/issues
9
+ Keywords: totp,2fa,otp,authentication,automation
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: pyotp<3,>=2.12
17
+ Dynamic: license-file
18
+
19
+ # kron-otp (Python)
20
+
21
+ A small Python TOTP engine backed by PyOTP, maintained in the [KronOTP monorepo](https://github.com/vibtoolshq/KronOTP).
22
+
23
+ ## Install
24
+
25
+ ```sh
26
+ python -m pip install kron-otp
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ import os
33
+ from kron_otp import KronOTP
34
+
35
+ secret = os.environ["TOTP_SECRET"] # Base32 provisioning secret, not an OTP
36
+ token = KronOTP.generate(secret) # six-digit string
37
+ verified = KronOTP.verify(secret, token)
38
+ print("Verification:", verified)
39
+ ```
40
+
41
+ - `generate(secret: str) -> str` returns a six-digit string or raises `ValueError` for invalid secrets.
42
+ - `verify(secret: str, token: str) -> bool` returns `False` for invalid secrets or tokens.
43
+ - Configuration: SHA-1, 6 digits, 30-second period, ±one 30-second verification window.
44
+ - The `pyotp>=2.12` dependency requires at least 112 bits of decoded secret material; use a securely generated 160-bit or longer Base32 secret.
45
+ - Supported Python: 3.10+.
46
+
47
+ ## Local tests
48
+
49
+ From the `python/` directory:
50
+
51
+ ```sh
52
+ python -m pip install -e .
53
+ python -m unittest discover -s tests -v
54
+ ```
55
+
56
+ Keep TOTP provisioning secrets private. Use server-side rate limits and replay protection; successful local code generation is not proof of authentication.
57
+
58
+ See the [integration and publishing guide](../docs/AUTOMATION_AND_PUBLISHING.md).
59
+
60
+ Licensed under the [MIT License](./LICENSE).
@@ -0,0 +1,42 @@
1
+ # kron-otp (Python)
2
+
3
+ A small Python TOTP engine backed by PyOTP, maintained in the [KronOTP monorepo](https://github.com/vibtoolshq/KronOTP).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ python -m pip install kron-otp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ import os
15
+ from kron_otp import KronOTP
16
+
17
+ secret = os.environ["TOTP_SECRET"] # Base32 provisioning secret, not an OTP
18
+ token = KronOTP.generate(secret) # six-digit string
19
+ verified = KronOTP.verify(secret, token)
20
+ print("Verification:", verified)
21
+ ```
22
+
23
+ - `generate(secret: str) -> str` returns a six-digit string or raises `ValueError` for invalid secrets.
24
+ - `verify(secret: str, token: str) -> bool` returns `False` for invalid secrets or tokens.
25
+ - Configuration: SHA-1, 6 digits, 30-second period, ±one 30-second verification window.
26
+ - The `pyotp>=2.12` dependency requires at least 112 bits of decoded secret material; use a securely generated 160-bit or longer Base32 secret.
27
+ - Supported Python: 3.10+.
28
+
29
+ ## Local tests
30
+
31
+ From the `python/` directory:
32
+
33
+ ```sh
34
+ python -m pip install -e .
35
+ python -m unittest discover -s tests -v
36
+ ```
37
+
38
+ Keep TOTP provisioning secrets private. Use server-side rate limits and replay protection; successful local code generation is not proof of authentication.
39
+
40
+ See the [integration and publishing guide](../docs/AUTOMATION_AND_PUBLISHING.md).
41
+
42
+ Licensed under the [MIT License](./LICENSE).
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kron-otp"
7
+ version = "1.0.0"
8
+ description = "Lightweight TOTP generation and verification for Python."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["totp", "2fa", "otp", "authentication", "automation"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "pyotp>=2.12,<3",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/vibtoolshq/KronOTP"
25
+ Repository = "https://github.com/vibtoolshq/KronOTP"
26
+ Issues = "https://github.com/vibtoolshq/KronOTP/issues"
27
+
28
+ [tool.setuptools]
29
+ py-modules = ["kron_otp"]
30
+
31
+ [tool.setuptools.package-dir]
32
+ "" = "src"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: kron-otp
3
+ Version: 1.0.0
4
+ Summary: Lightweight TOTP generation and verification for Python.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/vibtoolshq/KronOTP
7
+ Project-URL: Repository, https://github.com/vibtoolshq/KronOTP
8
+ Project-URL: Issues, https://github.com/vibtoolshq/KronOTP/issues
9
+ Keywords: totp,2fa,otp,authentication,automation
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: pyotp<3,>=2.12
17
+ Dynamic: license-file
18
+
19
+ # kron-otp (Python)
20
+
21
+ A small Python TOTP engine backed by PyOTP, maintained in the [KronOTP monorepo](https://github.com/vibtoolshq/KronOTP).
22
+
23
+ ## Install
24
+
25
+ ```sh
26
+ python -m pip install kron-otp
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ import os
33
+ from kron_otp import KronOTP
34
+
35
+ secret = os.environ["TOTP_SECRET"] # Base32 provisioning secret, not an OTP
36
+ token = KronOTP.generate(secret) # six-digit string
37
+ verified = KronOTP.verify(secret, token)
38
+ print("Verification:", verified)
39
+ ```
40
+
41
+ - `generate(secret: str) -> str` returns a six-digit string or raises `ValueError` for invalid secrets.
42
+ - `verify(secret: str, token: str) -> bool` returns `False` for invalid secrets or tokens.
43
+ - Configuration: SHA-1, 6 digits, 30-second period, ±one 30-second verification window.
44
+ - The `pyotp>=2.12` dependency requires at least 112 bits of decoded secret material; use a securely generated 160-bit or longer Base32 secret.
45
+ - Supported Python: 3.10+.
46
+
47
+ ## Local tests
48
+
49
+ From the `python/` directory:
50
+
51
+ ```sh
52
+ python -m pip install -e .
53
+ python -m unittest discover -s tests -v
54
+ ```
55
+
56
+ Keep TOTP provisioning secrets private. Use server-side rate limits and replay protection; successful local code generation is not proof of authentication.
57
+
58
+ See the [integration and publishing guide](../docs/AUTOMATION_AND_PUBLISHING.md).
59
+
60
+ Licensed under the [MIT License](./LICENSE).
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/kron_otp.py
5
+ src/kron_otp.egg-info/PKG-INFO
6
+ src/kron_otp.egg-info/SOURCES.txt
7
+ src/kron_otp.egg-info/dependency_links.txt
8
+ src/kron_otp.egg-info/requires.txt
9
+ src/kron_otp.egg-info/top_level.txt
10
+ tests/test_kron_otp.py
@@ -0,0 +1 @@
1
+ pyotp<3,>=2.12
@@ -0,0 +1 @@
1
+ kron_otp
@@ -0,0 +1,74 @@
1
+ """KronOTP: a minimal, stateless TOTP engine backed by PyOTP."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import binascii
7
+ import hashlib
8
+ import re
9
+
10
+ import pyotp
11
+
12
+
13
+ class KronOTP:
14
+ """Generate and verify standard six-digit, 30-second SHA-1 TOTP codes."""
15
+
16
+ @staticmethod
17
+ def _normalize_secret(secret: str) -> str:
18
+ """Normalize Base32 input and reject invalid or non-canonical keys."""
19
+ if not isinstance(secret, str):
20
+ raise ValueError("TOTP secret must be a Base32 string.")
21
+
22
+ # Ignore whitespace and case; retain no copy of the raw secret in errors.
23
+ cleaned = "".join(secret.split()).upper()
24
+ unpadded = cleaned.rstrip("=")
25
+ padding_count = len(cleaned) - len(unpadded)
26
+ remainder = len(unpadded) % 8
27
+ required_padding = (-len(unpadded)) % 8
28
+
29
+ if (
30
+ not re.fullmatch(r"[A-Z2-7]+", unpadded)
31
+ or remainder not in (0, 2, 4, 5, 7)
32
+ or (padding_count and padding_count != required_padding)
33
+ ):
34
+ raise ValueError("Invalid TOTP secret: expected valid Base32.")
35
+
36
+ try:
37
+ decoded = base64.b32decode(unpadded + "=" * required_padding)
38
+ except (binascii.Error, ValueError):
39
+ raise ValueError("Invalid TOTP secret: expected valid Base32.") from None
40
+
41
+ # Reject altered encodings (including nonzero unused padding bits).
42
+ if not decoded or base64.b32encode(decoded).decode("ascii").rstrip("=") != unpadded:
43
+ raise ValueError("Invalid TOTP secret: expected valid Base32.")
44
+
45
+ return unpadded
46
+
47
+ @staticmethod
48
+ def _totp(secret: str) -> pyotp.TOTP:
49
+ """Create the same TOTP configuration as the JavaScript module."""
50
+ return pyotp.TOTP(
51
+ KronOTP._normalize_secret(secret),
52
+ digits=6,
53
+ interval=30,
54
+ digest=hashlib.sha1,
55
+ )
56
+
57
+ @staticmethod
58
+ def generate(secret: str) -> str:
59
+ """Return a six-digit code; raise ValueError for an invalid secret."""
60
+ try:
61
+ return KronOTP._totp(secret).now()
62
+ except (TypeError, ValueError, binascii.Error):
63
+ raise ValueError("Invalid TOTP secret: expected valid Base32.") from None
64
+
65
+ @staticmethod
66
+ def verify(secret: str, token: str) -> bool:
67
+ """Verify a code with a one-step (±30-second) clock-drift window."""
68
+ if not isinstance(token, str) or re.fullmatch(r"[0-9]{6}", token) is None:
69
+ return False
70
+
71
+ try:
72
+ return bool(KronOTP._totp(secret).verify(token, valid_window=1))
73
+ except (TypeError, ValueError, binascii.Error):
74
+ return False
@@ -0,0 +1,43 @@
1
+ """Focused tests for the Python KronOTP engine.
2
+
3
+ Run from python/: python -m unittest discover -s tests -v
4
+ """
5
+
6
+ import unittest
7
+
8
+ from src.kron_otp import KronOTP
9
+
10
+
11
+ class KronOTPTests(unittest.TestCase):
12
+ # RFC 6238 SHA-1 reference key: 20 decoded bytes (160 bits).
13
+ SECRET = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
14
+
15
+ def test_generate_and_verify(self) -> None:
16
+ token = KronOTP.generate(self.SECRET)
17
+ print(f"Generated TOTP: {token}")
18
+
19
+ self.assertRegex(token, r"^[0-9]{6}$")
20
+ self.assertTrue(KronOTP.verify(self.SECRET, token))
21
+
22
+ def test_secret_normalization(self) -> None:
23
+ token = KronOTP.generate(self.SECRET)
24
+ self.assertTrue(
25
+ KronOTP.verify("gezd gnbv gy3t qojq gezd gnbv gy3t qojq", token)
26
+ )
27
+
28
+ def test_invalid_tokens(self) -> None:
29
+ for token in ("", "12345", "1234567", "abcdef", 123456, None):
30
+ with self.subTest(token=token):
31
+ self.assertFalse(KronOTP.verify(self.SECRET, token))
32
+
33
+ def test_invalid_secrets(self) -> None:
34
+ # The former 80-bit fixture is below PyOTP 2.12+'s 112-bit minimum.
35
+ for secret in ("", " ", "not-base32!", "A", "AB", None, "JBSWY3DPEHPK3PXP"):
36
+ with self.subTest(secret=secret):
37
+ with self.assertRaises(ValueError):
38
+ KronOTP.generate(secret)
39
+ self.assertFalse(KronOTP.verify(secret, "123456"))
40
+
41
+
42
+ if __name__ == "__main__":
43
+ unittest.main()