Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

### Fixed — only `exact` payment options are signed

- `extractPaymentDetails` took the 402's first option whatever its scheme, and
every caller signs an exact transfer. A gateway listing `upto` or
`batch-settlement` first would have had an exact payment signed against its
terms, against `upto` for the ceiling. It now selects an `exact` option (or one
with no scheme, v1) in any position, and throws when there is none.

## [3.26.2] - 2026-11-07

### Fixed — a failed job says what happened to the payment
Expand Down
14 changes: 12 additions & 2 deletions src/x402.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,20 @@ export function extractPaymentDetails(
extra?: { name?: string; version?: string; feePayer?: string };
resource?: ResourceInfo;
} {
const accepts = paymentRequired.accepts || [];
if (accepts.length === 0) {
const offered = paymentRequired.accepts || [];
if (offered.length === 0) {
throw new Error("No payment options in payment required response");
}
// Every caller signs an exact transfer. sol.blockrun.ai also offers
// batch-settlement and a Base gateway may offer upto; signing exact against
// those terms is refused at best, and against upto pays its ceiling. An option
// with no scheme is exact (v1).
const accepts = offered.filter((opt) => !opt.scheme || opt.scheme === "exact");
if (accepts.length === 0) {
throw new Error(
`This client signs the exact scheme, but the 402 only offers ${offered.map((opt) => JSON.stringify(opt.scheme)).join(", ")}`
);
}

// If preferred network specified, try to find matching option
let option = null;
Expand Down
Loading
Loading