thruput-signing 0.43.0

Off-chain transaction signing and construction for Thruput
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
//! Canonical transaction hashing.

use crate::SigningError;
use sha2::{Digest, Sha256};
use thruput_xdr::transaction::Transaction;
use thruput_xdr::types::SHA256Hash;

/// Hashes the canonical XDR encoding of the inner transaction body.
pub fn transaction_hash(tx: &Transaction) -> Result<SHA256Hash, SigningError> {
    let tx_bytes = xdrs::txs::encode(tx).map_err(|e| SigningError::XdrEncode(e.to_string()))?;
    let digest: [u8; 32] = Sha256::digest(&tx_bytes).into();
    Ok(SHA256Hash::from(digest))
}