pub struct Ed25519SingleKeyAccount { /* private fields */ }ed25519 only.Expand description
An Ed25519 account using the modern SingleKey authenticator format.
This account type uses the SingleSender > SingleKey > AnyPublicKey::Ed25519
authenticator path, which is the modern unified format recommended for new
implementations.
Note: This produces a DIFFERENT address than Ed25519Account for the
same private key because it uses scheme ID 2 instead of 0.
§Authentication Key Derivation
The authentication key is derived as:
auth_key = SHA3-256(BCS(AnyPublicKey::Ed25519) || 0x02)Where BCS(AnyPublicKey::Ed25519) = 0x00 || ULEB128(32) || public_key_bytes
§Example
use aptos_sdk::account::Ed25519SingleKeyAccount;
// Generate a new random account
let account = Ed25519SingleKeyAccount::generate();
println!("Address: {}", account.address());Implementations§
Source§impl Ed25519SingleKeyAccount
impl Ed25519SingleKeyAccount
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'
§Errors
Returns an error if the mnemonic phrase is invalid or if 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.
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 Ed25519SingleKeyAccount
impl Account for Ed25519SingleKeyAccount
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 Ed25519SingleKeyAccount
impl Clone for Ed25519SingleKeyAccount
Source§fn clone(&self) -> Ed25519SingleKeyAccount
fn clone(&self) -> Ed25519SingleKeyAccount
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more