diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 011bbae4..5108940e 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -16,6 +16,7 @@ use internals::write_err; pub use secp256k1::rand; pub use secp256k1::{self, constants, KeyPair, Parity, Secp256k1, Verification, XOnlyPublicKey}; +use crate::crypto::ecdsa; use crate::hash_types::{PubkeyHash, WPubkeyHash}; use crate::network::constants::Network; use crate::prelude::*; @@ -251,6 +252,16 @@ impl PublicKey { ) -> PublicKey { sk.public_key(secp) } + + /// Checks that `sig` is a valid ECDSA signature for `msg` using this public key. + pub fn verify( + &self, + secp: &Secp256k1, + msg: &secp256k1::Message, + sig: &ecdsa::Signature, + ) -> Result<(), Error> { + Ok(secp.verify_ecdsa(msg, &sig.sig, &self.inner)?) + } } impl From for XOnlyPublicKey {