Skip to content

Commit f5c6f45

Browse files
committed
derive nonces from ThreadRng in synopsis and make clippy happy
1 parent 48a0e28 commit f5c6f45

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

schnorr_fun/src/blind.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
//!
2323
//! # Synopsis
2424
//! ```
25-
//! use schnorr_fun::{blind, Blinder, Message, Schnorr};
26-
//! use secp256kfun::{g, marker::Public, Scalar, G, nonce::Deterministic,};
25+
//! use schnorr_fun::{blind, Blinder, Message, Schnorr, nonce};
26+
//! use secp256kfun::{g, marker::Public, Scalar, G, derive_nonce, nonce::Deterministic};
27+
//! use rand::rngs::ThreadRng;
2728
//! use sha2::Sha256;
2829
//!
29-
//! let schnorr = Schnorr::<Sha256, Deterministic<Sha256>>::new(Deterministic::<Sha256>::default());
30-
//! // Generate a secret & public key for the party that will blindly sign a message
30+
//! let nonce_gen = nonce::Synthetic::<Sha256, nonce::GlobalRng<ThreadRng>>::default();
31+
//! let schnorr = Schnorr::<Sha256, _>::new(nonce_gen);
32+
//! // Generate a secret & public key for the blind signing server
3133
//! let mut secret = Scalar::random(&mut rand::thread_rng());
3234
//! let (public_key, secret_needs_negation) = g!(secret * G).normalize().into_point_with_even_y();
3335
//! secret.conditional_negate(secret_needs_negation);
@@ -37,12 +39,15 @@
3739
//! // Here we request two nonces corresponding to two sessions, such that we will retrieve one signature.
3840
//! let n_sessions = 2;
3941
//!
40-
//! // The blind signing server replies with N public nonces to the user and remembers this number of sessions.
42+
//! // The blind signing server sends out N public nonces to the user and remembers this number of sessions.
4143
//! let mut nonces = vec![];
4244
//! let mut pub_nonces = vec![];
4345
//! for _ in 0..n_sessions {
44-
//! let mut nonce = Scalar::random(&mut rand::thread_rng());
45-
//! // TODO: Probably want to reintroduce a singular nonce struct? And move musig/frost to "binonce"
46+
//! let mut nonce = derive_nonce!(
47+
//! nonce_gen => schnorr.nonce_gen(),
48+
//! secret => secret,
49+
//! public => [public_key]
50+
//! );
4651
//! let (pub_nonce, nonce_negated) = g!(nonce * G).normalize().into_point_with_even_y();
4752
//! nonce.conditional_negate(nonce_negated);
4853
//! nonces.push(nonce);
@@ -99,17 +104,18 @@
99104
//! }
100105
//! ```
101106
102-
use crate::fun::rand_core::{CryptoRng, RngCore};
103-
use crate::{Message, Schnorr, Signature};
107+
use crate::{
108+
fun::rand_core::{CryptoRng, RngCore},
109+
Message, Schnorr, Signature, Vec,
110+
};
104111
use rand::Rng;
105-
use secp256kfun::nonce::{AddTag, NonceGen};
106112
use secp256kfun::{
107113
digest::{generic_array::typenum::U32, Digest},
108114
g,
109115
marker::*,
116+
nonce::{AddTag, NonceGen},
110117
s, Point, Scalar, G,
111118
};
112-
use std::vec::Vec;
113119

114120
/// Use [`BlindingTweaks`] to create the blinded public key, challenge, and nonce needed for a blinded signature
115121
///

schnorr_fun/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub mod musig;
3030

3131
#[cfg(feature = "alloc")]
3232
pub mod blind;
33+
#[cfg(feature = "alloc")]
3334
pub use blind::*;
3435

3536
mod signature;

0 commit comments

Comments
 (0)