Skip to main content

MultiKeyAccount

Struct MultiKeyAccount 

Source
pub struct MultiKeyAccount { /* private fields */ }
Expand description

A multi-key account supporting M-of-N threshold signatures with mixed key types.

Unlike MultiEd25519Account, this account type supports mixed signature schemes (e.g., 2-of-3 where one key is Ed25519 and two are Secp256k1).

§Example

use aptos_sdk::account::{MultiKeyAccount, AnyPrivateKey};
use aptos_sdk::crypto::{Ed25519PrivateKey, Secp256k1PrivateKey};

// Create a 2-of-3 multisig with mixed key types
let keys = vec![
    AnyPrivateKey::ed25519(Ed25519PrivateKey::generate()),
    AnyPrivateKey::secp256k1(Secp256k1PrivateKey::generate()),
    AnyPrivateKey::ed25519(Ed25519PrivateKey::generate()),
];
let account = MultiKeyAccount::new(keys, 2).unwrap();

println!("Address: {}", account.address());
println!("Threshold: {}/{}", account.threshold(), account.num_keys());

Implementations§

Source§

impl MultiKeyAccount

Source

pub fn new(private_keys: Vec<AnyPrivateKey>, threshold: u8) -> AptosResult<Self>

Creates a new multi-key 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 private keys (can be mixed types)
  • threshold - The required number of signatures (M in M-of-N)
§Errors

This function will return an error if:

  • No private keys are provided
  • The threshold exceeds the number of keys
  • The multi-key public key creation fails (e.g., too many keys, invalid threshold)
Source

pub fn from_keys( public_keys: Vec<AnyPublicKey>, private_keys: Vec<(u8, AnyPrivateKey)>, threshold: u8, ) -> AptosResult<Self>

Creates a multi-key account from public keys with a subset of private keys.

Use this when you don’t have all the private keys.

§Arguments
  • public_keys - All the public keys in the account
  • private_keys - The private keys you own, with their indices
  • threshold - The required number of signatures
§Errors

This function will return an error if:

  • The multi-key public key creation fails
  • A private key index is out of bounds
  • A private key doesn’t match the public key at its index (wrong type or bytes)
Source

pub fn view_only( public_keys: Vec<AnyPublicKey>, threshold: u8, ) -> AptosResult<Self>

Creates a view-only multi-key account (no signing capability).

§Errors

Returns an error if the multi-key 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) -> &MultiKeyPublicKey

Returns the multi-key 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 key_types(&self) -> Vec<AnyPublicKeyVariant>

Returns the key types for each index.

Source

pub fn sign_message(&self, message: &[u8]) -> AptosResult<MultiKeySignature>

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 private keys to meet the threshold.

Source

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

Signs a message using specific key indices.

§Errors

This function will return an error if:

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

pub fn verify( &self, message: &[u8], signature: &MultiKeySignature, ) -> 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 auth_key(&self) -> AuthenticationKey

Returns the authentication key for this account.

Source

pub fn aggregate_signatures( signatures: Vec<(u8, AnySignature)>, ) -> AptosResult<MultiKeySignature>

Collects individual signatures into a multi-key signature.

§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, AnySignature)>

Creates an individual signature contribution.

§Errors

Returns an error if we don’t have a private key at the specified index.

Trait Implementations§

Source§

impl Account for MultiKeyAccount

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 MultiKeyAccount

Source§

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

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

impl Display for MultiKeyAccount

Source§

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

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

impl From<MultiKeyAccount> for AnyAccount

Source§

fn from(account: MultiKeyAccount) -> 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