Skip to content

[x402] Optional intent-layer audit before agent signs x402 payment #102

Open

Description

@SentVan23

Context
BofAI/x402 signs x402 payments from agent fetch (typescript/packages/http/fetch/src/index.ts — @x402/fetch / wrapFetchWithPayment or equivalent). An optional intent-layer audit before the agent signs the x402 payment (~200–300ms) can catch prompt-injected pay/retry loops without wrapping the payment scheme itself. Keep AUTO_POST off until a human confirms the insertion.

Matched code (typescript/packages/http/fetch/src/index.ts)

* @throws {Error} If a payment has already been attempted for this request
 * @throws {Error} If there's an error creating the payment header
 */
export function wrapFetchWithPayment(
  fetch: typeof

XAPS is a pre-execution audit tollbooth for agents: dual-LLM + rules, ~$0.01 per approved audit, returns a portable receipt. Not a walled garden — a guardrail on the open road.

Suggested integration

from xaps import XapsClient, XapsRejectedError

receipt = XapsClient(base_url="https://api.xaps.network").audit(
    action="execute_smart_contract",
    contract_address=TARGET_CONTRACT,
    amount=float(AMOUNT),
)
if receipt["audit"]["status"] != "APPROVED":
    raise XapsRejectedError(receipt["audit"].get("beta_attack", "REJECTED"), receipt=receipt)

Next steps

  1. Drop the snippet at the hot path (or add MCP io.github.APMC1/xaps).
  2. Register an agent wallet: POST https://api.xaps.network/agents/register ($1 trial).
  3. Agent card + MCP install: https://api.xaps.network/.well-known/xaps-agent-card.json
  4. Happy to open a PR with the exact insertion point if useful.

— XAPS team (distribution outreach; replies welcome)

Activity

  1. SentVan23 commented on Sep 17, 2026

    @SentVan23
    Author

    Follow-up — the original issue asked the payer to audit before wrapFetchWithPayment signs (typescript/packages/http/fetch/src/index.ts). That still stands.

    The missing half is the payee / facilitator step. No agent key. Independently clear the receipt and refuse unless it matches this 402:

    const cleared = await fetch("https://api.xaps.network/receipts/clear", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        receipt_id, // from header X-XAPS-Receipt
        require_use_case: "value_move",
        amount,     // this 402
        pay_to,     // this payTo
        resource,   // this resource URL
      }),
    }).then((r) => r.json());
    if (!cleared.clear) throw new Error("unaudited value_move");

    Payers attach X-XAPS-Receipt. Payees/facilitators clear. Mismatched amount / pay_to / resource fail closed.

    Public SDK (now on APMC1/xaps-sdk main): independent_clearance / require_value_clearance
    Agent card: https://api.xaps.network/.well-known/xaps-agent-card.json

    Happy to open a small PR at the wrapFetchWithPayment insertion if useful.

  2. roger-gan commented on Sep 18, 2026

    @roger-gan
    Contributor

    Thanks for the proposal.

    x402 already provides onBeforePaymentCreation for payer-side checks and onBeforeVerify / onBeforeSettle for resource server or facilitator checks, so intent auditing can be implemented without modifying wrapFetchWithPayment.

    We’ll review the suggested receipt flow and consider how it fits with the existing hook and extension model.

  3. devotedpronet-cyber commented on Sep 24, 2026

    @devotedpronet-cyber

    Related angle — GetAgentCap adds spend caps + alerts on top of an agent wallet (EVM + Solana), separate layer from intent-layer signing audit but same problem space (agent overspend). https://getagentcap.com / API: https://github.com/devotedpronet-cyber/getagentcap-api

  4. TheAliphant commented on Sep 26, 2026

    @TheAliphant

    MACH Base is live x402 infrastructure for Base-chain reads with no signup or API key. We are trying to verify the cleanest caller-pays integration path for your agent/runtime. A live compatibility call is GET https://api.mach.gallery/api/base/block-number ($0.005 USDC on Base); discovery: https://api.mach.gallery/.well-known/x402 ; OpenAPI: https://api.mach.gallery/openapi.json . If this fits your stack, one real paid call is enough to validate it. If not, a short note on the blocking integration/policy is useful. MACH conversation=e5d7073f73af35876e58b5b9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions