Skip to content

Commit c6fc3d7

Browse files
committed
run cargo fmt
1 parent 2f0f9d8 commit c6fc3d7

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

examples/musig.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
extern crate secp256k1;
22

33
use secp256k1::musig::{
4-
new_nonce_pair, AggregatedNonce, KeyAggCache, PartialSignature, PublicNonce,
5-
Session, SessionSecretRand,
4+
new_nonce_pair, AggregatedNonce, KeyAggCache, PartialSignature, PublicNonce, Session,
5+
SessionSecretRand,
66
};
7-
use secp256k1::{Keypair, Message, PublicKey, Scalar, Secp256k1, SecretKey, pubkey_sort};
7+
use secp256k1::{pubkey_sort, Keypair, Message, PublicKey, Scalar, Secp256k1, SecretKey};
88

99
fn main() {
1010
let secp = Secp256k1::new();
@@ -78,12 +78,10 @@ fn main() {
7878
let session = Session::new(&secp, &musig_key_agg_cache, agg_nonce, msg);
7979

8080
let keypair1 = Keypair::from_secret_key(&secp, &seckey1);
81-
let partial_sign1 =
82-
session.partial_sign(&secp, sec_nonce1, &keypair1, &musig_key_agg_cache);
81+
let partial_sign1 = session.partial_sign(&secp, sec_nonce1, &keypair1, &musig_key_agg_cache);
8382

8483
let keypair2 = Keypair::from_secret_key(&secp, &seckey2);
85-
let partial_sign2 =
86-
session.partial_sign(&secp, sec_nonce2, &keypair2, &musig_key_agg_cache);
84+
let partial_sign2 = session.partial_sign(&secp, sec_nonce2, &keypair2, &musig_key_agg_cache);
8785

8886
let is_partial_signature_valid =
8987
session.partial_verify(&secp, &musig_key_agg_cache, partial_sign1, pub_nonce1, pubkey1);

src/key.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,17 @@ impl<'de> serde::Deserialize<'de> for XOnlyPublicKey {
16191619
/// # let pubkeys = [pub_key1, pub_key2];
16201620
/// # let mut pubkeys_ref: Vec<&PublicKey> = pubkeys.iter().collect();
16211621
/// # let pubkeys_ref = pubkeys_ref.as_mut_slice();
1622-
/// #
1622+
/// #
16231623
/// # pubkey_sort(&secp, pubkeys_ref);
16241624
/// # }
16251625
/// ```
16261626
pub fn pubkey_sort<C: Verification>(secp: &Secp256k1<C>, pubkeys: &mut [&PublicKey]) {
16271627
let cx = secp.ctx().as_ptr();
16281628
unsafe {
1629-
let mut pubkeys_ref = core::slice::from_raw_parts(pubkeys.as_c_ptr() as *mut *const ffi::PublicKey, pubkeys.len());
1629+
let mut pubkeys_ref = core::slice::from_raw_parts(
1630+
pubkeys.as_c_ptr() as *mut *const ffi::PublicKey,
1631+
pubkeys.len(),
1632+
);
16301633
if secp256k1_ec_pubkey_sort(cx, pubkeys_ref.as_mut_c_ptr(), pubkeys_ref.len()) == 0 {
16311634
unreachable!("Invalid public keys for sorting function")
16321635
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ pub use crate::context::{
192192
};
193193
use crate::ffi::types::AlignedType;
194194
use crate::ffi::CPtr;
195-
pub use crate::key::{InvalidParityValue, Keypair, Parity, PublicKey, SecretKey, XOnlyPublicKey, pubkey_sort};
195+
pub use crate::key::{
196+
pubkey_sort, InvalidParityValue, Keypair, Parity, PublicKey, SecretKey, XOnlyPublicKey,
197+
};
196198
pub use crate::scalar::Scalar;
197199

198200
/// Trait describing something that promises to be a 32-byte uniformly random number.

src/musig.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use std;
1313

1414
use crate::ffi::{self, CPtr};
1515
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,
1718
};
1819

1920
/// Musig partial signature parsing errors
@@ -43,9 +44,7 @@ pub struct SessionSecretRand([u8; 32]);
4344
impl 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

8180
impl 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)]
9290
pub 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

Comments
 (0)