Struct Bip39Account

Source
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

Source

pub fn mnemonic(&self) -> &str

Returns the mnemonic phrase used for this account

Source

pub fn account(&self) -> &Account

Returns a reference to the underlying Neo account

Source

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

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 account
  • mnemonic - 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§

Source§

impl Debug for Bip39Account

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,