For use in your UseThatApp Web Apps
Project description
usethatapp
A small utility library for UseThatApp web applications providing helpers to verify signatures and decrypt RSA/OAEP-encrypted messages.
Features
- Verify PSS/SHA256 signatures
- Decrypt OAEP/SHA256 encrypted messages
- Helpers to load RSA keys from files or PEM strings
Install
From PyPI:
pip install usethatapp
Requirements
- Python >= 3.8
- cryptography>=46.0.5,<47
Quick usage
The package exposes a simple API in usethatapp.webapps and helpers in
usethatapp.encryption.
Example: verify signature and decrypt message from a requestAccessLevel() envelope
from usethatapp.webapps import get_version
# The envelope returned by requestAccessLevel() via postMessage
envelope = {
"type": "level",
"responseTo": "<request-id>",
"message": {
"contents": "0x...",
"signature": "0xdeadbeef..."
}
}
public_key_path = "./keys/public.pem"
private_key_path = "./keys/private.pem"
try:
version = get_version(envelope, public_key_path, private_key_path)
except ValueError as e:
print(f"Error: {e}")
else:
if version.lower() == 'pro':
# expose pro features
print('Pro version detected!')
else:
# hide pro features
print('Free version detected.')
Loading keys directly
You can also use the Keys helper from usethatapp.encryption to load
keys from PEM strings or files:
from usethatapp.encryption import Keys
pub = Keys.read_public_key_from_file('keys/public.pem')
priv = Keys.read_private_key_from_file('keys/private.pem')
API reference
-
usethatapp.webapps.get_version(envelope, public_key_path, private_key_path, encoding='utf-8')
- envelope: dict or JSON string — the full postMessage envelope returned by
requestAccessLevel(). Must havetype("level"),responseTo, and amessagedict containingcontentsandsignature(hex strings, optionally prefixed with 0x). Envelopes withtype"error"raise aValueError. - public_key_path / private_key_path: paths to PEM key files
- encoding: attempt to decode decrypted bytes (defaults to 'utf-8')
- returns: decoded string or raw bytes
- envelope: dict or JSON string — the full postMessage envelope returned by
-
usethatapp.encryption.decrypt_message(private_key, encrypted_message) -> bytes
-
usethatapp.encryption.verify_signature(public_key, signature, message) -> bool
-
usethatapp.encryption.Keys: convenience class with these methods:
- read_public_key_from_string(pem_str)
- read_public_key_from_file(file_path)
- read_private_key_from_string(pem_str)
- read_private_key_from_file(file_path)
License
This project is licensed under the MIT License. details.
Links
- Homepage: https://github.com/UseThatApp/python
- Documentation: https://docs.usethatapp.com
- Changelog: https://github.com/UseThatApp/python/blob/main/CHANGELOG.md
Contact
For support: support@usethatapp.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file usethatapp-0.3.0.tar.gz.
File metadata
- Download URL: usethatapp-0.3.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cbc1f75cba742c9cf85f1cd4c3d2245fdca5d2b641d2d0473b3cb88be40c56c
|
|
| MD5 |
45fed20174093143a47393695bf6688f
|
|
| BLAKE2b-256 |
1decc4092990776c5b207df68177d14f9f6830804d671c806cc3a926ad7d582b
|
File details
Details for the file usethatapp-0.3.0-py3-none-any.whl.
File metadata
- Download URL: usethatapp-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
443e54d4ea93b3e80df286c79d11f7c8285972775828f847278c411e0264465e
|
|
| MD5 |
9374d63cb2527af4d0a38f43cfce7d5d
|
|
| BLAKE2b-256 |
a8f09ddb8ff5602f17f2506890c387da62b4103fae3df35f5677baa66a80e266
|