diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2024-06-28 13:38:09 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2024-06-28 13:38:13 +0200 |
| commit | bdb47ee691f0302c05daaf0278b606fbaf319f61 (patch) | |
| tree | 3c414c0adbcfa8a76255502e9d5d38bdbb31d5d0 /src/message.rs | |
| parent | 0f523a185ff67848e890156c04b95f765969051d (diff) | |
Update dependency version
Additionally, we start using `ethdigest` instead of the `sha3` crate for
doing Keccak-256 hashing and representing digest types in code.
Diffstat (limited to 'src/message.rs')
| -rw-r--r-- | src/message.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/message.rs b/src/message.rs index 1c0d594..449a16e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,6 +1,6 @@ //! Ethereum message for signing. -use crate::hash; +use ethdigest::Digest; use std::io::Write as _; /// A message to be signed with an Ethereum specific prefix. @@ -11,13 +11,13 @@ where T: AsRef<[u8]>, { /// Computes the 32-byte message used for ECDSA signing with a private key. - pub fn signing_message(&self) -> [u8; 32] { + pub fn signing_message(&self) -> Digest { digest(self.0.as_ref()) } } /// Computes the Ethereum-specific digest for a message. -fn digest(data: &[u8]) -> [u8; 32] { +fn digest(data: &[u8]) -> Digest { let mut buffer = Vec::with_capacity(46 + data.len()); buffer.extend_from_slice(b"\x19Ethereum Signed Message:\n"); // Display implementation for `usize` should not error when writing to an @@ -27,7 +27,7 @@ fn digest(data: &[u8]) -> [u8; 32] { write!(buffer, "{}", data.len()).expect("unexpected error writing number"); buffer.extend_from_slice(data); - hash::keccak256(buffer) + Digest::of(buffer) } #[cfg(test)] @@ -38,7 +38,7 @@ mod tests { fn computes_digest() { assert_eq!( digest(b"hello world!"), - hash::keccak256(b"\x19Ethereum Signed Message:\n12hello world!"), + Digest::of(b"\x19Ethereum Signed Message:\n12hello world!"), ); } } |
