pub struct Ed25519Account { /* private fields */ }ed25519 only.Expand description
An Ed25519 account for signing transactions.
This is the most common account type on Aptos.
§Example
use aptos_sdk::account::Ed25519Account;
// Generate a new random account
let account = Ed25519Account::generate();
println!("Address: {}", account.address());Implementations§
Source§impl Ed25519Account
impl Ed25519Account
Sourcepub fn from_private_key(private_key: Ed25519PrivateKey) -> Self
pub fn from_private_key(private_key: Ed25519PrivateKey) -> Self
Creates an account from a private key.
Sourcepub fn from_private_key_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_private_key_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates an account from private key bytes.
§Errors
Returns an error if the bytes are not a valid Ed25519 private key (must be exactly 32 bytes).
Sourcepub fn from_private_key_hex(hex_str: &str) -> AptosResult<Self>
pub fn from_private_key_hex(hex_str: &str) -> AptosResult<Self>
Creates an account from a private key hex string.
§Errors
This function will return an error if:
- The hex string is invalid or cannot be decoded
- The decoded bytes are not a valid Ed25519 private key
Sourcepub fn from_mnemonic(mnemonic: &str, index: u32) -> AptosResult<Self>
Available on crate feature mnemonic only.
pub fn from_mnemonic(mnemonic: &str, index: u32) -> AptosResult<Self>
mnemonic only.Creates an account from a BIP-39 mnemonic phrase.
Uses the standard Aptos derivation path: m/44'/637'/0'/0'/index'
§Arguments
mnemonic- A BIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words)index- The account index in the derivation path
§Example
use aptos_sdk::account::Ed25519Account;
let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
let account = Ed25519Account::from_mnemonic(mnemonic, 0).unwrap();§Errors
Returns an error if the mnemonic phrase is invalid or if key derivation fails.
Sourcepub fn generate_with_mnemonic() -> AptosResult<(Self, String)>
Available on crate feature mnemonic only.
pub fn generate_with_mnemonic() -> AptosResult<(Self, String)>
mnemonic only.Generates a new account with a random mnemonic.
Returns both the account and the mnemonic phrase (for backup).
§Errors
Returns an error if mnemonic generation or key derivation fails.
Sourcepub fn address(&self) -> AccountAddress
pub fn address(&self) -> AccountAddress
Returns the account address.
Sourcepub fn public_key(&self) -> &Ed25519PublicKey
pub fn public_key(&self) -> &Ed25519PublicKey
Returns the public key.
Sourcepub fn private_key(&self) -> &Ed25519PrivateKey
pub fn private_key(&self) -> &Ed25519PrivateKey
Returns a reference to the private key.
Warning: Handle with care to avoid leaking sensitive key material.
Sourcepub fn sign_message(&self, message: &[u8]) -> Ed25519Signature
pub fn sign_message(&self, message: &[u8]) -> Ed25519Signature
Signs a message and returns the Ed25519 signature.
Trait Implementations§
Source§impl Account for Ed25519Account
impl Account for Ed25519Account
Source§fn address(&self) -> AccountAddress
fn address(&self) -> AccountAddress
Source§fn authentication_key(&self) -> AuthenticationKey
fn authentication_key(&self) -> AuthenticationKey
Source§fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
Source§fn signature_scheme(&self) -> u8
fn signature_scheme(&self) -> u8
Source§impl Clone for Ed25519Account
impl Clone for Ed25519Account
Source§fn clone(&self) -> Ed25519Account
fn clone(&self) -> Ed25519Account
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more