Skip to content

Commit d318169

Browse files
committed
musig: rename musig_sort_pubkeys to just sort_pubkeys
This function is useful for Musig but may be useful elsewhere. Rename it to be more general, and mention it in the Musig docs.
1 parent fdae0fd commit d318169

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

examples/musig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
let mut pubkeys_ref: Vec<&PublicKey> = pubkeys.iter().collect();
2020
let pubkeys_ref = pubkeys_ref.as_mut_slice();
2121

22-
secp.musig_sort_pubkeys(pubkeys_ref);
22+
secp.sort_pubkeys(pubkeys_ref);
2323

2424
let mut musig_key_agg_cache = KeyAggCache::new(&secp, pubkeys_ref);
2525

src/key.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,8 @@ impl<'de> serde::Deserialize<'de> for XOnlyPublicKey {
16201620
impl<C: Verification> Secp256k1<C> {
16211621
/// Sort public keys using lexicographic (of compressed serialization) order.
16221622
///
1623+
/// This is the canonical way to sort public keys for use with Musig2.
1624+
///
16231625
/// Example:
16241626
///
16251627
/// ```rust
@@ -1636,10 +1638,10 @@ impl<C: Verification> Secp256k1<C> {
16361638
/// # let mut pubkeys_ref: Vec<&PublicKey> = pubkeys.iter().collect();
16371639
/// # let pubkeys_ref = pubkeys_ref.as_mut_slice();
16381640
/// #
1639-
/// # secp.musig_sort_pubkeys(pubkeys_ref);
1641+
/// # secp.sort_pubkeys(pubkeys_ref);
16401642
/// # }
16411643
/// ```
1642-
pub fn musig_sort_pubkeys(&self, pubkeys: &mut [&PublicKey]) {
1644+
pub fn sort_pubkeys(&self, pubkeys: &mut [&PublicKey]) {
16431645
let cx = self.ctx().as_ptr();
16441646
unsafe {
16451647
let mut pubkeys_ref = core::slice::from_raw_parts(

src/musig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ impl KeyAggCache {
281281
/// ensures the same resulting `agg_pk` for the same multiset of pubkeys.
282282
/// This is useful to do before aggregating pubkeys, such that the order of pubkeys
283283
/// does not affect the combined public key.
284+
/// To do this, call [`Secp256k1::sort_pubkeys`].
284285
///
285286
/// # Returns
286287
///

0 commit comments

Comments
 (0)