pub struct KeyManager;Expand description
Main interface for key management operations
This is the recommended API for library integration. It provides simple, safe methods for common key operations.
Implementations§
Source§impl KeyManager
impl KeyManager
Sourcepub fn generate_keypair() -> Keypair
pub fn generate_keypair() -> Keypair
Generate a new Solana keypair
§Example
use sol_safekey::KeyManager;
let keypair = KeyManager::generate_keypair();
println!("Public key: {}", keypair.pubkey());Sourcepub fn encrypt_with_password(
private_key: &str,
password: &str,
) -> EncryptionResult<String>
pub fn encrypt_with_password( private_key: &str, password: &str, ) -> EncryptionResult<String>
Encrypt a private key with a password
§Arguments
private_key- The private key in base58 string formatpassword- The password to use for encryption
§Returns
Base64-encoded encrypted string
§Example
use sol_safekey::KeyManager;
let keypair = KeyManager::generate_keypair();
let private_key = keypair.to_base58_string();
let encrypted = KeyManager::encrypt_with_password(
&private_key,
"my_password"
).unwrap();Sourcepub fn decrypt_with_password(
encrypted_data: &str,
password: &str,
) -> EncryptionResult<String>
pub fn decrypt_with_password( encrypted_data: &str, password: &str, ) -> EncryptionResult<String>
Decrypt a private key with a password
§Arguments
encrypted_data- Base64-encoded encrypted datapassword- The password used for encryption
§Returns
The original private key in base58 string format
§Example
use sol_safekey::KeyManager;
let encrypted = "..."; // from encryption
let decrypted = KeyManager::decrypt_with_password(
encrypted,
"my_password"
).unwrap();Sourcepub fn get_public_key(private_key: &str) -> EncryptionResult<String>
pub fn get_public_key(private_key: &str) -> EncryptionResult<String>
Sourcepub fn keypair_to_encrypted_json(
keypair: &Keypair,
password: &str,
) -> EncryptionResult<String>
pub fn keypair_to_encrypted_json( keypair: &Keypair, password: &str, ) -> EncryptionResult<String>
Sourcepub fn keypair_from_encrypted_json(
json_data: &str,
password: &str,
) -> EncryptionResult<Keypair>
pub fn keypair_from_encrypted_json( json_data: &str, password: &str, ) -> EncryptionResult<Keypair>
Auto Trait Implementations§
impl Freeze for KeyManager
impl RefUnwindSafe for KeyManager
impl Send for KeyManager
impl Sync for KeyManager
impl Unpin for KeyManager
impl UnwindSafe for KeyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more