Skip to content

Commit

Permalink
Generating random DKG public keys should only be a test function
Browse files Browse the repository at this point in the history
For some reason, it was part of WASM bindings too
  • Loading branch information
cygnusv committed Sep 23, 2024
1 parent 7c32b2d commit 18252f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
19 changes: 8 additions & 11 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{collections::HashMap, fmt, io};

use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::UniformRand;
use ferveo_common::serialization;
pub use ferveo_tdec::api::{
prepare_combine_simple, share_combine_precomputed, share_combine_simple,
Expand Down Expand Up @@ -171,14 +170,6 @@ impl DkgPublicKey {
pub fn serialized_size() -> usize {
U48::to_usize()
}

/// Generate a random DKG public key.
/// Use this for testing only.
pub fn random() -> Self {
let mut rng = thread_rng();
let g1 = G1Affine::rand(&mut rng);
Self(ferveo_tdec::DkgPublicKey(g1))
}
}

pub type UnblindingKey = FieldPoint;
Expand Down Expand Up @@ -374,7 +365,7 @@ pub struct SharedSecret(pub ferveo_tdec::api::SharedSecret<E>);
#[cfg(test)]
mod test_ferveo_api {

use ark_std::iterable::Iterable;
use ark_std::{iterable::Iterable, UniformRand};
use ferveo_tdec::SecretBox;
use itertools::{izip, Itertools};
use rand::{
Expand Down Expand Up @@ -429,9 +420,15 @@ mod test_ferveo_api {
(messages, validators, validator_keypairs)
}

fn random_dkg_public_key() -> DkgPublicKey {
let mut rng = thread_rng();
let g1 = G1Affine::rand(&mut rng);
DkgPublicKey(ferveo_tdec::DkgPublicKey(g1))
}

#[test]
fn test_dkg_pk_serialization() {
let dkg_pk = DkgPublicKey::random();
let dkg_pk = random_dkg_public_key();
let serialized = dkg_pk.to_bytes().unwrap();
let deserialized = DkgPublicKey::from_bytes(&serialized).unwrap();
assert_eq!(serialized.len(), 48_usize);
Expand Down
8 changes: 0 additions & 8 deletions ferveo/src/bindings_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,6 @@ pub struct DkgPublicKey(InnerDkgPublicKey);
generate_equals!(DkgPublicKey);
generate_boxed_bytes_serialization!(DkgPublicKey, InnerDkgPublicKey);

#[wasm_bindgen]
impl DkgPublicKey {
#[wasm_bindgen]
pub fn random() -> DkgPublicKey {
Self(api::DkgPublicKey::random())
}
}

#[wasm_bindgen]
pub struct Dkg(api::Dkg);

Expand Down

0 comments on commit 18252f2

Please sign in to comment.