x402-safe-fetch 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +10 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ export const PRESIGN_GUARD_URL = "https://presign-guard.fizzl.eu";
|
|
|
51
51
|
export const INJECTION_CAP = "$0.02"; // presign-guard's injection check costs $0.01; never more than twice that
|
|
52
52
|
// The header a checked answer carries: green, orange, red (only with onInjection "flag" or a function) or unchecked.
|
|
53
53
|
export const ANSWER_CHECK_HEADER = "x-answer-check";
|
|
54
|
-
export const VERSION = "0.16.
|
|
54
|
+
export const VERSION = "0.16.1";
|
|
55
55
|
// Doctor sees which calls come from this package (in its usage counts), nothing more.
|
|
56
56
|
const DOCTOR_HEADERS = { accept: "application/json", "user-agent": `x402-safe-fetch/${VERSION}` };
|
|
57
57
|
export const BASE = "eip155:8453";
|
|
@@ -159,8 +159,15 @@ export function payableOption(accepts, network, maxUsd) {
|
|
|
159
159
|
// Base and other EVM chains: "exact" first (what most clients register), then "auth-capture" (Coinbase's escrow:
|
|
160
160
|
// the buyer signs once, the USDC is held and only captured when the seller delivers, e.g. Atom's domain checkout).
|
|
161
161
|
// Either is paid only if your register() added its scheme, and both stay within the budget (x402's spend controls
|
|
162
|
-
// read the amount, which for auth-capture is the most that can be captured).
|
|
163
|
-
|
|
162
|
+
// read the amount, which for auth-capture is the most that can be captured). Of several options of a scheme, the
|
|
163
|
+
// cheapest within the budget: a 402 that lists $0.50 before $0.01 to the same seller is paid a cent, not refused
|
|
164
|
+
// (or overpaid) because the first one costs more.
|
|
165
|
+
const cheapest = (scheme) => on
|
|
166
|
+
.filter((a) => a?.scheme === scheme)
|
|
167
|
+
.map((a) => ({ a, usd: usdOfOption(a, network) }))
|
|
168
|
+
.filter((x) => x.usd !== null && x.usd > 0 && !(x.usd > cap + 1e-9))
|
|
169
|
+
.sort((x, y) => x.usd - y.usd)[0]?.a;
|
|
170
|
+
return cheapest("exact") ?? cheapest("auth-capture") ?? on.find((a) => a?.scheme === "exact") ?? on.find((a) => a?.scheme === "auth-capture") ?? on[0] ?? null;
|
|
164
171
|
}
|
|
165
172
|
|
|
166
173
|
// The code that stopped the payment: the preflight's first reason at its verdict's level (no_go, then caution), as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x402-safe-fetch",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "A fetch for AI agents that checks an unknown x402 endpoint ($0.001 x402 Doctor preflight) before paying it, and never pays above your budget.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|