Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(web3): delegate x402 payments to the module

Steven Enamakel0bee6b31decb
diff --git a/crates/openhuman-core/src/core/runtime/bootstrap.rs b/crates/openhuman-core/src/core/runtime/bootstrap.rs
index 53c6166c8e..f431f37948 100644
--- a/crates/openhuman-core/src/core/runtime/bootstrap.rs
+++ b/crates/openhuman-core/src/core/runtime/bootstrap.rs
@@ -166,19 +166,6 @@ pub(crate) async fn bootstrap_core_runtime(
// share one JSONL-backed store. Idempotent.
crate::platform::cost::init_global(cfg.cost.clone(), &workspace_dir);
- // --- x402 payment ledger ---
- // Initializes the JSONL-backed spending ledger for machine-payable API
- // payments (x402 protocol). Budget defaults can be overridden via
- // the `openhuman.x402_update_budget` RPC. Gated on the Web3 domain (#4808
- // review): under `harness()`/`none()` the x402 controllers are absent, so
- // their ledger must not initialize either.
- if domains.allows(crate::core::all::DomainGroup::Web3) {
- let x402_session = format!("x402-{}", uuid::Uuid::new_v4());
- crate::web3::x402::init_ledger(&workspace_dir, &x402_session);
- } else {
- log::debug!("[boot] x402 payment ledger SKIPPED — Web3 domain disabled");
- }
-
// --- Sub-agent definition registry bootstrap ---
// Loads built-in archetype definitions plus any custom TOML files
// under `<workspace>/agents/*.toml`. Idempotent — safe to call
diff --git a/crates/openhuman-core/src/web3/mod.rs b/crates/openhuman-core/src/web3/mod.rs
index 3f0a4c1bb5..c0146b050b 100644
--- a/crates/openhuman-core/src/web3/mod.rs
+++ b/crates/openhuman-core/src/web3/mod.rs
@@ -32,14 +32,7 @@ pub mod dapp;
#[cfg(feature = "web3")]
mod module_tools;
#[cfg(feature = "web3")]
-pub mod seams;
-#[cfg(feature = "web3")]
pub mod swap;
-/// The swap/bridge/dapp request and quote types, re-exported from
-/// `tinywallet-web3` under their historical path.
-#[cfg(feature = "web3")]
-pub use tinywallet_web3::crypto::service as types;
-
// Ungated family members: `wallet` and `x402` are facades in their own right —
// each keeps its own `stub.rs` and gates its real submodules on the same
// default-ON `web3` feature. Always-compiled callers resolve through those
diff --git a/crates/openhuman-core/src/web3/x402/mod.rs b/crates/openhuman-core/src/web3/x402/mod.rs
index 457bcc45d8..cdd74d6f39 100644
--- a/crates/openhuman-core/src/web3/x402/mod.rs
+++ b/crates/openhuman-core/src/web3/x402/mod.rs
@@ -1,102 +1,23 @@
-//! x402 — HTTP 402 payment protocol for machine-payable APIs.
+//! Host RPC facade for module-owned x402 payments.
//!
-//! The protocol lives in the `tinywallet-x402` crate (`vendor/tinywallet`): the
-//! 402 client, the EVM EIP-3009 and Solana SPL payment builders, the spending
-//! ledger and the `x402_request` agent tool. This module is the host side of
-//! it — what OpenHuman adds and nothing more:
-//!
-//! - [`seams`] — the wallet ([`seams::WalletPaymentSigner`]: keyring secret,
-//! decrypt, the wallet module) and outbound-proxy policy
-//! ([`seams::RuntimeProxyPolicy`]) the crate is handed. The mnemonic never
-//! enters the crate.
-//! - `schemas` — the `x402_*` RPC controllers (namespace strings are wire
-//! contracts).
-//! - [`budget`] — where the spending limits come from (defaults plus the
-//! `OPENHUMAN_X402_*` environment overrides).
-//! - this file — a facade re-exporting the crate so existing callers
-//! (`http_request`, boot, the tool registry) keep their paths.
-//!
-//! Protocol spec: <https://x402.org> / coinbase/x402 (v2).
-//!
-//! ## Compile-time gate (`web3` feature)
-//!
-//! `pub mod x402;` is ALWAYS compiled — it is a facade. The real payment
-//! machinery is gated behind the optional `web3` Cargo feature (shared with
-//! `openhuman::web3::wallet` + `openhuman::web3` and enabled in the desktop product). When the feature is off, [`stub`]
-//! takes its place and exposes the always-on entry points (`init_ledger`,
-//! `all_x402_registered_controllers`, `all_x402_controller_schemas`) with
-//! no-op / empty bodies. The `X402RequestTool` and the http_request 402-retry
-//! path are `#[cfg(feature = "web3")]` at their call sites, so the rest of the
-//! payment surface (`PaymentRecord`, `store`, `SettlementResponse`, …) is not
-//! referenced when off and need not be stubbed.
+//! TinyWallet owns challenge parsing, chain selection, payment construction,
+//! signing, budget reservation, ledger records, and settlement parsing. The
+//! host retains generic HTTP execution, explicit user approval, and secret
+//! custody; payment material crosses only the confidential module call.
-#[cfg(feature = "web3")]
-pub(crate) mod budget;
-#[cfg(feature = "web3")]
-mod proxy_compat;
-#[cfg(feature = "web3")]
-mod records;
#[cfg(feature = "web3")]
mod schemas;
-#[cfg(feature = "web3")]
-pub(crate) mod seams;
-#[cfg(feature = "web3")]
-pub use records::pending_record;
#[cfg(feature = "web3")]
pub use schemas::all_controller_schemas as all_x402_controller_schemas;
#[cfg(feature = "web3")]
pub use schemas::all_registered_controllers as all_x402_registered_controllers;
#[cfg(feature = "web3")]
-pub use tinywallet_x402::ledger::{PaymentRecord, PaymentStatus, SpendingBudget};
-#[cfg(feature = "web3")]
-pub use tinywallet_x402::protocol::{handle_402, X402Client, X402Error, X402PaymentResult};
-#[cfg(feature = "web3")]
-pub use tinywallet_x402::wire::{
- EvmAuthorization, EvmPaymentProof, PaymentChain, PaymentPayload, PaymentProof, PaymentRequired,
- PaymentRequirements, ResourceInfo, SettlementResponse, SolanaPaymentProof,
-};
-
-/// The process-wide spending ledger, as the crate exposes it.
-#[cfg(feature = "web3")]
-pub(crate) mod store {
- pub use tinywallet_x402::ledger::{with_ledger, with_ledger_mut};
-}
-
-/// Open the spending ledger under `workspace_dir` for this process.
-///
-/// The limits are [`budget::budget_from_env`]: the crate's defaults with any
-/// `OPENHUMAN_X402_*` override applied.
-#[cfg(feature = "web3")]
-pub fn init_ledger(workspace_dir: &std::path::Path, session_id: &str) {
- tinywallet_x402::ledger::init_global(workspace_dir, session_id, budget::budget_from_env());
-}
-
-/// End-to-end 402 handler for the HTTP tool layer: parse the challenge, check
-/// the budget, and have the wallet build and sign the payment.
-#[cfg(feature = "web3")]
-pub async fn handle_402_and_pay(
- response_headers: &reqwest::header::HeaderMap,
- request_url: &str,
-) -> Result<X402PaymentResult, X402Error> {
- tinywallet_x402::protocol::handle_402_and_pay(&seams::payments(), response_headers, request_url)
- .await
-}
-
-/// The `x402_request` agent tool, wired to OpenHuman's wallet, chain
-/// transport, proxy and network policy. `allowed_domains` is the same list
-/// passed to the other agent network tools.
-#[cfg(feature = "web3")]
-pub fn request_tool(
- security: std::sync::Arc<crate::security::SecurityPolicy>,
- allowed_domains: Vec<String>,
-) -> tinywallet_x402::tools::X402RequestTool {
- seams::request_tool(security, allowed_domains)
-}
+pub use tinywallet_bus::wire::{X402PaymentRecord as PaymentRecord, X402PaymentStatus as PaymentStatus};
-// ---------------------------------------------------------------------------
-// Disabled facade — compiled only when the `web3` feature is OFF.
-// ---------------------------------------------------------------------------
+/// Kept as a compatibility no-op. The module-owned ledger opens lazily when
+/// the first x402 service operation is requested, scoped to the active workspace.
+pub fn init_ledger(_workspace_dir: &std::path::Path, _session_id: &str) {}
#[cfg(not(feature = "web3"))]
mod stub;
diff --git a/crates/openhuman-core/src/web3/x402/stub.rs b/crates/openhuman-core/src/web3/x402/stub.rs
index e4971b6254..065538e8f2 100644
--- a/crates/openhuman-core/src/web3/x402/stub.rs
+++ b/crates/openhuman-core/src/web3/x402/stub.rs
@@ -12,18 +12,9 @@
//! (`cargo check --no-default-features`) is
//! the only thing that catches drift.
-use std::path::Path;
-
use crate::core::all::RegisteredController;
use crate::core::ControllerSchema;
-/// No-op: there is no spending ledger to initialise when x402 is compiled out.
-/// Mirrors `store::init_global` (re-exported as `init_ledger`). The boot call
-/// site is additionally runtime-gated on `DomainGroup::Web3`.
-pub fn init_ledger(_workspace_dir: &Path, _session_id: &str) {
- log::debug!("[x402-stub] init_ledger ignored (web3 disabled)");
-}
-
/// No x402 controller schemas when the domain is compiled out.
pub fn all_x402_controller_schemas() -> Vec<ControllerSchema> {
Vec::new()