@@ -98,6 +98,17 @@ int sign(const secp256k1_context* ctx, struct signer_secrets *signer_secrets, st
98
98
/* The same for all signers */
99
99
secp256k1_musig_session session ;
100
100
101
+ /* For adapter signature, committing to random scalar */
102
+ int nonce_parity ;
103
+ unsigned char adaptor_key [32 ];
104
+ secp256k1_pubkey adaptor ;
105
+ if (!fill_random (adaptor_key , sizeof (adaptor_key ))) {
106
+ return 0 ;
107
+ }
108
+ if (!secp256k1_ec_pubkey_create (ctx , & adaptor , adaptor_key )) {
109
+ return 0 ;
110
+ }
111
+
101
112
for (i = 0 ; i < N_SIGNERS ; i ++ ) {
102
113
unsigned char seckey [32 ];
103
114
unsigned char session_id [32 ];
@@ -126,7 +137,7 @@ int sign(const secp256k1_context* ctx, struct signer_secrets *signer_secrets, st
126
137
if (!secp256k1_musig_nonce_agg (ctx , & agg_pubnonce , pubnonces , N_SIGNERS )) {
127
138
return 0 ;
128
139
}
129
- if (!secp256k1_musig_nonce_process (ctx , & session , & agg_pubnonce , msg32 , cache , NULL )) {
140
+ if (!secp256k1_musig_nonce_process (ctx , & session , & agg_pubnonce , msg32 , cache , & adaptor )) {
130
141
return 0 ;
131
142
}
132
143
/* partial_sign will clear the secnonce by setting it to 0. That's because
@@ -156,7 +167,18 @@ int sign(const secp256k1_context* ctx, struct signer_secrets *signer_secrets, st
156
167
return 0 ;
157
168
}
158
169
}
159
- return secp256k1_musig_partial_sig_agg (ctx , sig64 , & session , partial_sigs , N_SIGNERS );
170
+
171
+ /* Since we are doing adaptor sig, complete pre-signature */
172
+ if (!secp256k1_musig_nonce_parity (ctx , & nonce_parity , & session )) {
173
+ return 0 ;
174
+ }
175
+ if (!secp256k1_musig_partial_sig_agg (ctx , sig64 , & session , partial_sigs , N_SIGNERS )){
176
+ return 0 ;
177
+ }
178
+ if (!secp256k1_musig_adapt (ctx , sig64 , sig64 , adaptor_key , nonce_parity )) {
179
+ return 0 ;
180
+ }
181
+ return 1 ;
160
182
}
161
183
162
184
int main (void ) {
0 commit comments