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: ACKb9cb37d69f
Tree-SHA512: e1d8127daafd18d3c9b5df6edc46a961ed49e87a44c650b92c695606002f1d4c1aee3e89822e188a65ba888abd50c5b6f247570d73fa8508d739efa8bc4df7f0
This commit is contained in:
commit
6f05b57233
16
src/key.rs
16
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<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
|
||||
|
|
Loading…
Reference in New Issue