rs-algochat
Pre-1.0 Notice: This library is under active development. The API may change between minor versions until 1.0.
Rust implementation of the AlgoChat protocol for encrypted messaging on Algorand.
Installation
Add to your Cargo.toml:
[]
= "0.2"
Usage
Client API
use ;
// Create client from a 32-byte seed
let client = from_seed.await?;
// Discover a recipient's public key on-chain
let key = client.discover_key.await?;
// Encrypt a message
let recipient_pk = key.unwrap.public_key;
let envelope = client.encrypt?;
// Decrypt a received message
let text = client.decrypt?;
// Sync and process new messages
let messages = client.sync.await?;
Low-Level Crypto
use ;
let = derive_keys_from_seed?;
let = derive_keys_from_seed?;
let envelope = encrypt_message?;
let encoded = envelope.encode;
let decoded = decode?;
let result = decrypt_message?;
Protocol
AlgoChat uses:
- X25519 for key agreement
- ChaCha20-Poly1305 for authenticated encryption
- HKDF-SHA256 for key derivation
The protocol supports bidirectional decryption, allowing senders to decrypt their own messages.
PSK Protocol (v1.1)
The PSK (Pre-Shared Key) protocol extends AlgoChat with an additional layer of symmetric key security:
- Hybrid encryption: Combines X25519 ECDH with a pre-shared key
- Two-level ratchet: Session + position derivation for forward secrecy
- Replay protection: Counter-based state tracking with configurable window
- Exchange URI: Out-of-band key sharing via
algochat-psk://URIs - Zeroized key material: Sensitive keys are zeroized after use
PSK Usage (Client API)
The AlgoChatClient manages PSK contacts and counter state automatically:
use ;
let client = from_seed.await?;
// Add a PSK contact (exchanged out-of-band via URI)
let uri = decode?;
client.add_psk_contact.await;
// Send — counter management is automatic
let = client.send_psk.await?;
// Receive — replay protection is automatic
let text = client.receive_psk.await?;
Low-Level PSK API
For direct control over encryption and counters:
use ;
let psk = ;
let mut state = new;
// Encrypt with PSK
let counter = state.advance_send_counter;
let envelope = encrypt_psk_message?;
// Encode for transmission
let encoded = encode_psk_envelope;
// Decode and decrypt
let decoded = decode_psk_envelope?;
let text = decrypt_psk_message?;
Cross-Implementation Compatibility
This implementation is fully compatible with:
- swift-algochat (Swift)
- ts-algochat (TypeScript)
- py-algochat (Python)
- kt-algochat (Kotlin)
License
MIT