aztec_wallet/account_provider.rs
1//! Account provider abstraction for wallet implementations.
2//!
3//! The [`AccountProvider`] trait decouples wallet implementations from specific
4//! account types. It provides a bridge between the account abstraction layer
5//! (which knows about secret keys, entrypoints, and signing) and the wallet
6//! layer (which coordinates PXE and node interactions).
7
8use async_trait::async_trait;
9
10use crate::error::Error;
11use crate::fee::GasSettings;
12use crate::pxe::TxExecutionRequest;
13use crate::tx::{AuthWitness, ExecutionPayload};
14use crate::types::{AztecAddress, CompleteAddress};
15use crate::wallet::{Aliased, ChainInfo, MessageHashOrIntent};
16
17/// Provides account operations needed by [`BaseWallet`](crate::BaseWallet).
18///
19/// This is the Rust equivalent of the abstract `getAccountFromAddress()`
20/// in the TS BaseWallet. Different wallet backends (embedded, CLI, extension)
21/// implement this to provide their own account lookup and transaction creation
22/// strategy.
23///
24/// The trait returns PXE-level [`TxExecutionRequest`] (opaque JSON) directly,
25/// handling the conversion from the account's structured request internally.
26/// This avoids a circular dependency between the wallet and account crates.
27#[async_trait]
28pub trait AccountProvider: Send + Sync {
29 /// Create a transaction execution request for the given account.
30 ///
31 /// This processes the execution payload through the account's entrypoint,
32 /// adding authentication and gas handling, then serializes the result
33 /// into the PXE's opaque request format.
34 async fn create_tx_execution_request(
35 &self,
36 from: &AztecAddress,
37 exec: ExecutionPayload,
38 gas_settings: GasSettings,
39 chain_info: &ChainInfo,
40 fee_payer: Option<AztecAddress>,
41 fee_payment_method: Option<u8>,
42 ) -> Result<TxExecutionRequest, Error>;
43
44 /// Create an authorization witness for the given account.
45 async fn create_auth_wit(
46 &self,
47 from: &AztecAddress,
48 intent: MessageHashOrIntent,
49 chain_info: &ChainInfo,
50 ) -> Result<AuthWitness, Error>;
51
52 /// Get the complete address for a managed account, if available.
53 async fn get_complete_address(
54 &self,
55 address: &AztecAddress,
56 ) -> Result<Option<CompleteAddress>, Error>;
57
58 /// Get all account addresses managed by this provider.
59 async fn get_accounts(&self) -> Result<Vec<Aliased<AztecAddress>>, Error>;
60}