pub struct Bip39Account { /* private fields */ }
Expand description
A BIP-39 compatible neo account that uses mnemonic phrases for key generation and recovery.
This implementation follows the BIP-39 standard for generating and recovering neo accounts using mnemonic phrases. The account can be created with a new random mnemonic or recovered from an existing mnemonic phrase.
§Examples
§Creating a new account
use neo3::neo_wallets::Bip39Account;
// Create a new account with a password
let password = "your_secure_password";
let account = Bip39Account::create(password).unwrap();
// The account will have a randomly generated 24-word mnemonic
println!("Mnemonic: {}", account.mnemonic());
§Recovering an existing account
use neo3::neo_wallets::Bip39Account;
// Recover an account using an existing mnemonic and password
let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"; // Your 24 word mnemonic
let password = "your_secure_password";
let recovered = Bip39Account::from_bip39_mnemonic(password, mnemonic).unwrap();
Implementations§
Source§impl Bip39Account
impl Bip39Account
Sourcepub fn create(password: &str) -> Result<Self, Box<dyn Error>>
pub fn create(password: &str) -> Result<Self, Box<dyn Error>>
Creates a new BIP-39 compatible neo account with a randomly generated mnemonic.
The private key for the wallet is calculated using:
Key = SHA-256(BIP_39_SEED(mnemonic, password))
The password is used as a BIP-39 passphrase and is required to recover the account later. The same password must be provided during recovery to generate the same keys.
§Arguments
password
- The passphrase used in BIP-39 seed generation. This must be saved to recover the account.
§Returns
A Result containing the new Bip39Account or an error if creation fails.
§Example
use neo3::neo_wallets::Bip39Account;
let account = Bip39Account::create("my secure password").unwrap();
// Save the mnemonic securely
let mnemonic = account.mnemonic().to_string();
Sourcepub fn from_bip39_mnemonic(
password: &str,
mnemonic: &str,
) -> Result<Self, Box<dyn Error>>
pub fn from_bip39_mnemonic( password: &str, mnemonic: &str, ) -> Result<Self, Box<dyn Error>>
Recovers a neo account from an existing BIP-39 mnemonic phrase and password.
This method will reconstruct the exact same neo account if provided with the same mnemonic and password combination that was used to create the original account.
§Arguments
password
- The same passphrase that was used when generating the original accountmnemonic
- The 24-word mnemonic phrase from the original account
§Returns
A Result containing the recovered Bip39Account or an error if recovery fails
§Example
use neo3::neo_wallets::Bip39Account;
let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"; // Your saved 24-word mnemonic
let password = "your_secure_password"; // Original password used
let account = Bip39Account::from_bip39_mnemonic(password, mnemonic).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bip39Account
impl RefUnwindSafe for Bip39Account
impl Send for Bip39Account
impl Sync for Bip39Account
impl Unpin for Bip39Account
impl UnwindSafe for Bip39Account
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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