use crate::config::SupportedChainId;
use crate::types::{Address, Amount};
use super::transaction::{TransactionBroadcast, TransactionRequest};
use super::typed_data::TypedDataPayload;
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait TypedDataSigner {
type Error;
async fn sign_typed_data_payload(
&self,
payload: &TypedDataPayload,
) -> Result<String, Self::Error>;
}
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait DigestSigner {
type Error;
async fn sign_digest(&self, digest: &[u8]) -> Result<String, Self::Error>;
}
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait Signer {
type Error;
#[must_use]
fn chain_id(&self) -> Option<SupportedChainId> {
None
}
async fn address(&self) -> Result<Address, Self::Error>;
async fn sign_message(&self, message: &[u8]) -> Result<String, Self::Error>;
async fn sign_typed_data_payload(
&self,
payload: &TypedDataPayload,
) -> Result<String, Self::Error>;
async fn send_transaction(
&self,
tx: &TransactionRequest,
) -> Result<TransactionBroadcast, Self::Error>;
async fn estimate_gas(&self, tx: &TransactionRequest) -> Result<Amount, Self::Error>;
}
impl<T> TypedDataSigner for T
where
T: Signer,
{
type Error = T::Error;
async fn sign_typed_data_payload(
&self,
payload: &TypedDataPayload,
) -> Result<String, Self::Error> {
Signer::sign_typed_data_payload(self, payload).await
}
}
impl<T> DigestSigner for T
where
T: Signer,
{
type Error = T::Error;
async fn sign_digest(&self, digest: &[u8]) -> Result<String, Self::Error> {
Signer::sign_message(self, digest).await
}
}
pub trait UserRejection {
#[must_use]
fn user_rejection_code(&self) -> Option<i32> {
None
}
}
impl UserRejection for String {}
impl UserRejection for &str {}
impl UserRejection for core::convert::Infallible {}