Skip to content

Commit

Permalink
Expose secret_key method for ecdsa::Keypair and eth::Keypair (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
muraca and jsdw authored Jul 8, 2024
1 parent 3648bd2 commit bb1a012
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions signer/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bb1a012

Please sign in to comment.