Metadata-Version: 2.4
Name: sibna
Version: 3.0.2
Summary: Sibna Protocol v3.0.2 — pure Python SDK (X3DH, Double Ratchet, sender-key groups, safety numbers, signed envelopes, encrypted storage, relay HTTP/WebSocket client)
Author-email: Sibna Security Team <security@sibna.dev>
License-Expression: Apache-2.0 OR MIT
Project-URL: Homepage, https://github.com/SibnaOfficial/libsa
Project-URL: Repository, https://github.com/SibnaOfficial/libsa
Project-URL: Documentation, https://github.com/SibnaOfficial/libsa#readme
Project-URL: Bug Tracker, https://github.com/SibnaOfficial/libsa/issues
Keywords: cryptography,encryption,signal,secure-messaging,e2ee,x3dh,double-ratchet,ml-kem-768
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Communications :: Chat
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=41.0
Requires-Dist: blake3>=1.0
Requires-Dist: pqcrypto>=0.3
Requires-Dist: requests>=2.31
Requires-Dist: aiohttp>=3.9
Dynamic: license-file

# Sibna Protocol — Python SDK

Pure-Python implementation of the Sibna Protocol (X3DH handshake, Double
Ratchet session encryption, sender-key group messaging, safety numbers,
envelope signing, encrypted storage, and the relay HTTP/WebSocket client).

No Rust core, FFI, or native library is required. All cryptography is provided
by maintained libraries (`cryptography`, `blake3`, `pqcrypto`).

Wire formats, domain-separation strings, KDF constructions, and limits match
the retained Rust core (`sibna-protc/core/`) and
`PROTOCOL_SPECIFICATION.md`.

Install:

    pip install sibna

## Capabilities

| Capability | Modules |
|---|---|
| Cryptographic primitives | `sibna.crypto` |
| X25519 / Ed25519 keys | `sibna.crypto.X25519KeyPair`, `Ed25519KeyPair` |
| ML-KEM-768 hybrid KEM | `sibna.crypto.ml_kem_768_*` |
| X3DH handshake | `sibna.x3dh` |
| Double Ratchet sessions | `sibna.ratchet`, `sibna.session` |
| Sender-key group messaging | `sibna.group` |
| Safety numbers | `sibna.safety_number` |
| Signed envelopes | `sibna.envelope` |
| Protocol padding | `sibna.padding` |
| Encrypted storage | `sibna.storage` |
| Synchronous HTTP relay client | `sibna.client.SibnaClient` |
| Asynchronous WebSocket relay client | `sibna.client.AsyncSibnaClient` |

## Quick start

```python
from sibna import (
    X25519KeyPair, Ed25519KeyPair, Session,
    generate_peer_bundle, make_signed_envelope,
    verify_signed_envelope,
)
from sibna.crypto import derive_identity_keys

# ── Alice creates her identity ──────────────────────────────────────
alice_ed = Ed25519KeyPair()
alice_x = X25519KeyPair()

# ── Bob creates his identity and prekey bundle ──────────────────────
bob_ed = Ed25519KeyPair()
bob_x = X25519KeyPair()
bob_spk = X25519KeyPair()
bob_opk = X25519KeyPair()

bob_bundle = generate_peer_bundle(
    identity_ed=bob_ed,
    identity_x25519=bob_x,
    signed_prekey=bob_spk,
    onetime_prekey=bob_opk,
    device_id_bytes=b"bob-device-01000",   # 16 bytes
    root_identity_key=bob_ed.public_key,
)

# ── Alice performs X3DH as initiator ────────────────────────────────
alice_session = Session()
ephemeral_pub = alice_session.initiate_as_initiator(
    identity=alice_x,
    ephemeral=X25519KeyPair(),
    peer_bundle=bob_bundle,
    our_device_id=b"alice-device-010",   # 16 bytes
    peer_device_id=b"bob-device-01000",   # 16 bytes
)

# ── Alice encrypts a message for Bob ────────────────────────────────
plaintext = b"Hello Bob from Alice via Sibna Protocol v3.0.2!"
ciphertext = alice_session.encrypt(plaintext, associated_data=b"v3.0.2")

# ── Alice creates a signed envelope to send over the relay ──────────
envelope = make_signed_envelope(
    alice_ed,
    recipient_id=bob_ed.public_key.hex(),
    payload_hex=ciphertext.hex(),
)
assert verify_signed_envelope(envelope)

# ── Bob establishes his side of the session and decrypts ────────────
bob_session = Session()
bob_session.initiate_as_responder(
    identity=bob_x,
    signed_prekey=bob_spk,
    onetime_prekey=bob_opk,
    peer_identity=alice_x.public_key,
    peer_ephemeral=ephemeral_pub,
    our_device_id=b"bob-device-01000",
    peer_device_id=b"alice-device-010",
)
decrypted = bob_session.decrypt(ciphertext, associated_data=b"v3.0.2")
assert decrypted == plaintext

print("Sibna SDK quick start: OK")
```

The package works offline for all cryptographic operations. The relay client
(`SibnaClient`, `AsyncSibnaClient`) requires a running Sibna relay server
(see `sibna-protc/server/`) and a valid JWT obtained through the Ed25519
challenge-response flow.

## Installation

```bash
pip install sibna
```

Supported: Python 3.9+ on Linux, macOS, and Windows.

Runtime dependencies: `cryptography`, `blake3`, `pqcrypto`, `requests`,
`aiohttp`.

## Development

```bash
pip install -e ".[dev]"
python -m pytest tests/
black --check sibna tests
mypy sibna
```

## Security

This SDK implements the Sibna Protocol v3.0.2. It has not received an
independent cryptographic audit. Do not describe it as formally verified or
production-ready without supporting evidence. See `SECURITY.md` and
`THREAT_MODEL.md` in `sibna-protc`.

License: Apache-2.0 OR MIT.
