rustywallet-keys
Secure secp256k1 private and public key management for cryptocurrency applications.
Features
- 🔐 Secure Key Generation - CSPRNG-based random key generation
- 📥 Multiple Import Formats - Hex, WIF, raw bytes
- 📤 Multiple Export Formats - Hex, WIF, decimal, raw bytes
- 🔑 Public Key Derivation - Compressed and uncompressed formats
- 🛡️ Secure Memory - Automatic zeroization on drop
- ✅ Validation - Comprehensive key validation
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use *;
// Generate a random private key
let private_key = random;
// Export to various formats
println!;
println!;
println!;
// Derive public key
let public_key = private_key.public_key;
println!;
Import Private Key
use *;
// From hex string
let key = from_hex?;
// From WIF
let key = from_wif?;
// From bytes
let bytes = ;
let key = from_bytes?;
Export Formats
use *;
let key = random;
// Hex (64 characters)
let hex = key.to_hex;
// WIF (Wallet Import Format)
let wif_mainnet = key.to_wif; // Starts with 'K' or 'L'
let wif_testnet = key.to_wif; // Starts with 'c'
// Decimal
let decimal = key.to_decimal;
// Raw bytes
let bytes: = key.to_bytes;
Public Key
use *;
let private_key = random;
let public_key = private_key.public_key;
// Compressed format (33 bytes, starts with 02 or 03)
let compressed = public_key.to_compressed;
let compressed_hex = public_key.to_hex;
// Uncompressed format (65 bytes, starts with 04)
let uncompressed = public_key.to_uncompressed;
let uncompressed_hex = public_key.to_hex;
Security
- Private keys are automatically zeroized when dropped
- Uses
secp256k1crate for cryptographic operations - Uses OS-level CSPRNG (
OsRng) for key generation
License
MIT License - see LICENSE for details.
Part of rustywallet
This crate is part of the rustywallet ecosystem.