x402-safe-pay 0.1.0 → 0.1.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/README.md +39 -4
- package/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,21 +19,56 @@ npm install x402-safe-pay
|
|
|
19
19
|
|
|
20
20
|
## Use
|
|
21
21
|
|
|
22
|
+
`withPayeeCheck(paidFetch, options)` takes the paying fetch your x402 or MPP client gives you and returns a fetch with the same signature.
|
|
23
|
+
|
|
24
|
+
### x402-fetch (x402 v1)
|
|
25
|
+
|
|
22
26
|
```js
|
|
23
|
-
import {
|
|
27
|
+
import { createWalletClient, http } from "viem";
|
|
28
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
29
|
+
import { base } from "viem/chains";
|
|
30
|
+
import { wrapFetchWithPayment } from "x402-fetch";
|
|
24
31
|
import { withPayeeCheck } from "x402-safe-pay";
|
|
25
32
|
|
|
26
|
-
const
|
|
27
|
-
const safeFetch = withPayeeCheck(
|
|
33
|
+
const client = createWalletClient({ account: privateKeyToAccount(process.env.PRIVATE_KEY), transport: http(), chain: base });
|
|
34
|
+
const safeFetch = withPayeeCheck(wrapFetchWithPayment(fetch, client));
|
|
28
35
|
|
|
29
36
|
const res = await safeFetch("https://api.example.com/v1/quote?symbol=ETH");
|
|
30
37
|
```
|
|
31
38
|
|
|
39
|
+
### @x402/fetch (x402 v2)
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
|
|
43
|
+
import { ExactEvmScheme } from "@x402/evm";
|
|
44
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
45
|
+
import { withPayeeCheck } from "x402-safe-pay";
|
|
46
|
+
|
|
47
|
+
const paidFetch = wrapFetchWithPaymentFromConfig(fetch, {
|
|
48
|
+
schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(privateKeyToAccount(process.env.PRIVATE_KEY)) }],
|
|
49
|
+
});
|
|
50
|
+
const safeFetch = withPayeeCheck(paidFetch);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### mppx (MPP)
|
|
54
|
+
|
|
55
|
+
`Mppx.create` makes the global `fetch` pay 402 answers. Keep the original fetch first and pass it as `plainFetch`, so the probe that reads the 402 does not pay:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { Mppx, tempo } from "mppx/client";
|
|
59
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
60
|
+
import { withPayeeCheck } from "x402-safe-pay";
|
|
61
|
+
|
|
62
|
+
const plainFetch = globalThis.fetch; // before Mppx.create
|
|
63
|
+
Mppx.create({ methods: [tempo({ account: privateKeyToAccount(process.env.PRIVATE_KEY) })] });
|
|
64
|
+
const safeFetch = withPayeeCheck(globalThis.fetch, { plainFetch });
|
|
65
|
+
```
|
|
66
|
+
|
|
32
67
|
Options:
|
|
33
68
|
|
|
34
69
|
| Option | Default | Meaning |
|
|
35
70
|
|---|---|---|
|
|
36
|
-
| `plainFetch` | `globalThis.fetch` | Unpaid fetch used to read the target's 402 |
|
|
71
|
+
| `plainFetch` | `globalThis.fetch` | Unpaid fetch used to read the target's 402 (must not pay: see the mppx example) |
|
|
37
72
|
| `checkUrl` | P0 `/check/payee` | Payee check endpoint |
|
|
38
73
|
| `cacheMs` | `3600000` | How long a verdict is reused for the same address |
|
|
39
74
|
| `blockOnReview` | `false` | Also refuse addresses marked `review` |
|
package/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// MIT licence. Source and terms: https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev/tools
|
|
9
9
|
|
|
10
10
|
export const DEFAULT_CHECK_URL = "https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev/check/payee";
|
|
11
|
-
export const VERSION = "0.1.
|
|
11
|
+
export const VERSION = "0.1.1";
|
|
12
12
|
|
|
13
13
|
export class PayeeRefusedError extends Error {
|
|
14
14
|
constructor(message, details) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x402-safe-pay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Check a payee before your AI agent pays it: wraps an x402/MPP paying fetch with a sanctions, wallet-risk and known-seller check on every new payee address.",
|
|
5
5
|
"keywords": ["x402", "mpp", "ai-agents", "agent-payments", "payee-check", "sanctions", "ofac", "wallet-risk", "fetch", "usdc", "base"],
|
|
6
6
|
"homepage": "https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev/tools",
|