Skip to content

Commit 408c124

Browse files
committed
Merge #618: Add a verify function to PublicKey
d60b891 Add a verify function to PublicKey (Tobin C. Harding) Pull request description: Expose signature verification functionality for schnorr signatures on the `XOnlyPublicKey` type. Idea from Kixunil: rust-bitcoin/rust-bitcoin#1744 (comment) ACKs for top commit: apoelstra: ACK d60b891 Tree-SHA512: 2ffa3de528b857c5b0a402815b71b35da913c668bea53b63801705fa6a86eb6d44766aa2395c02f67a4712b451c77caf627af9450183ae70957abf246a63c279
2 parents 7c8270a + d60b891 commit 408c124

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/key.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ use serde::ser::SerializeTuple;
1212

1313
use crate::ffi::types::c_uint;
1414
use crate::ffi::{self, CPtr};
15-
#[cfg(all(feature = "global-context", feature = "rand-std"))]
16-
use crate::schnorr;
1715
use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey};
18-
use crate::{constants, from_hex, Scalar, Secp256k1, Signing, Verification};
16+
use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification};
1917
#[cfg(feature = "global-context")]
20-
use crate::{ecdsa, Message, SECP256K1};
18+
use crate::{ecdsa, SECP256K1};
2119
#[cfg(feature = "bitcoin_hashes")]
2220
use crate::{hashes, ThirtyTwoByteHash};
2321

@@ -1316,6 +1314,16 @@ impl XOnlyPublicKey {
13161314
pub fn public_key(&self, parity: Parity) -> PublicKey {
13171315
PublicKey::from_x_only_public_key(*self, parity)
13181316
}
1317+
1318+
/// Checks that `sig` is a valid schnorr signature for `msg` using this public key.
1319+
pub fn verify<C: Verification>(
1320+
&self,
1321+
secp: &Secp256k1<C>,
1322+
msg: &Message,
1323+
sig: &schnorr::Signature,
1324+
) -> Result<(), Error> {
1325+
secp.verify_schnorr(sig, msg, self)
1326+
}
13191327
}
13201328

13211329
/// Represents the parity passed between FFI function calls.

0 commit comments

Comments
 (0)