@@ -13,7 +13,7 @@ use std;
13
13
14
14
use crate :: ffi:: { self , CPtr } ;
15
15
use crate :: {
16
- from_hex, schnorr, Error , Keypair , Message , PublicKey , Scalar , Secp256k1 , SecretKey , Signing ,
16
+ from_hex, schnorr, Error , Keypair , PublicKey , Scalar , Secp256k1 , SecretKey , Signing ,
17
17
Verification , XOnlyPublicKey ,
18
18
} ;
19
19
@@ -154,7 +154,7 @@ impl fmt::Display for InvalidTweakErr {
154
154
/// for maximal mis-use resistance.
155
155
/// * `pub_key`: [`PublicKey`] that we will use to create partial signature. The secnonce
156
156
/// output of this function cannot be used to sign for any other public key.
157
- /// * `msg`: Optional [`Message`] that will be signed later on. Provide this for maximal misuse resistance.
157
+ /// * `msg`: Optional message that will be signed later on. Provide this for maximal misuse resistance.
158
158
/// * `extra_rand`: Additional randomness for mis-use resistance. Provide this for maximal misuse resistance
159
159
///
160
160
/// Remember that nonce reuse will immediately leak the secret key!
@@ -184,7 +184,7 @@ pub fn new_nonce_pair<C: Signing>(
184
184
key_agg_cache : Option < & KeyAggCache > ,
185
185
sec_key : Option < SecretKey > ,
186
186
pub_key : PublicKey ,
187
- msg : Option < Message > ,
187
+ msg : Option < & [ u8 ; 32 ] > ,
188
188
extra_rand : Option < [ u8 ; 32 ] > ,
189
189
) -> ( SecretNonce , PublicNonce ) {
190
190
let cx = secp. ctx ( ) . as_ptr ( ) ;
@@ -596,15 +596,15 @@ impl KeyAggCache {
596
596
/// * `session_secrand`: [`SessionSecretRand`] Uniform random identifier for this session. Each call to this
597
597
/// function must have a UNIQUE `session_secrand`.
598
598
/// * `pub_key`: [`PublicKey`] of the signer creating the nonce.
599
- /// * `msg`: [`Message`] that will be signed later on.
599
+ /// * `msg`: message that will be signed later on.
600
600
/// * `extra_rand`: Additional randomness for mis-use resistance
601
601
///
602
602
/// Example:
603
603
///
604
604
/// ```rust
605
605
/// # #[cfg(feature = "std")]
606
606
/// # #[cfg(feature = "rand")] {
607
- /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message };
607
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
608
608
/// # use secp256k1::musig::{KeyAggCache, SessionSecretRand};
609
609
/// # let secp = Secp256k1::new();
610
610
/// # let sk1 = SecretKey::new(&mut rand::rng());
@@ -616,9 +616,8 @@ impl KeyAggCache {
616
616
/// // The session id must be sampled at random. Read documentation for more details.
617
617
/// let session_secrand = SessionSecretRand::from_rng(&mut rand::rng());
618
618
///
619
- /// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
620
- ///
621
619
/// // Provide the current time for mis-use resistance
620
+ /// let msg = b"Public message we want to sign!!";
622
621
/// let extra_rand : Option<[u8; 32]> = None;
623
622
/// let (_sec_nonce, _pub_nonce) = key_agg_cache.nonce_gen(&secp, session_secrand, pub_key1, msg, extra_rand);
624
623
/// # }
@@ -628,7 +627,7 @@ impl KeyAggCache {
628
627
secp : & Secp256k1 < C > ,
629
628
session_secrand : SessionSecretRand ,
630
629
pub_key : PublicKey ,
631
- msg : Message ,
630
+ msg : & [ u8 ; 32 ] ,
632
631
extra_rand : Option < [ u8 ; 32 ] > ,
633
632
) -> ( SecretNonce , PublicNonce ) {
634
633
// The secret key here is supplied as NULL. This is okay because we supply the
@@ -900,7 +899,7 @@ impl AggregatedNonce {
900
899
/// ```rust
901
900
/// # #[cfg(feature = "std")]
902
901
/// # #[cfg(feature = "rand")] {
903
- /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message };
902
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
904
903
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand};
905
904
/// # let secp = Secp256k1::new();
906
905
/// # let sk1 = SecretKey::new(&mut rand::rng());
@@ -911,7 +910,7 @@ impl AggregatedNonce {
911
910
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
912
911
/// // The session id must be sampled at random. Read documentation for more details.
913
912
///
914
- /// let msg = Message::from_digest_slice( b"Public Message we want to sign!!").unwrap() ;
913
+ /// let msg = b"Public message we want to sign!!";
915
914
///
916
915
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
917
916
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
@@ -1056,14 +1055,14 @@ impl Session {
1056
1055
/// * `secp` : [`Secp256k1`] context object initialized for signing
1057
1056
/// * `key_agg_cache`: [`KeyAggCache`] to be used for this session
1058
1057
/// * `agg_nonce`: [`AggregatedNonce`], the aggregate nonce
1059
- /// * `msg`: [`Message`] that will be signed later on.
1058
+ /// * `msg`: message that will be signed later on.
1060
1059
///
1061
1060
/// Example:
1062
1061
///
1063
1062
/// ```rust
1064
1063
/// # #[cfg(feature = "std")]
1065
1064
/// # #[cfg(feature = "rand")] {
1066
- /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message };
1065
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
1067
1066
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, Session, SessionSecretRand};
1068
1067
/// # let secp = Secp256k1::new();
1069
1068
/// # let sk1 = SecretKey::new(&mut rand::rng());
@@ -1074,7 +1073,7 @@ impl Session {
1074
1073
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
1075
1074
/// // The session id must be sampled at random. Read documentation for more details.
1076
1075
///
1077
- /// let msg = Message::from_digest_slice( b"Public Message we want to sign!!").unwrap() ;
1076
+ /// let msg = b"Public message we want to sign!!";
1078
1077
///
1079
1078
/// // Provide the current time for mis-use resistance
1080
1079
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
@@ -1100,7 +1099,7 @@ impl Session {
1100
1099
secp : & Secp256k1 < C > ,
1101
1100
key_agg_cache : & KeyAggCache ,
1102
1101
agg_nonce : AggregatedNonce ,
1103
- msg : Message ,
1102
+ msg : & [ u8 ; 32 ] ,
1104
1103
) -> Self {
1105
1104
let mut session = MaybeUninit :: < ffi:: MusigSession > :: uninit ( ) ;
1106
1105
@@ -1199,7 +1198,7 @@ impl Session {
1199
1198
/// # #[cfg(not(secp256k1_fuzz))]
1200
1199
/// # #[cfg(feature = "std")]
1201
1200
/// # #[cfg(feature = "rand")] {
1202
- /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message };
1201
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
1203
1202
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand, Session};
1204
1203
/// # let secp = Secp256k1::new();
1205
1204
/// # let sk1 = SecretKey::new(&mut rand::rng());
@@ -1210,7 +1209,7 @@ impl Session {
1210
1209
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
1211
1210
/// // The session id must be sampled at random. Read documentation for more details.
1212
1211
///
1213
- /// let msg = Message::from_digest_slice( b"Public Message we want to sign!!").unwrap() ;
1212
+ /// let msg = b"Public message we want to sign!!";
1214
1213
///
1215
1214
/// // Provide the current time for mis-use resistance
1216
1215
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
@@ -1280,7 +1279,7 @@ impl Session {
1280
1279
///
1281
1280
/// ```rust
1282
1281
/// # #[cfg(feature = "rand-std")] {
1283
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
1282
+ /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, AggregatedNonce, Session};
1284
1283
/// # let secp = Secp256k1::new();
1285
1284
/// # let sk1 = SecretKey::new(&mut rand::rng());
1286
1285
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
@@ -1290,7 +1289,7 @@ impl Session {
1290
1289
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
1291
1290
/// // The session id must be sampled at random. Read documentation for more details.
1292
1291
///
1293
- /// let msg = Message::from_digest_slice( b"Public Message we want to sign!!").unwrap() ;
1292
+ /// let msg = b"Public message we want to sign!!";
1294
1293
///
1295
1294
/// // Provide the current time for mis-use resistance
1296
1295
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
@@ -1381,7 +1380,7 @@ mod tests {
1381
1380
use super :: * ;
1382
1381
#[ cfg( feature = "std" ) ]
1383
1382
#[ cfg( feature = "rand" ) ]
1384
- use crate :: { Message , PublicKey , Secp256k1 , SecretKey } ;
1383
+ use crate :: { PublicKey , Secp256k1 , SecretKey } ;
1385
1384
1386
1385
#[ test]
1387
1386
#[ cfg( feature = "std" ) ]
@@ -1490,8 +1489,7 @@ mod tests {
1490
1489
1491
1490
let key_agg_cache = KeyAggCache :: new ( & secp, & [ & pubkey1, & pubkey2] ) ;
1492
1491
1493
- let msg_bytes: [ u8 ; 32 ] = * b"this_could_be_the_hash_of_a_msg!" ;
1494
- let msg = Message :: from_digest_slice ( & msg_bytes) . unwrap ( ) ;
1492
+ let msg: & [ u8 ; 32 ] = b"This message is exactly 32 bytes" ;
1495
1493
1496
1494
// Test nonce generation with KeyAggCache
1497
1495
let session_secrand1 = SessionSecretRand :: from_rng ( & mut rng) ;
@@ -1530,8 +1528,7 @@ mod tests {
1530
1528
1531
1529
let key_agg_cache = KeyAggCache :: new ( & secp, & [ & pubkey1, & pubkey2] ) ;
1532
1530
1533
- let msg_bytes: [ u8 ; 32 ] = * b"this_could_be_the_hash_of_a_msg!" ;
1534
- let msg = Message :: from_digest_slice ( & msg_bytes) . unwrap ( ) ;
1531
+ let msg: & [ u8 ; 32 ] = b"This message is exactly 32 bytes" ;
1535
1532
1536
1533
let session_secrand1 = SessionSecretRand :: from_rng ( & mut rng) ;
1537
1534
let ( _, pub_nonce1) = key_agg_cache. nonce_gen ( & secp, session_secrand1, pubkey1, msg, None ) ;
@@ -1580,8 +1577,7 @@ mod tests {
1580
1577
let pubkeys = [ & pubkey1, & pubkey2] ;
1581
1578
let key_agg_cache = KeyAggCache :: new ( & secp, & pubkeys) ;
1582
1579
1583
- let msg_bytes: [ u8 ; 32 ] = * b"this_could_be_the_hash_of_a_msg!" ;
1584
- let msg = Message :: from_digest_slice ( & msg_bytes) . unwrap ( ) ;
1580
+ let msg: & [ u8 ; 32 ] = b"This message is exactly 32 bytes" ;
1585
1581
1586
1582
let session_secrand1 = SessionSecretRand :: from_rng ( & mut rng) ;
1587
1583
let ( sec_nonce1, pub_nonce1) =
@@ -1664,8 +1660,7 @@ mod tests {
1664
1660
let pubkeys = [ & pubkey1, & pubkey2] ;
1665
1661
let key_agg_cache = KeyAggCache :: new ( & secp, & pubkeys) ;
1666
1662
1667
- let msg_bytes: [ u8 ; 32 ] = * b"this_could_be_the_hash_of_a_msg!" ;
1668
- let msg = Message :: from_digest_slice ( & msg_bytes) . unwrap ( ) ;
1663
+ let msg: & [ u8 ; 32 ] = b"This message is exactly 32 bytes" ;
1669
1664
1670
1665
let session_secrand1 = SessionSecretRand :: from_rng ( & mut rng) ;
1671
1666
let ( sec_nonce1, pub_nonce1) =
@@ -1688,23 +1683,23 @@ mod tests {
1688
1683
// Test signature verification
1689
1684
let aggregated_signature = session. partial_sig_agg ( & [ & partial_sign1, & partial_sign2] ) ;
1690
1685
let agg_pk = key_agg_cache. agg_pk ( ) ;
1691
- aggregated_signature. verify ( & secp, & agg_pk, & msg_bytes ) . unwrap ( ) ;
1686
+ aggregated_signature. verify ( & secp, & agg_pk, msg ) . unwrap ( ) ;
1692
1687
1693
1688
// Test assume_valid
1694
1689
let schnorr_sig = aggregated_signature. assume_valid ( ) ;
1695
- secp. verify_schnorr ( & schnorr_sig, & msg_bytes , & agg_pk) . unwrap ( ) ;
1690
+ secp. verify_schnorr ( & schnorr_sig, msg , & agg_pk) . unwrap ( ) ;
1696
1691
1697
1692
// Test with wrong aggregate (repeated sigs)
1698
1693
let aggregated_signature = session. partial_sig_agg ( & [ & partial_sign1, & partial_sign1] ) ;
1699
- aggregated_signature. verify ( & secp, & agg_pk, & msg_bytes ) . unwrap_err ( ) ;
1694
+ aggregated_signature. verify ( & secp, & agg_pk, msg ) . unwrap_err ( ) ;
1700
1695
let schnorr_sig = aggregated_signature. assume_valid ( ) ;
1701
- secp. verify_schnorr ( & schnorr_sig, & msg_bytes , & agg_pk) . unwrap_err ( ) ;
1696
+ secp. verify_schnorr ( & schnorr_sig, msg , & agg_pk) . unwrap_err ( ) ;
1702
1697
1703
1698
// Test with swapped sigs -- this will work. Unlike keys, sigs are not ordered.
1704
1699
let aggregated_signature = session. partial_sig_agg ( & [ & partial_sign2, & partial_sign1] ) ;
1705
- aggregated_signature. verify ( & secp, & agg_pk, & msg_bytes ) . unwrap ( ) ;
1700
+ aggregated_signature. verify ( & secp, & agg_pk, msg ) . unwrap ( ) ;
1706
1701
let schnorr_sig = aggregated_signature. assume_valid ( ) ;
1707
- secp. verify_schnorr ( & schnorr_sig, & msg_bytes , & agg_pk) . unwrap ( ) ;
1702
+ secp. verify_schnorr ( & schnorr_sig, msg , & agg_pk) . unwrap ( ) ;
1708
1703
}
1709
1704
1710
1705
#[ test]
@@ -1724,8 +1719,7 @@ mod tests {
1724
1719
let pubkeys_ref = pubkeys_ref. as_mut_slice ( ) ;
1725
1720
1726
1721
let key_agg_cache = KeyAggCache :: new ( & secp, pubkeys_ref) ;
1727
- let msg_bytes: [ u8 ; 32 ] = * b"this_could_be_the_hash_of_a_msg!" ;
1728
- let msg = Message :: from_digest_slice ( & msg_bytes) . unwrap ( ) ;
1722
+ let msg: & [ u8 ; 32 ] = b"This message is exactly 32 bytes" ;
1729
1723
1730
1724
let session_secrand1 = SessionSecretRand :: from_rng ( & mut rng) ;
1731
1725
let ( _, pub_nonce1) = key_agg_cache. nonce_gen ( & secp, session_secrand1, pubkey1, msg, None ) ;
0 commit comments