69
69
//! .collect();
70
70
//! // create a unique session ID for this signing session
71
71
//! let sid = [
72
- //! frost_key.joint_public_key.to_bytes().as_slice(),
73
72
//! verification_shares_bytes.concat().as_slice(),
74
73
//! b"frost-very-unique-id".as_slice(),
75
74
//! b"0".as_slice(),
83
82
//! # ]
84
83
//! # .concat();
85
84
//! // generate nonces for this signing session
86
- //! let nonce = frost.gen_nonce(&secret_share, &sid);
87
- //! # let nonce3 = frost.gen_nonce(&secret_share3, &sid3);
85
+ //! let nonce = frost.gen_nonce(&secret_share, &sid, Some(frost_key.joint_public_key), None );
86
+ //! # let nonce3 = frost.gen_nonce(&secret_share3, &sid3, Some(frost_key.joint_public_key), None );
88
87
//! // share your public nonce with the other signing participant(s)
89
88
//! # let recieved_nonce3 = nonce3.public();
90
89
//! // recieve public nonces from other participants with their index
@@ -111,7 +110,6 @@ use crate::{Message, Schnorr, Signature, Vec};
111
110
use core:: iter;
112
111
use rand_core:: { CryptoRng , RngCore } ;
113
112
use secp256kfun:: {
114
- derive_nonce,
115
113
digest:: { generic_array:: typenum:: U32 , Digest } ,
116
114
g,
117
115
hash:: { HashAdd , Tagged } ,
@@ -851,36 +849,35 @@ impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen + AddTag> Frost<H, NG> {
851
849
impl < H : Digest < OutputSize = U32 > + Clone , NG : NonceGen + AddTag > Frost < H , NG > {
852
850
/// Generate nonces for secret shares
853
851
///
854
- /// It is very important that you use a unique `sid` for this signing session and to also carefully
855
- /// consider the implications of your choice of underlying [`NonceGen`].
852
+ /// This method should be used carefully.
853
+ /// This calls [`NonceKeyPair::generate`] internally with the `MuSig` instance's `NonceGen`.
854
+ /// See documentation for that for more usage info.
856
855
///
857
856
/// When choosing a `secret` to use, if you are generating nonces prior to KeyGen completion,
858
857
/// use the static first coefficient of your polynomial.
859
858
/// Otherwise you can use your secret share of the joint FROST key.
860
859
///
861
860
/// The application must decide upon a unique `sid` for this FROST multisignature.
862
- /// For example, the concatenation of: my_signing_index, joint_key, verfication_shares
861
+ /// For example, the concatenation of: my_signing_index, verfication_shares, purpose
863
862
///
864
863
/// ## Return Value
865
864
///
866
865
/// A NonceKeyPair comprised of secret scalars [r1, r2] and public nonces [R1, R2]
867
- pub fn gen_nonce ( & self , secret : & Scalar , sid : & [ u8 ] ) -> NonceKeyPair {
868
- let r1 = derive_nonce ! (
869
- nonce_gen => self . schnorr. nonce_gen( ) ,
870
- secret => secret,
871
- public => [ b"r1-frost" , sid]
872
- ) ;
873
- let r2 = derive_nonce ! (
874
- nonce_gen => self . schnorr. nonce_gen( ) ,
875
- secret => secret,
876
- public => [ b"r2-frost" , sid]
877
- ) ;
878
- let R1 = g ! ( r1 * G ) . normalize ( ) ;
879
- let R2 = g ! ( r2 * G ) . normalize ( ) ;
880
- NonceKeyPair {
881
- public : Nonce ( [ R1 , R2 ] ) ,
882
- secret : [ r1, r2] ,
883
- }
866
+ /// [`NonceKeyPair::generate`]: crate::binonce::NonceKeyPair::generate
867
+ pub fn gen_nonce (
868
+ & self ,
869
+ secret : & Scalar ,
870
+ session_id : & [ u8 ] ,
871
+ public_key : Option < Point < impl Normalized > > ,
872
+ message : Option < Message < ' _ > > ,
873
+ ) -> NonceKeyPair {
874
+ NonceKeyPair :: generate (
875
+ self . schnorr . nonce_gen ( ) ,
876
+ secret,
877
+ session_id,
878
+ public_key,
879
+ message,
880
+ )
884
881
}
885
882
}
886
883
@@ -977,7 +974,13 @@ mod test {
977
974
b"frost-prop-test" . as_slice( ) ,
978
975
]
979
976
. concat( ) ;
980
- let nonces: Vec <NonceKeyPair > = signer_indexes. iter( ) . map( |i| frost. gen_nonce( & secret_shares[ * i as usize ] , & [ sid. as_slice( ) , [ * i as u8 ] . as_slice( ) ] . concat( ) ) ) . collect( ) ;
977
+ let nonces: Vec <NonceKeyPair > = signer_indexes. iter( ) . map( |i|
978
+ frost. gen_nonce(
979
+ & secret_shares[ * i as usize ] ,
980
+ & [ sid. as_slice( ) , [ * i as u8 ] . as_slice( ) ] . concat( ) ,
981
+ Some ( frost_keys[ signer_indexes[ 0 ] ] . joint_public_key) ,
982
+ None )
983
+ ) . collect( ) ;
981
984
982
985
let mut recieved_nonces: Vec <_> = vec![ ] ;
983
986
for ( i, nonce) in signer_indexes. iter( ) . zip( nonces. clone( ) ) {
@@ -1102,36 +1105,39 @@ mod test {
1102
1105
1103
1106
// Create unique session IDs for these signing sessions
1104
1107
let sid1 = [
1105
- xonly_frost_key. joint_public_key . to_bytes ( ) . as_slice ( ) ,
1106
1108
verification_shares_bytes. concat ( ) . as_slice ( ) ,
1107
1109
b"frost-end-to-end-test-1" . as_slice ( ) ,
1108
1110
b"0" . as_slice ( ) ,
1109
1111
]
1110
1112
. concat ( ) ;
1111
1113
1112
1114
let sid2 = [
1113
- xonly_frost_key. joint_public_key . to_bytes ( ) . as_slice ( ) ,
1114
1115
verification_shares_bytes. concat ( ) . as_slice ( ) ,
1115
1116
b"frost-end-to-end-test-2" . as_slice ( ) ,
1116
1117
b"2" . as_slice ( ) ,
1117
1118
]
1118
1119
. concat ( ) ;
1119
1120
1120
- let nonce1 = frost. gen_nonce ( & secret_share1, & sid1) ;
1121
- let nonce3 = frost. gen_nonce ( & secret_share3, & sid2) ;
1121
+ let message = Message :: plain ( "test" , b"test" ) ;
1122
+ let nonce1 = frost. gen_nonce (
1123
+ & secret_share1,
1124
+ & sid1,
1125
+ Some ( xonly_frost_key. joint_public_key ) ,
1126
+ Some ( message) ,
1127
+ ) ;
1128
+ let nonce3 = frost. gen_nonce (
1129
+ & secret_share3,
1130
+ & sid2,
1131
+ Some ( xonly_frost_key. joint_public_key ) ,
1132
+ Some ( message) ,
1133
+ ) ;
1122
1134
let nonces = vec ! [ ( 0 , nonce1. public( ) ) , ( 2 , nonce3. public( ) ) ] ;
1123
1135
let nonces2 = vec ! [ ( 0 , nonce1. public( ) ) , ( 2 , nonce3. public( ) ) ] ;
1124
1136
1125
- let session =
1126
- frost. start_sign_session ( & xonly_frost_key, nonces, Message :: plain ( "test" , b"test" ) ) ;
1127
-
1137
+ let session = frost. start_sign_session ( & xonly_frost_key, nonces, message) ;
1128
1138
dbg ! ( & session) ;
1129
1139
{
1130
- let session2 = frost. start_sign_session (
1131
- & xonly_frost_key2,
1132
- nonces2,
1133
- Message :: plain ( "test" , b"test" ) ,
1134
- ) ;
1140
+ let session2 = frost. start_sign_session ( & xonly_frost_key2, nonces2, message) ;
1135
1141
assert_eq ! ( session2, session) ;
1136
1142
}
1137
1143
0 commit comments