@@ -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,21 @@ 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(feature = "std")]
391
+ /// # #[cfg(feature = "rand")] {
392
+ /// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
393
+ /// # use secp256k1::musig::KeyAggCache;
392
394
/// # let secp = Secp256k1::new();
393
- /// # let sk1 = SecretKey::new(&mut rng());
395
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
394
396
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
395
- /// # let sk2 = SecretKey::new(&mut rng());
397
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
396
398
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
397
399
/// #
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]);
399
401
///
400
402
/// let tweak: [u8; 32] = *b"this could be a BIP32 tweak....\0";
401
403
/// 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();
403
405
/// # }
404
406
/// ```
405
407
pub fn pubkey_ec_tweak_add < C : Verification > (
@@ -445,19 +447,20 @@ impl KeyAggCache {
445
447
/// Example:
446
448
///
447
449
/// ```rust
448
- /// # # [cfg(any(test, feature = "rand-std"))] {
449
- /// # use secp256k1::rand::{rng, RngCore};
450
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey};
450
+ /// # #[cfg(feature = "std")]
451
+ /// # #[cfg(feature = "rand")] {
452
+ /// # use secp256k1::{Scalar, Secp256k1, SecretKey, Keypair, PublicKey};
453
+ /// # use secp256k1::musig::KeyAggCache;
451
454
/// # let secp = Secp256k1::new();
452
- /// # let sk1 = SecretKey::new(&mut rng());
455
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
453
456
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
454
- /// # let sk2 = SecretKey::new(&mut rng());
457
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
455
458
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
456
459
///
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]);
458
461
///
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();
461
464
/// # }
462
465
/// ```
463
466
pub fn pubkey_xonly_tweak_add < C : Verification > (
@@ -519,25 +522,25 @@ impl KeyAggCache {
519
522
/// Example:
520
523
///
521
524
/// ```rust
522
- /// # # [cfg(any(test, feature = "rand-std"))] {
523
- /// # use secp256k1::rand::{rng, RngCore};
524
- /// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message};
525
+ /// # #[cfg(feature = "std")]
526
+ /// # # [cfg(feature = "rand")] {
527
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
528
+ /// # use secp256k1::musig::{KeyAggCache, SessionSecretRand};
525
529
/// # let secp = Secp256k1::new();
526
- /// # let sk1 = SecretKey::new(&mut rng());
530
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
527
531
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
528
- /// # let sk2 = SecretKey::new(&mut rng());
532
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
529
533
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
530
534
/// #
531
- /// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
535
+ /// let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
532
536
/// // 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 rand:: rng());
534
538
///
535
539
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
536
540
///
537
541
/// // Provide the current time for mis-use resistance
538
542
/// 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);
541
544
/// # }
542
545
/// ```
543
546
pub fn nonce_gen < C : Signing > (
@@ -707,30 +710,29 @@ impl AggregatedNonce {
707
710
/// Example:
708
711
///
709
712
/// ```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};
713
+ /// # #[cfg(feature = "std")]
714
+ /// # # [cfg(feature = "rand")] {
715
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
716
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand};
713
717
/// # let secp = Secp256k1::new();
714
- /// # let sk1 = SecretKey::new(&mut rng());
718
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
715
719
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
716
- /// # let sk2 = SecretKey::new(&mut rng());
720
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
717
721
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
718
722
///
719
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
723
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
720
724
/// // The session id must be sampled at random. Read documentation for more details.
721
725
///
722
726
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
723
727
///
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 rand::rng());
729
+ /// let (_sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
727
730
///
728
731
/// // 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 rand::rng());
733
+ /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
732
734
///
733
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
735
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
734
736
/// # }
735
737
/// ```
736
738
pub fn new < C : Signing > ( secp : & Secp256k1 < C > , nonces : & [ & PublicNonce ] ) -> Self {
@@ -869,33 +871,32 @@ impl Session {
869
871
/// Example:
870
872
///
871
873
/// ```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};
874
+ /// # #[cfg(feature = "std")]
875
+ /// # # [cfg(feature = "rand")] {
876
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
877
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, Session, SessionSecretRand};
875
878
/// # let secp = Secp256k1::new();
876
- /// # let sk1 = SecretKey::new(&mut rng());
879
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
877
880
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
878
- /// # let sk2 = SecretKey::new(&mut rng());
881
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
879
882
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
880
883
///
881
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
884
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
882
885
/// // The session id must be sampled at random. Read documentation for more details.
883
886
///
884
887
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
885
888
///
886
889
/// // Provide the current time for mis-use resistance
887
- /// let session_secrand1 = SessionSecretRand::new (&mut rng());
890
+ /// let session_secrand1 = SessionSecretRand::from_rng (&mut rand:: rng());
888
891
/// 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);
891
893
///
892
894
/// // 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 rand:: rng());
894
896
/// 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);
897
898
///
898
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
899
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
899
900
///
900
901
/// let session = Session::new(
901
902
/// &secp,
@@ -1005,31 +1006,30 @@ impl Session {
1005
1006
/// Example:
1006
1007
///
1007
1008
/// ```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};
1009
+ /// # #[cfg(feature = "std")]
1010
+ /// # # [cfg(feature = "rand")] {
1011
+ /// # use secp256k1::{Secp256k1, SecretKey, Keypair, PublicKey, Message};
1012
+ /// # use secp256k1::musig::{AggregatedNonce, KeyAggCache, SessionSecretRand, Session};
1011
1013
/// # let secp = Secp256k1::new();
1012
- /// # let sk1 = SecretKey::new(&mut rng());
1014
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
1013
1015
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1014
- /// # let sk2 = SecretKey::new(&mut rng());
1016
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
1015
1017
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
1016
1018
///
1017
- /// # let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
1019
+ /// # let key_agg_cache = KeyAggCache::new(&secp, &[& pub_key1, & pub_key2]);
1018
1020
/// // The session id must be sampled at random. Read documentation for more details.
1019
1021
///
1020
1022
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
1021
1023
///
1022
1024
/// // 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 rand::rng());
1026
+ /// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None);
1026
1027
///
1027
1028
/// // 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 rand::rng());
1030
+ /// let (_sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None);
1031
1031
///
1032
- /// let aggnonce = AggregatedNonce::new(&secp, &[pub_nonce1, pub_nonce2]);
1032
+ /// let aggnonce = AggregatedNonce::new(&secp, &[& pub_nonce1, & pub_nonce2]);
1033
1033
///
1034
1034
/// let session = Session::new(
1035
1035
/// &secp,
@@ -1044,7 +1044,7 @@ impl Session {
1044
1044
/// sec_nonce1,
1045
1045
/// &keypair,
1046
1046
/// &key_agg_cache,
1047
- /// ).unwrap() ;
1047
+ /// );
1048
1048
///
1049
1049
/// assert!(session.partial_verify(
1050
1050
/// &secp,
@@ -1088,13 +1088,12 @@ impl Session {
1088
1088
/// * `partial_sigs`: Array of [`PartialSignature`] to be aggregated
1089
1089
///
1090
1090
/// ```rust
1091
- /// # # [cfg(any(test, feature = "rand-std"))] {
1092
- /// # use secp256k1::rand::{rng, RngCore};
1091
+ /// # # [cfg(feature = "rand-std")] {
1093
1092
/// # use secp256k1::{KeyAggCache, Secp256k1, SecretKey, Keypair, PublicKey, SessionSecretRand, Message, AggregatedNonce, Session};
1094
1093
/// # let secp = Secp256k1::new();
1095
- /// # let sk1 = SecretKey::new(&mut rng());
1094
+ /// # let sk1 = SecretKey::new(&mut rand:: rng());
1096
1095
/// # let pub_key1 = PublicKey::from_secret_key(&secp, &sk1);
1097
- /// # let sk2 = SecretKey::new(&mut rng());
1096
+ /// # let sk2 = SecretKey::new(&mut rand:: rng());
1098
1097
/// # let pub_key2 = PublicKey::from_secret_key(&secp, &sk2);
1099
1098
///
1100
1099
/// let key_agg_cache = KeyAggCache::new(&secp, &[pub_key1, pub_key2]);
@@ -1103,12 +1102,12 @@ impl Session {
1103
1102
/// let msg = Message::from_digest_slice(b"Public Message we want to sign!!").unwrap();
1104
1103
///
1105
1104
/// // Provide the current time for mis-use resistance
1106
- /// let session_secrand1 = SessionSecretRand::new (&mut rng());
1105
+ /// let session_secrand1 = SessionSecretRand::from_rng (&mut rand:: rng());
1107
1106
/// let (mut sec_nonce1, pub_nonce1) = key_agg_cache.nonce_gen(&secp, session_secrand1, pub_key1, msg, None)
1108
1107
/// .expect("non zero session id");
1109
1108
///
1110
1109
/// // Signer two does the same. Possibly on a different device
1111
- /// let session_secrand2 = SessionSecretRand::new (&mut rng());
1110
+ /// let session_secrand2 = SessionSecretRand::from_rng (&mut rand:: rng());
1112
1111
/// let (mut sec_nonce2, pub_nonce2) = key_agg_cache.nonce_gen(&secp, session_secrand2, pub_key2, msg, None)
1113
1112
/// .expect("non zero session id");
1114
1113
///
0 commit comments