aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/sign.rs18
-rw-r--r--src/lib.rs1
-rw-r--r--src/typeddata.rs12
3 files changed, 13 insertions, 18 deletions
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index f0a7c89..81420c4 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -4,7 +4,7 @@ use crate::cmd::{self, AccountOptions};
use anyhow::{ensure, Context as _, Result};
use clap::Parser;
use hdwallet::{
- hash,
+ message::EthereumMessage,
transaction::{LegacyTransaction, Transaction},
typeddata::TypedData,
};
@@ -88,20 +88,12 @@ pub fn run(options: Options) -> Result<()> {
}
}
Input::Message { message } => {
- let bytes = cmd::read_input(&message)?;
- let message = hash::keccak256({
- let mut buffer = Vec::with_capacity(46 + bytes.len());
- buffer.extend_from_slice(b"\x19Ethereum Signed Message:\n");
- buffer.extend_from_slice(bytes.len().to_string().as_bytes());
- buffer.extend_from_slice(&bytes);
- buffer
- });
- println!("{}", account.sign(message));
+ let message = EthereumMessage(cmd::read_input(&message)?);
+ println!("{}", account.sign(message.signing_message()));
}
Input::TypedData { typed_data } => {
- let bytes = cmd::read_input(&typed_data)?;
- let typed_data = serde_json::from_slice::<TypedData>(&bytes)?;
- println!("{}", account.sign(typed_data.digest()));
+ let typed_data = serde_json::from_slice::<TypedData>(&cmd::read_input(&typed_data)?)?;
+ println!("{}", account.sign(typed_data.signing_message()));
}
Input::Raw { message } => {
println!("{}", account.sign(message));
diff --git a/src/lib.rs b/src/lib.rs
index 62474bd..ba715bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,6 +7,7 @@
pub mod account;
pub mod hash;
pub mod hdk;
+pub mod message;
pub mod mnemonic;
mod rand;
mod serialization;
diff --git a/src/typeddata.rs b/src/typeddata.rs
index 9bf6d5f..3e734dd 100644
--- a/src/typeddata.rs
+++ b/src/typeddata.rs
@@ -24,8 +24,10 @@ pub struct TypedData {
}
impl TypedData {
- /// Returns the EIP-712 digest of the typed data.
- pub fn digest(&self) -> [u8; 32] {
+ /// Returns the 32-byte message to be used for siging the typed data.
+ ///
+ /// This is the EIP-712 digest of the typed data.
+ pub fn signing_message(&self) -> [u8; 32] {
self.digest
}
}
@@ -418,7 +420,7 @@ mod tests {
)
.unwrap();
assert_eq!(
- typed_data.digest(),
+ typed_data.signing_message(),
hex!("be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2"),
);
}
@@ -477,7 +479,7 @@ mod tests {
)
.unwrap();
assert_eq!(
- typed_data.digest(),
+ typed_data.signing_message(),
hex!("abb8645e0bd6fcaceb11634c67729a125a7e3cfcc35ee7dec5b003cc83b14d49"),
);
}
@@ -541,7 +543,7 @@ mod tests {
)
.unwrap();
assert_eq!(
- typed_data.digest(),
+ typed_data.signing_message(),
hex!("a150d6fdc3fe189531a29808ccdd2808005c24274de09187af619f69377221a1"),
);
}