diff --git a/signer/src/ecdsa.rs b/signer/src/ecdsa.rs index 8531d4b51c..e5b6c4507c 100644 --- a/signer/src/ecdsa.rs +++ b/signer/src/ecdsa.rs @@ -160,8 +160,12 @@ impl Keypair { /// Sign some message. These bytes can be used directly in a Substrate `MultiSignature::Ecdsa(..)`. pub fn sign(&self, message: &[u8]) -> Signature { - let message_hash = sp_crypto_hashing::blake2_256(message); - let wrapped = Message::from_digest_slice(&message_hash).expect("Message is 32 bytes; qed"); + self.sign_prehashed(&sp_crypto_hashing::blake2_256(message)) + } + + /// Signs a pre-hashed message. + pub fn sign_prehashed(&self, message_hash: &[u8; 32]) -> Signature { + let wrapped = Message::from_digest_slice(message_hash).expect("Message is 32 bytes; qed"); Signature(internal::sign(&self.0.secret_key(), &wrapped)) } } diff --git a/signer/src/eth.rs b/signer/src/eth.rs index 63d23bf384..2096c8a192 100644 --- a/signer/src/eth.rs +++ b/signer/src/eth.rs @@ -106,10 +106,12 @@ impl Keypair { /// Signs an arbitrary message payload. pub fn sign(&self, signer_payload: &[u8]) -> Signature { - let message_hash = keccak(signer_payload); - let wrapped = - Message::from_digest_slice(message_hash.as_bytes()).expect("Message is 32 bytes; qed"); - Signature(ecdsa::internal::sign(&self.0 .0.secret_key(), &wrapped)) + self.sign_prehashed(&keccak(signer_payload).0) + } + + /// Signs a pre-hashed message. + pub fn sign_prehashed(&self, message_hash: &[u8; 32]) -> Signature { + Signature(self.0.sign_prehashed(message_hash).0) } }