Skip to main content

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 failures
  • EnSyncAuthError: Authentication failures
  • EnSyncPublishError: Event publishing failures
  • EnSyncSubscriptionError: Subscription failures
  • EnSyncValidationError: 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 encrypt
  • recipient_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 structure
  • private_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 encrypt
  • recipient_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 payload
  • encrypted_key (str): Encrypted message key for this recipient
  • private_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ensync_core-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ensync_core-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file ensync_core-0.1.1.tar.gz.

File metadata

  • Download URL: ensync_core-0.1.1.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

Hashes for ensync_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7ccc1ef0cc66ad598296433dd4f1fae5286dea3c24c6ff9ea0f773c630b548ed
MD5 e9c4fbde2795718b1f3cf36e9583c0e7
BLAKE2b-256 c2618c251962a884b7a56ea45fe9276cdcd7a6b74079282b66e9ceba2a2ca890

See more details on using hashes here.

File details

Details for the file ensync_core-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ensync_core-0.1.1-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

Hashes for ensync_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bffff95fc0c0c4246323eac8f3f6528974ced20f1fb9df6c7931d6b2c81b2ce4
MD5 f5a3746a4b1f4955daebc1a579150f60
BLAKE2b-256 4453152a2618ba8179969e50280f813ef36cd2c2f36c4cd6bbffc4068e1e8d4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page