@@ -18,7 +18,7 @@ use crate::{Message, PublicKey, Secp256k1, SecretKey, Tweak};
1818use crate :: { Signing , Verification } ;
1919use secp256k1:: Parity ;
2020
21- #[ cfg( feature = "rand" ) ]
21+ #[ cfg( feature = "actual- rand" ) ]
2222use rand:: { CryptoRng , RngCore } ;
2323
2424/// Cached data related to a key aggregation.
@@ -43,7 +43,7 @@ impl MusigSessionId {
4343 }
4444
4545 /// Creates a new [`MusigSessionId`] with random bytes from the given rng
46- #[ cfg( feature = "rand" ) ]
46+ #[ cfg( feature = "actual- rand" ) ]
4747 pub fn new < R : RngCore + CryptoRng > ( rng : & mut R ) -> Self {
4848 let mut session_id = [ 0u8 ; 32 ] ;
4949 rng. fill_bytes ( & mut session_id) ;
@@ -627,74 +627,6 @@ impl fmt::Display for ParseError {
627627///
628628/// The [`schnorr::Signature`] with the adaptor applied.
629629///
630- /// Example:
631- ///
632- /// ```rust
633- /// # # [cfg(any(test, feature = "rand-std"))] {
634- /// # use secp256k1_zkp::rand::{thread_rng, RngCore};
635- /// # use secp256k1_zkp::{MusigKeyAggCache, Secp256k1, SecretKey, KeyPair, PublicKey, MusigSessionId, Message, MusigAggNonce, MusigSession, Tweak, adapt};
636- /// # let secp = Secp256k1::new();
637- /// # let sk1 = SecretKey::new(&mut thread_rng());
638- /// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
639- /// # let sk2 = SecretKey::new(&mut thread_rng());
640- /// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
641- ///
642- /// let key_agg_cache = MusigKeyAggCache::new(&secp, &[pub_key1, pub_key2]);
643- /// // The session id must be sampled at random. Read documentation for more details.
644- ///
645- /// let msg = Message::from_slice(b"Public Message we want to sign!!").unwrap();
646- ///
647- /// // Provide the current time for mis-use resistance
648- /// let session_id1 = MusigSessionId::new(&mut thread_rng());
649- /// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_id1, pub_key1, msg, None)
650- /// .expect("non zero session id");
651- ///
652- /// // Signer two does the same. Possibly on a different device
653- /// let session_id2 = MusigSessionId::new(&mut thread_rng());
654- /// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_id2, pub_key2, msg, None)
655- /// .expect("non zero session id");
656- ///
657- /// let aggnonce = MusigAggNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
658- ///
659- /// // Tweak with a secret adaptor
660- /// let adapt_sec = SecretKey::new(&mut thread_rng());
661- /// let adapt_pub = PublicKey::from_secret_key(&secp, &adapt_sec);
662- /// let adapt_sec = Tweak::from_slice(adapt_sec.as_ref()).unwrap();
663- ///
664- /// let session = MusigSession::with_adaptor(
665- /// &secp,
666- /// &key_agg_cache,
667- /// aggnonce,
668- /// msg,
669- /// adapt_pub, // adaptor here
670- /// );
671- ///
672- /// let partial_sig1 = session.partial_sign(
673- /// &secp,
674- /// sec_nonce1,
675- /// &KeyPair::from_secret_key(&secp, &sk1),
676- /// &key_agg_cache,
677- /// ).unwrap();
678- ///
679- /// // Other party creates the other partial signature
680- /// let partial_sig2 = session.partial_sign(
681- /// &secp,
682- /// sec_nonce2,
683- /// &KeyPair::from_secret_key(&secp, &sk2),
684- /// &key_agg_cache,
685- /// ).unwrap();
686- ///
687- /// let nonce_parity = session.nonce_parity();
688- /// let pre_sig = session.partial_sig_agg(&[partial_sig1, partial_sig2]);
689- ///
690- /// // Note that without the adaptor, the aggregated signature will fail verification
691- /// let agg_pk = key_agg_cache.agg_pk();
692- /// assert!(secp.verify_schnorr(&pre_sig, &msg, &agg_pk).is_err());
693- /// // Get the final schnorr signature
694- /// let schnorr_sig = adapt(pre_sig, adapt_sec, nonce_parity);
695- /// assert!(secp.verify_schnorr(&schnorr_sig, &msg, &agg_pk).is_ok());
696- /// # }
697- /// ```
698630pub fn adapt (
699631 pre_sig : schnorr:: Signature ,
700632 sec_adaptor : Tweak ,
@@ -1240,51 +1172,6 @@ impl MusigSession {
12401172 ///
12411173 /// - If the provided [`MusigSecNonce`] has already been used for signing
12421174 ///
1243- /// # Example:
1244- ///
1245- /// ```rust
1246- /// # # [cfg(any(test, feature = "rand-std"))] {
1247- /// # use secp256k1_zkp::rand::{thread_rng, RngCore};
1248- /// # use secp256k1_zkp::{MusigKeyAggCache, Secp256k1, SecretKey, KeyPair, PublicKey, MusigSessionId, Message, MusigAggNonce, MusigSession};
1249- /// # let secp = Secp256k1::new();
1250- /// # let sk1 = SecretKey::new(&mut thread_rng());
1251- /// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1252- /// # let sk2 = SecretKey::new(&mut thread_rng());
1253- /// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
1254- ///
1255- /// # let key_agg_cache = MusigKeyAggCache::new(&secp, &[pub_key1, pub_key2]);
1256- /// // The session id must be sampled at random. Read documentation for more details.
1257- ///
1258- /// let msg = Message::from_slice(b"Public Message we want to sign!!").unwrap();
1259- ///
1260- /// // Provide the current time for mis-use resistance
1261- /// let session_id1 = MusigSessionId::new(&mut thread_rng());
1262- /// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_id1, pub_key1, msg, None)
1263- /// .expect("non zero session id");
1264- ///
1265- /// // Signer two does the same. Possibly on a different device
1266- /// let session_id2 = MusigSessionId::new(&mut thread_rng());
1267- /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_id2, pub_key2, msg, None)
1268- /// .expect("non zero session id");
1269- ///
1270- /// let aggnonce = MusigAggNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
1271- ///
1272- /// let session = MusigSession::new(
1273- /// &secp,
1274- /// &key_agg_cache,
1275- /// aggnonce,
1276- /// msg,
1277- /// );
1278- ///
1279- /// let keypair = KeyPair::from_secret_key(&secp, &sk1);
1280- /// let _partial_sig = session.partial_sign(
1281- /// &secp,
1282- /// sec_nonce1,
1283- /// &keypair,
1284- /// &key_agg_cache,
1285- /// ).unwrap();
1286- /// # }
1287- /// ```
12881175 pub fn partial_sign < C : Signing > (
12891176 & self ,
12901177 secp : & Secp256k1 < C > ,
@@ -1551,7 +1438,7 @@ impl fmt::Display for MusigSignError {
15511438 }
15521439}
15531440
1554- #[ cfg( test) ]
1441+ #[ cfg( all ( test, feature = "global-context" ) ) ]
15551442mod tests {
15561443 use super :: * ;
15571444 use rand:: { thread_rng, RngCore } ;
0 commit comments