Skip to content

Commit 89e63bf

Browse files
committed
clean doc todos
1 parent 26e2ebf commit 89e63bf

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

schnorr_fun/src/musig.rs

+18-35
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
//! ## Synopsis
44
//!
55
//! ```
6-
//! use schnorr_fun::{musig::MuSig, Schnorr, Message, nonce::Deterministic};
6+
//! use schnorr_fun::{musig::MuSig, nonce::Deterministic, Message, Schnorr};
77
//! use sha2::Sha256;
88
//! // use sha256 with deterministic nonce generation
99
//! let musig = MuSig::<Sha256, Schnorr<Sha256, Deterministic<Sha256>>>::default();
1010
//! // create a keylist
1111
//! use schnorr_fun::fun::Scalar;
12-
//! let kp1 = musig.schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
12+
//! let kp1 = musig
13+
//! .schnorr
14+
//! .new_keypair(Scalar::random(&mut rand::thread_rng()));
1315
//! let public_key1 = kp1.public_key();
1416
//! # let kp2 = musig.schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
1517
//! # let public_key2 = kp2.public_key();
1618
//! # let kp3 = musig.schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
1719
//! # let public_key3 = kp3.public_key();
1820
//! // recieve the public keys of all other participants to form the aggregate key.
19-
//! let keylist = musig.new_keylist(vec![
20-
//! public_key1,
21-
//! public_key2,
22-
//! public_key3,
23-
//! ]);
21+
//! let keylist = musig.new_keylist(vec![public_key1, public_key2, public_key3]);
2422
//! let agg_key = keylist.agg_public_key();
2523
//!
26-
//! // create unique nonce, and send public nonce to other parties.
24+
//! // create a unique nonce, and send the public nonce to other parties.
2725
//! let p1_nonce = musig.gen_nonces(kp1.secret_key(), &keylist, b"session-id-1337");
2826
//! let p1_public_nonce = p1_nonce.public();
2927
//! # let p2_nonce = musig.gen_nonces(kp2.secret_key(), &keylist, b"session-id-1337");
@@ -34,8 +32,8 @@
3432
//! let nonces = vec![p1_public_nonce, p2_public_nonce, p3_public_nonce];
3533
//! let message = Message::plain("my-app", b"chancellor on brink of second bailout for banks");
3634
//! // start the signing session
37-
//! let mut session = musig.start_sign_session(&keylist, nonces, message).unwrap();
38-
//! // sign with our (single) local keypair
35+
//! let session = musig.start_sign_session(&keylist, nonces, message).unwrap();
36+
//! // sign with our single local keypair
3937
//! let p1_sig = musig.sign(&keylist, 0, kp1.secret_key(), p1_nonce, &session);
4038
//! # let p2_sig = musig.sign(&keylist, 1, kp2.secret_key(), p2_nonce, &session);
4139
//! # let p3_sig = musig.sign(&keylist, 2, kp3.secret_key(), p3_nonce, &session);
@@ -45,7 +43,9 @@
4543
//! // combine them with ours into the final signature
4644
//! let sig = musig.combine_partial_signatures(&keylist, &session, [p1_sig, p2_sig, p3_sig]);
4745
//! // check it's a valid normal Schnorr signature
48-
//! musig.schnorr.verify(&keylist.agg_verification_key(), message, &sig);
46+
//! musig
47+
//! .schnorr
48+
//! .verify(&keylist.agg_verification_key(), message, &sig);
4949
//! ```
5050
//!
5151
//! ## Description
@@ -210,10 +210,7 @@ impl<H: Digest<OutputSize = U32> + Clone, S> MuSig<H, S> {
210210
/// let my_keypair = musig.schnorr.new_keypair(my_secret_key);
211211
/// let my_public_key = my_keypair.public_key();
212212
/// // Note the keys have to come in the same order on the other side!
213-
/// let keylist = musig.new_keylist(vec![
214-
/// their_public_key,
215-
/// my_public_key,
216-
/// ]);
213+
/// let keylist = musig.new_keylist(vec![their_public_key, my_public_key]);
217214
/// ```
218215
pub fn new_keylist(&self, parties: Vec<XOnly>) -> KeyList {
219216
let keys = parties.clone();
@@ -255,7 +252,6 @@ impl<H: Digest<OutputSize = U32> + Clone, S> MuSig<H, S> {
255252
}
256253

257254
impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen> MuSig<H, Schnorr<H, NG>> {
258-
/// TODO
259255
/// Generate nonces for your local keys in keylist.
260256
///
261257
/// It is very important to carefully consider the implications of your choice of underlying
@@ -268,17 +264,14 @@ impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen> MuSig<H, Schnorr<H, NG>>
268264
///
269265
/// Using a [`Deterministic`] nonce generator means you **must** never start two signing
270266
/// sessions with nonces generated from the same `sid`. If you do your secret key will be
271-
/// recoverable from the two partial signatures you created with the same nonce. The upside is
272-
/// that you can call [`start_sign_session_deterministic`] with the `sid` you originally passed
273-
/// to `gen_nonces` without having to store the output of `gen_nonces`.
267+
/// recoverable from the two partial signatures you created with the same nonce.
274268
///
275269
/// Note that the API allows you to BYO nonces by creating `NonceKeyPair`s manually.
276270
///
277271
/// [`NonceGen`]: secp256kfun::nonce::NonceGen
278272
/// [`Synthetic`]: secp256kfun::nonce::Synthetic
279273
/// [`Deterministic`]: secp256kfun::nonce::Deterministic
280274
/// [`start_sign_session`]: Self::start_sign_session
281-
/// [`start_sign_session_deterministic`]: Self::start_sign_session_deterministic
282275
/// [`NonceKeyPair`]: schnorr_fun::binonce::NonceKeyPair
283276
pub fn gen_nonces(&self, secret: &Scalar, keylist: &KeyList, sid: &[u8]) -> NonceKeyPair {
284277
let r1 = derive_nonce!(
@@ -329,15 +322,14 @@ pub struct Adaptor {
329322
///
330323
/// ## Security
331324
///
332-
/// This struct has **secret nonces** in it up until you call [`clear_secrets`] or [`sign`]. If
333-
/// a malicious party gains access to it before and you generate a partial signature with this session they
325+
/// This struct has **secret nonces** in it up until you call [`sign`]. If a malicious party
326+
/// gains access to it before and you generate a partial signature with this session they
334327
/// will be able to recover your secret key. If this is a concern simply avoid serializing this
335328
/// struct (until you've cleared it) and recreate it only when you need it.
336329
///
337330
/// [`start_sign_session`]: MuSig::start_sign_session
338331
/// [`start_encrypted_sign_session`]: MuSig::start_encrypted_sign_session
339-
/// [`clear_secrets`]: SignSession::clear_secrets
340-
/// [`sign_all`]: MuSig::sign_all
332+
/// [`sign`]: MuSig::sign
341333
#[derive(Debug, Clone, PartialEq)]
342334
#[cfg_attr(
343335
feature = "serde",
@@ -390,9 +382,8 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
390382
/// i.e. a session to produce an adaptor signature under `encryption_key`.
391383
/// See [`adaptor`] for a more general description of adaptor signatures.
392384
///
393-
/// You must provide you local secret nonces (the public portion must be shared with the other
394-
/// signer(s)). If you are using deterministic nonce generation it's possible to use
395-
/// [`start_encrypted_sign_session_deterministic`] instead.
385+
/// You must provide the public nonces (where your public portions must be
386+
/// shared with the other signer(s)).
396387
///
397388
/// ## Return Value
398389
///
@@ -405,7 +396,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
405396
/// Panics if number of local or remote nonces passed in does not align with the parties in
406397
/// `keylist`.
407398
///
408-
/// [`start_encrypted_sign_session_deterministic`]: Self::start_sign_session_deterministic
409399
/// [`adaptor`]: crate::adaptor
410400
pub fn start_encrypted_sign_session(
411401
&self,
@@ -419,7 +409,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
419409
Some(SignSession {
420410
b,
421411
c,
422-
// local_secret_nonce,
423412
public_nonces,
424413
R,
425414
nonce_needs_negation,
@@ -482,12 +471,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
482471
}
483472

484473
/// Generates a partial signature (or partial encrypted signature depending on `T`) for the local_secret_nonce.
485-
///
486-
/// TODO
487-
/// This can only be called once per session as it clears the session (see also [`clear_secrets`]).
488-
/// Calling `sign` again will return an empty vector.
489-
///
490-
/// [`clear_secrets`]: SignSession::clear_secrets
491474
pub fn sign<T>(
492475
&self,
493476
keylist: &KeyList,

0 commit comments

Comments
 (0)