Skip to content

Commit 0b1dcc6

Browse files
committed
Add option to sign with extra nonce
Add option to create an adaptor signature by signing with an extra nonce
1 parent a865263 commit 0b1dcc6

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

core/src/core/transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ impl TxKernel {
742742
&sig,
743743
&self.msg_to_sign()?,
744744
None,
745+
None,
745746
&pubkey,
746747
Some(&pubkey),
747748
false,
@@ -2400,7 +2401,7 @@ mod test {
24002401
let pubkey = excess.to_pubkey(&keychain.secp()).unwrap();
24012402

24022403
let excess_sig =
2403-
aggsig::sign_single(&keychain.secp(), &msg, &skey, None, Some(&pubkey)).unwrap();
2404+
aggsig::sign_single(&keychain.secp(), &msg, &skey, None, None, Some(&pubkey)).unwrap();
24042405

24052406
kernel.excess = excess;
24062407
kernel.excess_sig = excess_sig;

core/src/libtx/aggsig.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn calculate_partial_sig(
9696
secp: &Secp256k1,
9797
sec_key: &SecretKey,
9898
sec_nonce: &SecretKey,
99+
sec_nonce_extra: Option<&SecretKey>,
99100
nonce_sum: &PublicKey,
100101
pubkey_sum: Option<&PublicKey>,
101102
msg: &secp::Message,
@@ -106,7 +107,7 @@ pub fn calculate_partial_sig(
106107
&msg,
107108
sec_key,
108109
Some(sec_nonce),
109-
None,
110+
sec_nonce_extra,
110111
Some(nonce_sum),
111112
pubkey_sum,
112113
Some(nonce_sum),
@@ -179,6 +180,7 @@ pub fn verify_partial_sig(
179180
secp: &Secp256k1,
180181
sig: &Signature,
181182
pub_nonce_sum: &PublicKey,
183+
pub_nonce_extra: Option<&PublicKey>,
182184
pubkey: &PublicKey,
183185
pubkey_sum: Option<&PublicKey>,
184186
msg: &secp::Message,
@@ -188,6 +190,7 @@ pub fn verify_partial_sig(
188190
sig,
189191
&msg,
190192
Some(&pub_nonce_sum),
193+
pub_nonce_extra,
191194
pubkey,
192195
pubkey_sum,
193196
true,
@@ -323,7 +326,7 @@ pub fn verify_single_from_commit(
323326
commit: &Commitment,
324327
) -> Result<(), Error> {
325328
let pubkey = commit.to_pubkey(secp)?;
326-
if !verify_single(secp, sig, msg, None, &pubkey, Some(&pubkey), false) {
329+
if !verify_single(secp, sig, msg, None, None, &pubkey, Some(&pubkey), false) {
327330
return Err(ErrorKind::Signature("Signature validation error".to_string()).into());
328331
}
329332
Ok(())
@@ -391,7 +394,7 @@ pub fn verify_completed_sig(
391394
pubkey_sum: Option<&PublicKey>,
392395
msg: &secp::Message,
393396
) -> Result<(), Error> {
394-
if !verify_single(secp, sig, msg, None, pubkey, pubkey_sum, true) {
397+
if !verify_single(secp, sig, msg, None, None, pubkey, pubkey_sum, true) {
395398
return Err(ErrorKind::Signature("Signature validation error".to_string()).into());
396399
}
397400
Ok(())
@@ -414,9 +417,19 @@ pub fn sign_single(
414417
msg: &Message,
415418
skey: &SecretKey,
416419
snonce: Option<&SecretKey>,
420+
snonce_extra: Option<&SecretKey>,
417421
pubkey_sum: Option<&PublicKey>,
418422
) -> Result<Signature, Error> {
419-
let sig = aggsig::sign_single(secp, &msg, skey, snonce, None, None, pubkey_sum, None)?;
423+
let sig = aggsig::sign_single(
424+
secp,
425+
&msg,
426+
skey,
427+
snonce,
428+
snonce_extra,
429+
None,
430+
pubkey_sum,
431+
None,
432+
)?;
420433
Ok(sig)
421434
}
422435

@@ -426,12 +439,20 @@ pub fn verify_single(
426439
sig: &Signature,
427440
msg: &Message,
428441
pubnonce: Option<&PublicKey>,
442+
pubnonce_extra: Option<&PublicKey>,
429443
pubkey: &PublicKey,
430444
pubkey_sum: Option<&PublicKey>,
431445
is_partial: bool,
432446
) -> bool {
433447
aggsig::verify_single(
434-
secp, sig, msg, pubnonce, pubkey, pubkey_sum, None, is_partial,
448+
secp,
449+
sig,
450+
msg,
451+
pubnonce,
452+
pubkey,
453+
pubkey_sum,
454+
pubnonce_extra,
455+
is_partial,
435456
)
436457
}
437458

core/src/libtx/secp_ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ mod test {
433433
let mut msg = [0u8; 32];
434434
thread_rng().fill(&mut msg);
435435
let msg = Message::from_slice(&msg).unwrap();
436-
let sig = aggsig::sign_single(&secp, &msg, &sk, None, None).unwrap();
436+
let sig = aggsig::sign_single(&secp, &msg, &sk, None, None, None).unwrap();
437437
let mut commit = [0u8; 33];
438438
commit[0] = 0x09;
439439
thread_rng().fill(&mut commit[1..]);

0 commit comments

Comments
 (0)