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
10pub use near_sdk::CryptoHash;
11
12/// Data that can be deterministically hashed for signing or verification.
13///
14/// Implementations of this trait typically represent a message formatted
15/// according to an external signing standard. The [`hash`] method returns
16/// the digest that should be signed or used for verification.
17pub trait Payload {
18 fn hash(&self) -> CryptoHash;
19}
20
21/// Extension of [`Payload`] for types that include a signature.
22///
23/// Implementers verify the signature and, when successful, return the
24/// signer's public key. This trait is mainly intended for internal use and
25/// does not constitute a stable public API.
26pub trait SignedPayload: Payload {
27 type PublicKey;
28
29 fn verify(&self) -> Option<Self::PublicKey>;
30}