A modern Rust library providing Ed25519 cryptographic operations with UniFFI bindings for Python and Swift.
- ✅ Ed25519 key pair generation
- ✅ Message signing and verification
- ✅ Python bindings via UniFFI
- ✅ Swift bindings via UniFFI
- ✅ Comprehensive error handling
- ✅ Cross-platform support (macOS, Linux, Windows)
- ✅ Modern ed25519-dalek 2.x API
- ✅ UniFFI 0.29.4 compatibility
chmod +x setup.sh
./setup.sh
The setup script will:
- Install uniffi-bindgen if needed
- Build the Rust library
- Generate Python and Swift bindings
- Create example scripts
- Run automated tests
import ed25519_uniffi
# Generate keypair
keypair = ed25519_uniffi.generate_keypair()
# Sign message
message = b"Hello, World!"
signature = ed25519_uniffi.sign_message(list(message), keypair.get_private_key())
# Verify signature
is_valid = ed25519_uniffi.verify_signature(list(message), signature, keypair.get_public_key())
print(f"Signature valid: {is_valid}")
# Get hex representations
print(f"Public key: {keypair.get_public_key_hex()}")
print(f"Private key: {keypair.get_private_key_hex()}")
import ed25519_uniffi
// Generate keypair
let keypair = generateKeypair()
// Sign message
let message = Array("Hello, World!".utf8)
let signature = try signMessage(message: message, privateKey: keypair.getPrivateKey())
// Verify signature
let isValid = try verifySignature(message: message, signature: signature, publicKey: keypair.getPublicKey())
print("Signature valid: \(isValid)")
Generate a new random Ed25519 keypair.
Returns: A new keypair with 32-byte public and private keys.
Sign a message using an Ed25519 private key.
Parameters:
message
: The message bytes to signprivate_key
: 32-byte private key
Returns: 64-byte signature or error
verify_signature(message: Vec<u8>, signature: Vec<u8>, public_key: Vec<u8>) -> Result<bool, Ed25519Error>
Verify an Ed25519 signature.
Parameters:
message
: The original message bytessignature
: 64-byte signature to verifypublic_key
: 32-byte public key
Returns: true
if signature is valid, false
otherwise, or error
Create a keypair from an existing private key.
Parameters:
private_key
: 32-byte private key
Returns: Keypair with derived public key or error
Contains an Ed25519 public/private key pair.
Methods:
get_public_key() -> Vec<u8>
- Get 32-byte public keyget_private_key() -> Vec<u8>
- Get 32-byte private keyget_public_key_hex() -> String
- Get public key as hex stringget_private_key_hex() -> String
- Get private key as hex string
Error types for cryptographic operations:
InvalidPrivateKey
- Invalid private key format or lengthInvalidPublicKey
- Invalid public key format or lengthInvalidSignature
- Invalid signature format or lengthSigningFailed
- Signing operation failedVerificationFailed
- Verification operation failed
ed25519-uniffi/
├── Cargo.toml # Rust dependencies and configuration
├── build.rs # Build script for UniFFI
├── uniffi-bindgen.rs # UniFFI bindgen executable
├── setup.sh # Automated setup script
├── src/
│ ├── lib.rs # Main Rust library
│ └── udl/ # Generated UDL files
├── bindings/
│ ├── python/ # Generated Python bindings
│ └── swift/ # Generated Swift bindings
├── examples/
│ ├── python_example.py # Python usage example
│ └── swift_example.swift # Swift usage example
└── README.md # This file
This implementation fixes several critical issues from the original bash script:
- ✅ Fixed
#[export]
syntax →#[derive(uniffi::Object)]
for structs - ✅ Added proper
#[uniffi::export]
for functions - ✅ Included required
uniffi::setup_scaffolding!()
macro - ✅ Correct error handling with
#[derive(uniffi::Error)]
- ✅ Replaced deprecated
Keypair
,SecretKey
,PublicKey
- ✅ Used modern
SigningKey
,VerifyingKey
,Signature
types - ✅ Proper key generation with
SigningKey::generate(&mut OsRng)
- ✅ Correct signing/verification patterns
- ✅ Custom
Ed25519Error
enum with detailed error messages - ✅ Proper
Result<T, E>
return types - ✅ Input validation for key and signature lengths
- ✅ Organized directory layout with
bindings/
,examples/
,src/
- ✅ Proper build configuration with
build.rs
- ✅ UniFFI bindgen script setup
- ✅ Handles macOS, Linux, and Windows
- ✅ Automatic dependency checking and installation
- ✅ Integrated testing and validation
- ✅ Colored output and progress indicators
Run the automated test suite:
./setup.sh
Or test Python bindings manually:
cd examples
python3 python_example.py
- Rust 1.70+
- Python 3.7+ (for Python bindings)
- Swift 5.0+ (for Swift bindings)
- uniffi-bindgen 0.29.4 (automatically installed by setup script)
uniffi = "0.29.4"
- UniFFI frameworked25519-dalek = "2.2.0"
- Ed25519 cryptographyrand = "0.8"
- Random number generationhex = "0.4"
- Hex encoding utilitiesthiserror = "1.0"
- Error handling
MIT OR Apache-2.0
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests with
./setup.sh
- Submit a pull request
If you encounter build errors:
- Ensure you have Rust 1.70+ installed
- Update your Rust toolchain:
rustup update
- Clean and rebuild:
cargo clean && cargo build --release
If Python can't find the module:
- Ensure the shared library is in
bindings/python/
- Check that Python can access the bindings directory
- Verify Python version compatibility (3.7+)
For Swift bindings:
- Create a proper Swift package or Xcode project
- Include all generated files from
bindings/swift/
- Link against the shared library
- Ensure Swift 5.0+ compatibility
See the examples/
directory for complete usage examples in both Python and Swift.