| Crates.io | nostr-double-ratchet |
| lib.rs | nostr-double-ratchet |
| version | 0.0.43 |
| created_at | 2026-01-24 21:01:54.379898+00 |
| updated_at | 2026-01-25 12:03:27.11119+00 |
| description | Nostr double ratchet library for Rust |
| homepage | |
| repository | https://files.iris.to/#/npub1xndmdgymsf4a34rzr7346vp8qcptxf75pjqweh8naa8rklgxpfqqmfjtce/nostr-double-ratchet |
| max_upload_size | |
| id | 2067487 |
| size | 185,007 |
Rust implementation of the Double Ratchet protocol for Nostr, providing forward-secure end-to-end encrypted messaging.
Based on Signal's Double Ratchet with header encryption, this crate implements secure session management over Nostr events. Messages are encrypted using NIP-44 and the double ratchet algorithm ensures forward secrecy even if keys are compromised.
use nostr_double_ratchet::{Session, Result};
use nostr::Keys;
// Initialize sessions
let alice_keys = Keys::generate();
let bob_keys = Keys::generate();
let shared_secret = [0u8; 32]; // Exchange securely via invite mechanism
let mut alice = Session::init(
bob_pubkey,
alice_keys.secret_key().to_secret_bytes(),
true, // initiator
shared_secret,
Some("alice".to_string()),
)?;
let mut bob = Session::init(
alice_pubkey,
bob_keys.secret_key().to_secret_bytes(),
false, // responder
shared_secret,
Some("bob".to_string()),
)?;
// Send encrypted message
let event = alice.send("Hello Bob!".to_string())?;
// Receive and decrypt
let plaintext = bob.receive(&event)?;
Run the test suite:
cargo test -p nostr-double-ratchet
Tests cover:
Session - Core double ratchet implementationSessionState - Serializable session state with all keys and countersHeader - Message metadata (sequence number, next public key, chain length)Core functionality complete. SessionManager and Invite mechanisms are stubs for future implementation.