Skip to content

Commit 67db587

Browse files
committed
Change context objects for schnorr sig methods
- The current schnorrsig verify methods should operate on verify context as is done throughout the bitcoin core - The API for convinience method is now slightly awkard as it requires both signing and verification contexts - Finally, and importantly the XonlyPublicKey::from_keypair now operates on Verification conetxt instead of signing.
1 parent 48683d8 commit 67db587

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,12 @@ impl XOnlyPublicKey {
722722

723723
/// Creates a new Schnorr public key from a Schnorr key pair.
724724
#[inline]
725-
pub fn from_keypair<C: Signing>(secp: &Secp256k1<C>, keypair: &KeyPair) -> XOnlyPublicKey {
725+
pub fn from_keypair(keypair: &KeyPair) -> XOnlyPublicKey {
726726
let mut pk_parity = 0;
727727
unsafe {
728728
let mut xonly_pk = ffi::XOnlyPublicKey::new();
729729
let ret = ffi::secp256k1_keypair_xonly_pub(
730-
secp.ctx,
730+
ffi::secp256k1_context_no_precomp,
731731
&mut xonly_pk,
732732
&mut pk_parity,
733733
keypair.as_ptr(),

src/schnorr.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::{from_hex, Error};
1111
use core::{fmt, ptr, str};
1212
use ffi::{self, CPtr};
1313
use {constants, Secp256k1};
14-
use {Message, Signing, KeyPair, XOnlyPublicKey};
14+
use {Message, Signing, Verification, KeyPair, XOnlyPublicKey};
1515

1616
/// Represents a Schnorr signature.
1717
pub struct Signature([u8; constants::SCHNORRSIG_SIGNATURE_SIZE]);
@@ -203,7 +203,9 @@ impl<C: Signing> Secp256k1<C> {
203203
rng.fill_bytes(&mut aux);
204204
self.schnorrsig_sign_helper(msg, keypair, aux.as_c_ptr() as *const ffi::types::c_void)
205205
}
206+
}
206207

208+
impl<C: Verification> Secp256k1<C> {
207209
/// Verify a Schnorr signature.
208210
#[deprecated(since = "0.21.0", note = "Use verify_schnorr instead.")]
209211
pub fn schnorrsig_verify(
@@ -250,7 +252,7 @@ impl<C: Signing> Secp256k1<C> {
250252
rng: &mut R,
251253
) -> (KeyPair, XOnlyPublicKey) {
252254
let sk = KeyPair::new(self, rng);
253-
let pubkey = XOnlyPublicKey::from_keypair(self, &sk);
255+
let pubkey = XOnlyPublicKey::from_keypair(&sk);
254256
(sk, pubkey)
255257
}
256258
}
@@ -393,7 +395,7 @@ mod tests {
393395
assert_eq!(SecretKey::from_str(sk_str).unwrap(), sk);
394396
let pk = ::key::PublicKey::from_keypair(&keypair);
395397
assert_eq!(::key::PublicKey::from_secret_key(&secp, &sk), pk);
396-
let xpk = XOnlyPublicKey::from_keypair(&secp, &keypair);
398+
let xpk = XOnlyPublicKey::from_keypair(&keypair);
397399
assert_eq!(XOnlyPublicKey::from(pk), xpk);
398400
}
399401

@@ -433,13 +435,12 @@ mod tests {
433435
0x63, 0x63, 0x63, 0x63,
434436
];
435437

436-
let s = Secp256k1::signing_only();
437438
let sk = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");
438439

439440
// In fuzzing mode secret->public key derivation is different, so
440441
// hard-code the epected result.
441442
#[cfg(not(fuzzing))]
442-
let pk = XOnlyPublicKey::from_keypair(&s, &sk);
443+
let pk = XOnlyPublicKey::from_keypair(&sk);
443444
#[cfg(fuzzing)]
444445
let pk = XOnlyPublicKey::from_slice(&[0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x06, 0x83, 0x7f, 0x30, 0xaa, 0x0c, 0xd0, 0x54, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66]).expect("pk");
445446

@@ -572,7 +573,7 @@ mod tests {
572573
let orig_pk = pk;
573574
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
574575
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");
575-
assert_eq!(XOnlyPublicKey::from_keypair(&s, &kp), pk);
576+
assert_eq!(XOnlyPublicKey::from_keypair(&kp), pk);
576577
assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak));
577578
}
578579
}

0 commit comments

Comments
 (0)