Metadata-Version: 2.5
Name: quantumpipe
Version: 0.1.0
Summary: Quantum resistant hybrid ML-KEM-768 + X25519 key exchange with ChaCha20-Blake3 AEAD
License: MIT
Requires-Python: >=3.12
Requires-Dist: blake3>=1.0.10
Requires-Dist: chab3>=0.1.0
Requires-Dist: cryptography>=50.0.2
Description-Content-Type: text/markdown

# quantumpipe

PSK-bootstrapped, mutually authenticated key exchange using hybrid ML-KEM-768 and X25519, with ChaCha20-Blake3 encrypted transport. Includes a sans-I/O protocol state machine and an asyncio WebSocket wrapper.

**Draft version 0.1.0:** The protocol and API are still likely to change. Do not use in production.

## Features

- **Registration:** establishes a persistent peer credential from a one-time shared registration secret, with out-of-band short authentication string verification.
- **Resumption:** authenticates subsequent connections using the stored credential and fresh ephemeral keys.
- **Encrypted traffic:** ordered, authenticated bidirectional channels with application-defined message kinds.
- **Flexible integration:** drive `Session` directly over any transport, or use `SecSocket` with `websockets` and FastAPI/Starlette-style connections.
- **Credential lifecycle:** atomic registration rotation, concurrent-registration arbitration, and verified/unverified state.

## Installation

```console
pip install quantumpipe
```

Python 3.12 or newer is required. Install `websockets` separately when using the WebSocket wrapper with the `websockets` library.

## Sans-I/O usage

Both sides initially receive the same registration secret out of band. The initiator selects its link ID; the responder discovers it while processing the first message.

```python
from quantumpipe import Message, Session, generate_registration_secret

secret = generate_registration_secret()
alice = Session({"peer": secret}, "peer")
bob = Session({"peer": secret})

msg1, = alice()
msg2, = bob(msg1)
msg3, = alice(msg2)
verification, = bob(msg3)

# Compare verification.sas on both sides through an authenticated
# out-of-band channel before accepting it. None proceeds unverified.
verification.answer = True
msg4, = bob(verification)
verification, = alice(msg4)
assert verification.answer is None
verification.answer = True
msg5, established = alice(verification)
bob_established, = bob(msg5)

frame, = alice(Message(b"hello", kind=1))
assert bob(frame) == [Message(b"hello", kind=1)]
```

After registration, persist each mutated store and use its composite credential for the next connection. Resumption completes in three messages and does not request another comparison. Application storage and persistence are deliberately outside the library.

## WebSocket usage

```python
from quantumpipe import SecSocket, Verification

async def verify(v: Verification) -> bool:
    return await compare_out_of_band(v.sas)

sock = SecSocket(
    websocket,
    store,
    "peer",  # omit on the responding side
    handlers={Verification: verify},
)
await sock.connect()  # use accept() on the responding side
await sock.send(b"hello")
message = await sock.receive()
await sock.close()
```

The entire handshake, including verification callbacks, has a 15-second default timeout configurable with `handshake_timeout`.

See `demo/client.py` and `demo/server.py` for a runnable example. Protocol details are in `docs/protocol.md`; state, storage, and error-handling policies are in `docs/design.md`.

## Development

```console
uv run pytest
uv build
```

The package version is derived from Git tags using `hatch-vcs`.

## License

MIT
