Skip to main content

MultiEd25519Account

Struct MultiEd25519Account 

Source
pub struct MultiEd25519Account { /* private fields */ }
Available on crate feature 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

Source

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 keys
  • threshold - 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)
Source

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 account
  • private_keys - The private keys you own, with their indices
  • threshold - 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
Source

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).

Source

pub fn address(&self) -> AccountAddress

Returns the account address.

Source

pub fn public_key(&self) -> &MultiEd25519PublicKey

Returns the multi-Ed25519 public key.

Source

pub fn num_keys(&self) -> usize

Returns the number of keys in the account.

Source

pub fn threshold(&self) -> u8

Returns the signature threshold.

Source

pub fn num_owned_keys(&self) -> usize

Returns the number of private keys we have.

Source

pub fn can_sign(&self) -> bool

Checks if we can sign (have enough private keys to meet threshold).

Source

pub fn owned_key_indices(&self) -> Vec<u8>

Returns the indices of the private keys we own.

Source

pub fn sign_with_indices( &self, message: &[u8], indices: &[u8], ) -> AptosResult<MultiEd25519Signature>

Signs a message using specific key indices.

§Arguments
  • message - The message to sign
  • indices - The indices of keys to use for signing
§Errors

Returns an error if:

  • We don’t own a key at the specified index
  • Not enough indices are provided to meet threshold
Source

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).

Source

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.

Source

pub fn auth_key(&self) -> AuthenticationKey

Returns the authentication key for this account.

Source

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
Source

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

Source§

fn address(&self) -> AccountAddress

Returns the account address.
Source§

fn public_key_bytes(&self) -> Vec<u8>

Returns the public key bytes.
Source§

fn sign(&self, message: &[u8]) -> AptosResult<Vec<u8>>

Signs a message and returns the signature bytes. Read more
Source§

fn authentication_key(&self) -> AuthenticationKey

Returns the authentication key.
Source§

fn signature_scheme(&self) -> u8

Returns the scheme identifier for this account type.
Source§

impl Debug for MultiEd25519Account

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for MultiEd25519Account

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<MultiEd25519Account> for AnyAccount

Source§

fn from(account: MultiEd25519Account) -> Self

Converts to this type from the input type.

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.

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> PolicyExt for T
where T: ?Sized,

Source§

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

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<A> Sponsor for A
where A: Account,

Source§

fn sponsor<S: Account>( &self, sender: &S, sender_sequence_number: u64, payload: TransactionPayload, chain_id: ChainId, ) -> AptosResult<SignedTransaction>

Sponsors a transaction for another account. Read more
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>

Sponsors a transaction with custom gas settings. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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

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

Source§

fn vzip(self) -> V

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