Add a verify function to PublicKey
To be uniform with `XOnlyPublicKey` add a `verify` function to the `PublicKey`.
This commit is contained in:
parent
14e82186d1
commit
b9cb37d69f
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