Skip to content

Commit

Permalink
cosmrs: error handling cleanup (#435)
Browse files Browse the repository at this point in the history
Followup from #434 which enables `ecdsa/std` and uses eyre's built-in
`Error`-trait based error propagation.
  • Loading branch information
tony-iqlusion authored Oct 3, 2023
1 parent 817aa47 commit 395d625
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cosmrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ k256 = { version = "0.13", default-features = false, features = ["ecdsa", "sha25
rand_core = { version = "0.6", default-features = false }
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1"
signature = { version = "2", features = ["std"] }
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
tendermint = { version = "0.34", features = ["secp256k1"] }
thiserror = "1"
Expand Down
8 changes: 2 additions & 6 deletions cosmrs/src/crypto/secp256k1/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
ErrorReport, Result,
};
use ecdsa::signature::{Keypair, Signer};
use eyre::eyre;
use k256::ecdsa::VerifyingKey;

#[cfg(feature = "getrandom")]
Expand Down Expand Up @@ -38,8 +37,7 @@ impl SigningKey {

/// Initialize from a raw scalar value (big endian).
pub fn from_slice(bytes: &[u8]) -> Result<Self> {
let signing_key =
k256::ecdsa::SigningKey::from_slice(bytes).map_err(|_| eyre!("invalid signing key"))?;
let signing_key = k256::ecdsa::SigningKey::from_slice(bytes)?;
Ok(Self::new(Box::new(signing_key)))
}

Expand All @@ -63,9 +61,7 @@ impl SigningKey {

/// Sign the given message, returning a signature.
pub fn sign(&self, msg: &[u8]) -> Result<Signature> {
self.inner
.try_sign(msg)
.map_err(|_| eyre!("signing failure"))
Ok(self.inner.try_sign(msg)?)
}

/// Get the [`PublicKey`] for this [`SigningKey`].
Expand Down

0 comments on commit 395d625

Please sign in to comment.