Skip to content

Commit 6f05b57

Browse files
committed
Merge #642: Add a verify function to PublicKey
b9cb37d 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: ACK b9cb37d Tree-SHA512: e1d8127daafd18d3c9b5df6edc46a961ed49e87a44c650b92c695606002f1d4c1aee3e89822e188a65ba888abd50c5b6f247570d73fa8508d739efa8bc4df7f0
2 parents 14e8218 + b9cb37d commit 6f05b57

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)