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
impl MultiKeyAccount
Sourcepub fn new(private_keys: Vec<AnyPrivateKey>, threshold: u8) -> AptosResult<Self>
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)
Sourcepub fn from_keys(
public_keys: Vec<AnyPublicKey>,
private_keys: Vec<(u8, AnyPrivateKey)>,
threshold: u8,
) -> AptosResult<Self>
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 accountprivate_keys- The private keys you own, with their indicesthreshold- 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)
Sourcepub fn view_only(
public_keys: Vec<AnyPublicKey>,
threshold: u8,
) -> AptosResult<Self>
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).
Sourcepub fn address(&self) -> AccountAddress
pub fn address(&self) -> AccountAddress
Returns the account address.
Sourcepub fn public_key(&self) -> &MultiKeyPublicKey
pub fn public_key(&self) -> &MultiKeyPublicKey
Returns the multi-key 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 key_types(&self) -> Vec<AnyPublicKeyVariant>
pub fn key_types(&self) -> Vec<AnyPublicKeyVariant>
Returns the key types for each index.
Sourcepub fn sign_message(&self, message: &[u8]) -> AptosResult<MultiKeySignature>
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.
Sourcepub fn sign_with_indices(
&self,
message: &[u8],
indices: &[u8],
) -> AptosResult<MultiKeySignature>
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
Sourcepub fn verify(
&self,
message: &[u8],
signature: &MultiKeySignature,
) -> AptosResult<()>
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).
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, AnySignature)>,
) -> AptosResult<MultiKeySignature>
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
Sourcepub fn create_signature_contribution(
&self,
message: &[u8],
key_index: u8,
) -> AptosResult<(u8, AnySignature)>
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
impl Account for MultiKeyAccount
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 MultiKeyAccount
impl Debug for MultiKeyAccount
Source§impl Display for MultiKeyAccount
impl Display for MultiKeyAccount
Source§impl From<MultiKeyAccount> for AnyAccount
impl From<MultiKeyAccount> for AnyAccount
Source§fn from(account: MultiKeyAccount) -> Self
fn from(account: MultiKeyAccount) -> Self
Auto Trait Implementations§
impl Freeze for MultiKeyAccount
impl RefUnwindSafe for MultiKeyAccount
impl Send for MultiKeyAccount
impl Sync for MultiKeyAccount
impl Unpin for MultiKeyAccount
impl UnwindSafe for MultiKeyAccount
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.