From b9cb37d69f463dfa28f7f7d3617b81f8a30e5585 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 9 Aug 2023 11:47:40 +1000 Subject: [PATCH] Add a verify function to PublicKey To be uniform with `XOnlyPublicKey` add a `verify` function to the `PublicKey`. --- src/key.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/key.rs b/src/key.rs index ecec179..fbba1c2 100644 --- a/src/key.rs +++ b/src/key.rs @@ -13,9 +13,11 @@ use serde::ser::SerializeTuple; use crate::ffi::types::c_uint; use crate::ffi::{self, CPtr}; use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey}; -use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification}; #[cfg(feature = "global-context")] -use crate::{ecdsa, SECP256K1}; +use crate::SECP256K1; +use crate::{ + constants, ecdsa, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification, +}; #[cfg(feature = "bitcoin_hashes")] use crate::{hashes, ThirtyTwoByteHash}; @@ -696,6 +698,16 @@ impl PublicKey { (XOnlyPublicKey(xonly_pk), parity) } } + + /// Checks that `sig` is a valid ECDSA signature for `msg` using this public key. + pub fn verify( + &self, + secp: &Secp256k1, + msg: &Message, + sig: &ecdsa::Signature, + ) -> Result<(), Error> { + secp.verify_ecdsa(msg, sig, self) + } } /// This trait enables interaction with the FFI layer and even though it is part of the public API