Add a verify function to PublicKey

To be uniform with `XOnlyPublicKey` add a `verify` function to the
`PublicKey`.
This commit is contained in:
Tobin C. Harding 2023-08-09 11:47:40 +10:00
parent 14e82186d1
commit b9cb37d69f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
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::{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<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