- Rust 1.70+ - Latest stable Rust compiler
- Cargo - Rust package manager
- Git - Version control system
[dependencies]
privacy-engine = "0.1.0"cargo builduse privacy_engine::encrypt::encrypt_message;
use privacy_engine::decrypt::decrypt_shared_secret;
use privacy_engine::types::{RecipientInfo, Protocol, EncryptResult};
use aes_gcm::{Aes256Gcm, aead::{Aead, KeyInit}, Key, Nonce};// Prepare your message
let message = b"Hello, secure world!";
// Define recipients
let recipients = vec![
RecipientInfo {
pubkey: user1_pubkey, // Vec<u8> - recipient's public key
protocol: Protocol::Starknet,
},
RecipientInfo {
pubkey: user2_pubkey, // Vec<u8> - recipient's public key
protocol: Protocol::X25519,
},
];
// Encrypt the message
let result: EncryptResult = encrypt_message(message, recipients)?;// For each recipient, decrypt using their private key
let recipient_key = &result.recipient_keys[0]; // Get the first recipient's wrapped key
// Unwrap the symmetric key using recipient's private key
let symmetric_key = decrypt_shared_secret(&recipient_private_key, recipient_key)?;
// Decrypt the message using the symmetric key
let cipher = Aes256Gcm::new(Key::<Aes256Gcm>::from_slice(&symmetric_key));
let nonce = Nonce::from_slice(&result.nonce);
let plaintext = cipher.decrypt(nonce, result.ciphertext.as_ref())?;
println!("Decrypted message: {}", String::from_utf8_lossy(&plaintext));Create a .env file in your project root:
# User 1 (Primary)
TEST_PRIVKEY=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
TEST_PUBKEY=0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890
TEST_MSG_HASH=0xdeadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234567890
# User 2 (Optional)
USER2_PRIVATEKEY=0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba
USER2_PUBLICKEY=0xfedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210cargo testcargo test --test starknet_multi -- --nocaptureThis will run the multi-recipient encryption test with detailed, formatted output showing each stage of the encryption/decryption process.
privacy-engine/ βββ src/ β βββ encrypt.rs # Main encryption functionality β βββ decrypt.rs # Decryption utilities β βββ types.rs # Core data structures β βββ traits/ β β βββ crypto.rs # Cryptographic protocol trait β βββ chains/ β βββ starknet.rs # Starknet protocol implementation β βββ x25519.rs # X25519 protocol implementation βββ tests/ β βββ starknet_multi.rs # Integration tests βββ docs/ # Documentation
use privacy_engine::encrypt::encrypt_message;
use privacy_engine::types::{RecipientInfo, Protocol};
// Encrypt for multiple recipients with different protocols
let message = b"Hello, secure world!";
let recipients = vec![
RecipientInfo {
pubkey: starknet_user_pubkey,
protocol: Protocol::Starknet,
},
RecipientInfo {
pubkey: x25519_user_pubkey,
protocol: Protocol::X25519,
},
];
let result = encrypt_message(message, recipients)?;
println!("Encrypted for {} recipients", result.recipient_keys.len());use privacy_engine::chains::starknet::StarknetProtocol;
use privacy_engine::chains::x25519::X25519Protocol;
// Starknet signing and verification
let starknet = StarknetProtocol;
let signature = starknet.sign_message(&private_key, &message_hash)?;
let is_valid = starknet.verify_signature(&public_key, &message_hash, &signature)?;
// X25519 key generation
let x25519 = X25519Protocol::new();
let (private_key, public_key) = x25519.generate_keypair()?;Check that your `.env` file is properly formatted and located in the project root.
- π Documentation: Check the API Reference for detailed function documentation
- π‘ Examples: Review the Examples for working code samples
- π Issues: Open an issue on GitHub for bugs or feature requests
- π¬ Discussions: Join community discussions for help and ideas
Ready to build secure, multi-protocol applications? π