The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(web3): delegate x402 types to the vendored tinywallet crate
Steven Enamakel05f764d75845
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.tomlindex d43dfb864e..b8eee4a56b 100644--- a/crates/openhuman-core/Cargo.toml+++ b/crates/openhuman-core/Cargo.toml@@ -610,6 +610,11 @@ tinyhosts = { path = "../../vendor/tinyhosts", default-features = false, feature# shipped binary, so that does not undo the shed.tinywallet-bus = { path = "../../vendor/tinywallet/crates/tinywallet-bus", default-features = false, features = ["btc", "evm", "solana", "tron", "keccak", "net", "wire", "eip712", "abi", "tx-codec"], optional = true }+# The x402 wire types (`tinywallet::x402`) only: the root crate's `x402` gate is+# serde + the already-linked `eip712` contract gate, so this does not bring back+# the key/tx/bitcoin stack that the note above keeps out of the binary.+tinywallet = { path = "../../vendor/tinywallet", default-features = false, features = ["x402"], optional = true }+# secp256k1 signing over the digests the wallet module hands back. Pure Rust,# and already in the graph beneath `coins-bip32` (which derives the key being# used, via tinywallet's `key` gate), so naming it directly costs nothing and@@ -919,6 +924,7 @@ voice = [# to derive a Solana ATA, which is address arithmetic rather than signing.web3 = ["dep:tinywallet-bus",+ "dep:tinywallet","dep:curve25519-dalek","modules",]diff --git a/crates/openhuman-core/src/web3/x402/types.rs b/crates/openhuman-core/src/web3/x402/types.rsindex 0ee688d766..58da55771c 100644--- a/crates/openhuman-core/src/web3/x402/types.rs+++ b/crates/openhuman-core/src/web3/x402/types.rs@@ -1,237 +1,6 @@//! Wire types for the x402 protocol (v2).//!-//! All header payloads are standard-base64-encoded JSON. Network identifiers-//! use CAIP-2 format (e.g. `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`).+//! Owned by the vendored `tinywallet` crate; re-exported here so the x402+//! host code keeps its `types::` paths.-use serde::{Deserialize, Serialize};--// ----------------------------------------------------------------------------// Constants-// -----------------------------------------------------------------------------pub const X402_VERSION: u8 = 2;--pub const HEADER_PAYMENT_REQUIRED: &str = "PAYMENT-REQUIRED";-pub const HEADER_PAYMENT_REQUIRED_V1: &str = "X-PAYMENT-REQUIRED";-pub const HEADER_PAYMENT_SIGNATURE: &str = "PAYMENT-SIGNATURE";-pub const HEADER_PAYMENT_SIGNATURE_V1: &str = "X-PAYMENT";-pub const HEADER_PAYMENT_RESPONSE: &str = "PAYMENT-RESPONSE";--pub const SOLANA_MAINNET_CAIP2: &str = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";-pub const SOLANA_DEVNET_CAIP2: &str = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";--pub const USDC_MINT_MAINNET: &str = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";-pub const USDC_MINT_DEVNET: &str = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";--pub const SPL_TOKEN_PROGRAM: &str = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";-pub const SPL_MEMO_PROGRAM: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";-pub const COMPUTE_BUDGET_PROGRAM: &str = "ComputeBudget111111111111111111111111111111";--// EVM / Base chain constants (CAIP-2 format: eip155:<chain_id>)-pub const BASE_MAINNET_CAIP2: &str = "eip155:8453";-pub const BASE_SEPOLIA_CAIP2: &str = "eip155:84532";-pub const ETHEREUM_MAINNET_CAIP2: &str = "eip155:1";--pub const USDC_BASE_MAINNET: &str = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";-pub const USDC_BASE_SEPOLIA: &str = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";-pub const USDC_ETHEREUM_MAINNET: &str = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";--// ----------------------------------------------------------------------------// 402 challenge — server → client (PAYMENT-REQUIRED header)-// -----------------------------------------------------------------------------#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct PaymentRequired {- pub x402_version: u8,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub error: Option<String>,- pub resource: ResourceInfo,- pub accepts: Vec<PaymentRequirements>,- #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")]- pub extensions: serde_json::Map<String, serde_json::Value>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct ResourceInfo {- pub url: String,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub description: Option<String>,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub mime_type: Option<String>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct PaymentRequirements {- pub scheme: String,- pub network: String,- /// Amount in atomic token units (e.g. 1 USDC = 1_000_000).- pub amount: String,- /// Token mint address (Solana) or contract address (EVM).- pub asset: String,- /// Recipient wallet address.- pub pay_to: String,- pub max_timeout_seconds: u64,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub extra: Option<PaymentExtra>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct PaymentExtra {- /// Facilitator pubkey that will co-sign as fee payer (Solana).- #[serde(default, skip_serializing_if = "Option::is_none")]- pub fee_payer: Option<String>,- /// Required memo value for transaction uniqueness (Solana).- #[serde(default, skip_serializing_if = "Option::is_none")]- pub memo: Option<String>,- /// EIP-712 domain name for the token contract (EVM, e.g. "USD Coin").- #[serde(default, skip_serializing_if = "Option::is_none")]- pub name: Option<String>,- /// EIP-712 domain version for the token contract (EVM, e.g. "2").- #[serde(default, skip_serializing_if = "Option::is_none")]- pub version: Option<String>,-}--// ----------------------------------------------------------------------------// Payment proof — client → server (PAYMENT-SIGNATURE header)-// -----------------------------------------------------------------------------#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct PaymentPayload {- pub x402_version: u8,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub resource: Option<ResourceInfo>,- pub accepted: PaymentRequirements,- pub payload: PaymentProof,- #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")]- pub extensions: serde_json::Map<String, serde_json::Value>,-}--/// Chain-specific payment proof. Serializes flat (untagged) so the facilitator-/// sees either `{ "transaction": "..." }` (Solana) or-/// `{ "signature": "0x...", "authorization": {...} }` (EVM).-#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(untagged)]-pub enum PaymentProof {- Solana(SolanaPaymentProof),- Evm(EvmPaymentProof),-}--/// Solana `exact` scheme payload — a partially-signed `VersionedTransaction`-/// serialized as standard base64. The facilitator adds its fee-payer signature-/// and broadcasts.-#[derive(Debug, Clone, Serialize, Deserialize)]-pub struct SolanaPaymentProof {- pub transaction: String,-}--/// EVM `exact` scheme payload — a signed EIP-3009 `transferWithAuthorization`-/// or plain ERC-20 transfer authorization for the facilitator to submit.-#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct EvmPaymentProof {- pub signature: String,- pub authorization: EvmAuthorization,-}--/// EIP-3009 `transferWithAuthorization` parameters signed by the token holder.-#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct EvmAuthorization {- pub from: String,- pub to: String,- pub value: String,- pub valid_after: String,- pub valid_before: String,- pub nonce: String,-}--// ----------------------------------------------------------------------------// Settlement response — server → client (PAYMENT-RESPONSE header)-// -----------------------------------------------------------------------------#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct SettlementResponse {- pub success: bool,- /// Base58 transaction signature (Solana) or hex tx hash (EVM).- pub transaction: String,- pub network: String,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub payer: Option<String>,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub error_reason: Option<String>,- #[serde(default, skip_serializing_if = "Option::is_none")]- pub amount: Option<String>,- #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")]- pub extensions: serde_json::Map<String, serde_json::Value>,-}--// ----------------------------------------------------------------------------// Internal helpers-// -----------------------------------------------------------------------------impl PaymentRequired {- /// Find the first `accepts` entry whose network starts with `"solana:"` and- /// whose scheme is `"exact"`.- pub fn solana_exact_requirement(&self) -> Option<&PaymentRequirements> {- self.accepts- .iter()- .find(|r| r.scheme == "exact" && r.network.starts_with("solana:"))- }-- /// Find the first `accepts` entry whose network starts with `"eip155:"` and- /// whose scheme is `"exact"`.- pub fn evm_exact_requirement(&self) -> Option<&PaymentRequirements> {- self.accepts- .iter()- .find(|r| r.scheme == "exact" && r.network.starts_with("eip155:"))- }-- /// Find the best payment option — prefer EVM (Base), fall back to Solana.- pub fn best_exact_requirement(&self) -> Option<(&PaymentRequirements, PaymentChain)> {- if let Some(sol) = self.solana_exact_requirement() {- Some((sol, PaymentChain::Solana))- } else if let Some(evm) = self.evm_exact_requirement() {- Some((evm, PaymentChain::Evm))- } else {- None- }- }-}--/// Which chain family a payment requirement targets.-#[derive(Debug, Clone, Copy, PartialEq, Eq)]-pub enum PaymentChain {- Solana,- Evm,-}--impl PaymentRequirements {- pub fn is_solana_mainnet(&self) -> bool {- self.network == SOLANA_MAINNET_CAIP2- }-- pub fn is_base_mainnet(&self) -> bool {- self.network == BASE_MAINNET_CAIP2- }-- /// Parse the EVM chain ID from an `eip155:<chain_id>` network string.- pub fn evm_chain_id(&self) -> Option<u64> {- self.network- .strip_prefix("eip155:")- .and_then(|s| s.parse().ok())- }-- pub fn fee_payer_pubkey(&self) -> Option<&str> {- self.extra.as_ref()?.fee_payer.as_deref()- }-- pub fn memo_value(&self) -> Option<&str> {- self.extra.as_ref()?.memo.as_deref()- }-}+pub use tinywallet::x402::*;