From d44618dc887bba0dafc990eee3f0088b6c4f1d26 Mon Sep 17 00:00:00 2001 From: Joey Yandle Date: Fri, 22 Sep 2023 08:36:01 -0400 Subject: [PATCH] add traits::Signer::new so we can have a consistent way of creating Signers --- src/traits.rs | 10 ++++++++++ src/v1.rs | 11 +++++++++++ src/v2.rs | 13 ++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/traits.rs b/src/traits.rs index 4e7b73e..c6580be 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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( + 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; diff --git a/src/v1.rs b/src/v1.rs index 4e61cb9..a9d6422 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -467,6 +467,17 @@ impl Signer { } impl traits::Signer for Signer { + fn new( + 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 } diff --git a/src/v2.rs b/src/v2.rs index 0f85f82..7711798 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -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( + 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 }