@@ -13,7 +13,8 @@ use std;
1313
1414use crate :: ffi:: { self , CPtr } ;
1515use crate :: {
16- schnorr, Error , Keypair , Message , PublicKey , Scalar , Secp256k1 , SecretKey , Signing , Verification , XOnlyPublicKey
16+ schnorr, Error , Keypair , Message , PublicKey , Scalar , Secp256k1 , SecretKey , Signing ,
17+ Verification , XOnlyPublicKey ,
1718} ;
1819
1920/// Musig partial signature parsing errors
@@ -43,9 +44,7 @@ pub struct SessionSecretRand([u8; 32]);
4344impl SessionSecretRand {
4445 /// Generates a new session ID using thread RNG.
4546 #[ cfg( all( feature = "rand" , feature = "std" ) ) ]
46- pub fn new ( ) -> Self {
47- Self :: from_rng ( & mut rand:: thread_rng ( ) )
48- }
47+ pub fn new ( ) -> Self { Self :: from_rng ( & mut rand:: thread_rng ( ) ) }
4948
5049 /// Creates a new [`SessionSecretRand`] with random bytes from the given rng
5150 #[ cfg( feature = "rand" ) ]
@@ -73,9 +72,9 @@ impl SessionSecretRand {
7372
7473/// Cached data related to a key aggregation.
7574#[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
76- pub struct KeyAggCache {
75+ pub struct KeyAggCache {
7776 data : ffi:: MusigKeyAggCache ,
78- aggregated_xonly_public_key : XOnlyPublicKey
77+ aggregated_xonly_public_key : XOnlyPublicKey ,
7978}
8079
8180impl CPtr for KeyAggCache {
@@ -86,7 +85,6 @@ impl CPtr for KeyAggCache {
8685 fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target { self . as_mut_ptr ( ) }
8786}
8887
89-
9088/// Musig tweaking related error.
9189#[ derive( Debug , Clone , Copy , Eq , PartialEq , PartialOrd , Ord , Hash ) ]
9290pub struct InvalidTweakErr ;
@@ -239,7 +237,9 @@ impl PartialSignature {
239237 /// # Errors:
240238 ///
241239 /// - MalformedArg: If the signature [`PartialSignature`] is out of curve order
242- pub fn from_byte_array ( data : & [ u8 ; ffi:: MUSIG_PART_SIG_SERIALIZED_LEN ] ) -> Result < Self , ParseError > {
240+ pub fn from_byte_array (
241+ data : & [ u8 ; ffi:: MUSIG_PART_SIG_SERIALIZED_LEN ] ,
242+ ) -> Result < Self , ParseError > {
243243 let mut partial_sig = MaybeUninit :: < ffi:: MusigPartialSignature > :: uninit ( ) ;
244244 unsafe {
245245 if ffi:: secp256k1_musig_partial_sig_parse (
@@ -306,7 +306,10 @@ impl KeyAggCache {
306306 let mut agg_pk = MaybeUninit :: < ffi:: XOnlyPublicKey > :: uninit ( ) ;
307307
308308 unsafe {
309- let pubkeys_ref = core:: slice:: from_raw_parts ( pubkeys. as_c_ptr ( ) as * const * const ffi:: PublicKey , pubkeys. len ( ) ) ;
309+ let pubkeys_ref = core:: slice:: from_raw_parts (
310+ pubkeys. as_c_ptr ( ) as * const * const ffi:: PublicKey ,
311+ pubkeys. len ( ) ,
312+ ) ;
310313
311314 if ffi:: secp256k1_musig_pubkey_agg (
312315 cx,
@@ -322,7 +325,7 @@ impl KeyAggCache {
322325 // secp256k1_musig_pubkey_agg overwrites the cache and the key so this is sound.
323326 let key_agg_cache = key_agg_cache. assume_init ( ) ;
324327 let agg_pk = XOnlyPublicKey :: from ( agg_pk. assume_init ( ) ) ;
325- KeyAggCache { data : key_agg_cache, aggregated_xonly_public_key : agg_pk }
328+ KeyAggCache { data : key_agg_cache, aggregated_xonly_public_key : agg_pk }
326329 }
327330 }
328331 }
@@ -645,7 +648,9 @@ impl PublicNonce {
645648 /// # Errors:
646649 ///
647650 /// - MalformedArg: If the [`PublicNonce`] is 132 bytes, but out of curve order
648- pub fn from_byte_array ( data : & [ u8 ; ffi:: MUSIG_PUBNONCE_SERIALIZED_LEN ] ) -> Result < Self , ParseError > {
651+ pub fn from_byte_array (
652+ data : & [ u8 ; ffi:: MUSIG_PUBNONCE_SERIALIZED_LEN ] ,
653+ ) -> Result < Self , ParseError > {
649654 let mut pub_nonce = MaybeUninit :: < ffi:: MusigPubNonce > :: uninit ( ) ;
650655 unsafe {
651656 if ffi:: secp256k1_musig_pubnonce_parse (
@@ -718,15 +723,17 @@ impl AggregatedNonce {
718723 /// # }
719724 /// ```
720725 pub fn new < C : Signing > ( secp : & Secp256k1 < C > , nonces : & [ & PublicNonce ] ) -> Self {
721-
722726 if nonces. is_empty ( ) {
723727 panic ! ( "Cannot aggregate an empty slice of nonces" ) ;
724728 }
725729
726730 let mut aggnonce = MaybeUninit :: < ffi:: MusigAggNonce > :: uninit ( ) ;
727731
728732 unsafe {
729- let pubnonces = core:: slice:: from_raw_parts ( nonces. as_c_ptr ( ) as * const * const ffi:: MusigPubNonce , nonces. len ( ) ) ;
733+ let pubnonces = core:: slice:: from_raw_parts (
734+ nonces. as_c_ptr ( ) as * const * const ffi:: MusigPubNonce ,
735+ nonces. len ( ) ,
736+ ) ;
730737
731738 if ffi:: secp256k1_musig_nonce_agg (
732739 secp. ctx ( ) . as_ptr ( ) ,
@@ -767,7 +774,9 @@ impl AggregatedNonce {
767774 /// # Errors:
768775 ///
769776 /// - MalformedArg: If the byte slice is 66 bytes, but the [`AggregatedNonce`] is invalid
770- pub fn from_byte_array ( data : & [ u8 ; ffi:: MUSIG_AGGNONCE_SERIALIZED_LEN ] ) -> Result < Self , ParseError > {
777+ pub fn from_byte_array (
778+ data : & [ u8 ; ffi:: MUSIG_AGGNONCE_SERIALIZED_LEN ] ,
779+ ) -> Result < Self , ParseError > {
771780 let mut aggnonce = MaybeUninit :: < ffi:: MusigAggNonce > :: uninit ( ) ;
772781 unsafe {
773782 if ffi:: secp256k1_musig_aggnonce_parse (
@@ -807,13 +816,17 @@ impl AggregatedSignature {
807816 /// signature is more performant. Thus it should be generally better to verify the signature using this function first
808817 /// and fall back to detection of violators if it fails.
809818 pub fn assume_valid ( self ) -> schnorr:: Signature {
810- schnorr:: Signature :: from_slice ( & self . 0 )
811- . expect ( "Invalid signature data" )
819+ schnorr:: Signature :: from_slice ( & self . 0 ) . expect ( "Invalid signature data" )
812820 }
813821
814822 /// Verify the aggregated signature against the aggregate public key and message
815823 /// before returning the signature.
816- pub fn verify < C : Verification > ( self , secp : & Secp256k1 < C > , aggregate_key : & XOnlyPublicKey , message : & [ u8 ] ) -> Result < schnorr:: Signature , Error > {
824+ pub fn verify < C : Verification > (
825+ self ,
826+ secp : & Secp256k1 < C > ,
827+ aggregate_key : & XOnlyPublicKey ,
828+ message : & [ u8 ] ,
829+ ) -> Result < schnorr:: Signature , Error > {
817830 let sig = schnorr:: Signature :: from_slice ( & self . 0 ) ?;
818831 secp. verify_schnorr ( & sig, message, aggregate_key)
819832 . map ( |_| sig)
@@ -1123,15 +1136,16 @@ impl Session {
11231136 /// # }
11241137 /// ```
11251138 pub fn partial_sig_agg ( & self , partial_sigs : & [ & PartialSignature ] ) -> AggregatedSignature {
1126-
11271139 if partial_sigs. is_empty ( ) {
11281140 panic ! ( "Cannot aggregate an empty slice of partial signatures" ) ;
11291141 }
11301142
11311143 let mut sig = [ 0u8 ; 64 ] ;
11321144 unsafe {
1133-
1134- let partial_sigs_ref = core:: slice:: from_raw_parts ( partial_sigs. as_ptr ( ) as * const * const ffi:: MusigPartialSignature , partial_sigs. len ( ) ) ;
1145+ let partial_sigs_ref = core:: slice:: from_raw_parts (
1146+ partial_sigs. as_ptr ( ) as * const * const ffi:: MusigPartialSignature ,
1147+ partial_sigs. len ( ) ,
1148+ ) ;
11351149
11361150 if ffi:: secp256k1_musig_partial_sig_agg (
11371151 ffi:: secp256k1_context_no_precomp,
0 commit comments