Add a verify function to PublicKey
Expose signature verification functionality for ECDSA signatures on the `PublicKey` type. We should have an identical function on `XOnlyPublicKey` but this will have to be done in `secp2561`.
This commit is contained in:
parent
12e014e288
commit
e04ac1e743
|
@ -16,6 +16,7 @@ use internals::write_err;
|
||||||
pub use secp256k1::rand;
|
pub use secp256k1::rand;
|
||||||
pub use secp256k1::{self, constants, KeyPair, Parity, Secp256k1, Verification, XOnlyPublicKey};
|
pub use secp256k1::{self, constants, KeyPair, Parity, Secp256k1, Verification, XOnlyPublicKey};
|
||||||
|
|
||||||
|
use crate::crypto::ecdsa;
|
||||||
use crate::hash_types::{PubkeyHash, WPubkeyHash};
|
use crate::hash_types::{PubkeyHash, WPubkeyHash};
|
||||||
use crate::network::constants::Network;
|
use crate::network::constants::Network;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -251,6 +252,16 @@ impl PublicKey {
|
||||||
) -> PublicKey {
|
) -> PublicKey {
|
||||||
sk.public_key(secp)
|
sk.public_key(secp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks that `sig` is a valid ECDSA signature for `msg` using this public key.
|
||||||
|
pub fn verify<C: secp256k1::Verification>(
|
||||||
|
&self,
|
||||||
|
secp: &Secp256k1<C>,
|
||||||
|
msg: &secp256k1::Message,
|
||||||
|
sig: &ecdsa::Signature,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
Ok(secp.verify_ecdsa(msg, &sig.sig, &self.inner)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PublicKey> for XOnlyPublicKey {
|
impl From<PublicKey> for XOnlyPublicKey {
|
||||||
|
|
Loading…
Reference in New Issue