From c28f6a387cff5f9840f445e6e4b71ec7772188d6 Mon Sep 17 00:00:00 2001 From: David Craven Date: Mon, 4 Sep 2023 15:14:54 +0200 Subject: [PATCH] Improve api. --- frost-core/src/frost/keys.rs | 54 +++++++++++++------------------- frost-core/src/frost/keys/dkg.rs | 8 ++--- frost-core/src/verifying_key.rs | 10 ++++++ 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/frost-core/src/frost/keys.rs b/frost-core/src/frost/keys.rs index 6e422df5..c8470f68 100644 --- a/frost-core/src/frost/keys.rs +++ b/frost-core/src/frost/keys.rs @@ -44,38 +44,6 @@ pub(crate) fn compute_group_commitment( VerifiableSecretSharingCommitment(group_commitment) } -/// Computes a verifying share for a peer given the group commitment. -#[cfg_attr(feature = "internals", visibility::make(pub))] -pub(crate) fn compute_verifying_share( - group_commitment: &VerifiableSecretSharingCommitment, - peer: Identifier, -) -> VerifyingShare { - VerifyingShare(evaluate_vss(group_commitment, peer)) -} - -/// Computes the group public key given the group commitment. -#[cfg_attr(feature = "internals", visibility::make(pub))] -pub(crate) fn compute_public_key( - group_commitment: &VerifiableSecretSharingCommitment, -) -> VerifyingKey { - VerifyingKey { - element: group_commitment.coefficients()[0].value(), - } -} - -/// Computes the public key package given a list of commitments. -#[cfg_attr(feature = "internals", visibility::make(pub))] -pub(crate) fn compute_public_key_package( - members: &BTreeSet>, - group_commitment: &VerifiableSecretSharingCommitment, -) -> PublicKeyPackage { - let mut verifying_keys = HashMap::new(); - for peer in members { - verifying_keys.insert(*peer, compute_verifying_share(group_commitment, *peer)); - } - PublicKeyPackage::new(verifying_keys, compute_public_key(group_commitment)) -} - /// Return a vector of randomly generated polynomial coefficients ([`Scalar`]s). pub(crate) fn generate_coefficients( size: usize, @@ -226,6 +194,15 @@ where pub fn serialize(&self) -> ::Serialization { ::serialize(&self.0) } + + /// Computes a verifying share for a peer given the group commitment. + #[cfg_attr(feature = "internals", visibility::make(pub))] + pub(crate) fn from_commitment( + commitment: &VerifiableSecretSharingCommitment, + peer: Identifier, + ) -> VerifyingShare { + VerifyingShare(evaluate_vss(commitment, peer)) + } } impl Debug for VerifyingShare @@ -724,6 +701,19 @@ where ciphersuite: (), } } + + /// Computes the public key package given a list of commitments. + #[cfg_attr(feature = "internals", visibility::make(pub))] + pub(crate) fn from_commitment( + members: &BTreeSet>, + commitment: &VerifiableSecretSharingCommitment, + ) -> PublicKeyPackage { + let mut verifying_keys = HashMap::new(); + for peer in members { + verifying_keys.insert(*peer, VerifyingShare::from_commitment(commitment, *peer)); + } + PublicKeyPackage::new(verifying_keys, VerifyingKey::from_commitment(commitment)) + } } fn validate_num_of_signers( diff --git a/frost-core/src/frost/keys/dkg.rs b/frost-core/src/frost/keys/dkg.rs index 5dd2ecb1..650e8343 100644 --- a/frost-core/src/frost/keys/dkg.rs +++ b/frost-core/src/frost/keys/dkg.rs @@ -40,9 +40,9 @@ use crate::{ }; use super::{ - compute_group_commitment, compute_public_key_package, evaluate_polynomial, - generate_coefficients, generate_secret_polynomial, validate_num_of_signers, KeyPackage, - PublicKeyPackage, SecretShare, SigningShare, VerifiableSecretSharingCommitment, + compute_group_commitment, evaluate_polynomial, generate_coefficients, + generate_secret_polynomial, validate_num_of_signers, KeyPackage, PublicKeyPackage, SecretShare, + SigningShare, VerifiableSecretSharingCommitment, }; /// DKG Round 1 structures. @@ -454,7 +454,7 @@ pub fn part3( .chain(iter::once(round2_secret_package.commitment.clone())) .collect(); let group_commitment = compute_group_commitment(&commitments); - let public_key_package = compute_public_key_package(&members, &group_commitment); + let public_key_package = PublicKeyPackage::from_commitment(&members, &group_commitment); let key_package = KeyPackage { identifier: round2_secret_package.identifier, secret_share: signing_share, diff --git a/frost-core/src/verifying_key.rs b/frost-core/src/verifying_key.rs index 2932613e..273c594a 100644 --- a/frost-core/src/verifying_key.rs +++ b/frost-core/src/verifying_key.rs @@ -76,6 +76,16 @@ where pub fn verify(&self, msg: &[u8], signature: &Signature) -> Result<(), Error> { C::verify_signature(msg, signature, self) } + + /// Computes the group public key given the group commitment. + #[cfg_attr(feature = "internals", visibility::make(pub))] + pub(crate) fn from_commitment( + commitment: &crate::frost::keys::VerifiableSecretSharingCommitment, + ) -> VerifyingKey { + VerifyingKey { + element: commitment.coefficients()[0].value(), + } + } } impl Debug for VerifyingKey