@@ -141,20 +141,20 @@ impl fmt::Display for InvalidTweakErr {
141
141
/// Example:
142
142
///
143
143
/// ```rust
144
- /// # # [cfg(any(test, feature = "rand-std"))] {
145
- /// # use secp256k1::rand::{rng, RngCore};
146
- /// # use secp256k1::{PublicKey, Secp256k1, SecretKey, new_nonce_pair, SessionSecretRand};
144
+ /// # #[cfg(feature = "std")]
145
+ /// # #[cfg(feature = "rand")] {
146
+ /// # use secp256k1::{PublicKey, Secp256k1, SecretKey};
147
+ /// # use secp256k1::musig::{new_nonce_pair, SessionSecretRand};
147
148
/// # let secp = Secp256k1::new();
148
149
/// // The session id must be sampled at random. Read documentation for more details.
149
- /// let session_secrand = SessionSecretRand::new (&mut rng());
150
- /// let sk = SecretKey::new(&mut rng());
150
+ /// let session_secrand = SessionSecretRand::from_rng (&mut rand:: rng());
151
+ /// let sk = SecretKey::new(&mut rand:: rng());
151
152
/// let pk = PublicKey::from_secret_key(&secp, &sk);
152
153
///
153
154
/// // Supply extra auxillary randomness to prevent misuse(for example, time of day)
154
155
/// let extra_rand : Option<[u8; 32]> = None;
155
156
///
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);
158
158
/// # }
159
159
/// ```
160
160
pub fn new_nonce_pair < C : Signing > (
@@ -297,16 +297,17 @@ impl KeyAggCache {
297
297
/// Example:
298
298
///
299
299
/// ```rust
300
- /// # # [cfg(any(test, feature = "rand-std"))] {
301
- /// # use secp256k1::rand::{rng, RngCore};
302
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
300
+ /// # #[cfg(feature = "std")]
301
+ /// # #[cfg(feature = "rand")] {
302
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey};
303
+ /// # use secp256k1::musig::KeyAggCache;
303
304
/// # let secp = Secp256k1::new();
304
- /// # let sk1 = SecretKey::new(&mut rng());
305
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
305
306
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
306
- /// # let sk2 = SecretKey::new(&mut rng());
307
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
307
308
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
308
309
/// #
309
- /// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
310
+ /// let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
310
311
/// let _agg_pk = key_agg_cache.agg_pk();
311
312
/// # }
312
313
/// ```
@@ -386,20 +387,22 @@ impl KeyAggCache {
386
387
/// Example:
387
388
///
388
389
/// ```rust
389
- /// # # [cfg(any(test, feature = "rand-std"))] {
390
- /// # use secp256k1::rand::{rng, RngCore};
391
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
390
+ /// # #[cfg(not(secp256k1_fuzz))]
391
+ /// # #[cfg(feature = "std")]
392
+ /// # #[cfg(feature = "rand")] {
393
+ /// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
394
+ /// # use secp256k1::musig::KeyAggCache;
392
395
/// # let secp = Secp256k1::new();
393
- /// # let sk1 = SecretKey::new(&mut rng());
396
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
394
397
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
395
- /// # let sk2 = SecretKey::new(&mut rng());
398
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
396
399
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
397
400
/// #
398
- /// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
401
+ /// let mut key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
399
402
///
400
403
/// let tweak: [u8; 32] = *b"this could be a BIP32 tweak....\0";
401
404
/// let tweak = Scalar::from_be_bytes(tweak).unwrap();
402
- /// let tweaked_key = key_agg_cache.pubkey_ec_tweak_add(&secp, tweak).unwrap();
405
+ /// let tweaked_key = key_agg_cache.pubkey_ec_tweak_add(&secp, & tweak).unwrap();
403
406
/// # }
404
407
/// ```
405
408
pub fn pubkey_ec_tweak_add < C : Verification > (
@@ -445,19 +448,21 @@ impl KeyAggCache {
445
448
/// Example:
446
449
///
447
450
/// ```rust
448
- /// # # [cfg(any(test, feature = "rand-std"))] {
449
- /// # use secp256k1::rand::{rng, RngCore};
450
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
451
+ /// # #[cfg(not(secp256k1_fuzz))]
452
+ /// # #[cfg(feature = "std")]
453
+ /// # #[cfg(feature = "rand")] {
454
+ /// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
455
+ /// # use secp256k1::musig::KeyAggCache;
451
456
/// # let secp = Secp256k1::new();
452
- /// # let sk1 = SecretKey::new(&mut rng());
457
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
453
458
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
454
- /// # let sk2 = SecretKey::new(&mut rng());
459
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
455
460
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
456
461
///
457
- /// let mut key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
462
+ /// let mut key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
458
463
///
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();
464
+ /// let tweak = Scalar::from_be_bytes(* b"Insecure tweak, Don't use this!!").unwrap(); // tweak could be from tap
465
+ /// let _x_only_key_tweaked = key_agg_cache.pubkey_xonly_tweak_add(&secp, & tweak).unwrap();
461
466
/// # }
462
467
/// ```
463
468
pub fn pubkey_xonly_tweak_add < C : Verification > (
@@ -519,25 +524,25 @@ impl KeyAggCache {
519
524
/// Example:
520
525
///
521
526
/// ```rust
522
- /// # # [cfg(any(test, feature = "rand-std"))] {
523
- /// # use secp256k1::rand::{rng, RngCore};
524
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message};
527
+ /// # #[cfg(feature = "std")]
528
+ /// # #[cfg(feature = "rand")] {
529
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
530
+ /// # use secp256k1::musig::{KeyAggCache, SessionSecretRand};
525
531
/// # let secp = Secp256k1::new();
526
- /// # let sk1 = SecretKey::new(&mut rng());
532
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
527
533
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
528
- /// # let sk2 = SecretKey::new(&mut rng());
534
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
529
535
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
530
536
/// #
531
- /// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
537
+ /// let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
532
538
/// // The session id must be sampled at random. Read documentation for more details.
533
- /// let session_secrand = SessionSecretRand::new (&mut rng());
539
+ /// let session_secrand = SessionSecretRand::from_rng (&mut rand:: rng());
534
540
///
535
541
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
536
542
///
537
543
/// // Provide the current time for mis-use resistance
538
544
/// 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");
545
+ /// let (_sec_nonce, _pub_nonce) = key_agg_cache.nonce_gen(&secp, session_secrand, pub_key1, msg, extra_rand);
541
546
/// # }
542
547
/// ```
543
548
pub fn nonce_gen < C : Signing > (
@@ -707,30 +712,29 @@ impl AggregatedNonce {
707
712
/// Example:
708
713
///
709
714
/// ```rust
710
- /// # # [cfg(any(test, feature = "rand-std"))] {
711
- /// # use secp256k1::rand::{rng, RngCore};
712
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce};
715
+ /// # #[cfg(feature = "std")]
716
+ /// # #[cfg(feature = "rand")] {
717
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
718
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand};
713
719
/// # let secp = Secp256k1::new();
714
- /// # let sk1 = SecretKey::new(&mut rng());
720
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
715
721
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
716
- /// # let sk2 = SecretKey::new(&mut rng());
722
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
717
723
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
718
724
///
719
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
725
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
720
726
/// // The session id must be sampled at random. Read documentation for more details.
721
727
///
722
728
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
723
729
///
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");
730
+ /// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
731
+ /// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
727
732
///
728
733
/// // 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");
734
+ /// let session_secrand2 = SessionSecretRand::from_rng(&mut rand::rng());
735
+ /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
732
736
///
733
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
737
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
734
738
/// # }
735
739
/// ```
736
740
pub fn new < C : Signing > ( secp : & Secp256k1 < C > , nonces : & [ & PublicNonce ] ) -> Self {
@@ -869,33 +873,32 @@ impl Session {
869
873
/// Example:
870
874
///
871
875
/// ```rust
872
- /// # # [cfg(any(test, feature = "rand-std"))] {
873
- /// # use secp256k1::rand::{rng, RngCore};
874
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
876
+ /// # #[cfg(feature = "std")]
877
+ /// # #[cfg(feature = "rand")] {
878
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
879
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, Session, SessionSecretRand};
875
880
/// # let secp = Secp256k1::new();
876
- /// # let sk1 = SecretKey::new(&mut rng());
881
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
877
882
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
878
- /// # let sk2 = SecretKey::new(&mut rng());
883
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
879
884
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
880
885
///
881
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
886
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
882
887
/// // The session id must be sampled at random. Read documentation for more details.
883
888
///
884
889
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
885
890
///
886
891
/// // Provide the current time for mis-use resistance
887
- /// let session_secrand1 = SessionSecretRand::new (&mut rng());
892
+ /// let session_secrand1 = SessionSecretRand::from_rng (&mut rand:: rng());
888
893
/// 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");
894
+ /// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, extra_rand1);
891
895
///
892
896
/// // Signer two does the same. Possibly on a different device
893
- /// let session_secrand2 = SessionSecretRand::new (&mut rng());
897
+ /// let session_secrand2 = SessionSecretRand::from_rng (&mut rand:: rng());
894
898
/// 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");
899
+ /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, extra_rand2);
897
900
///
898
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
901
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
899
902
///
900
903
/// let session = Session::new(
901
904
/// &secp,
@@ -1005,31 +1008,31 @@ impl Session {
1005
1008
/// Example:
1006
1009
///
1007
1010
/// ```rust
1008
- /// # # [cfg(any(test, feature = "rand-std"))] {
1009
- /// # use secp256k1::rand::{rng, RngCore};
1010
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
1011
+ /// # #[cfg(not(secp256k1_fuzz))]
1012
+ /// # #[cfg(feature = "std")]
1013
+ /// # #[cfg(feature = "rand")] {
1014
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
1015
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand, Session};
1011
1016
/// # let secp = Secp256k1::new();
1012
- /// # let sk1 = SecretKey::new(&mut rng());
1017
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
1013
1018
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1014
- /// # let sk2 = SecretKey::new(&mut rng());
1019
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
1015
1020
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
1016
1021
///
1017
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
1022
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
1018
1023
/// // The session id must be sampled at random. Read documentation for more details.
1019
1024
///
1020
1025
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
1021
1026
///
1022
1027
/// // 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");
1028
+ /// let session_secrand1 = SessionSecretRand::from_rng(&mut rand::rng());
1029
+ /// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
1026
1030
///
1027
1031
/// // 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");
1032
+ /// let session_secrand2 = SessionSecretRand::from_rng(&mut rand::rng());
1033
+ /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
1031
1034
///
1032
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
1035
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
1033
1036
///
1034
1037
/// let session = Session::new(
1035
1038
/// &secp,
@@ -1044,7 +1047,7 @@ impl Session {
1044
1047
/// sec_nonce1,
1045
1048
/// &keypair,
1046
1049
/// &key_agg_cache,
1047
- /// ).unwrap() ;
1050
+ /// );
1048
1051
///
1049
1052
/// assert!(session.partial_verify(
1050
1053
/// &secp,
@@ -1088,13 +1091,12 @@ impl Session {
1088
1091
/// * `partial_sigs`: Array of [`PartialSignature`] to be aggregated
1089
1092
///
1090
1093
/// ```rust
1091
- /// # # [cfg(any(test, feature = "rand-std"))] {
1092
- /// # use secp256k1::rand::{rng, RngCore};
1094
+ /// # #[cfg(feature = "rand-std")] {
1093
1095
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
1094
1096
/// # let secp = Secp256k1::new();
1095
- /// # let sk1 = SecretKey::new(&mut rng());
1097
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
1096
1098
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1097
- /// # let sk2 = SecretKey::new(&mut rng());
1099
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
1098
1100
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
1099
1101
///
1100
1102
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1103,12 +1105,12 @@ impl Session {
1103
1105
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
1104
1106
///
1105
1107
/// // Provide the current time for mis-use resistance
1106
- /// let session_secrand1 = SessionSecretRand::new (&mut rng());
1108
+ /// let session_secrand1 = SessionSecretRand::from_rng (&mut rand:: rng());
1107
1109
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
1108
1110
/// .expect("non zero session id");
1109
1111
///
1110
1112
/// // Signer two does the same. Possibly on a different device
1111
- /// let session_secrand2 = SessionSecretRand::new (&mut rng());
1113
+ /// let session_secrand2 = SessionSecretRand::from_rng (&mut rand:: rng());
1112
1114
/// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
1113
1115
/// .expect("non zero session id");
1114
1116
///
0 commit comments