zenith_types/
lib.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![doc = include_str!("../README.md")]
#![warn(
    missing_copy_implementations,
    missing_debug_implementations,
    missing_docs,
    unreachable_pub,
    clippy::missing_const_for_fn,
    rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod bindings;
pub use bindings::{
    mintCall, HostOrders, Passage, RollupOrders, RollupPassage, Transactor, Zenith,
};

mod block;
pub use block::{decode_txns, encode_txns, Alloy2718Coder, Coder, ZenithBlock, ZenithTransaction};

mod orders;
pub use orders::{AggregateOrders, SignedOrder};

mod req;
pub use req::SignRequest;

mod resp;
pub use resp::SignResponse;

use alloy_primitives::{address, Address};

/// System address with permission to mint tokens on pre-deploys.
pub const MINTER_ADDRESS: Address = address!("00000000000000000000746f6b656e61646d696e");

/// A [`RequestSigner`] signs [`SignRequest`]s by delegating to an
/// [`alloy::signers::Signer`].
pub trait RequestSigner {
    /// Signs a [`SignRequest`] and returns the [`alloy_primitives::Signature`].
    fn sign_request(
        &self,
        request: &SignRequest,
    ) -> impl std::future::Future<Output = Result<alloy_primitives::Signature, alloy::signers::Error>>
           + Send;
}

impl<T> RequestSigner for T
where
    T: alloy::signers::Signer + Send + Sync,
{
    async fn sign_request(
        &self,
        request: &SignRequest,
    ) -> Result<alloy_primitives::Signature, alloy::signers::Error> {
        let hash = request.signing_hash();
        self.sign_hash(&hash).await
    }
}