KeyManager

Struct KeyManager 

Source
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

Source

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());
Source

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 format
  • password - 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();
Source

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 data
  • password - 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();
Source

pub fn get_public_key(private_key: &str) -> EncryptionResult<String>

Get public key from a private key

§Arguments
  • private_key - Private key in base58 string format
§Returns

Public key as a base58 string

Source

pub fn keypair_to_encrypted_json( keypair: &Keypair, password: &str, ) -> EncryptionResult<String>

Encrypt a keypair to a JSON keystore format

This creates a standard encrypted keystore file compatible with Solana tools.

§Arguments
  • keypair - The Solana keypair to encrypt
  • password - The password for encryption
§Returns

JSON string containing the encrypted keystore

Source

pub fn keypair_from_encrypted_json( json_data: &str, password: &str, ) -> EncryptionResult<Keypair>

Decrypt a keypair from encrypted JSON keystore

§Arguments
  • json_data - The encrypted keystore JSON string
  • password - The password used for encryption
§Returns

The restored Keypair

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V