@@ -22,7 +22,7 @@ pub struct Signer<D: Digest> {
2222 params : Parameters ,
2323 sk : BlsSigningKey ,
2424 vk : VerificationKey ,
25- closed_reg : ClosedKeyRegistration < D > ,
25+ closed_reg : Option < ClosedKeyRegistration < D > > ,
2626}
2727
2828impl < D : Clone + Digest + FixedOutput > Signer < D > {
@@ -41,7 +41,7 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
4141 params,
4242 sk,
4343 vk,
44- closed_reg,
44+ closed_reg : Some ( closed_reg ) ,
4545 }
4646 }
4747
@@ -58,59 +58,27 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
5858 Self :: set_signer ( signer_index, stake, params, sk, vk, closed_reg)
5959 }
6060
61- /// Create a basic signer (no registration data) for given input
62- pub ( crate ) fn set_basic_signer (
63- signer_index : u64 ,
64- stake : Stake ,
65- params : Parameters ,
66- sk : BlsSigningKey ,
67- vk : VerificationKey ,
68- ) -> Signer < D > {
69- Self {
70- signer_index,
71- stake,
72- params,
73- sk,
74- vk,
75- closed_reg : todo ! ( ) ,
76- }
77- }
78-
79- /// Create a core signer (no registration data) for given input
80- #[ deprecated( since = "0.5.0" , note = "Use `set_basic_signer` instead" ) ]
81- pub fn set_core_signer (
82- signer_index : u64 ,
83- stake : Stake ,
84- params : Parameters ,
85- sk : BlsSigningKey ,
86- vk : VerificationKey ,
87- ) -> Signer < D > {
88- Self :: set_basic_signer ( signer_index, stake, params, sk, vk)
89- }
90-
9161 /// This function produces a signature following the description of Section 2.4.
9262 /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]`
9363 /// wins the lottery by evaluating the dense mapping.
9464 /// It records all the winning indexes in `Self.indexes`.
9565 /// If it wins at least one lottery, it stores the signer's merkle tree index. The proof of membership
9666 /// will be handled by the aggregator.
9767 pub fn sign ( & self , msg : & [ u8 ] ) -> Option < SingleSignature > {
98- // let closed_reg = self.closed_reg.as_ref().expect("Closed registration not found! Cannot produce SingleSignatures. Use core_sign to produce core signatures (not valid for an StmCertificate).");
99- let msgp = self
100- . closed_reg
68+ let closed_reg = self . closed_reg . as_ref ( ) . expect ( "Closed registration not found! Cannot produce SingleSignatures. Use core_sign to produce core signatures (not valid for an StmCertificate)." ) ;
69+ let msgp = closed_reg
10170 . merkle_tree
10271 . to_merkle_tree_batch_commitment ( )
10372 . concatenate_with_message ( msg) ;
10473 let sigma = self . sk . sign ( & msgp) ;
10574
106- let indexes = self . check_lottery ( & msgp, & sigma, self . closed_reg . total_stake ) ;
75+ let indexes = self . check_lottery ( & msgp, & sigma, closed_reg. total_stake ) ;
10776
108- // let signature = self.basic_sign(&msgp, closed_reg.total_stake)?;
10977 if !indexes. is_empty ( ) {
11078 Some ( SingleSignature {
11179 sigma,
112- signer_index : self . signer_index ,
11380 indexes,
81+ signer_index : self . signer_index ,
11482 } )
11583 } else {
11684 None
@@ -133,36 +101,6 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
133101 self . stake
134102 }
135103
136- /// A basic signature generated without closed key registration.
137- /// The basic signature can be verified by basic verifier.
138- /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]`
139- /// wins the lottery by evaluating the dense mapping.
140- /// It records all the winning indexes in `Self.indexes`.
141- pub fn basic_sign ( & self , msg : & [ u8 ] , total_stake : Stake ) -> Option < SingleSignature > {
142- let sigma = self . sk . sign ( msg) ;
143-
144- let indexes = self . check_lottery ( msg, & sigma, total_stake) ;
145- if !indexes. is_empty ( ) {
146- Some ( SingleSignature {
147- sigma,
148- indexes,
149- signer_index : self . signer_index ,
150- } )
151- } else {
152- None
153- }
154- }
155-
156- /// A basic signature generated without closed key registration.
157- /// The basic signature can be verified by basic verifier.
158- /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]`
159- /// wins the lottery by evaluating the dense mapping.
160- /// It records all the winning indexes in `Self.indexes`.
161- #[ deprecated( since = "0.5.0" , note = "Use `basic_sign` instead" ) ]
162- pub fn core_sign ( & self , msg : & [ u8 ] , total_stake : Stake ) -> Option < SingleSignature > {
163- Self :: basic_sign ( self , msg, total_stake)
164- }
165-
166104 /// Collects and returns the winning indices.
167105 pub fn check_lottery ( & self , msg : & [ u8 ] , sigma : & BlsSignature , total_stake : Stake ) -> Vec < u64 > {
168106 let mut indexes = Vec :: new ( ) ;
@@ -192,12 +130,76 @@ impl<D: Clone + Digest + FixedOutput> Signer<D> {
192130
193131 /// Get closed key registration
194132 pub ( crate ) fn get_closed_key_registration ( & self ) -> Option < ClosedKeyRegistration < D > > {
195- Some ( self . closed_reg . clone ( ) )
133+ self . closed_reg . clone ( )
196134 }
197135
198136 /// Get closed key registration
199137 #[ deprecated( since = "0.5.0" , note = "Use `get_closed_key_registration` instead" ) ]
200138 pub fn get_closed_reg ( & self ) -> Option < ClosedKeyRegistration < D > > {
201139 Self :: get_closed_key_registration ( self )
202140 }
141+
142+ /// Create a basic signer (no registration data) for given input
143+ #[ cfg( feature = "basic_verifier" ) ]
144+ pub ( crate ) fn set_basic_signer (
145+ signer_index : u64 ,
146+ stake : Stake ,
147+ params : Parameters ,
148+ sk : BlsSigningKey ,
149+ vk : VerificationKey ,
150+ ) -> Signer < D > {
151+ Self {
152+ signer_index,
153+ stake,
154+ params,
155+ sk,
156+ vk,
157+ closed_reg : None ,
158+ }
159+ }
160+
161+ /// Create a core signer (no registration data) for given input
162+ #[ deprecated( since = "0.5.0" , note = "Use `set_basic_signer` instead" ) ]
163+ #[ cfg( feature = "basic_verifier" ) ]
164+ pub fn set_core_signer (
165+ signer_index : u64 ,
166+ stake : Stake ,
167+ params : Parameters ,
168+ sk : BlsSigningKey ,
169+ vk : VerificationKey ,
170+ ) -> Signer < D > {
171+ Self :: set_basic_signer ( signer_index, stake, params, sk, vk)
172+ }
173+
174+ /// A basic signature generated without closed key registration.
175+ /// The basic signature can be verified by basic verifier.
176+ /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]`
177+ /// wins the lottery by evaluating the dense mapping.
178+ /// It records all the winning indexes in `Self.indexes`.
179+ #[ cfg( feature = "basic_verifier" ) ]
180+ pub fn basic_sign ( & self , msg : & [ u8 ] , total_stake : Stake ) -> Option < SingleSignature > {
181+ let sigma = self . sk . sign ( msg) ;
182+
183+ let indexes = self . check_lottery ( msg, & sigma, total_stake) ;
184+ if !indexes. is_empty ( ) {
185+ Some ( SingleSignature {
186+ sigma,
187+ indexes,
188+ signer_index : self . signer_index ,
189+ } )
190+ } else {
191+ None
192+ }
193+ }
194+
195+ /// A basic signature generated without closed key registration.
196+ /// The basic signature can be verified by basic verifier.
197+ /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]`
198+ /// wins the lottery by evaluating the dense mapping.
199+ /// It records all the winning indexes in `Self.indexes`.
200+ #[ deprecated( since = "0.5.0" , note = "Use `basic_sign` instead" ) ]
201+ #[ cfg( feature = "basic_verifier" ) ]
202+ pub fn core_sign ( & self , msg : & [ u8 ] , total_stake : Stake ) -> Option < SingleSignature > {
203+ Self :: basic_sign ( self , msg, total_stake)
204+ }
203205}
0 commit comments