| Crates.io | solana-ecies |
| lib.rs | solana-ecies |
| version | 0.1.1 |
| created_at | 2025-04-23 18:06:31.538543+00 |
| updated_at | 2025-04-23 18:11:35.626824+00 |
| description | ECIES encryption for Solana keypairs using X25519, AES-256-GCM, and HKDF |
| homepage | |
| repository | https://github.com/pupplecat/solana-ecies |
| max_upload_size | |
| id | 1646083 |
| size | 101,504 |
solana-ecies is a Rust library implementing the Elliptic Curve Integrated Encryption Scheme (ECIES) for Solana keypairs. It uses X25519 for key exchange, AES-256-GCM for encryption, and HKDF for key derivation. The library is designed to securely encrypt and decrypt data, such as challenges in Solana-based escrow systems, using Solana's Ed25519 keypairs converted to X25519.
This library is ideal for Solana developers building secure applications, such as escrow-based program, where sensitive data needs to be encrypted off-chain and decrypted by authorized parties.
Pubkey and Keypair) to X25519 for seamless use.Add solana-ecies to your Cargo.toml:
[dependencies]
solana-ecies = "0.1.0"
The library provides two main functions:
ecies_encrypt: Encrypts a 32-byte challenge under a recipient’s Solana public key (Pubkey).ecies_decrypt: Decrypts the ciphertext using the recipient’s Solana keypair (Keypair).use solana_ecies::{ecies_encrypt, ecies_decrypt};
use solana_sdk::{pubkey::Pubkey, signer::keypair::Keypair};
use rand::RngCore;
fn main() {
// Generate a recipient keypair
let recipient_keypair = Keypair::new();
let recipient_pubkey = recipient_keypair.pubkey();
// Generate a random 32-byte challenge
let challenge: [u8; 32] = rand::rng().random();
// Encrypt the challenge
let encrypted_challenge = ecies_encrypt(&recipient_pubkey, &challenge)
.expect("Encryption failed");
// Decrypt the challenge
let decrypted_challenge = ecies_decrypt(&recipient_keypair, &encrypted_challenge)
.expect("Decryption failed");
// Verify the result
assert_eq!(challenge, decrypted_challenge);
println!("Successfully encrypted and decrypted challenge!");
}
ed25519-dalek’s to_montgomery for public keys and SHA-512 hashing with clamping for secret keys, following RFC 7748.rand::rng().random() to prevent reuse.rand or OsRng).Keypair secret keys in a secure environment.challenge_hash in escrow applications to prevent unauthorized claims.Run unit tests to verify encryption and decryption:
cargo test
The library includes tests for:
Pubkey and Keypair types.Contributions are welcome! Please submit issues or pull requests to the GitHub repository. Ensure tests pass and follow Rust coding conventions.
This project is licensed under the MIT License (LICENSE)
Built for Solana developers creating secure escrow-based applications. Inspired by cryptographic best practices and the Solana ecosystem.