Crates.io | ether-link |
lib.rs | ether-link |
version | 0.1.1 |
source | src |
created_at | 2025-04-22 00:02:38.413791+00 |
updated_at | 2025-05-21 01:39:40.356584+00 |
description | lightweight rust library for ethereum communication |
homepage | |
repository | https://github.com/bongkow/ether-link |
max_upload_size | |
id | 1643385 |
size | 139,140 |
A lightweight Rust library focused on enabling secure communication between Ethereum address owners. Ether-Link provides simple yet powerful tools for Ethereum key management, message signing, signature verification, and end-to-end encryption - allowing Ethereum wallet owners to securely exchange both authenticated and encrypted messages. Using EIP-5630 compliant ECIES encryption, address owners can communicate privately by encrypting messages that only specific Ethereum addresses can decrypt, while maintaining message authenticity through cryptographic signatures.
Ether-Link is specifically designed to facilitate:
Add this to your Cargo.toml
:
[dependencies]
ether-link = "0.1.1"
Ether-Link enables a simple communication pattern between Ethereum address owners:
use ether_link::Wallet;
fn main() {
// Generate a fresh Ethereum key pair
let wallet = Wallet::new();
println!("Private Key: {}", wallet.privkey);
println!("Ethereum Address: {}", wallet.address);
println!("Compressed Public Key: {}", wallet.pubkey_compressed);
println!("Uncompressed Public Key: {}", wallet.pubkey_uncompressed);
}
use ether_link::Wallet;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a wallet using an existing private key
// warning: Do not send anything to the wallet below.
let private_key = "0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d";
let wallet = Wallet::from_private_key(Some(private_key))?;
println!("Ethereum Address: {}", wallet.address);
// Should print: 0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b
Ok(())
}
use ether_link::Wallet;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let wallet = Wallet::new();
let message = "Hello, Ethereum!";
let signature_json = wallet.sign_message(message).await?;
println!("Signature: {}", signature_json);
Ok(())
}
use ether_link::Wallet;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let wallet = Wallet::new();
let message = "Secret message for recipient!";
let recipient_pubkey = "0x027a4066efb9f66a65cf5f30c5ccdc7c0cdd9608f699eb3c5da2172ea2f6f579dc"; // Recipient's compressed public key
let encrypted = wallet.encrypt_message(message, recipient_pubkey)?;
println!("Encrypted: {}", encrypted);
Ok(())
}
use ether_link::Wallet;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let wallet = Wallet::new(); // The recipient's wallet
let encrypted_message = "0x0123..."; // Encrypted message from sender
let decrypted = wallet.decrypt_message(encrypted_message)?;
println!("Decrypted message: {}", decrypted);
Ok(())
}
use ether_link::EthereumSignature;
use serde_json::Value;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Assume signature_json is the output from sign_message
let signature_json: Value = serde_json::from_str(&signature_json_str)?;
let address = signature_json["address"].as_str().unwrap();
let signed_message = signature_json["signed_message"].as_str().unwrap();
let signature = signature_json["signature"].as_str().unwrap();
let eth_signature = EthereumSignature::new(
address.to_string(),
signed_message.to_string(),
signature.to_string()
);
let is_valid = eth_signature.verify()?;
println!("Signature is valid: {}", is_valid);
Ok(())
}
Wallet
: Core structure for generating and managing Ethereum key pairsnew()
: Create a new random walletfrom_private_key()
: Create a wallet from an existing private keysign_message()
: Async method to sign messages with timestamps for securityencrypt_message()
: Method to encrypt messages using EIP-5630 compliant ECIES (Elliptic Curve Integrated Encryption Scheme) with AES-256-GCM encryption and HKDF key derivation for a specific recipient's public keydecrypt_message()
: Method to decrypt ECIES encrypted messages (EIP-5630) using AES-256-GCM decryption with HKDF key derivation for messages encrypted for this walletEthereumSignature
: Structure to verify signed messages against Ethereum addressesThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)