Merge rust-bitcoin/rust-secp256k1#642: Add a `verify` function to `PublicKey`

b9cb37d69f Add a verify function to PublicKey (Tobin C. Harding)

Pull request description:

  To be uniform with `XOnlyPublicKey` add a `verify` function to the `PublicKey`.

  Should have been done when we did #618

ACKs for top commit:
  apoelstra:
    ACK b9cb37d69f

Tree-SHA512: e1d8127daafd18d3c9b5df6edc46a961ed49e87a44c650b92c695606002f1d4c1aee3e89822e188a65ba888abd50c5b6f247570d73fa8508d739efa8bc4df7f0
This commit is contained in:
Andrew Poelstra 2023-08-11 18:53:49 +00:00
commit 6f05b57233
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 14 additions and 2 deletions

View File

@ -13,9 +13,11 @@ use serde::ser::SerializeTuple;
use crate::ffi::types::c_uint; use crate::ffi::types::c_uint;
use crate::ffi::{self, CPtr}; use crate::ffi::{self, CPtr};
use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey}; use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey};
use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification};
#[cfg(feature = "global-context")] #[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")] #[cfg(feature = "bitcoin_hashes")]
use crate::{hashes, ThirtyTwoByteHash}; use crate::{hashes, ThirtyTwoByteHash};
@ -696,6 +698,16 @@ impl PublicKey {
(XOnlyPublicKey(xonly_pk), parity) (XOnlyPublicKey(xonly_pk), parity)
} }
} }
/// Checks that `sig` is a valid ECDSA signature for `msg` using this public key.
pub fn verify<C: Verification>(
&self,
secp: &Secp256k1<C>,
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 /// This trait enables interaction with the FFI layer and even though it is part of the public API