Struct blsttc::PublicKeySet
source · [−]pub struct PublicKeySet { /* private fields */ }
Expand description
A public key and an associated set of public key shares.
Implementations
sourceimpl 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<T, I, S: Borrow<SignatureShare>>(
&self,
shares: I
) -> Result<Signature> where
I: IntoIterator<Item = (T, S)>,
T: IntoFr,
pub fn combine_signatures<T, I, S: Borrow<SignatureShare>>(
&self,
shares: I
) -> Result<Signature> where
I: IntoIterator<Item = (T, S)>,
T: IntoFr,
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).expect("failed to sign msg"))).collect();
// Validate the signature shares.
for (i, sig_share) in &sig_shares {
pk_set.public_key_share(*i).verify(sig_share, msg).expect("signature verification failed");
}
// 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.
pk_set.public_key().verify(&sig, msg).expect("signature verification failed");
sourcepub fn decrypt<'a, T, I>(&self, shares: I, ct: &Ciphertext) -> Result<Vec<u8>> where
I: IntoIterator<Item = (T, &'a DecryptionShare)>,
T: IntoFr,
pub fn decrypt<'a, T, I>(&self, shares: I, ct: &Ciphertext) -> Result<Vec<u8>> where
I: IntoIterator<Item = (T, &'a DecryptionShare)>,
T: IntoFr,
Combines the shares to decrypt the ciphertext.
sourcepub fn derive_child(&self, index: &[u8]) -> Self
pub fn derive_child(&self, index: &[u8]) -> Self
Derives a child public key set for a given index.
sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Self>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self>
Deserializes from big endian bytes
Trait Implementations
sourceimpl Clone for PublicKeySet
impl Clone for PublicKeySet
sourcefn clone(&self) -> PublicKeySet
fn clone(&self) -> PublicKeySet
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for PublicKeySet
impl Debug for PublicKeySet
sourceimpl<'de> Deserialize<'de> for PublicKeySet
impl<'de> Deserialize<'de> for PublicKeySet
sourcefn 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
sourceimpl From<Commitment> for PublicKeySet
impl From<Commitment> for PublicKeySet
sourcefn from(commit: Commitment) -> PublicKeySet
fn from(commit: Commitment) -> PublicKeySet
Performs the conversion.
sourceimpl Hash for PublicKeySet
impl Hash for PublicKeySet
sourceimpl Ord for PublicKeySet
impl Ord for PublicKeySet
sourceimpl PartialEq<PublicKeySet> for PublicKeySet
impl PartialEq<PublicKeySet> for PublicKeySet
sourcefn eq(&self, other: &PublicKeySet) -> bool
fn eq(&self, other: &PublicKeySet) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PublicKeySet) -> bool
fn ne(&self, other: &PublicKeySet) -> bool
This method tests for !=
.
sourceimpl PartialOrd<PublicKeySet> for PublicKeySet
impl PartialOrd<PublicKeySet> for PublicKeySet
sourcefn partial_cmp(&self, other: &PublicKeySet) -> Option<Ordering>
fn partial_cmp(&self, other: &PublicKeySet) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for PublicKeySet
impl Serialize for PublicKeySet
impl Eq for PublicKeySet
impl StructuralEq for PublicKeySet
impl StructuralPartialEq for PublicKeySet
Auto Trait Implementations
impl RefUnwindSafe for PublicKeySet
impl Send for PublicKeySet
impl Sync for PublicKeySet
impl Unpin for PublicKeySet
impl UnwindSafe for PublicKeySet
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more