Skip to content

Commit

Permalink
add traits::Signer::new so we can have a consistent way of creating S…
Browse files Browse the repository at this point in the history
…igners
  • Loading branch information
xoloki committed Sep 22, 2023
1 parent e941799 commit d44618d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ use crate::{

/// A trait which provides a common `Signer` interface for `v1` and `v2`
pub trait Signer {
/// Create a new `Signer`
fn new<RNG: RngCore + CryptoRng>(
party_id: u32,
key_ids: &[u32],
num_signers: u32,
num_keys: u32,
threshold: u32,
rng: &mut RNG,
) -> Self;

/// Get the signer ID for this signer
fn get_id(&self) -> u32;

Expand Down
11 changes: 11 additions & 0 deletions src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ impl Signer {
}

impl traits::Signer for Signer {
fn new<RNG: RngCore + CryptoRng>(
party_id: u32,
key_ids: &[u32],
_num_signers: u32,
num_keys: u32,
threshold: u32,
rng: &mut RNG,
) -> Self {
Signer::new(party_id, key_ids, num_keys, threshold, rng)
}

fn get_id(&self) -> u32 {
self.id
}
Expand Down
13 changes: 12 additions & 1 deletion src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,18 @@ pub type SignerState = PartyState;
/// Typedef so we can use the same tokens for v1 and v2
pub type Signer = Party;

impl crate::traits::Signer for Party {
impl traits::Signer for Party {
fn new<RNG: RngCore + CryptoRng>(
party_id: u32,
key_ids: &[u32],
num_signers: u32,
num_keys: u32,
threshold: u32,
rng: &mut RNG,
) -> Self {
Party::new(party_id, key_ids, num_signers, num_keys, threshold, rng)
}

fn get_id(&self) -> u32 {
self.party_id
}
Expand Down

0 comments on commit d44618d

Please sign in to comment.