pub struct MultiEd25519Account { /* private fields */ }ed25519 only.Expand description
A multi-Ed25519 account supporting M-of-N threshold signatures.
This account type holds multiple Ed25519 keys and requires a threshold number of signatures to authorize transactions.
§Example
use aptos_sdk::account::MultiEd25519Account;
use aptos_sdk::crypto::Ed25519PrivateKey;
// Create a 2-of-3 multisig account
let keys: Vec<_> = (0..3).map(|_| Ed25519PrivateKey::generate()).collect();
let account = MultiEd25519Account::new(keys, 2).unwrap();
println!("Address: {}", account.address());
println!("Threshold: {}/{}", account.threshold(), account.num_keys());
// Sign a message
let message = b"hello";
let signature = account.sign(message);Implementations§
Source§impl MultiEd25519Account
impl MultiEd25519Account
Sourcepub fn new(
private_keys: Vec<Ed25519PrivateKey>,
threshold: u8,
) -> AptosResult<Self>
pub fn new( private_keys: Vec<Ed25519PrivateKey>, threshold: u8, ) -> AptosResult<Self>
Creates a new multi-Ed25519 account from private keys.
All provided private keys will be used for signing. The threshold specifies how many signatures are required.
§Arguments
private_keys- The Ed25519 private keysthreshold- The required number of signatures (M in M-of-N)
§Example
// 2-of-3 multisig where we own all 3 keys
let keys: Vec<_> = (0..3).map(|_| Ed25519PrivateKey::generate()).collect();
let account = MultiEd25519Account::new(keys, 2).unwrap();§Errors
This function will return an error if:
- No private keys are provided
- The threshold exceeds the number of keys
- The multi-Ed25519 public key creation fails (e.g., too many keys, invalid threshold)
Sourcepub fn from_keys(
public_keys: Vec<Ed25519PublicKey>,
private_keys: Vec<(u8, Ed25519PrivateKey)>,
threshold: u8,
) -> AptosResult<Self>
pub fn from_keys( public_keys: Vec<Ed25519PublicKey>, private_keys: Vec<(u8, Ed25519PrivateKey)>, threshold: u8, ) -> AptosResult<Self>
Creates a multi-Ed25519 account from public keys with a subset of private keys.
Use this when you don’t have all the private keys (e.g., a 2-of-3 where you only own 2 keys).
§Arguments
public_keys- All the Ed25519 public keys in the accountprivate_keys- The private keys you own, with their indicesthreshold- The required number of signatures
§Example
// 2-of-3 multisig where we own keys 0 and 2
let all_public_keys = vec![pk0, pk1, pk2];
let my_keys = vec![(0, sk0), (2, sk2)];
let account = MultiEd25519Account::from_keys(all_public_keys, my_keys, 2).unwrap();§Errors
This function will return an error if:
- The multi-Ed25519 public key creation fails
- A private key index is out of bounds
- A private key doesn’t match the public key at its index
Sourcepub fn view_only(
public_keys: Vec<Ed25519PublicKey>,
threshold: u8,
) -> AptosResult<Self>
pub fn view_only( public_keys: Vec<Ed25519PublicKey>, threshold: u8, ) -> AptosResult<Self>
Creates a view-only multi-Ed25519 account (no signing capability).
This is useful for verifying signatures or looking up account information when you don’t have any private keys.
§Errors
Returns an error if the multi-Ed25519 public key creation fails (e.g., no keys provided, too many keys, invalid threshold).
Sourcepub fn address(&self) -> AccountAddress
pub fn address(&self) -> AccountAddress
Returns the account address.
Sourcepub fn public_key(&self) -> &MultiEd25519PublicKey
pub fn public_key(&self) -> &MultiEd25519PublicKey
Returns the multi-Ed25519 public key.
Sourcepub fn num_owned_keys(&self) -> usize
pub fn num_owned_keys(&self) -> usize
Returns the number of private keys we have.
Sourcepub fn can_sign(&self) -> bool
pub fn can_sign(&self) -> bool
Checks if we can sign (have enough private keys to meet threshold).
Sourcepub fn owned_key_indices(&self) -> Vec<u8> ⓘ
pub fn owned_key_indices(&self) -> Vec<u8> ⓘ
Returns the indices of the private keys we own.
Sourcepub fn sign_with_indices(
&self,
message: &[u8],
indices: &[u8],
) -> AptosResult<MultiEd25519Signature>
pub fn sign_with_indices( &self, message: &[u8], indices: &[u8], ) -> AptosResult<MultiEd25519Signature>
Sourcepub fn verify(
&self,
message: &[u8],
signature: &MultiEd25519Signature,
) -> AptosResult<()>
pub fn verify( &self, message: &[u8], signature: &MultiEd25519Signature, ) -> AptosResult<()>
Verifies a signature against a message.
§Errors
Returns an error if signature verification fails (e.g., invalid signature, insufficient signatures, signature mismatch).
Sourcepub fn sign(&self, message: &[u8]) -> AptosResult<MultiEd25519Signature>
pub fn sign(&self, message: &[u8]) -> AptosResult<MultiEd25519Signature>
Signs a message using the owned private keys.
Will use up to threshold keys for signing.
§Errors
Returns an error if we don’t have enough keys to meet the threshold.
Sourcepub fn auth_key(&self) -> AuthenticationKey
pub fn auth_key(&self) -> AuthenticationKey
Returns the authentication key for this account.
Sourcepub fn aggregate_signatures(
signatures: Vec<(u8, Ed25519Signature)>,
) -> AptosResult<MultiEd25519Signature>
pub fn aggregate_signatures( signatures: Vec<(u8, Ed25519Signature)>, ) -> AptosResult<MultiEd25519Signature>
Collects individual signatures into a multi-signature.
Use this when collecting signatures from multiple parties.
§Errors
This function will return an error if:
- No signatures are provided
- Too many signatures are provided (more than 32)
- Signer indices are out of bounds or duplicated
Sourcepub fn create_signature_contribution(
&self,
message: &[u8],
key_index: u8,
) -> AptosResult<(u8, Ed25519Signature)>
pub fn create_signature_contribution( &self, message: &[u8], key_index: u8, ) -> AptosResult<(u8, Ed25519Signature)>
Creates an individual signature contribution for this account.
Returns the signature with the signer index. Use this when contributing your signature to a multi-party signing flow.
§Errors
Returns an error if we don’t have a private key at the specified index.
Trait Implementations§
Source§impl Account for MultiEd25519Account
impl Account for MultiEd25519Account
Source§fn address(&self) -> AccountAddress
fn address(&self) -> AccountAddress
Source§fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>
Source§fn authentication_key(&self) -> AuthenticationKey
fn authentication_key(&self) -> AuthenticationKey
Source§fn signature_scheme(&self) -> u8
fn signature_scheme(&self) -> u8
Source§impl Debug for MultiEd25519Account
impl Debug for MultiEd25519Account
Source§impl Display for MultiEd25519Account
impl Display for MultiEd25519Account
Source§impl From<MultiEd25519Account> for AnyAccount
impl From<MultiEd25519Account> for AnyAccount
Source§fn from(account: MultiEd25519Account) -> Self
fn from(account: MultiEd25519Account) -> Self
Auto Trait Implementations§
impl Freeze for MultiEd25519Account
impl RefUnwindSafe for MultiEd25519Account
impl Send for MultiEd25519Account
impl Sync for MultiEd25519Account
impl Unpin for MultiEd25519Account
impl UnwindSafe for MultiEd25519Account
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<A> Sponsor for Awhere
A: Account,
impl<A> Sponsor for Awhere
A: Account,
Source§fn sponsor<S: Account>(
&self,
sender: &S,
sender_sequence_number: u64,
payload: TransactionPayload,
chain_id: ChainId,
) -> AptosResult<SignedTransaction>
fn sponsor<S: Account>( &self, sender: &S, sender_sequence_number: u64, payload: TransactionPayload, chain_id: ChainId, ) -> AptosResult<SignedTransaction>
Source§fn sponsor_with_gas<S: Account>(
&self,
sender: &S,
sender_sequence_number: u64,
payload: TransactionPayload,
chain_id: ChainId,
max_gas_amount: u64,
gas_unit_price: u64,
) -> AptosResult<SignedTransaction>
fn sponsor_with_gas<S: Account>( &self, sender: &S, sender_sequence_number: u64, payload: TransactionPayload, chain_id: ChainId, max_gas_amount: u64, gas_unit_price: u64, ) -> AptosResult<SignedTransaction>
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.