Skip to content

Commit b9cb37d

Browse files
committed
Add a verify function to PublicKey
To be uniform with `XOnlyPublicKey` add a `verify` function to the `PublicKey`.
1 parent 14e8218 commit b9cb37d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/key.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ use serde::ser::SerializeTuple;
1313
use crate::ffi::types::c_uint;
1414
use crate::ffi::{self, CPtr};
1515
use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey};
16-
use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification};
1716
#[cfg(feature = "global-context")]
18-
use crate::{ecdsa, SECP256K1};
17+
use crate::SECP256K1;
18+
use crate::{
19+
constants, ecdsa, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification,
20+
};
1921
#[cfg(feature = "bitcoin_hashes")]
2022
use crate::{hashes, ThirtyTwoByteHash};
2123

@@ -696,6 +698,16 @@ impl PublicKey {
696698
(XOnlyPublicKey(xonly_pk), parity)
697699
}
698700
}
701+
702+
/// Checks that `sig` is a valid ECDSA signature for `msg` using this public key.
703+
pub fn verify<C: Verification>(
704+
&self,
705+
secp: &Secp256k1<C>,
706+
msg: &Message,
707+
sig: &ecdsa::Signature,
708+
) -> Result<(), Error> {
709+
secp.verify_ecdsa(msg, sig, self)
710+
}
699711
}
700712

701713
/// This trait enables interaction with the FFI layer and even though it is part of the public API

0 commit comments

Comments
 (0)