@@ -41,6 +41,12 @@ use mockall::automock;
4141/// MultiSigner is the cryptographic engine in charge of producing multi signatures from individual signatures
4242#[ cfg_attr( test, automock) ]
4343pub trait MultiSigner : Sync + Send {
44+ /// Get current message
45+ fn get_current_message ( & self ) -> Option < Bytes > ;
46+
47+ /// Update current message
48+ fn update_current_message ( & mut self , message : Bytes ) -> Result < ( ) , String > ;
49+
4450 /// Get protocol parameters
4551 fn get_protocol_parameters ( & self ) -> Option < ProtocolParameters > ;
4652
@@ -89,6 +95,7 @@ pub trait MultiSigner: Sync + Send {
8995
9096/// MultiSignerImpl is an implementation of the MultiSigner
9197pub struct MultiSignerImpl {
98+ current_message : Option < Bytes > ,
9299 protocol_parameters : Option < ProtocolParameters > ,
93100 stakes : Vec < ( ProtocolPartyId , ProtocolStake ) > ,
94101 signers : HashMap < ProtocolPartyId , ProtocolSignerVerificationKey > ,
@@ -108,6 +115,7 @@ impl MultiSignerImpl {
108115 pub fn new ( ) -> Self {
109116 debug ! ( "New MultiSignerImpl created" ) ;
110117 Self {
118+ current_message : None ,
111119 protocol_parameters : None ,
112120 stakes : Vec :: new ( ) ,
113121 signers : HashMap :: new ( ) ,
@@ -145,6 +153,17 @@ impl MultiSignerImpl {
145153}
146154
147155impl MultiSigner for MultiSignerImpl {
156+ /// Get current message
157+ fn get_current_message ( & self ) -> Option < Bytes > {
158+ self . current_message . clone ( )
159+ }
160+
161+ /// Update current message
162+ fn update_current_message ( & mut self , message : Bytes ) -> Result < ( ) , String > {
163+ self . current_message = Some ( message) ;
164+ Ok ( ( ) )
165+ }
166+
148167 /// Get protocol parameters
149168 fn get_protocol_parameters ( & self ) -> Option < ProtocolParameters > {
150169 self . protocol_parameters
@@ -204,7 +223,7 @@ impl MultiSigner for MultiSignerImpl {
204223 party_id, index
205224 ) ;
206225
207- let message = & self . message ( ) ;
226+ let message = & self . get_current_message ( ) . unwrap ( ) ;
208227 let clerk = self . clerk ( ) ;
209228 match clerk. verify_sig ( signature, index, message) {
210229 Ok ( _) => {
@@ -270,7 +289,7 @@ impl MultiSigner for MultiSignerImpl {
270289 fn create_multi_signature ( & mut self ) -> Result < Option < ProtocolMultiSignature > , String > {
271290 debug ! ( "Create multi signature" ) ;
272291
273- let message = & self . message ( ) ;
292+ let message = & self . get_current_message ( ) . unwrap ( ) ;
274293 let signatures: ( Vec < ProtocolSingleSignature > , Vec < ProtocolLotteryIndex > ) = self
275294 . single_signatures
276295 . iter ( )
@@ -328,6 +347,10 @@ mod tests {
328347 use rand_chacha:: ChaCha20Rng ;
329348 use rand_core:: { RngCore , SeedableRng } ;
330349
350+ fn message ( ) -> Bytes {
351+ Vec :: from_hex ( "7724e03fb8d84a376a43b8f41518a11c" ) . unwrap ( )
352+ }
353+
331354 fn setup_protocol_parameters ( ) -> ProtocolParameters {
332355 ProtocolParameters {
333356 m : 10 ,
@@ -415,6 +438,21 @@ mod tests {
415438 assert_eq ! ( secret_key, secret_key_restored) ;
416439 }
417440
441+ #[ test]
442+ fn test_multi_signer_current_message_ok ( ) {
443+ let mut multi_signer = MultiSignerImpl :: new ( ) ;
444+
445+ let current_message_expected = Vec :: from_hex ( "7724e03fb8d84a376a43b8f41518a11c" ) . unwrap ( ) ;
446+ multi_signer
447+ . update_current_message ( current_message_expected. clone ( ) )
448+ . expect ( "update current message failed" ) ;
449+
450+ let current_message = multi_signer
451+ . get_current_message ( )
452+ . expect ( "current message should have been retrieved" ) ;
453+ assert_eq ! ( current_message_expected, current_message)
454+ }
455+
418456 #[ test]
419457 fn test_multi_signer_protocol_parameters_ok ( ) {
420458 let mut multi_signer = MultiSignerImpl :: new ( ) ;
@@ -471,7 +509,11 @@ mod tests {
471509 #[ test]
472510 fn test_multi_signer_multi_signature_ok ( ) {
473511 let mut multi_signer = MultiSignerImpl :: new ( ) ;
474- let message = multi_signer. message ( ) ;
512+
513+ let message = message ( ) ;
514+ multi_signer
515+ . update_current_message ( message. clone ( ) )
516+ . expect ( "update current message failed" ) ;
475517
476518 let protocol_parameters = setup_protocol_parameters ( ) ;
477519 multi_signer
0 commit comments