| Crates.io | sol-safekey |
| lib.rs | sol-safekey |
| version | 0.1.0 |
| created_at | 2025-10-03 14:57:06.548591+00 |
| updated_at | 2025-10-03 14:57:06.548591+00 |
| description | A powerful command-line tool for secure Solana key management with Triple-Factor 2FA |
| homepage | https://github.com/0xfnzero/sol-safekey |
| repository | https://github.com/0xfnzero/sol-safekey |
| max_upload_size | |
| id | 1866796 |
| size | 433,817 |
Securely generate, manage, and encrypt Solana private keys with military-grade triple-factor authentication combining hardware fingerprint, master password, security question, and 2FA verification.
ไธญๆ | English | Website | Telegram | Discord
| Document | Description | Language |
|---|---|---|
| README.md | Complete project overview, CLI usage | English |
| README_CN.md | ๅฎๆด้กน็ฎๆฆ่ฟฐใCLI ไฝฟ็จ | ไธญๆ |
| INTEGRATION.md | Library integration guide | English |
| INTEGRATION_CN.md | ๅบ้ๆๆๅ | ไธญๆ |
| SOLANA_OPS.md | Solana operations (transfer, balance) | English |
| SOLANA_OPS_CN.md | Solana ๆไฝ๏ผ่ฝฌ่ดฆใไฝ้ข๏ผ | ไธญๆ |
| LIBRARY_VS_CLI.md | Library vs CLI comparison | English |
| LIBRARY_VS_CLI_CN.md | ๅบ vs CLI ๅฏนๆฏ | ไธญๆ |
Quick Navigation:
The Most Secure Wallet Protection Available! Sol SafeKey now features a revolutionary Triple-Factor Authentication System that combines:
This means your wallet requires all four components to unlock - making it virtually impossible for attackers to access your funds even if they steal your encrypted wallet file!
# Step 1: Setup 2FA (one-time setup)
sol-safekey setup-2fa
# Step 2: Generate your secure wallet
sol-safekey gen-2fa-wallet -o my-secure-wallet.json
# Step 3: Unlock your wallet when needed
sol-safekey unlock-2fa-wallet -f my-secure-wallet.json
What happens during generation:
Add to your Cargo.toml:
[dependencies]
sol-safekey = "0.1.0"
This installs the minimal library without CLI dependencies - perfect for integration into your Rust projects.
Optional features:
# Enable 2FA features (hardware fingerprint, TOTP, etc.)
sol-safekey = { version = "0.1.0", features = ["2fa"] }
# Enable Solana operations (balance, transfer, etc.)
sol-safekey = { version = "0.1.0", features = ["solana-ops"] }
# Enable all features
sol-safekey = { version = "0.1.0", features = ["full"] }
Quick Example:
use sol_safekey::KeyManager;
fn main() {
// Generate new keypair
let keypair = KeyManager::generate_keypair();
// Encrypt with password
let encrypted = KeyManager::encrypt_with_password(
&keypair.to_base58_string(),
"your_password"
).unwrap();
// Decrypt
let decrypted = KeyManager::decrypt_with_password(
&encrypted,
"your_password"
).unwrap();
}
๐ See INTEGRATION.md for complete library integration guide.
For command-line usage, install with full features:
cargo install sol-safekey --features full
Or build from source:
git clone https://github.com/0xfnzero/sol-safekey.git
cd sol-safekey
cargo build --release --features full
The binary will be available at target/release/sol-safekey.
Sol SafeKey can be used in three ways:
Perfect for trading bots, automated tools, and applications that need secure key management.
BotKeyManageruse sol_safekey::bot_helper::BotKeyManager;
use solana_sdk::signature::Keypair;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manager = BotKeyManager::new();
// Interactive unlock (prompts user for password)
let private_key = manager.unlock_keystore_interactive("bot_wallet.json")?;
let keypair = Keypair::from_base58_string(&private_key);
println!("๐ Bot started with wallet: {}", keypair.pubkey());
// Your bot logic here...
Ok(())
}
See examples/simple_bot.rs for a complete working example:
# Run the bot example
cargo run --example simple_bot
The example includes:
Add to your Cargo.toml:
[dependencies]
sol-safekey = "0.1.0"
solana-sdk = "3.0"
# Optional: For Solana operations (balance, transfer, etc.)
sol-safekey = { version = "0.1.0", features = ["solana-ops"] }
tokio = { version = "1.0", features = ["full"] }
Then use in your bot code:
use sol_safekey::bot_helper::BotKeyManager;
let manager = BotKeyManager::new();
// First run: Generate wallet
let pubkey = manager.generate_keystore_interactive("wallet.json")?;
// Every run: Unlock wallet
let private_key = manager.unlock_keystore_interactive("wallet.json")?;
If you need to perform Solana operations (check balance, transfer, etc.), enable the solana-ops feature:
[dependencies]
sol-safekey = { version = "0.1.0", features = ["solana-ops"] }
Example - Check Balance:
use sol_safekey::{KeyManager, solana_utils::*};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Load wallet
let keypair = KeyManager::keypair_from_encrypted_json(&json, password)?;
// Create Solana client
let client = SolanaClient::new("https://api.mainnet-beta.solana.com".to_string());
// Check balance
let balance = client.get_sol_balance(&keypair.pubkey()).await?;
println!("Balance: {} SOL", lamports_to_sol(balance));
Ok(())
}
๐ Complete Solana Operations Guide: See SOLANA_OPS.md for detailed documentation including:
Integrate encryption functionality directly into your projects.
Add to your Cargo.toml:
[dependencies]
sol-safekey = "0.1.0"
Or without CLI features:
[dependencies]
sol-safekey = { version = "0.1.0", default-features = false }
use sol_safekey::KeyManager;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate keypair
let keypair = KeyManager::generate_keypair();
println!("Public key: {}", keypair.pubkey());
// Encrypt with password
let private_key = keypair.to_base58_string();
let encrypted = KeyManager::encrypt_with_password(&private_key, "password")?;
// Decrypt
let decrypted = KeyManager::decrypt_with_password(&encrypted, "password")?;
// Create encrypted JSON keystore
let keystore = KeyManager::keypair_to_encrypted_json(&keypair, "password")?;
// Restore from keystore
let restored = KeyManager::keypair_from_encrypted_json(&keystore, "password")?;
Ok(())
}
# Clone repository
git clone https://github.com/0xfnzero/sol-safekey.git
cd sol-safekey
# Build
cargo build --release
# Or use the build script (macOS/Linux)
./build.sh
# Install to system (optional)
cargo install --path .
# View help
sol-safekey --help
# Generate keypair format
sol-safekey gen-keypair -o my-wallet.json
# Generate encrypted keystore (interactive password input)
sol-safekey gen-keystore -o secure-wallet.json
# Unlock keystore (interactive password input)
sol-safekey unlock -f secure-wallet.json
# Or provide password as argument for non-interactive use
sol-safekey gen-keystore -o secure-wallet.json -p mypassword
sol-safekey unlock -f secure-wallet.json -p mypassword
# 1. First-time setup: Configure your 2FA
sol-safekey setup-2fa
# This will:
# - Collect your device's hardware fingerprint
# - Guide you to set a strong master password (8+ chars, 3 types)
# - Let you choose and answer a security question
# - Generate a 2FA secret and show QR code
# - Verify setup with your authenticator app
# 2. Generate your secure wallet
sol-safekey gen-2fa-wallet -o my-wallet.json
# This creates TWO files:
# - my-wallet.json: Triple-factor encrypted (requires device + password + security question + 2FA)
# - XXXXXXXX_keystore.json: Password-only backup (recover private key cross-device using master password)
# 3. Unlock your wallet
sol-safekey unlock-2fa-wallet -f my-wallet.json
# You'll need to provide:
# - Master password
# - Security question answer
# - Current 2FA code from your authenticator app
When using sol-safekey as a library, the main interface is the KeyManager struct:
KeyManager::generate_keypair()Generate a new Solana keypair.
let keypair = KeyManager::generate_keypair();
KeyManager::encrypt_with_password(private_key, password)Encrypt a private key with a password.
let encrypted = KeyManager::encrypt_with_password(&private_key, "password")?;
KeyManager::decrypt_with_password(encrypted_data, password)Decrypt an encrypted private key.
let decrypted = KeyManager::decrypt_with_password(&encrypted, "password")?;
KeyManager::get_public_key(private_key)Derive public key from a private key.
let public_key = KeyManager::get_public_key(&private_key)?;
KeyManager::keypair_to_encrypted_json(keypair, password)Create an encrypted keystore JSON from a keypair.
let json = KeyManager::keypair_to_encrypted_json(&keypair, "password")?;
KeyManager::keypair_from_encrypted_json(json_data, password)Restore a keypair from encrypted JSON.
let keypair = KeyManager::keypair_from_encrypted_json(&json, "password")?;
use sol_safekey::KeyManager;
let keypair = KeyManager::generate_keypair();
let encrypted = KeyManager::encrypt_with_password(
&keypair.to_base58_string(),
"password"
)?;
use sol_safekey::KeyManager;
// Save to keystore
let keypair = KeyManager::generate_keypair();
let keystore = KeyManager::keypair_to_encrypted_json(&keypair, "password")?;
std::fs::write("wallet.json", keystore)?;
// Load from keystore
let keystore = std::fs::read_to_string("wallet.json")?;
let keypair = KeyManager::keypair_from_encrypted_json(&keystore, "password")?;
use sol_safekey::KeyManager;
use std::collections::HashMap;
let mut wallets: HashMap<String, String> = HashMap::new();
let password = "master_password";
// Create multiple wallets
for i in 0..3 {
let keypair = KeyManager::generate_keypair();
let encrypted = KeyManager::encrypt_with_password(
&keypair.to_base58_string(),
password
)?;
wallets.insert(format!("wallet_{}", i), encrypted);
}
setup-2faOne-time setup for triple-factor authentication
sol-safekey setup-2fa
Process:
Password Requirements:
MyPass123! (has uppercase, lowercase, digits, special)secure2024# (has lowercase, digits, special)password (too weak)Pass123 (only 7 characters)gen-2fa-walletGenerate triple-factor encrypted wallet with automatic keystore backup
sol-safekey gen-2fa-wallet -o my-wallet.json
What you get:
my-wallet.json: Triple-factor encrypted wallet
XXXXXXXX_keystore.json: Cross-device backup
sol-safekey unlock -f XXXXXXXX_keystore.json -p <password>Input Process:
unlock-2fa-walletUnlock triple-factor encrypted wallet
sol-safekey unlock-2fa-wallet -f my-wallet.json
Requirements:
Security Features:
gen-keypairGenerate keypair format private key
sol-safekey gen-keypair -o wallet.json
gen-keyGenerate string format private key
sol-safekey gen-key -s 3 -o keys.json
gen-keystoreGenerate encrypted keystore file
sol-safekey gen-keystore -p password123 -o secure.json
encryptEncrypt existing private key
sol-safekey encrypt -k "your_private_key_string" -p password123
decryptDecrypt private key string
sol-safekey decrypt -e "encrypted_data" -p password123
unlockDecrypt private key from file (including keystore backups)
sol-safekey unlock -f encrypted-file.json -p password123
# Unlock keystore backup
sol-safekey unlock -f XXXXXXXX_keystore.json -p your_master_password
addressView wallet address from private key
# From plain private key
sol-safekey address -k YOUR_PRIVATE_KEY
# From encrypted private key
sol-safekey address -e ENCRYPTED_KEY -p password123
# From file
sol-safekey address -f keys.json
# From encrypted file
sol-safekey address -f encrypted-keys.json -p password123
| Option | Short | Description |
|---|---|---|
--output |
-o |
Output file path |
--segments |
-s |
Number of segments |
--password |
-p |
Password |
--private-key |
-k |
Private key string |
--encrypted-key |
-e |
Encrypted data |
--file-path |
-f |
File path |
{
"encrypted_private_key": "base64_encrypted_data_with_all_factors",
"public_key": "GfkFnJY5pcPp2xeGYTH...",
"version": "triple_factor_v1",
"question_index": 2,
"created_at": "2025-09-30T10:15:30Z"
}
{
"encrypted_private_key": "base64_encrypted_data_password_only",
"public_key": "GfkFnJY5pcPp2xeGYTH...",
"encryption_type": "password_only",
"created_at": "2025-09-30T10:15:30Z",
"note": "Recover private key cross-device using master password"
}
[89, 252, 28, 23, ...] // 64-byte array
{
"private_key": "5D1iwg89hSXfoqA28ioE...",
"public_key": "GfkFnJY5pcPp2xeGYTH...",
"segments": ["5D1iwg89hS", "XfoqA28io", "E..."],
"created_at": "2025-09-21T04:03:37+00:00"
}
Hardware Fingerprint Collection
Key Derivation (PBKDF2)
2FA Secret Generation
Encryption
Decryption + Verification
Available questions (select one during setup):
Note: Answers are normalized (lowercase, trimmed) for consistency.
Device Binding
Password Management
Security Question
2FA Setup
Keystore Backup
XXXXXXXX_keystore.json backup filesol-safekey unlock -f XXXXXXXX_keystore.json -p <password>Recovery Planning
XXXXXXXX_keystore.json file is your only cross-device recovery optionsetup-2fa to configure new triple-factor setupXXXXXXXX_keystore.json backup filesol-safekey unlock -f XXXXXXXX_keystore.json -p <master_password>setup-2fa on new device for future securitysetup-2fa again to configure new 2FAsetup-2fa again with new security questioncargo build
cargo test
cargo build --release
# Or use build script
./build.sh
sol-safekey/
โโโ src/
โ โโโ lib.rs # Core encryption/decryption logic
โ โโโ main.rs # CLI interface
โ โโโ totp.rs # TOTP implementation
โ โโโ secure_totp.rs # Secure TOTP manager
โ โโโ hardware_fingerprint.rs # Hardware fingerprint collection
โ โโโ security_question.rs # Security question handling
โโโ Cargo.toml # Dependencies
โโโ build.sh # Build script
โโโ README.md # This file
Issues and Pull Requests are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.
โญ If this project helps you secure your Solana assets, please give it a star!
Made with โค๏ธ for the Solana community