@@ -13,7 +13,8 @@ use std;
13
13
14
14
use crate :: ffi:: { self , CPtr } ;
15
15
use 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 ,
17
18
} ;
18
19
19
20
/// Musig partial signature parsing errors
@@ -43,9 +44,7 @@ pub struct SessionSecretRand([u8; 32]);
43
44
impl SessionSecretRand {
44
45
/// Generates a new session ID using thread RNG.
45
46
#[ 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 ( ) ) }
49
48
50
49
/// Creates a new [`SessionSecretRand`] with random bytes from the given rng
51
50
#[ cfg( feature = "rand" ) ]
@@ -73,9 +72,9 @@ impl SessionSecretRand {
73
72
74
73
/// Cached data related to a key aggregation.
75
74
#[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
76
- pub struct KeyAggCache {
75
+ pub struct KeyAggCache {
77
76
data : ffi:: MusigKeyAggCache ,
78
- aggregated_xonly_public_key : XOnlyPublicKey
77
+ aggregated_xonly_public_key : XOnlyPublicKey ,
79
78
}
80
79
81
80
impl CPtr for KeyAggCache {
@@ -86,7 +85,6 @@ impl CPtr for KeyAggCache {
86
85
fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target { self . as_mut_ptr ( ) }
87
86
}
88
87
89
-
90
88
/// Musig tweaking related error.
91
89
#[ derive( Debug , Clone , Copy , Eq , PartialEq , PartialOrd , Ord , Hash ) ]
92
90
pub struct InvalidTweakErr ;
@@ -239,7 +237,9 @@ impl PartialSignature {
239
237
/// # Errors:
240
238
///
241
239
/// - 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 > {
243
243
let mut partial_sig = MaybeUninit :: < ffi:: MusigPartialSignature > :: uninit ( ) ;
244
244
unsafe {
245
245
if ffi:: secp256k1_musig_partial_sig_parse (
@@ -306,7 +306,10 @@ impl KeyAggCache {
306
306
let mut agg_pk = MaybeUninit :: < ffi:: XOnlyPublicKey > :: uninit ( ) ;
307
307
308
308
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
+ ) ;
310
313
311
314
if ffi:: secp256k1_musig_pubkey_agg (
312
315
cx,
@@ -322,7 +325,7 @@ impl KeyAggCache {
322
325
// secp256k1_musig_pubkey_agg overwrites the cache and the key so this is sound.
323
326
let key_agg_cache = key_agg_cache. assume_init ( ) ;
324
327
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 }
326
329
}
327
330
}
328
331
}
@@ -645,7 +648,9 @@ impl PublicNonce {
645
648
/// # Errors:
646
649
///
647
650
/// - 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 > {
649
654
let mut pub_nonce = MaybeUninit :: < ffi:: MusigPubNonce > :: uninit ( ) ;
650
655
unsafe {
651
656
if ffi:: secp256k1_musig_pubnonce_parse (
@@ -718,15 +723,17 @@ impl AggregatedNonce {
718
723
/// # }
719
724
/// ```
720
725
pub fn new < C : Signing > ( secp : & Secp256k1 < C > , nonces : & [ & PublicNonce ] ) -> Self {
721
-
722
726
if nonces. is_empty ( ) {
723
727
panic ! ( "Cannot aggregate an empty slice of nonces" ) ;
724
728
}
725
729
726
730
let mut aggnonce = MaybeUninit :: < ffi:: MusigAggNonce > :: uninit ( ) ;
727
731
728
732
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
+ ) ;
730
737
731
738
if ffi:: secp256k1_musig_nonce_agg (
732
739
secp. ctx ( ) . as_ptr ( ) ,
@@ -767,7 +774,9 @@ impl AggregatedNonce {
767
774
/// # Errors:
768
775
///
769
776
/// - 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 > {
771
780
let mut aggnonce = MaybeUninit :: < ffi:: MusigAggNonce > :: uninit ( ) ;
772
781
unsafe {
773
782
if ffi:: secp256k1_musig_aggnonce_parse (
@@ -807,13 +816,17 @@ impl AggregatedSignature {
807
816
/// signature is more performant. Thus it should be generally better to verify the signature using this function first
808
817
/// and fall back to detection of violators if it fails.
809
818
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" )
812
820
}
813
821
814
822
/// Verify the aggregated signature against the aggregate public key and message
815
823
/// 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 > {
817
830
let sig = schnorr:: Signature :: from_slice ( & self . 0 ) ?;
818
831
secp. verify_schnorr ( & sig, message, aggregate_key)
819
832
. map ( |_| sig)
@@ -1123,15 +1136,16 @@ impl Session {
1123
1136
/// # }
1124
1137
/// ```
1125
1138
pub fn partial_sig_agg ( & self , partial_sigs : & [ & PartialSignature ] ) -> AggregatedSignature {
1126
-
1127
1139
if partial_sigs. is_empty ( ) {
1128
1140
panic ! ( "Cannot aggregate an empty slice of partial signatures" ) ;
1129
1141
}
1130
1142
1131
1143
let mut sig = [ 0u8 ; 64 ] ;
1132
1144
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
+ ) ;
1135
1149
1136
1150
if ffi:: secp256k1_musig_partial_sig_agg (
1137
1151
ffi:: secp256k1_context_no_precomp,
0 commit comments