pub struct Account { /* private fields */ }Implementations§
Source§impl Account
impl Account
Sourcepub fn private_key(&self) -> &PrivateKey
pub fn private_key(&self) -> &PrivateKey
Returns the private key of the account.
Sourcepub fn get_encrypted_key(&self, secret: &str) -> Result<Ciphertext>
pub fn get_encrypted_key(&self, secret: &str) -> Result<Ciphertext>
Encrypts the private key into a ciphertext using a secret.
§Arguments
secret- The secret used for encryption.
§Returns
The ciphertext.
§Example
ⓘ
use std::str::FromStr;
use aleo_agent::account::Account;
use aleo_agent::PrivateKey;
let acc = Account::from_private_key("PRIVATE KEY").unwrap();
let encrypted_key = acc.get_encrypted_key("secret").expect("failed to encrypt key");
let recover_account = Account::from_encrypted_key(&encrypted_key, "secret").expect("failed to decrypt key");
assert_eq!(acc.private_key().to_string(), recover_account.private_key().to_string());Source§impl Account
impl Account
Sourcepub fn from_seed(seed: u64) -> Result<Self>
pub fn from_seed(seed: u64) -> Result<Self>
Generates a new Account from a seed.
§Example
use rand::Rng;
use rand_chacha::ChaChaRng;
use rand_chacha::rand_core::{SeedableRng};
use aleo_agent::account::Account;
use aleo_agent::PrivateKey;
let mut rng = ChaChaRng::from_entropy();
let seed : u64 = rng.gen();
let account = Account::from_seed(seed).unwrap();
let mut rng_from_seed = ChaChaRng::seed_from_u64(seed);
let private_key = PrivateKey::new(&mut rng_from_seed).expect("failed to recover private key from seed");
assert_eq!(account.private_key().to_string(), private_key.to_string());Sourcepub fn from_private_key(key: &str) -> Result<Self>
pub fn from_private_key(key: &str) -> Result<Self>
Generates a new Account from a private key string.
§Example
ⓘ
use std::str::FromStr;
use aleo_agent::account::Account;
use aleo_agent::PrivateKey;
let private_key = PrivateKey::from_str("YOUR PRIVATE KEY").unwrap();
let account = Account::from_private_key("YOUR PRIVATE KEY").unwrap();
assert_eq!(account.private_key().to_string(), private_key.to_string());Sourcepub fn from_encrypted_key(ciphertext: &Ciphertext, secret: &str) -> Result<Self>
pub fn from_encrypted_key(ciphertext: &Ciphertext, secret: &str) -> Result<Self>
Decrypts a private key from ciphertext using a secret.
§Arguments
ciphertext- The ciphertext of the encrypted private key.secret- The secret used for decryption.
§Returns
The decrypted Account.
§Example
ⓘ
use std::str::FromStr;
use aleo_agent::account::Account;
use aleo_agent::PrivateKey;
let acc = Account::from_private_key("YOUR PRIVATE KET").unwrap();
let encrypted_key = acc.get_encrypted_key("SECRET").expect("failed to encrypt key");
let recover_account = Account::from_encrypted_key(&encrypted_key, "secret").expect("failed to decrypt key");
assert_eq!(acc.private_key().to_string(), recover_account.private_key().to_string());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Account
impl RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl UnwindSafe for Account
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more