Skip to content

Commit

Permalink
Improve api.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Sep 4, 2023
1 parent 352e7d9 commit c28f6a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
54 changes: 22 additions & 32 deletions frost-core/src/frost/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,6 @@ pub(crate) fn compute_group_commitment<C: Ciphersuite>(
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<C: Ciphersuite>(
group_commitment: &VerifiableSecretSharingCommitment<C>,
peer: Identifier<C>,
) -> VerifyingShare<C> {
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<C: Ciphersuite>(
group_commitment: &VerifiableSecretSharingCommitment<C>,
) -> VerifyingKey<C> {
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<C: Ciphersuite>(
members: &BTreeSet<Identifier<C>>,
group_commitment: &VerifiableSecretSharingCommitment<C>,
) -> PublicKeyPackage<C> {
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<C: Ciphersuite, R: RngCore + CryptoRng>(
size: usize,
Expand Down Expand Up @@ -226,6 +194,15 @@ where
pub fn serialize(&self) -> <C::Group as Group>::Serialization {
<C::Group as Group>::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<C>,
peer: Identifier<C>,
) -> VerifyingShare<C> {
VerifyingShare(evaluate_vss(commitment, peer))
}
}

impl<C> Debug for VerifyingShare<C>
Expand Down Expand Up @@ -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<Identifier<C>>,
commitment: &VerifiableSecretSharingCommitment<C>,
) -> PublicKeyPackage<C> {
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<C: Ciphersuite>(
Expand Down
8 changes: 4 additions & 4 deletions frost-core/src/frost/keys/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -454,7 +454,7 @@ pub fn part3<C: Ciphersuite>(
.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,
Expand Down
10 changes: 10 additions & 0 deletions frost-core/src/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ where
pub fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<(), Error<C>> {
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<C>,
) -> VerifyingKey<C> {
VerifyingKey {
element: commitment.coefficients()[0].value(),
}
}
}

impl<C> Debug for VerifyingKey<C>
Expand Down

0 comments on commit c28f6a3

Please sign in to comment.