defuse_crypto/payload.rs
1//! Traits for hashing and verifying message payloads used within Intents.
2//!
3//! These traits provide a small abstraction layer over various signing
4//! standards supported by Intents. Each standard (e.g. BIP-322, TIP-191,
5//! ERC-191) defines its own structure that implements [`Payload`] and
6//! [`SignedPayload`]. The implementations expose a uniform API so the
7//! Intents engine can compute message hashes and verify signatures without
8//! knowing the concrete standard.
9
10/// 32-byte cryptographic hash output.
11pub type CryptoHash = [u8; 32];
12
13/// Data that can be deterministically hashed for signing or verification.
14///
15/// Implementations of this trait typically represent a message formatted
16/// according to an external signing standard. The [`hash`] method returns
17/// the digest that should be signed or used for verification.
18pub trait Payload {
19 fn hash(&self) -> CryptoHash;
20}
21
22/// Extension of [`Payload`] for types that include a signature.
23///
24/// Implementers verify the signature and, when successful, return the
25/// signer's public key. This trait is mainly intended for internal use and
26/// does not constitute a stable public API.
27pub trait SignedPayload: Payload {
28 type PublicKey;
29
30 fn verify(&self) -> Option<Self::PublicKey>;
31}