pub struct PublicKeySet { /* private fields */ }
Expand description
A public key and an associated set of public key shares.
Implementations§
Source§impl PublicKeySet
impl PublicKeySet
Sourcepub fn threshold(&self) -> usize
pub fn threshold(&self) -> usize
Returns the threshold t
: any set of t + 1
signature shares can be combined into a full
signature.
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Returns the public key.
Returns the i
-th public key share.
Sourcepub fn combine_signatures<'a, T, I>(
&self,
shares: I,
) -> Result<Signature, Error>
pub fn combine_signatures<'a, T, I>( &self, shares: I, ) -> Result<Signature, Error>
Combines the shares into a signature that can be verified with the main public key.
The validity of the shares is not checked: If one of them is invalid, the resulting signature also is. Only returns an error if there is a duplicate index or too few shares.
Validity of signature shares should be checked beforehand, or validity of the result afterwards:
let sk_set = SecretKeySet::random(3, &mut rand::thread_rng());
let sk_shares: Vec<_> = (0..6).map(|i| sk_set.secret_key_share(i)).collect();
let pk_set = sk_set.public_keys();
let msg = "Happy birthday! If this is signed, at least four people remembered!";
// Create four signature shares for the message.
let sig_shares: BTreeMap<_, _> = (0..4).map(|i| (i, sk_shares[i].sign(msg))).collect();
// Validate the signature shares.
for (i, sig_share) in &sig_shares {
assert!(pk_set.public_key_share(*i).verify(sig_share, msg));
}
// Combine them to produce the main signature.
let sig = pk_set.combine_signatures(&sig_shares).expect("not enough shares");
// Validate the main signature. If the shares were valid, this can't fail.
assert!(pk_set.public_key().verify(&sig, msg));
Sourcepub fn combine_signatures_with_threshold<'a, T, I>(
threshold: usize,
shares: I,
) -> Result<Signature, Error>
pub fn combine_signatures_with_threshold<'a, T, I>( threshold: usize, shares: I, ) -> Result<Signature, Error>
Combines the shares into a signature that can be verified with the main public key. taking a threshold value as argument
Trait Implementations§
Source§impl Clone for PublicKeySet
impl Clone for PublicKeySet
Source§fn clone(&self) -> PublicKeySet
fn clone(&self) -> PublicKeySet
Returns a copy 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 PublicKeySet
impl Debug for PublicKeySet
Source§impl<'de> Deserialize<'de> for PublicKeySet
impl<'de> Deserialize<'de> for PublicKeySet
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PublicKeySet, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PublicKeySet, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Commitment> for PublicKeySet
impl From<Commitment> for PublicKeySet
Source§fn from(commit: Commitment) -> PublicKeySet
fn from(commit: Commitment) -> PublicKeySet
Converts to this type from the input type.
Source§impl Hash for PublicKeySet
impl Hash for PublicKeySet
Source§impl Ord for PublicKeySet
impl Ord for PublicKeySet
Source§fn cmp(&self, other: &PublicKeySet) -> Ordering
fn cmp(&self, other: &PublicKeySet) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for PublicKeySet
impl PartialEq for PublicKeySet
Source§impl PartialOrd for PublicKeySet
impl PartialOrd for PublicKeySet
Source§impl Serialize for PublicKeySet
impl Serialize for PublicKeySet
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for PublicKeySet
impl StructuralPartialEq for PublicKeySet
Auto Trait Implementations§
impl Freeze for PublicKeySet
impl RefUnwindSafe for PublicKeySet
impl Send for PublicKeySet
impl Sync for PublicKeySet
impl Unpin for PublicKeySet
impl UnwindSafe for PublicKeySet
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