Repository navigation
Conversation
🟡 Heimdall Review Status
|
|
Friendly ping: checks pass and the branch merges cleanly. The hook is optional and off by default, so existing x402 action provider users see no change; it only lets an agent approve or block a payment (for example after a pay guard or spend policy check) before signing. Glad to adjust naming or move it behind a config flag if that fits the action provider better. |
|
Adding a concrete use case in support of this. We run a payee screening service for x402, and the place such a check has to run is exactly here: after the 402 is read and a payment option is selected, before anything is signed, with payTo and network in hand. Today an AgentKit user cannot do that without forking the provider, because the x402 client is built inside it. It may also help with triage. #1539, #1544, #1545, #1553, #1585, #1646, #1657 and #1662 all ask for some form of check before an x402 payment (sanctions, spend policy, seller checks). With this hook, each of those becomes a function a user passes in rather than a separate action provider to review, and the x402 provider itself stays vendor neutral. One small suggestion: if a blocked payment returned its reason to the agent in the same JSON shape as the existing "Payment exceeds limit" error, the model could tell the user why it stopped. |
For frameworks that create their own x402 client and accept a hook (x402Client.onBeforePaymentCreation, or a beforePayment option such as the one proposed in coinbase/agentkit#1577). Same checks and options as withSafePay; the check is paid by the x402Client passed in options.client. 4 new tests (18 total), checked on @x402/fetch 2.30 and 2.32.
|
Supporting this. Here is a concrete use for the hook, already published. I maintain Tolca, a pre-payment seller check for x402 (it screens the payTo wallet against OFAC SDN crypto addresses and Circle's USDC freeze, checks the asset is official USDC, and compares price and payTo with the seller's Bazaar listing; allow / review / block with a signed receipt). import { x402Client } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { tolcaBeforePayment } from "tolca-safe-pay";
const checkClient = new x402Client().register("eip155:8453", new ExactEvmScheme(signer));
x402ActionProvider({
beforePayment: tolcaBeforePayment({ client: checkClient }),
});Block stops the payment, review stops it unless an With this hook merged, the separate action provider in #1646 becomes optional: developers could plug the check in with one option instead. |
520fc05 to
1e48e05
Compare
2f4dadb to
32c81af
Compare
Closes #1576
Adds an optional
beforePayment(TypeScript) /before_payment(Python) field to the x402 action provider config. The provider builds its x402 client internally, so users could not reach the SDK's existing hook; this passes the function tox402Client.onBeforePaymentCreation/x402ClientSync.on_before_payment_creation. Returning{ abort: true, reason }(TS) or anAbortResult(Python) blocks the payment before it is signed. Uses: screeningpayToagainst a sanctions list, per-seller spend policies, audit logging.Parameters<x402Client["onBeforePaymentCreation"]>[0].Checked locally:
jest src/action-providers/x402(23 passed),tsc --noEmit, eslint, prettier;pytest tests/action_providers/x402(12 passed), ruff check and format.🤖 Generated with Claude Code