Skip to main content

Standalone Ultra-Secure Communication Protocol - Python SDK

Project description

Sibna Protocol — Python SDK

Python SDK for the Sibna encrypted communication protocol.


Before You Start — What You Need

This SDK does not work standalone. It requires a compiled native library built from the sibna-protc Rust project:

OS Required File
Windows sibna_core.dll
Linux libsibna_core.so
macOS libsibna_core.dylib

To build the library:

cd sibna-protc/core
cargo build --release --features ffi
# Output is in: target/release/

Then copy the resulting file into the same sibna/ folder as this SDK.


Installation

# External dependencies (this SDK is NOT zero-dependencies)
pip install cryptography          # For Identity + signature verification
pip install requests              # For the sync HTTP client
pip install aiohttp               # For async + WebSocket

What This SDK Does

sibna (core — requires the compiled native library)

Function / Class What it does
is_available() Checks if the native library is loaded
generate_key() Generates a random 32-byte key
encrypt(key, data) Encrypts data (ChaCha20-Poly1305)
decrypt(key, data) Decrypts data
random_bytes(n) Generates cryptographically secure random bytes
Context() Manages identity and encrypted sessions
Context.generate_identity() Generates an identity keypair (Ed25519 + X25519)
Context.generate_prekey_bundle() Generates a bundle to upload to the prekey server
Context.perform_handshake(...) Runs X3DH and creates a Double Ratchet session
Context.session_encrypt(...) Encrypts a message over an existing session
Context.session_decrypt(...) Decrypts a message

sibna.client (networking — requires requests / aiohttp)

Class What it does
Identity Ed25519 keypair for server authentication
SibnaClient Synchronous HTTP client
AsyncSibnaClient Async + WebSocket client

Basic Example — Simple Encryption

import sibna

# Check the library is available
if not sibna.is_available():
    raise RuntimeError("Native library not found. Build it from sibna-protc first.")

# Encrypt and decrypt
key = sibna.generate_key()          # Random 32-byte key
ct  = sibna.encrypt(key, b"Hello")
pt  = sibna.decrypt(key, ct)
assert pt == b"Hello"

# With associated data (authenticated but not encrypted)
ct  = sibna.encrypt(key, b"Secret", associated_data=b"context-header")
pt  = sibna.decrypt(key, ct, associated_data=b"context-header")

Advanced Example — Double Ratchet Session

import sibna

# On Alice's device
alice_ctx = sibna.Context(password=b"AlicePass1!")
alice_ed, alice_x = alice_ctx.generate_identity()
alice_bundle = alice_ctx.generate_prekey_bundle()

# On Bob's device
bob_ctx = sibna.Context(password=b"BobPass1!")
bob_ed, bob_x = bob_ctx.generate_identity()
bob_bundle = bob_ctx.generate_prekey_bundle()

# Alice initiates the handshake with Bob
alice_ctx.perform_handshake(
    peer_id=bob_ed,          # Bob's identity key (used as session ID)
    peer_bundle=bob_bundle,  # Bob's bundle (fetched from prekey server)
    initiator=True,
)

# Bob accepts the handshake from Alice
bob_ctx.perform_handshake(
    peer_id=alice_ed,
    peer_bundle=alice_bundle,
    initiator=False,
)

# Alice encrypts
ciphertext = alice_ctx.session_encrypt(bob_ed, b"Hello Bob!")

# Bob decrypts
plaintext = bob_ctx.session_decrypt(alice_ed, ciphertext)
assert plaintext == b"Hello Bob!"

Example — HTTP Client

from sibna.client import SibnaClient
import sibna

# Set up encryption context
ctx = sibna.Context()
ctx.generate_identity()
bundle = ctx.generate_prekey_bundle()

# Connect to server
client = SibnaClient(server="http://localhost:8080")
client.generate_identity()   # Separate identity for server auth
client.authenticate()         # JWT challenge-response flow
client.upload_prekey(bundle.hex())

# Send an encrypted message (payload is pre-encrypted by Context)
ciphertext = ctx.session_encrypt(b"peer_id_here", b"Hello!")
client.send_message(
    recipient_id="peer_identity_hex",
    payload_hex=ciphertext.hex(),
)

# Receive messages
messages = client.fetch_inbox()
for msg in messages:
    plaintext = ctx.session_decrypt(
        bytes.fromhex(msg["sender_id"]),
        bytes.fromhex(msg["payload_hex"]),
    )
    print(plaintext.decode())

Common Errors

Error Cause Fix
LibraryNotFoundError Native library not found Build sibna-protc with Rust
SibnaError(13) Tampered data or wrong key Check key and associated_data
SibnaError(7) Session does not exist Call perform_handshake() first
SibnaError(10) Weak password Use a password with uppercase, lowercase, and digits
MissingDependencyError Python package not installed pip install cryptography requests aiohttp

A Note on Dependencies

This SDK is not zero-dependencies:

  • __init__.py requires the compiled Rust native library
  • client.py requires cryptography, requests, and aiohttp

The Rust core itself has no runtime dependencies once compiled.


License

Apache-2.0

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

sibna-1.7.0.tar.gz (778.5 kB view details)

Uploaded Source

Built Distribution

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

sibna-1.7.0-py3-none-any.whl (780.2 kB view details)

Uploaded Python 3

File details

Details for the file sibna-1.7.0.tar.gz.

File metadata

  • Download URL: sibna-1.7.0.tar.gz
  • Upload date:
  • Size: 778.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sibna-1.7.0.tar.gz
Algorithm Hash digest
SHA256 a997f3758e4167905a0c8e753d1d0f39b1d1ab2be2e56c854a8910588ba3e39f
MD5 4be667c9a549406d36bebc799c18e07e
BLAKE2b-256 f8f4111f350b6aca46d6ab5cde81727bfcb4cc9aab2272c732ef1779c5ab59dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for sibna-1.7.0.tar.gz:

Publisher: workflow.yml on SibnaOfficial/libsa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sibna-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: sibna-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 780.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sibna-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a76aa6f246d1e3d272a334280169bba6f188cf92e43cb6ab520d84bc773f5129
MD5 c3005661850b9d93b9f61c7e9864f750
BLAKE2b-256 32246693eb33ba19b9e472f1e516a4c688c194c0c70989573f4413e05da291e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sibna-1.7.0-py3-none-any.whl:

Publisher: workflow.yml on SibnaOfficial/libsa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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