Adding KeyPair::serialize_sec. Closes #298

This commit is contained in:
Dr Maxim Orlovsky 2021-06-19 11:06:27 +02:00
parent 05f4278499
commit 7e2f7fef72
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
2 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,7 @@ license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-secp256k1/" homepage = "https://github.com/rust-bitcoin/rust-secp256k1/"
repository = "https://github.com/rust-bitcoin/rust-secp256k1/" repository = "https://github.com/rust-bitcoin/rust-secp256k1/"
documentation = "https://docs.rs/secp256k1/" documentation = "https://docs.rs/secp256k1/"
description = "Rust bindings for Pieter Wuille's `libsecp256k1` library. Implements ECDSA for the SECG elliptic curve group secp256k1 and related utilities." description = "Rust wrapper library for Pieter Wuille's `libsecp256k1`. Implements ECDSA and BIP 340 signatures for the SECG elliptic curve group secp256k1 and related utilities."
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ] keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
readme = "README.md" readme = "README.md"
autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330 autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330

View File

@ -211,6 +211,12 @@ impl KeyPair {
} }
} }
/// Serialize the key pair as a secret key byte value
#[inline]
pub fn serialize_sec<V: Verification>(&self, secp: &Secp256k1<V>) -> [u8; constants::SECRET_KEY_SIZE] {
*SecretKey::from_keypair(secp, self).as_ref()
}
/// Tweak a keypair by adding the given tweak to the secret key and updating the /// Tweak a keypair by adding the given tweak to the secret key and updating the
/// public key accordingly. /// public key accordingly.
/// Will return an error if the resulting key would be invalid or if /// Will return an error if the resulting key would be invalid or if