From 7e2f7fef72f90a439e52f1911f22911f609e2301 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 19 Jun 2021 11:06:27 +0200 Subject: [PATCH] Adding KeyPair::serialize_sec. Closes #298 --- Cargo.toml | 2 +- src/schnorrsig.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e545b2e..6f9920f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-secp256k1/" repository = "https://github.com/rust-bitcoin/rust-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" ] readme = "README.md" autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330 diff --git a/src/schnorrsig.rs b/src/schnorrsig.rs index d8c48a0..88a3276 100644 --- a/src/schnorrsig.rs +++ b/src/schnorrsig.rs @@ -211,6 +211,12 @@ impl KeyPair { } } + /// Serialize the key pair as a secret key byte value + #[inline] + pub fn serialize_sec(&self, secp: &Secp256k1) -> [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 /// public key accordingly. /// Will return an error if the resulting key would be invalid or if