Skip to content

Commit 50034cc

Browse files
committed
Merge #342: Change context objects for verification methods
21aa914 Change context objects for schnorr sig methods (sanket1729) Pull request description: - The current schnorrsig verify methods should operate on verify context as is done throughout the bitcoin core - Finally, and importantly the XonlyPublicKey::from_keypair now operates without any context parameter. ACKs for top commit: apoelstra: ACK 21aa914 Tree-SHA512: 035338f19839805a080eb262ae7b93ab187dabb63086c8b7f6015f3a6006986604dc2c6f329a99a20ddfa78c1ee518f44cd5eee2f73810fbdc83ff8df7d12506
2 parents ada3f98 + 21aa914 commit 50034cc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,12 @@ impl XOnlyPublicKey {
765765

766766
/// Creates a new Schnorr public key from a Schnorr key pair.
767767
#[inline]
768-
pub fn from_keypair<C: Signing>(secp: &Secp256k1<C>, keypair: &KeyPair) -> XOnlyPublicKey {
768+
pub fn from_keypair(keypair: &KeyPair) -> XOnlyPublicKey {
769769
let mut pk_parity = 0;
770770
unsafe {
771771
let mut xonly_pk = ffi::XOnlyPublicKey::new();
772772
let ret = ffi::secp256k1_keypair_xonly_pub(
773-
secp.ctx,
773+
ffi::secp256k1_context_no_precomp,
774774
&mut xonly_pk,
775775
&mut pk_parity,
776776
keypair.as_ptr(),

src/schnorr.rs

+10-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(
@@ -237,6 +239,9 @@ impl<C: Signing> Secp256k1<C> {
237239
}
238240
}
239241
}
242+
}
243+
244+
impl <C: Signing> Secp256k1<C> {
240245

241246
/// Generates a random Schnorr KeyPair and its associated Schnorr PublicKey.
242247
/// Convenience function for `schnorrsig::KeyPair::new` and
@@ -250,7 +255,7 @@ impl<C: Signing> Secp256k1<C> {
250255
rng: &mut R,
251256
) -> (KeyPair, XOnlyPublicKey) {
252257
let sk = KeyPair::new(self, rng);
253-
let pubkey = XOnlyPublicKey::from_keypair(self, &sk);
258+
let pubkey = XOnlyPublicKey::from_keypair(&sk);
254259
(sk, pubkey)
255260
}
256261
}
@@ -393,7 +398,7 @@ mod tests {
393398
assert_eq!(SecretKey::from_str(sk_str).unwrap(), sk);
394399
let pk = ::key::PublicKey::from_keypair(&keypair);
395400
assert_eq!(::key::PublicKey::from_secret_key(&secp, &sk), pk);
396-
let xpk = XOnlyPublicKey::from_keypair(&secp, &keypair);
401+
let xpk = XOnlyPublicKey::from_keypair(&keypair);
397402
assert_eq!(XOnlyPublicKey::from(pk), xpk);
398403
}
399404

@@ -433,13 +438,12 @@ mod tests {
433438
0x63, 0x63, 0x63, 0x63,
434439
];
435440

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

439443
// In fuzzing mode secret->public key derivation is different, so
440444
// hard-code the epected result.
441445
#[cfg(not(fuzzing))]
442-
let pk = XOnlyPublicKey::from_keypair(&s, &sk);
446+
let pk = XOnlyPublicKey::from_keypair(&sk);
443447
#[cfg(fuzzing)]
444448
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");
445449

@@ -572,7 +576,7 @@ mod tests {
572576
let orig_pk = pk;
573577
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
574578
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");
575-
assert_eq!(XOnlyPublicKey::from_keypair(&s, &kp), pk);
579+
assert_eq!(XOnlyPublicKey::from_keypair(&kp), pk);
576580
assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak));
577581
}
578582
}

0 commit comments

Comments
 (0)