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 1 commit
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
6 changes: 5 additions & 1 deletion signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ 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);
self.sign_prehashed(&sp_crypto_hashing::blake2_256(message));
}

/// Signs a pre-hashed message.
pub fn sign_prehashed(&self, message_hash: &H256) -> 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: 7 additions & 3 deletions signer/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ impl Keypair {

/// Signs a pre-hashed message.
pub fn sign_prehashed(&self, message_hash: &H256) -> Signature {
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.0.sign_prehashed(message_hash).into()
}
}

Expand Down Expand Up @@ -171,6 +169,12 @@ impl AsRef<[u8; 65]> for Signature {
}
}

impl From<ecdsa::Signature> for Signature {
fn from(s: ecdsa::Signature) -> Self {
Self(s.0)
}
}
muraca marked this conversation as resolved.
Show resolved Hide resolved

/// A 20-byte cryptographic identifier.
#[derive(Debug, Copy, Clone, PartialEq, Eq, codec::Encode)]
pub struct AccountId20(pub [u8; 20]);
Expand Down
Loading