penumbra_txhash/
auth_hash.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/// A hash of a transaction's _authorizing data_, describing both its effects on
/// the chain state as well as the cryptographic authorization of those effects.
///
/// In practice this is simply a hash of the `TransactionBody`.
///
/// The transaction's binding signature is formed over the transaction's
/// `AuthHash`.  Because the binding signature is formed using the randomness
/// for the balance commitments for each action, this prevents replaying proofs
/// from one transaction to another without knowledge of the openings of the
/// balance commitments, binding the proofs to the transaction they were
/// originally computed for.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct AuthHash(pub [u8; 32]);

impl std::fmt::Debug for AuthHash {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_tuple("AuthHash")
            .field(&hex::encode(self.0))
            .finish()
    }
}

impl AuthHash {
    pub fn as_bytes(&self) -> &[u8] {
        &self.0[..]
    }
}

pub trait AuthorizingData {
    fn auth_hash(&self) -> AuthHash;
}