pub struct Mnemonic { /* private fields */ }Available on crate feature
mnemonic only.Expand description
A BIP-39 mnemonic phrase for key derivation.
§Example
use aptos_sdk::account::Mnemonic;
// Generate a new mnemonic
let mnemonic = Mnemonic::generate(24).unwrap();
println!("Mnemonic: {}", mnemonic.phrase());
// Parse an existing mnemonic
let mnemonic = Mnemonic::from_phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about").unwrap();Implementations§
Source§impl Mnemonic
impl Mnemonic
Sourcepub fn generate(word_count: usize) -> AptosResult<Self>
pub fn generate(word_count: usize) -> AptosResult<Self>
Sourcepub fn from_phrase(phrase: &str) -> AptosResult<Self>
pub fn from_phrase(phrase: &str) -> AptosResult<Self>
Creates a mnemonic from an existing phrase.
§Errors
Returns an error if the phrase is not a valid BIP-39 mnemonic.
Sourcepub fn to_seed(&self) -> AptosResult<[u8; 64]>
pub fn to_seed(&self) -> AptosResult<[u8; 64]>
Derives the seed from this mnemonic.
Uses an empty passphrase by default.
§Errors
Returns an error if the mnemonic cannot be re-parsed (should not happen since the phrase was validated during construction).
Sourcepub fn to_seed_with_passphrase(&self, passphrase: &str) -> AptosResult<[u8; 64]>
pub fn to_seed_with_passphrase(&self, passphrase: &str) -> AptosResult<[u8; 64]>
Derives the seed from this mnemonic with a passphrase.
§Errors
Returns an error if the mnemonic phrase cannot be re-parsed. This should never happen because the phrase is validated during construction, but returning an error is safer than panicking.
Sourcepub fn derive_ed25519_key(&self, index: u32) -> AptosResult<Ed25519PrivateKey>
Available on crate feature ed25519 only.
pub fn derive_ed25519_key(&self, index: u32) -> AptosResult<Ed25519PrivateKey>
ed25519 only.Derives an Ed25519 private key using the Aptos derivation path.
Path: m/44'/637'/0'/0'/index'
§Errors
Returns an error if key derivation fails or the derived key is invalid.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mnemonic
impl RefUnwindSafe for Mnemonic
impl Send for Mnemonic
impl Sync for Mnemonic
impl Unpin for Mnemonic
impl UnsafeUnpin for Mnemonic
impl UnwindSafe for Mnemonic
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