Core utilities for EnSync SDK - encryption, decryption, and error handling
Project description
EnSync Core
Core utilities for EnSync SDK packages. This package provides shared functionality including encryption, error handling, and common utilities.
Features
- End-to-End Encryption: Ed25519 elliptic curve cryptography
- Hybrid Encryption: AES-GCM with Ed25519 key exchange for multi-recipient scenarios
- Error Handling: Unified error classes for EnSync operations
- Type Safety: Full type hints for better IDE support
Installation
pip install ensync-core
Note: This package is automatically installed as a dependency of ensync-sdk and ensync-sdk-ws. You typically don't need to install it directly.
Usage
Error Handling
from ensync_core import EnSyncError
try:
# Your EnSync operations
pass
except EnSyncError as e:
print(f"EnSync error: {e}")
print(f"Error type: {e.error_type}")
Encryption Utilities
For advanced use cases, you can use the encryption utilities directly:
from ensync_core.ecc_crypto import (
encrypt_ed25519,
decrypt_ed25519,
hybrid_encrypt,
hybrid_decrypt
)
# Traditional Ed25519 encryption (single recipient)
encrypted_data = encrypt_ed25519(payload_bytes, recipient_public_key)
decrypted_data = decrypt_ed25519(encrypted_data, private_key)
# Hybrid encryption (multiple recipients)
encrypted = hybrid_encrypt(payload_bytes, [recipient_key1, recipient_key2])
# Returns: {"encryptedPayload": "...", "encryptedKeys": {"recipientId": "..."}}
API Reference
EnSyncError
Custom exception class for EnSync operations.
class EnSyncError(Exception):
def __init__(self, message: str, error_type: str = "EnSyncGenericError"):
self.message = message
self.error_type = error_type
Common Error Types:
EnSyncConnectionError: Connection failuresEnSyncAuthError: Authentication failuresEnSyncPublishError: Event publishing failuresEnSyncSubscriptionError: Subscription failuresEnSyncValidationError: Input validation errors
Encryption Functions
encrypt_ed25519(data: bytes, recipient_public_key: bytes) -> dict
Encrypts data using Ed25519 public key cryptography.
Parameters:
data(bytes): Data to encryptrecipient_public_key(bytes): Recipient's public key
Returns: Dictionary with encrypted data structure
decrypt_ed25519(encrypted_data: dict, private_key: str) -> str
Decrypts Ed25519 encrypted data.
Parameters:
encrypted_data(dict): Encrypted data structureprivate_key(str): Private key for decryption
Returns: Decrypted data as string
hybrid_encrypt(data: bytes, recipient_keys: list[bytes]) -> dict
Encrypts data for multiple recipients using hybrid encryption (AES-GCM + Ed25519).
Parameters:
data(bytes): Data to encryptrecipient_keys(list[bytes]): List of recipient public keys
Returns: Dictionary with encrypted payload and per-recipient keys
hybrid_decrypt(encrypted_payload: str, encrypted_key: str, private_key: str) -> str
Decrypts hybrid encrypted data.
Parameters:
encrypted_payload(str): Encrypted payloadencrypted_key(str): Encrypted message key for this recipientprivate_key(str): Private key for decryption
Returns: Decrypted data as string
Security
Encryption Details
- Algorithm: Ed25519 (Curve25519) for asymmetric encryption
- Hybrid Mode: AES-256-GCM for payload, Ed25519 for key exchange
- Key Size: 32 bytes (256 bits)
- Nonce: Randomly generated for each encryption
Best Practices
- Never log or expose private keys
- Store keys securely (use environment variables or key management systems)
- Validate all inputs before encryption/decryption
- Use hybrid encryption for multi-recipient scenarios to improve performance
Related Packages
- ensync-sdk: Main SDK with gRPC client (recommended)
- ensync-sdk-ws: WebSocket alternative client
Documentation
For complete documentation, visit:
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
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 ensync_core-0.1.0.tar.gz.
File metadata
- Download URL: ensync_core-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8bbff54f3e803248e9f8a23c34dd35e9ed99970ccd30549b548851ceec2df92
|
|
| MD5 |
1ce82d05d768dc2417654fdce2d3ae27
|
|
| BLAKE2b-256 |
d7880a66f541c8faa48ce9de0c7437db4938a82e7a65fb9b34b85b1aaf199e70
|
File details
Details for the file ensync_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ensync_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c189f5b927ed14048e5ede7bcf861bf821ad37cbece72f261c1b8c5d0e0bd64f
|
|
| MD5 |
647f11cbb8dcff7318410bed21394dcc
|
|
| BLAKE2b-256 |
e52e52382844d5917546e40cbc5ed8314edf1dfd02966aa76c9b5affc2473f4f
|