# Enigma Protocol
A standalone orchestrator crate that wires identity, ratchet-style key evolution, packet framing, and AEAD wrapping into a cohesive messaging stack. It focuses on producing deterministic, testable flows that applications can embed without taking a dependency on storage or UI layers.
## Features
- In-memory double-ratchet style key schedule derived from pre-shared secrets
- Envelope encoding via `enigma-packet` and transport privacy via `enigma-aead`
- Attachment helpers (init, chunk, end) aligned with the packet schema
- Transport abstraction plus in-memory duplex transport for tests
- Async client orchestrator with event-driven receive path
## Quickstart
```rust
use std::sync::Arc;
use enigma_identity::LocalIdentity;
use enigma_protocol::{in_memory_duplex_pair, AttachmentKind, InitiatorOrResponder, MessengerClient, SessionBootstrap};
#[tokio::main]
async fn main() -> enigma_protocol::Result<()> {
let alice_identity = LocalIdentity::new("alice")?;
let bob_identity = LocalIdentity::new("bob")?;
let (transport_a, transport_b) = in_memory_duplex_pair(32);
let mut alice = MessengerClient::new(alice_identity, Arc::clone(&transport_a));
let mut bob = MessengerClient::new(bob_identity, Arc::clone(&transport_b));
let shared = [7u8; 32];
alice.ensure_session_with(
"bob",
SessionBootstrap::PreSharedSecret {
secret32: shared,
role: InitiatorOrResponder::Initiator,
remote_dh_pub: None,
},
)?;
bob.ensure_session_with(
"alice",
SessionBootstrap::PreSharedSecret {
secret32: shared,
role: InitiatorOrResponder::Responder,
remote_dh_pub: None,
},
)?;
alice.send_text("bob", "hello world").await?;
if let Some(event) = bob.poll_once().await? {
println!("received: {:?}", event);
}
let bytes = vec![0u8; 4096];
alice
.send_attachment_bytes(
"bob",
AttachmentKind::File,
Some("blob.bin"),
Some("application/octet-stream"),
&bytes,
1024,
)
.await?;
Ok(())
}
```
## Crate Relationships
| Local identity, bundles | `enigma-identity` |
| Ratchet key schedule | `enigma-double-ratchet` compatible adapter |
| Packet schema + validation | `enigma-packet` |
| AEAD and packet framing | `enigma-aead` |
| Optional WebRTC transport | `enigma-transport-webrtc` feature |
## Testing
Run `cargo test` to execute the unit and integration suite. All tests rely solely on the in-memory duplex transport.