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.4.0.tar.gz (776.0 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.4.0-py3-none-any.whl (777.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sibna-1.4.0.tar.gz
Algorithm Hash digest
SHA256 60ca098eb4e7c138be77cb4b9cb43861790be32dd7999c4f8f78b07b8b457e2a
MD5 f015571cfc0843f1a84090e529329051
BLAKE2b-256 061f6a1eb20d92a6f94a09aa42093cc91fe7676d412e74afbcad0452036d9fa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sibna-1.4.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.4.0-py3-none-any.whl.

File metadata

  • Download URL: sibna-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 777.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aed77a8e8cf0ee7f32b2a937c2c6e01ad707b2ab56a66af58f0cda2e66ccadcb
MD5 c66366f19190a40ad6e92e1622d78dbb
BLAKE2b-256 42e0530e8430ad1d1bac650d0926db8bf236aac93cc679f88f4fb985a5b62ed5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sibna-1.4.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