pub struct MultiEd25519PublicKey { /* private fields */ }Available on crate feature
ed25519 only.Expand description
A multi-Ed25519 public key.
This is a collection of Ed25519 public keys with a threshold value. M-of-N signatures are required where M = threshold and N = number of keys.
§Example
ⓘ
use aptos_sdk::crypto::{Ed25519PrivateKey, MultiEd25519PublicKey};
let keys: Vec<_> = (0..3).map(|_| Ed25519PrivateKey::generate().public_key()).collect();
let multi_pk = MultiEd25519PublicKey::new(keys, 2).unwrap(); // 2-of-3Implementations§
Source§impl MultiEd25519PublicKey
impl MultiEd25519PublicKey
Sourcepub fn new(
public_keys: Vec<Ed25519PublicKey>,
threshold: u8,
) -> AptosResult<Self>
pub fn new( public_keys: Vec<Ed25519PublicKey>, threshold: u8, ) -> AptosResult<Self>
Creates a new multi-Ed25519 public key.
§Arguments
public_keys- The individual Ed25519 public keysthreshold- The number of signatures required (M in M-of-N)
§Errors
Returns an error if:
- No public keys are provided
- More than 32 public keys are provided
- Threshold is 0
- Threshold exceeds the number of keys
Sourcepub fn public_keys(&self) -> &[Ed25519PublicKey]
pub fn public_keys(&self) -> &[Ed25519PublicKey]
Returns the individual public keys.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serializes the public key to bytes.
Format: public_key_1 || public_key_2 || … || public_key_n || threshold
Sourcepub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates a public key from bytes.
§Errors
Returns AptosError::InvalidPublicKey if:
- The bytes are empty
- The bytes are too short (less than 33 bytes for one key + threshold)
- The key bytes length is not a multiple of 32 bytes
- Any individual public key fails to parse
- The threshold is invalid (0, exceeds number of keys, etc.)
Sourcepub fn to_address(&self) -> AccountAddress
pub fn to_address(&self) -> AccountAddress
Derives the account address for this multi-Ed25519 public key.
Sourcepub fn to_authentication_key(&self) -> [u8; 32]
pub fn to_authentication_key(&self) -> [u8; 32]
Derives the authentication key for this public key.
Sourcepub fn verify(
&self,
message: &[u8],
signature: &MultiEd25519Signature,
) -> AptosResult<()>
pub fn verify( &self, message: &[u8], signature: &MultiEd25519Signature, ) -> AptosResult<()>
Verifies a multi-Ed25519 signature against a message.
§Errors
This function will return an error if:
- The number of signatures is less than the threshold
- Any individual signature verification fails
- A signer index is out of bounds
Trait Implementations§
Source§impl Clone for MultiEd25519PublicKey
impl Clone for MultiEd25519PublicKey
Source§fn clone(&self) -> MultiEd25519PublicKey
fn clone(&self) -> MultiEd25519PublicKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MultiEd25519PublicKey
impl Debug for MultiEd25519PublicKey
Source§impl<'de> Deserialize<'de> for MultiEd25519PublicKey
impl<'de> Deserialize<'de> for MultiEd25519PublicKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for MultiEd25519PublicKey
impl Display for MultiEd25519PublicKey
Source§impl PartialEq for MultiEd25519PublicKey
impl PartialEq for MultiEd25519PublicKey
Source§impl PublicKey for MultiEd25519PublicKey
impl PublicKey for MultiEd25519PublicKey
Source§fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates a public key from bytes. Read more
Source§impl Serialize for MultiEd25519PublicKey
impl Serialize for MultiEd25519PublicKey
Source§impl Verifier for MultiEd25519PublicKey
impl Verifier for MultiEd25519PublicKey
Source§type Signature = MultiEd25519Signature
type Signature = MultiEd25519Signature
The signature type this verifier can check.
Source§fn verify(
&self,
message: &[u8],
signature: &MultiEd25519Signature,
) -> AptosResult<()>
fn verify( &self, message: &[u8], signature: &MultiEd25519Signature, ) -> AptosResult<()>
Verifies that the signature is valid for the given message. Read more
impl Eq for MultiEd25519PublicKey
impl StructuralPartialEq for MultiEd25519PublicKey
Auto Trait Implementations§
impl Freeze for MultiEd25519PublicKey
impl RefUnwindSafe for MultiEd25519PublicKey
impl Send for MultiEd25519PublicKey
impl Sync for MultiEd25519PublicKey
impl Unpin for MultiEd25519PublicKey
impl UnwindSafe for MultiEd25519PublicKey
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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> IntoMoveArg for Twhere
T: Serialize,
impl<T> IntoMoveArg for Twhere
T: Serialize,
Source§fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
Converts this value into BCS-encoded bytes. Read more
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
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.