alloy_signer/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4    html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![cfg_attr(not(test), warn(unused_crate_dependencies))]
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8
9mod error;
10pub use error::{Error, Result, UnsupportedSignerOperation};
11
12mod signer;
13pub use signer::{Either, Signer, SignerSync};
14
15pub mod utils;
16
17pub use alloy_primitives::Signature;
18pub use k256;
19
20/// Utility to get and set the chain ID on a transaction and the resulting signature within a
21/// signer's `sign_transaction`.
22#[macro_export]
23macro_rules! sign_transaction_with_chain_id {
24    // async (
25    //    signer: impl Signer,
26    //    tx: &mut impl SignableTransaction<Signature>,
27    //    sign: lazy Signature,
28    // )
29    ($signer:expr, $tx:expr, $sign:expr) => {{
30        if let Some(chain_id) = $signer.chain_id() {
31            if !$tx.set_chain_id_checked(chain_id) {
32                return Err(alloy_signer::Error::TransactionChainIdMismatch {
33                    signer: chain_id,
34                    // we can only end up here if the tx has a chain id
35                    tx: $tx.chain_id().unwrap(),
36                });
37            }
38        }
39
40        $sign.map_err(alloy_signer::Error::other)
41    }};
42}