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 hierarchy for EnSync operations. Exposed through ensync_core.error.

Common Error Types:

  • EnSyncConnectionError: Connection failures
  • EnSyncAuthError: Authentication failures
  • EnSyncPublishError: Message publishing failures
  • EnSyncSubscriptionError: Message 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.2.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.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ensync_core-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 64a54fcd55917260af69aca61471614b2506e5b17d6aa951d90c07d425ad8b93
MD5 701393fc82b417dc77464f3b43c6d9d3
BLAKE2b-256 47f3db702e261c237b3d35fc8f750f73597462ceef0d1c3f03649450599a540e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ensync_core-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba54daac6b08990caf2894bd199aaa278c2c2318b525657da8d2bf1294f2b0fa
MD5 496cfd64b76d4417e17f0c2af9da62c3
BLAKE2b-256 5eb92e8f6c880eb778a5c0452e7bc09f0f83333b9a6e5a549d3eb69ce7666cfe

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