Skip to content

Commit c3d77e7

Browse files
committed
musig: fix all the doctests
Pretty-much all of the doctests included in rust-bitcoin#716 corresponded to an old version of the API. I'm unsure why it is that my local CI accepted this. The Github CI did not.
1 parent 034eb3d commit c3d77e7

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

src/musig.rs

+57-57
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,20 @@ impl fmt::Display for InvalidTweakErr {
141141
/// Example:
142142
///
143143
/// ```rust
144-
/// # # [cfg(any(test, feature = "rand-std"))] {
144+
/// # # [cfg(feature = "rand")] {
145145
/// # use secp256k1::rand::{rng, RngCore};
146-
/// # use secp256k1::{PublicKey, Secp256k1, SecretKey, new_nonce_pair, SessionSecretRand};
146+
/// # use secp256k1::{PublicKey, Secp256k1, SecretKey};
147+
/// # use secp256k1::musig::{new_nonce_pair, SessionSecretRand};
147148
/// # let secp = Secp256k1::new();
148149
/// // The session id must be sampled at random. Read documentation for more details.
149-
/// let session_secrand = SessionSecretRand::new(&mut rng());
150+
/// let session_secrand = SessionSecretRand::from_rng(&mut rng());
150151
/// let sk = SecretKey::new(&mut rng());
151152
/// let pk = PublicKey::from_secret_key(&secp, &sk);
152153
///
153154
/// // Supply extra auxillary randomness to prevent misuse(for example, time of day)
154155
/// let extra_rand : Option<[u8; 32]> = None;
155156
///
156-
/// let (_sec_nonce, _pub_nonce) = new_nonce_pair(&secp, session_secrand, None, Some(sk), pk, None, None)
157-
/// .expect("non zero session id");
157+
/// let (_sec_nonce, _pub_nonce) = new_nonce_pair(&secp, session_secrand, None, Some(sk), pk, None, None);
158158
/// # }
159159
/// ```
160160
pub fn new_nonce_pair<C: Signing>(
@@ -297,16 +297,17 @@ impl KeyAggCache {
297297
/// Example:
298298
///
299299
/// ```rust
300-
/// # # [cfg(any(test, feature = "rand-std"))] {
300+
/// # #[cfg(feature = "rand")] {
301301
/// # use secp256k1::rand::{rng, RngCore};
302-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
302+
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
303+
/// # use secp256k1::musig::KeyAggCache;
303304
/// # let secp = Secp256k1::new();
304305
/// # let sk1 = SecretKey::new(&mut rng());
305306
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
306307
/// # let sk2 = SecretKey::new(&mut rng());
307308
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
308309
/// #
309-
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
310+
/// let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
310311
/// let _agg_pk = key_agg_cache.agg_pk();
311312
/// # }
312313
/// ```
@@ -386,20 +387,21 @@ impl KeyAggCache {
386387
/// Example:
387388
///
388389
/// ```rust
389-
/// # # [cfg(any(test, feature = "rand-std"))] {
390+
/// # #[cfg(feature = "rand")] {
390391
/// # use secp256k1::rand::{rng, RngCore};
391-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
392+
/// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
393+
/// # use secp256k1::musig::KeyAggCache;
392394
/// # let secp = Secp256k1::new();
393395
/// # let sk1 = SecretKey::new(&mut rng());
394396
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
395397
/// # let sk2 = SecretKey::new(&mut rng());
396398
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
397399
/// #
398-
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
400+
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
399401
///
400402
/// let tweak: [u8; 32] = *b"this could be a BIP32 tweak....\0";
401403
/// let tweak = Scalar::from_be_bytes(tweak).unwrap();
402-
/// let tweaked_key = key_agg_cache.pubkey_ec_tweak_add(&secp, tweak).unwrap();
404+
/// let tweaked_key = key_agg_cache.pubkey_ec_tweak_add(&secp, &tweak).unwrap();
403405
/// # }
404406
/// ```
405407
pub fn pubkey_ec_tweak_add<C: Verification>(
@@ -445,19 +447,20 @@ impl KeyAggCache {
445447
/// Example:
446448
///
447449
/// ```rust
448-
/// # # [cfg(any(test, feature = "rand-std"))] {
450+
/// # #[cfg(feature = "rand")] {
449451
/// # use secp256k1::rand::{rng, RngCore};
450-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
452+
/// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
453+
/// # use secp256k1::musig::KeyAggCache;
451454
/// # let secp = Secp256k1::new();
452455
/// # let sk1 = SecretKey::new(&mut rng());
453456
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
454457
/// # let sk2 = SecretKey::new(&mut rng());
455458
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
456459
///
457-
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
460+
/// let mut key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
458461
///
459-
/// let tweak = SecretKey::from_slice(b"Insecure tweak, Don't use this!!").unwrap(); // tweak could be from tap
460-
/// let _x_only_key_tweaked = key_agg_cache.pubkey_xonly_tweak_add(&secp, tweak).unwrap();
462+
/// let tweak = Scalar::from_be_bytes(*b"Insecure tweak, Don't use this!!").unwrap(); // tweak could be from tap
463+
/// let _x_only_key_tweaked = key_agg_cache.pubkey_xonly_tweak_add(&secp, &tweak).unwrap();
461464
/// # }
462465
/// ```
463466
pub fn pubkey_xonly_tweak_add<C: Verification>(
@@ -519,25 +522,25 @@ impl KeyAggCache {
519522
/// Example:
520523
///
521524
/// ```rust
522-
/// # # [cfg(any(test, feature = "rand-std"))] {
525+
/// # # [cfg(feature = "rand")] {
523526
/// # use secp256k1::rand::{rng, RngCore};
524-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message};
527+
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
528+
/// # use secp256k1::musig::{KeyAggCache, SessionSecretRand};
525529
/// # let secp = Secp256k1::new();
526530
/// # let sk1 = SecretKey::new(&mut rng());
527531
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
528532
/// # let sk2 = SecretKey::new(&mut rng());
529533
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
530534
/// #
531-
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
535+
/// let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
532536
/// // The session id must be sampled at random. Read documentation for more details.
533-
/// let session_secrand = SessionSecretRand::new(&mut rng());
537+
/// let session_secrand = SessionSecretRand::from_rng(&mut rng());
534538
///
535539
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
536540
///
537541
/// // Provide the current time for mis-use resistance
538542
/// let extra_rand : Option<[u8; 32]> = None;
539-
/// let (_sec_nonce, _pub_nonce) = key_agg_cache.nonce_gen(&secp, session_secrand, pub_key1, msg, extra_rand)
540-
/// .expect("non zero session id");
543+
/// let (_sec_nonce, _pub_nonce) = key_agg_cache.nonce_gen(&secp, session_secrand, pub_key1, msg, extra_rand);
541544
/// # }
542545
/// ```
543546
pub fn nonce_gen<C: Signing>(
@@ -707,30 +710,29 @@ impl AggregatedNonce {
707710
/// Example:
708711
///
709712
/// ```rust
710-
/// # # [cfg(any(test, feature = "rand-std"))] {
713+
/// # # [cfg(feature = "rand")] {
711714
/// # use secp256k1::rand::{rng, RngCore};
712-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce};
715+
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
716+
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand};
713717
/// # let secp = Secp256k1::new();
714718
/// # let sk1 = SecretKey::new(&mut rng());
715719
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
716720
/// # let sk2 = SecretKey::new(&mut rng());
717721
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
718722
///
719-
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
723+
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
720724
/// // The session id must be sampled at random. Read documentation for more details.
721725
///
722726
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
723727
///
724-
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
725-
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
726-
/// .expect("non zero session id");
728+
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rng());
729+
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
727730
///
728731
/// // Signer two does the same: Possibly on a different device
729-
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
730-
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
731-
/// .expect("non zero session id");
732+
/// let session_secrand2 = SessionSecretRand::from_rng(&mut rng());
733+
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
732734
///
733-
/// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
735+
/// let aggnonce = AggregatedNonce::new(&secp, &[&pub_nonce1, &pub_nonce2]);
734736
/// # }
735737
/// ```
736738
pub fn new<C: Signing>(secp: &Secp256k1<C>, nonces: &[&PublicNonce]) -> Self {
@@ -869,33 +871,32 @@ impl Session {
869871
/// Example:
870872
///
871873
/// ```rust
872-
/// # # [cfg(any(test, feature = "rand-std"))] {
874+
/// # # [cfg(feature = "rand")] {
873875
/// # use secp256k1::rand::{rng, RngCore};
874-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
876+
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
877+
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, Session, SessionSecretRand};
875878
/// # let secp = Secp256k1::new();
876879
/// # let sk1 = SecretKey::new(&mut rng());
877880
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
878881
/// # let sk2 = SecretKey::new(&mut rng());
879882
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
880883
///
881-
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
884+
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
882885
/// // The session id must be sampled at random. Read documentation for more details.
883886
///
884887
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
885888
///
886889
/// // Provide the current time for mis-use resistance
887-
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
890+
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rng());
888891
/// let extra_rand1 : Option<[u8; 32]> = None;
889-
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, extra_rand1)
890-
/// .expect("non zero session id");
892+
/// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, extra_rand1);
891893
///
892894
/// // Signer two does the same. Possibly on a different device
893-
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
895+
/// let session_secrand2 = SessionSecretRand::from_rng(&mut rng());
894896
/// let extra_rand2 : Option<[u8; 32]> = None;
895-
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, extra_rand2)
896-
/// .expect("non zero session id");
897+
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, extra_rand2);
897898
///
898-
/// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
899+
/// let aggnonce = AggregatedNonce::new(&secp, &[&pub_nonce1, &pub_nonce2]);
899900
///
900901
/// let session = Session::new(
901902
/// &secp,
@@ -1005,31 +1006,30 @@ impl Session {
10051006
/// Example:
10061007
///
10071008
/// ```rust
1008-
/// # # [cfg(any(test, feature = "rand-std"))] {
1009+
/// # # [cfg(feature = "rand")] {
10091010
/// # use secp256k1::rand::{rng, RngCore};
1010-
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
1011+
/// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
1012+
/// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand, Session};
10111013
/// # let secp = Secp256k1::new();
10121014
/// # let sk1 = SecretKey::new(&mut rng());
10131015
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
10141016
/// # let sk2 = SecretKey::new(&mut rng());
10151017
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
10161018
///
1017-
/// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
1019+
/// # let key_agg_cache = KeyAggCache::new(&secp, &[&pub_key1, &pub_key2]);
10181020
/// // The session id must be sampled at random. Read documentation for more details.
10191021
///
10201022
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
10211023
///
10221024
/// // Provide the current time for mis-use resistance
1023-
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
1024-
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
1025-
/// .expect("non zero session id");
1025+
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rng());
1026+
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
10261027
///
10271028
/// // Signer two does the same. Possibly on a different device
1028-
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
1029-
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
1030-
/// .expect("non zero session id");
1029+
/// let session_secrand2 = SessionSecretRand::from_rng(&mut rng());
1030+
/// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
10311031
///
1032-
/// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
1032+
/// let aggnonce = AggregatedNonce::new(&secp, &[&pub_nonce1, &pub_nonce2]);
10331033
///
10341034
/// let session = Session::new(
10351035
/// &secp,
@@ -1044,7 +1044,7 @@ impl Session {
10441044
/// sec_nonce1,
10451045
/// &keypair,
10461046
/// &key_agg_cache,
1047-
/// ).unwrap();
1047+
/// );
10481048
///
10491049
/// assert!(session.partial_verify(
10501050
/// &secp,
@@ -1088,7 +1088,7 @@ impl Session {
10881088
/// * `partial_sigs`: Array of [`PartialSignature`] to be aggregated
10891089
///
10901090
/// ```rust
1091-
/// # # [cfg(any(test, feature = "rand-std"))] {
1091+
/// # # [cfg(feature = "rand-std")] {
10921092
/// # use secp256k1::rand::{rng, RngCore};
10931093
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
10941094
/// # let secp = Secp256k1::new();
@@ -1103,12 +1103,12 @@ impl Session {
11031103
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
11041104
///
11051105
/// // Provide the current time for mis-use resistance
1106-
/// let session_secrand1 = SessionSecretRand::new(&mut rng());
1106+
/// let session_secrand1 = SessionSecretRand::from_rng(&mut rng());
11071107
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
11081108
/// .expect("non zero session id");
11091109
///
11101110
/// // Signer two does the same. Possibly on a different device
1111-
/// let session_secrand2 = SessionSecretRand::new(&mut rng());
1111+
/// let session_secrand2 = SessionSecretRand::from_rng(&mut rng());
11121112
/// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
11131113
/// .expect("non zero session id");
11141114
///

0 commit comments

Comments
 (0)