3
3
//! ## Synopsis
4
4
//!
5
5
//! ```
6
- //! use schnorr_fun::{musig::MuSig, Schnorr , Message, nonce::Deterministic };
6
+ //! use schnorr_fun::{musig::MuSig, nonce::Deterministic , Message, Schnorr };
7
7
//! use sha2::Sha256;
8
8
//! // use sha256 with deterministic nonce generation
9
9
//! let musig = MuSig::<Sha256, Schnorr<Sha256, Deterministic<Sha256>>>::default();
10
10
//! // create a keylist
11
11
//! 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()));
13
15
//! let public_key1 = kp1.public_key();
14
16
//! # let kp2 = musig.schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
15
17
//! # let public_key2 = kp2.public_key();
16
18
//! # let kp3 = musig.schnorr.new_keypair(Scalar::random(&mut rand::thread_rng()));
17
19
//! # let public_key3 = kp3.public_key();
18
20
//! // 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]);
24
22
//! let agg_key = keylist.agg_public_key();
25
23
//!
26
- //! // create unique nonce, and send public nonce to other parties.
24
+ //! // create a unique nonce, and send the public nonce to other parties.
27
25
//! let p1_nonce = musig.gen_nonces(kp1.secret_key(), &keylist, b"session-id-1337");
28
26
//! let p1_public_nonce = p1_nonce.public();
29
27
//! # let p2_nonce = musig.gen_nonces(kp2.secret_key(), &keylist, b"session-id-1337");
34
32
//! let nonces = vec![p1_public_nonce, p2_public_nonce, p3_public_nonce];
35
33
//! let message = Message::plain("my-app", b"chancellor on brink of second bailout for banks");
36
34
//! // 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
39
37
//! let p1_sig = musig.sign(&keylist, 0, kp1.secret_key(), p1_nonce, &session);
40
38
//! # let p2_sig = musig.sign(&keylist, 1, kp2.secret_key(), p2_nonce, &session);
41
39
//! # let p3_sig = musig.sign(&keylist, 2, kp3.secret_key(), p3_nonce, &session);
45
43
//! // combine them with ours into the final signature
46
44
//! let sig = musig.combine_partial_signatures(&keylist, &session, [p1_sig, p2_sig, p3_sig]);
47
45
//! // 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);
49
49
//! ```
50
50
//!
51
51
//! ## Description
@@ -210,10 +210,7 @@ impl<H: Digest<OutputSize = U32> + Clone, S> MuSig<H, S> {
210
210
/// let my_keypair = musig.schnorr.new_keypair(my_secret_key);
211
211
/// let my_public_key = my_keypair.public_key();
212
212
/// // 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]);
217
214
/// ```
218
215
pub fn new_keylist ( & self , parties : Vec < XOnly > ) -> KeyList {
219
216
let keys = parties. clone ( ) ;
@@ -255,7 +252,6 @@ impl<H: Digest<OutputSize = U32> + Clone, S> MuSig<H, S> {
255
252
}
256
253
257
254
impl < H : Digest < OutputSize = U32 > + Clone , NG : NonceGen > MuSig < H , Schnorr < H , NG > > {
258
- /// TODO
259
255
/// Generate nonces for your local keys in keylist.
260
256
///
261
257
/// 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>>
268
264
///
269
265
/// Using a [`Deterministic`] nonce generator means you **must** never start two signing
270
266
/// 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.
274
268
///
275
269
/// Note that the API allows you to BYO nonces by creating `NonceKeyPair`s manually.
276
270
///
277
271
/// [`NonceGen`]: secp256kfun::nonce::NonceGen
278
272
/// [`Synthetic`]: secp256kfun::nonce::Synthetic
279
273
/// [`Deterministic`]: secp256kfun::nonce::Deterministic
280
274
/// [`start_sign_session`]: Self::start_sign_session
281
- /// [`start_sign_session_deterministic`]: Self::start_sign_session_deterministic
282
275
/// [`NonceKeyPair`]: schnorr_fun::binonce::NonceKeyPair
283
276
pub fn gen_nonces ( & self , secret : & Scalar , keylist : & KeyList , sid : & [ u8 ] ) -> NonceKeyPair {
284
277
let r1 = derive_nonce ! (
@@ -329,15 +322,14 @@ pub struct Adaptor {
329
322
///
330
323
/// ## Security
331
324
///
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
334
327
/// will be able to recover your secret key. If this is a concern simply avoid serializing this
335
328
/// struct (until you've cleared it) and recreate it only when you need it.
336
329
///
337
330
/// [`start_sign_session`]: MuSig::start_sign_session
338
331
/// [`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
341
333
#[ derive( Debug , Clone , PartialEq ) ]
342
334
#[ cfg_attr(
343
335
feature = "serde" ,
@@ -390,9 +382,8 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
390
382
/// i.e. a session to produce an adaptor signature under `encryption_key`.
391
383
/// See [`adaptor`] for a more general description of adaptor signatures.
392
384
///
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)).
396
387
///
397
388
/// ## Return Value
398
389
///
@@ -405,7 +396,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
405
396
/// Panics if number of local or remote nonces passed in does not align with the parties in
406
397
/// `keylist`.
407
398
///
408
- /// [`start_encrypted_sign_session_deterministic`]: Self::start_sign_session_deterministic
409
399
/// [`adaptor`]: crate::adaptor
410
400
pub fn start_encrypted_sign_session (
411
401
& self ,
@@ -419,7 +409,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
419
409
Some ( SignSession {
420
410
b,
421
411
c,
422
- // local_secret_nonce,
423
412
public_nonces,
424
413
R ,
425
414
nonce_needs_negation,
@@ -482,12 +471,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> MuSig<H, Schnorr<H, NG>> {
482
471
}
483
472
484
473
/// 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
491
474
pub fn sign < T > (
492
475
& self ,
493
476
keylist : & KeyList ,
0 commit comments