11use secp256kfun:: {
2- Slice ,
32 digest:: { self } ,
43 hash:: HashInto ,
5- marker:: * ,
64} ;
75
86/// A message to be signed.
9- ///
10- /// The `S` parameter is a [`Secrecy`] which is used when signing a verifying to check whether the
11- /// challenge scalar produced with the message should be secret.
127#[ derive( Debug , Clone , Copy , PartialEq ) ]
13- pub struct Message < ' a , S = Public > {
8+ pub struct Message < ' a > {
149 /// The message bytes
15- pub bytes : Slice < ' a , S > ,
10+ pub bytes : & ' a [ u8 ] ,
1611 /// The optional application tag to separate the signature from other applications.
1712 #[ deprecated(
1813 since = "0.11.0" ,
@@ -26,12 +21,12 @@ pub struct Message<'a, S = Public> {
2621}
2722
2823#[ allow( deprecated) ]
29- impl < ' a , S : Secrecy > Message < ' a , S > {
24+ impl < ' a > Message < ' a > {
3025 /// Create a raw message with no domain separation. The message bytes will be passed straight into the
3126 /// challenge hash. Usually, you only use this when signing a pre-hashed message.
3227 pub fn raw ( bytes : & ' a [ u8 ] ) -> Self {
3328 Message {
34- bytes : Slice :: from ( bytes ) ,
29+ bytes,
3530 app_tag : None ,
3631 bip340_domain_sep : None ,
3732 }
@@ -51,8 +46,8 @@ impl<'a, S: Secrecy> Message<'a, S> {
5146 ///
5247 /// # Example
5348 /// ```
54- /// use schnorr_fun::{ Message, fun::marker::Public} ;
55- /// let message = Message::<Public>:: new("my-app/sign", b"hello world");
49+ /// use schnorr_fun::Message;
50+ /// let message = Message::new("my-app/sign", b"hello world");
5651 /// ```
5752 pub fn new ( domain_sep : & ' static str , bytes : & ' a [ u8 ] ) -> Self {
5853 assert ! ( !domain_sep. is_empty( ) , "domain separator must not be empty" ) ;
@@ -61,7 +56,7 @@ impl<'a, S: Secrecy> Message<'a, S> {
6156 "domain separator must be 33 bytes or less"
6257 ) ;
6358 Message {
64- bytes : Slice :: from ( bytes ) ,
59+ bytes,
6560 app_tag : None ,
6661 bip340_domain_sep : Some ( domain_sep) ,
6762 }
@@ -88,7 +83,7 @@ impl<'a, S: Secrecy> Message<'a, S> {
8883 assert ! ( app_tag. len( ) <= 64 , "tag must be 64 bytes or less" ) ;
8984 assert ! ( !app_tag. is_empty( ) , "tag must not be empty" ) ;
9085 Message {
91- bytes : Slice :: from ( bytes ) ,
86+ bytes,
9287 app_tag : Some ( app_tag) ,
9388 bip340_domain_sep : None ,
9489 }
@@ -102,15 +97,15 @@ impl<'a, S: Secrecy> Message<'a, S> {
10297 /// Length of the message as it is hashed
10398 pub fn len ( & self ) -> usize {
10499 match ( self . app_tag , self . bip340_domain_sep ) {
105- ( Some ( _) , _) => 64 + self . bytes . as_inner ( ) . len ( ) ,
106- ( _, Some ( _) ) => 33 + self . bytes . as_inner ( ) . len ( ) , // BIP340 style uses 33-byte prefix
107- ( None , None ) => self . bytes . as_inner ( ) . len ( ) ,
100+ ( Some ( _) , _) => 64 + self . bytes . len ( ) ,
101+ ( _, Some ( _) ) => 33 + self . bytes . len ( ) , // BIP340 style uses 33-byte prefix
102+ ( None , None ) => self . bytes . len ( ) ,
108103 }
109104 }
110105}
111106
112107#[ allow( deprecated) ]
113- impl < S > HashInto for Message < ' _ , S > {
108+ impl HashInto for Message < ' _ > {
114109 fn hash_into ( self , hash : & mut impl digest:: Update ) {
115110 if let Some ( prefix) = self . app_tag {
116111 let mut padded_prefix = [ 0u8 ; 64 ] ;
@@ -122,7 +117,7 @@ impl<S> HashInto for Message<'_, S> {
122117 padded_prefix[ ..domain_sep. len ( ) ] . copy_from_slice ( domain_sep. as_bytes ( ) ) ;
123118 hash. update ( & padded_prefix) ;
124119 }
125- hash. update ( self . bytes . as_inner ( ) ) ;
120+ hash. update ( self . bytes ) ;
126121 }
127122}
128123
@@ -134,13 +129,13 @@ mod test {
134129 #[ test]
135130 fn bip340_domain_separation ( ) {
136131 // Test that BIP340 domain separation uses 33-byte prefix
137- let msg = Message :: < Public > :: new ( "test" , b"hello" ) ;
132+ let msg = Message :: new ( "test" , b"hello" ) ;
138133
139134 // Expected: "test" padded to 33 bytes + "hello"
140135 let mut expected_hash = Sha256 :: default ( ) ;
141136 let mut padded_prefix = [ 0u8 ; 33 ] ;
142137 padded_prefix[ ..4 ] . copy_from_slice ( b"test" ) ;
143- expected_hash. update ( & padded_prefix) ;
138+ expected_hash. update ( padded_prefix) ;
144139 expected_hash. update ( b"hello" ) ;
145140
146141 let mut actual_hash = Sha256 :: default ( ) ;
@@ -154,20 +149,20 @@ mod test {
154149
155150 #[ test]
156151 fn message_new_fixed_key_signature ( ) {
157- use crate :: { fun:: s , new_with_deterministic_nonces} ;
152+ use crate :: { Signature , fun:: prelude :: * , new_with_deterministic_nonces} ;
158153 use core:: str:: FromStr ;
159154
160155 // Fixed test to ensure Message::new domain separation doesn't accidentally change
161156 let schnorr = new_with_deterministic_nonces :: < Sha256 > ( ) ;
162157 let secret_key = s ! ( 42 ) ;
163158 let keypair = schnorr. new_keypair ( secret_key) ;
164159
165- let message = Message :: < Public > :: new ( "test-app" , b"test message" ) ;
160+ let message = Message :: new ( "test-app" , b"test message" ) ;
166161 let signature = schnorr. sign ( & keypair, message) ;
167162
168163 // This signature was generated with the current implementation and should never change
169164 // to ensure backwards compatibility
170- let expected_sig = crate :: Signature :: < Public > :: from_str (
165+ let expected_sig = Signature :: from_str (
171166 "5c49762df465f21993af631caedb3e478793142e15f200e70511e5af71387e52a3b9b6af189fa4b28a767254f2a8977f2e9db1866ad4dfbb083bb4fbd8dfe82e"
172167 ) . unwrap ( ) ;
173168
0 commit comments