aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account.rs10
-rw-r--r--src/account/prehashed.rs50
-rw-r--r--src/cmd.rs2
-rw-r--r--src/cmd/sign.rs2
-rw-r--r--src/transaction/accesslist.rs2
-rw-r--r--src/transaction/eip1559.rs2
-rw-r--r--src/transaction/eip2930.rs2
-rw-r--r--src/transaction/legacy.rs2
-rw-r--r--src/typeddata.rs2
9 files changed, 14 insertions, 60 deletions
diff --git a/src/account.rs b/src/account.rs
index 8fd3343..fb31a8a 100644
--- a/src/account.rs
+++ b/src/account.rs
@@ -1,6 +1,5 @@
//! Module implementing `secp256k1` private key.
-mod prehashed;
mod public;
mod signature;
@@ -9,7 +8,7 @@ use crate::hash;
use anyhow::Result;
use ethaddr::Address;
use k256::{
- ecdsa::{signature::DigestSigner as _, SigningKey},
+ ecdsa::{signature::hazmat::PrehashSigner as _, SigningKey},
SecretKey,
};
use std::fmt::{self, Debug, Formatter};
@@ -52,7 +51,12 @@ impl PrivateKey {
/// Generate a signature for the specified message.
pub fn sign(&self, message: [u8; 32]) -> Signature {
- Signature(SigningKey::from(&self.0).sign_digest(prehashed::message(message)))
+ self.try_sign(message).expect("signature operation failed")
+ }
+
+ /// Generate a signature for the specified message.
+ pub fn try_sign(&self, message: [u8; 32]) -> Result<Signature> {
+ Ok(Signature(SigningKey::from(&self.0).sign_prehash(&message)?))
}
}
diff --git a/src/account/prehashed.rs b/src/account/prehashed.rs
deleted file mode 100644
index 0cd4660..0000000
--- a/src/account/prehashed.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-//! The `k256` crate only supports signing messages by passing message bytes and
-//! specifying a hasher, or specifying an already partially updated hasher.
-//!
-//! This module provides a `Digest` implementation that can be used as an
-//! allowing `k256` signing to be done on a prehashed messsage.
-
-use k256::ecdsa::digest::{
- core_api::{
- Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, FixedOutputCore, UpdateCore,
- },
- HashMarker, Output, OutputSizeUser,
-};
-use sha3::Keccak256Core;
-
-/// Returns a prehashed message.
-pub fn message(message: [u8; 32]) -> Prehashed {
- CoreWrapper::from_core(Core(message))
-}
-
-/// A pre-hashed meessage digest shim.
-pub type Prehashed = CoreWrapper<Core>;
-
-#[derive(Clone, Default)]
-pub struct Core(pub [u8; 32]);
-
-impl BufferKindUser for Core {
- type BufferKind = <Keccak256Core as BufferKindUser>::BufferKind;
-}
-
-impl BlockSizeUser for Core {
- type BlockSize = <Keccak256Core as BlockSizeUser>::BlockSize;
-}
-
-impl FixedOutputCore for Core {
- fn finalize_fixed_core(&mut self, _: &mut Buffer<Self>, out: &mut Output<Self>) {
- *out = self.0.into()
- }
-}
-
-impl HashMarker for Core {}
-
-impl OutputSizeUser for Core {
- type OutputSize = <Keccak256Core as OutputSizeUser>::OutputSize;
-}
-
-impl UpdateCore for Core {
- fn update_blocks(&mut self, _: &[Block<Self>]) {
- unimplemented!()
- }
-}
diff --git a/src/cmd.rs b/src/cmd.rs
index 7dca231..e2e772c 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -36,7 +36,7 @@ struct AccountOptions {
/// Manually specified HD path for deriving the account key. This option can
/// not be used in conjunction with the "--account-index" option.
- #[clap(long, env, conflicts_with = "account-index")]
+ #[clap(long, env, conflicts_with = "account_index")]
hd_path: Option<String>,
}
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index 10b21e7..a8df0df 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -58,7 +58,7 @@ enum Input {
/// Sign a raw data.
Raw {
/// The 32 byte message to sign specified as a hexadecimal string.
- #[clap(name = "BYTES", parse(try_from_str = permissive_hex_digest))]
+ #[clap(name = "BYTES", value_parser = permissive_hex_digest)]
message: [u8; 32],
},
}
diff --git a/src/transaction/accesslist.rs b/src/transaction/accesslist.rs
index 0147350..91e8602 100644
--- a/src/transaction/accesslist.rs
+++ b/src/transaction/accesslist.rs
@@ -18,7 +18,7 @@ impl StorageSlot {
}
/// An EIP-2930 access list.
-#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
+#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
#[serde(transparent)]
pub struct AccessList(pub Vec<(Address, Vec<StorageSlot>)>);
diff --git a/src/transaction/eip1559.rs b/src/transaction/eip1559.rs
index f93b931..18680d5 100644
--- a/src/transaction/eip1559.rs
+++ b/src/transaction/eip1559.rs
@@ -8,7 +8,7 @@ use ethnum::U256;
use serde::Deserialize;
/// An EIP-1559 Ethereum transaction.
-#[derive(Clone, Debug, Deserialize, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
pub struct Eip1559Transaction {
/// The chain ID for the transaction.
#[serde(rename = "chainId", with = "ethnum::serde::permissive")]
diff --git a/src/transaction/eip2930.rs b/src/transaction/eip2930.rs
index 5cd0f02..ee342d0 100644
--- a/src/transaction/eip2930.rs
+++ b/src/transaction/eip2930.rs
@@ -8,7 +8,7 @@ use ethnum::U256;
use serde::Deserialize;
/// An EIP-2930 Ethereum transaction.
-#[derive(Clone, Debug, Deserialize, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
pub struct Eip2930Transaction {
/// The chain ID for the transaction.
#[serde(rename = "chainId", with = "ethnum::serde::permissive")]
diff --git a/src/transaction/legacy.rs b/src/transaction/legacy.rs
index 231d9f8..81798ce 100644
--- a/src/transaction/legacy.rs
+++ b/src/transaction/legacy.rs
@@ -6,7 +6,7 @@ use ethnum::U256;
use serde::Deserialize;
/// A Legacy Ethereum transaction.
-#[derive(Clone, Debug, Deserialize, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
pub struct LegacyTransaction {
/// The nonce for the transaction.
#[serde(with = "ethnum::serde::permissive")]
diff --git a/src/typeddata.rs b/src/typeddata.rs
index fe252a4..2a5021f 100644
--- a/src/typeddata.rs
+++ b/src/typeddata.rs
@@ -266,7 +266,7 @@ impl Types {
let mut buffer = vec![0_u8; 32 * value.len()];
for (i, element) in value.into_iter().enumerate() {
- buffer[(i * 32)..][..32].copy_from_slice(&self.encode_value(&*inner, element)?);
+ buffer[(i * 32)..][..32].copy_from_slice(&self.encode_value(inner, element)?);
}
hash::keccak256(&buffer)
}