Skip to content

Commit

Permalink
Propagate error details in CryptoError::TxHashingError.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Apr 29, 2024
1 parent 69e1990 commit 0242e4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions kairos-crypto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum CryptoError {

/// Unable to compute transaction hash - invalid data given.
#[cfg(feature = "tx")]
#[error("unable to hash transaction data")]
TxHashingError,
#[error("unable to hash transaction data: {error}")]
TxHashingError { error: String },
/// Signing algorithm is not available in `kairos-tx`.
#[cfg(feature = "tx")]
#[error("algorithm not available in tx format")]
Expand Down
11 changes: 6 additions & 5 deletions kairos-crypto/src/implementations/casper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ impl CryptoSigner for Signer {

#[cfg(feature = "tx")]
fn verify_tx(&self, tx: kairos_tx::asn::Transaction) -> Result<(), CryptoError> {
let tx_hash = tx
.payload
.hash()
.map_err(|_e| CryptoError::TxHashingError)?;
let tx_hash = tx.payload.hash().map_err(|e| CryptoError::TxHashingError {
error: e.to_string(),
})?;
let signature: Vec<u8> = tx.signature.into();
self.verify(tx_hash, signature)?;

Expand All @@ -104,7 +103,9 @@ impl CryptoSigner for Signer {
payload: kairos_tx::asn::SigningPayload,
) -> Result<kairos_tx::asn::Transaction, CryptoError> {
// Compute payload signature.
let tx_hash = payload.hash().map_err(|_e| CryptoError::TxHashingError)?;
let tx_hash = payload.hash().map_err(|e| CryptoError::TxHashingError {
error: e.to_string(),
})?;
let signature = self.sign(tx_hash)?;

// Prepare public key.
Expand Down

0 comments on commit 0242e4c

Please sign in to comment.