Skip to content

Commit ba0221c

Browse files
committed
feat: add document and remove user_id
1 parent a62a9f6 commit ba0221c

60 files changed

Lines changed: 13176 additions & 226 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/docs.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Documentation
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
jobs:
12+
deploy:
13+
environment:
14+
name: github-pages
15+
url: ${{ steps.deployment.outputs.page_url }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/configure-pages@v6
19+
- uses: actions/checkout@v6
20+
- uses: actions/setup-python@v6
21+
with:
22+
python-version: 3.x
23+
- run: pip install zensical
24+
- run: zensical build --clean
25+
- uses: actions/upload-pages-artifact@v5
26+
with:
27+
path: site
28+
- uses: actions/deploy-pages@v5
29+
id: deployment

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ciphertoken"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55

66
[lib]

‎README.md‎

Lines changed: 33 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2,156 +2,66 @@
22

33
# CipherToken
44

5-
**CipherToken** is a modern, high-performance Python library for cryptography and JWT (JSON Web Token) management.
6-
It is implemented in **Rust** using **PyO3**, providing both speed and security for generating, encoding, decoding, and verifying tokens.
5+
**CipherToken** is a **next-generation** token engine built for developers who demand speed, security, and reliability. Currently focused on **JWT**, it provides a complete token lifecycle — from key generation and token minting to verification, rotation, and expiry tracking — all backed by the raw performance of **Rust**.
76

8-
The library is designed to be modular, organized into **submodules** for secret management, time utilities, algorithms, and token handling.
9-
It supports both **synchronous** and **asynchronous** operations
7+
- Python 3.8+
8+
- HMAC, RSA, ECDSA, RSA-PSS, EdDSA
9+
- Sync and Async APIs via **Tokio**
1010

11-
---
12-
13-
## Library Overview
14-
15-
CipherToken is structured into the following main parts:
16-
17-
### 1. `secret` Module
18-
Handles key generation for symmetric (HMAC) and asymmetric (RSA) algorithms:
19-
20-
- `secret_key()` – Generate a random HMAC key (default 32 bytes)
21-
- `secret_key_with_size(size: int)` – Generate HMAC key with a custom size
22-
- `generate_hmac_secret(size: int)` – Generate an HMAC secret key
23-
- `generate_hmac_secret_async(size: int)` – Async version of HMAC key generation
24-
- `generate_rsa_keypair(bits: Optional[int] = 2048)` – Generate RSA private/public key pair
25-
26-
---
27-
28-
### 2. `time` Module
29-
Provides utility functions for time conversion and timestamps:
30-
31-
- `now()` – Current UNIX timestamp
32-
- `seconds(n: int)` – Convert n seconds to seconds
33-
- `minutes(n: int)` – Convert n minutes to seconds
34-
- `hours(n: int)` – Convert n hours to seconds
35-
- `days(n: int)` – Convert n days to seconds
36-
- `weeks(n: int)` – Convert n weeks to seconds
37-
38-
---
39-
40-
### 3. `utils` Module
41-
Contains useful constants:
42-
43-
- `DEFAULT_SECRET_SIZE` – Default key size
44-
- `MIN_SECRET_SIZE` – Minimum allowed key size
45-
- `TOKEN_ACCESS` – Access token type
46-
- `TOKEN_REFRESH` – Refresh token type
11+
Built by **[Cipher-Unit](https://cipherunit.xyz/)**.
4712

4813
---
4914

50-
### 4. `algorithms` Module
51-
Defines algorithm constants for token signing:
15+
## Documentation
5216

53-
- HMAC: `HS256`, `HS384`, `HS512`
54-
- RSA: `RS256`, `RS384`, `RS512`
55-
- ECDSA: `ES256`, `ES384`
56-
- RSA-PSS: `PS256`, `PS384`, `PS512`
57-
- Edwards Curve: `EDDSA`
17+
📖 **Official Documentation:** [https://cipherunits.github.io/CipherToken/](https://cipherunits.github.io/CipherToken/)
5818

5919
---
6020

61-
### 5. `CipherToken` Class
62-
Main class for managing JWTs:
63-
64-
- **Constructor:**
65-
```python
66-
from ciphertoken import CipherToken
67-
68-
CipherToken(secret: str, algorithm: str, access_ttl: int, refresh_ttl: int)
69-
```
70-
71-
### Synchronous methods:
72-
```python
73-
access(user_id: int, extra_payload: Optional[dict] = None) -> str
74-
refresh(user_id: int, extra_payload: Optional[dict] = None) -> str
75-
decode(token: str) -> dict
76-
verify(token: str) -> bool
77-
rotation(refresh_token: str, extra_payload: Optional[dict] = None) -> Tuple[str, str]
78-
inspect(token: str) -> dict
79-
remaining_time(token: str) -> Optional[int]
80-
algorithm_name() -> str
81-
```
82-
83-
### Asynchronous methods:
84-
```python
85-
await access_async(user_id: int, extra_payload: Optional[dict] = None) -> str
86-
await refresh_async(user_id: int, extra_payload: Optional[dict] = None) -> str
87-
await decode_async(token: str) -> dict
88-
await verify_async(token: str) -> bool
89-
await rotation_async(refresh_token: str, extra_payload: Optional[dict] = None) -> Tuple[str, str]
90-
```
91-
92-
### Helper Functions:
93-
94-
`is_jwt_format(token: str) – Check if a string is a valid JWT`
95-
96-
`validate_jwt_format(token: str) – Validate JWT structure`
97-
9821
## Installation
9922

100-
CipherToken is available via PyPI. Install it with:
101-
102-
`pip install ciphertoken`
23+
```bash
24+
pip install ciphertoken
25+
```
10326

10427
---
10528

106-
### Usage Example
29+
## Quick Example
10730

10831
```python
109-
from ciphertoken.secret import secret_key
11032
from ciphertoken import CipherToken
111-
from ciphertoken.time import minutes, days
112-
from ciphertoken.utils import TOKEN_REFRESH
11333
from ciphertoken.algorithms import HS256
34+
from ciphertoken.time import minutes, days
35+
from ciphertoken.jwt import access, refresh, rotation
11436

115-
# Generate a secret key
116-
key = secret_key()
117-
118-
# Create a CipherToken instance
119-
token = CipherToken(secret=key, algorithm=HS256, access_ttl=minutes(10), refresh_ttl=days(7))
120-
121-
# Generate access and refresh tokens
122-
access_token = token.access(user_id=123)
123-
refresh_token = token.refresh(user_id=123)
124-
125-
# Verify and decode tokens
126-
payload = token.decode(access_token)
127-
is_valid = token.verify(access_token)
128-
129-
# Async usage
130-
import asyncio
131-
132-
async def generate_async_token():
133-
access_token = await token.access_async(user_id=123)
134-
payload = await token.decode_async(access_token)
135-
return payload
37+
token = CipherToken(
38+
secret="your-strong-secret-key",
39+
algorithm=HS256,
40+
access_ttl=minutes(10),
41+
refresh_ttl=days(7),
42+
)
13643

137-
asyncio.run(generate_async_token())
44+
access_token = access(token, payload={"user_id": 42})
45+
refresh_token = refresh(token, payload={"user_id": 42})
46+
new_access, new_refresh = rotation(token, refresh_token)
13847

48+
print(token.verify(access_token)) # True
49+
print(token.decode(access_token))
13950
```
14051

141-
### Implementation Notes
142-
143-
- Built in Rust using PyO3 for maximum speed and memory safety
52+
---
14453

145-
- Supports synchronous and asynchronous workflows
54+
## Contribute
14655

147-
- Fully modular: secret, time, utils, algorithms, and CipherToken class
56+
Contributions are welcome! Whether it's bug fixes, new algorithms, documentation improvements, or feature suggestions — feel free to open an issue or pull request.
14857

149-
- Secure key handling with HMAC and RSA support
58+
- **Repository:** [https://github.com/cipherunits/CipherToken](https://github.com/cipherunits/CipherToken)
59+
- **Issues:** [https://github.com/cipherunits/CipherToken/issues](https://github.com/cipherunits/CipherToken/issues)
15060

151-
- Easily extendable for additional algorithms
61+
Please read the code of conduct and contribution guidelines before submitting. All contributions must follow the MIT license.
15262

63+
---
15364

154-
### Summary
65+
## License
15566

156-
CipherToken is a modern, Rust-backed Python library for authentication and JWT management.
157-
It is ideal for web APIs, microservices, or any system that requires secure token generation, verification, and rotation.
67+
**MIT** — see [LICENSE](LICENSE) for details.

‎ciphertoken/__init__.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Public Python API for ciphertoken."""
2+
3+
from .algorithms import EDDSA, ES256, ES384, HS256, HS384, HS512, PS256, PS384, PS512, RS256, RS384, RS512
4+
from .ciphertoken import CipherToken, is_jwt_format, validate_jwt_format
5+
from .jwt import TOKEN_ACCESS as JWT_TOKEN_ACCESS, TOKEN_REFRESH as JWT_TOKEN_REFRESH
6+
from .jwt import access as jwt_access, refresh as jwt_refresh, rotation as jwt_rotation
7+
from .jwt import access_async as jwt_access_async, refresh_async as jwt_refresh_async, rotation_async as jwt_rotation_async
8+
from .secret import generate_hmac_secret, generate_hmac_secret_async, generate_rsa_keypair, secret_key, secret_key_with_size
9+
from .time import days, hours, minutes, now, seconds, weeks
10+
from .utils import DEFAULT_SECRET_SIZE, MIN_SECRET_SIZE, TOKEN_ACCESS, TOKEN_REFRESH
11+
12+
__all__ = [
13+
"CipherToken",
14+
"is_jwt_format",
15+
"validate_jwt_format",
16+
"EDDSA",
17+
"ES256",
18+
"ES384",
19+
"HS256",
20+
"HS384",
21+
"HS512",
22+
"PS256",
23+
"PS384",
24+
"PS512",
25+
"RS256",
26+
"RS384",
27+
"RS512",
28+
"JWT_TOKEN_ACCESS",
29+
"JWT_TOKEN_REFRESH",
30+
"jwt_access",
31+
"jwt_refresh",
32+
"jwt_rotation",
33+
"jwt_access_async",
34+
"jwt_refresh_async",
35+
"jwt_rotation_async",
36+
"generate_hmac_secret",
37+
"generate_hmac_secret_async",
38+
"generate_rsa_keypair",
39+
"secret_key",
40+
"secret_key_with_size",
41+
"days",
42+
"hours",
43+
"minutes",
44+
"now",
45+
"seconds",
46+
"weeks",
47+
"DEFAULT_SECRET_SIZE",
48+
"MIN_SECRET_SIZE",
49+
"TOKEN_ACCESS",
50+
"TOKEN_REFRESH",
51+
]

‎ciphertoken/__init__.pyi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from .algorithms import EDDSA, ES256, ES384, HS256, HS384, HS512, PS256, PS384, PS512, RS256, RS384, RS512
22
from .ciphertoken import CipherToken, is_jwt_format, validate_jwt_format
3+
from .jwt import TOKEN_ACCESS as JWT_TOKEN_ACCESS, TOKEN_REFRESH as JWT_TOKEN_REFRESH
4+
from .jwt import access as jwt_access, refresh as jwt_refresh, rotation as jwt_rotation
5+
from .jwt import access_async as jwt_access_async, refresh_async as jwt_refresh_async, rotation_async as jwt_rotation_async
36
from .secret import generate_hmac_secret, generate_hmac_secret_async, generate_rsa_keypair, secret_key, secret_key_with_size
47
from .time import days, hours, minutes, now, seconds, weeks
58
from .utils import DEFAULT_SECRET_SIZE, MIN_SECRET_SIZE, TOKEN_ACCESS, TOKEN_REFRESH
9+
1.99 KB
Binary file not shown.
871 Bytes
Binary file not shown.
696 Bytes
Binary file not shown.
603 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)