Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented sign_prehashed for ecdsa::Keypair and eth::Keypair #1598

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
10 changes: 6 additions & 4 deletions signer/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading