Expose secret_key method for ecdsa::Keypair and eth::Keypair (#1628)

* Expose `secret_key` method for `ecdsa::Keypair` and `eth::Keypair`

* cargo fmt

* fix eth::secret_key

---------

Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Matteo MuracaandJames Wilson authored and GitHub committed 2024-07-08 14:30:00 +01:00
1 parent 3648bd2e60
commit bb1a012560
2 files changed
+10

No files matched your search

+5
View File
@@ -157,6 +157,11 @@ impl Keypair {
PublicKey(self.0.public_key().serialize())
}
/// Obtain the [`SecretKey`] part of this key pair. This should be kept secret.
pub fn secret_key(&self) -> SecretKeyBytes {
*self.0.secret_key().as_ref()
}
/// Sign some message. These bytes can be used directly in a Substrate `MultiSignature::Ecdsa(..)`.
pub fn sign(&self, message: &[u8]) -> Signature {
self.sign_prehashed(&sp_crypto_hashing::blake2_256(message))
+5
View File
@@ -97,6 +97,11 @@ impl Keypair {
.map_err(|_| Error::InvalidSeed)
}
/// Obtain the [`ecdsa::SecretKeyBytes`] of this keypair.
pub fn secret_key(&self) -> SecretKeyBytes {
self.0.secret_key()
}
/// Obtain the [`eth::PublicKey`] of this keypair.
pub fn public_key(&self) -> PublicKey {
let uncompressed = self.0 .0.public_key().serialize_uncompressed();