Skip to content

Commit

Permalink
Add a verify function to PublicKey
Browse files Browse the repository at this point in the history
To be uniform with `XOnlyPublicKey` add a `verify` function to the
`PublicKey`.
  • Loading branch information
tcharding committed Aug 11, 2023
1 parent 14e8218 commit b9cb37d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9cb37d

Please sign in to comment.