kohaku-userop-kit 0.0.1

EIP-4337 client
use alloy::{
    primitives::{Address, Bytes, U256},
    rpc::types::Authorization,
};
use alloy_sol_types::Eip712Domain;

pub mod simple_7702_smart_account;
pub mod simple_smart_account;

#[cfg_attr(native, async_trait::async_trait)]
#[cfg_attr(wasm, async_trait::async_trait(?Send))]
pub trait SmartAccount {
    type Call;

    /// Get the address of this smart account.
    fn address(&self) -> Address;

    /// 4337 EntryPoint address for this smart account.
    fn entry_point(&self) -> Address;

    /// EIP-712 domain for this smart account, which is used for signing UserOperations.
    fn domain(&self) -> Eip712Domain;

    /// 4337 nonce for this smart account.
    async fn nonce(&self) -> Result<U256, SmartAccountError>;

    /// EIP-7702 authorization for this smart account.
    async fn authorization(&self) -> Result<Authorization, SmartAccountError>;

    /// Returns a dummy signature that can be used for gas estimation.
    fn dummy_signature(&self) -> Bytes;

    /// Encodes the provided call data into the format expected by this smart account's EntryPoint.
    fn abi_encode_call(call_data: &Self::Call) -> Bytes;
}

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SmartAccountError {
    #[error("Provider error: {0}")]
    ProviderError(#[from] alloy::transports::RpcError<alloy::transports::TransportErrorKind>),
    #[error(transparent)]
    Other(#[from] anyhow::Error),
}