twzrd-x402-gate 0.9.4 → 0.9.6
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/QUICKSTART.md +45 -57
- package/README.md +230 -293
- package/bin/twzrd-bounty-preflight.js +63 -0
- package/bin/twzrd-evidence-bundle.js +33 -0
- package/bin/twzrd-payment-decision.js +25 -0
- package/dist/adoption-proof.d.ts +9 -0
- package/dist/adoption-proof.d.ts.map +1 -1
- package/dist/adoption-proof.js +15 -3
- package/dist/adoption-proof.js.map +1 -1
- package/dist/auto-gate.d.ts +32 -2
- package/dist/auto-gate.d.ts.map +1 -1
- package/dist/auto-gate.js +85 -16
- package/dist/auto-gate.js.map +1 -1
- package/dist/bounty-preflight-cli.d.ts +25 -0
- package/dist/bounty-preflight-cli.d.ts.map +1 -0
- package/dist/bounty-preflight-cli.js +155 -0
- package/dist/bounty-preflight-cli.js.map +1 -0
- package/dist/bounty-preflight.d.ts +140 -0
- package/dist/bounty-preflight.d.ts.map +1 -0
- package/dist/bounty-preflight.js +208 -0
- package/dist/bounty-preflight.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -2
- package/dist/config.js.map +1 -1
- package/dist/consumer-adjacency.d.ts +79 -0
- package/dist/consumer-adjacency.d.ts.map +1 -0
- package/dist/consumer-adjacency.js +236 -0
- package/dist/consumer-adjacency.js.map +1 -0
- package/dist/decision-ledger-file.d.ts +49 -0
- package/dist/decision-ledger-file.d.ts.map +1 -0
- package/dist/decision-ledger-file.js +95 -0
- package/dist/decision-ledger-file.js.map +1 -0
- package/dist/decision-token.d.ts +23 -1
- package/dist/decision-token.d.ts.map +1 -1
- package/dist/decision-token.js +44 -14
- package/dist/decision-token.js.map +1 -1
- package/dist/directory.d.ts +35 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +95 -0
- package/dist/directory.js.map +1 -0
- package/dist/evaluate.d.ts +20 -0
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +71 -0
- package/dist/evaluate.js.map +1 -1
- package/dist/evidence-bundle.d.ts +139 -0
- package/dist/evidence-bundle.d.ts.map +1 -0
- package/dist/evidence-bundle.js +213 -0
- package/dist/evidence-bundle.js.map +1 -0
- package/dist/gate.d.ts +13 -0
- package/dist/gate.d.ts.map +1 -1
- package/dist/gate.js +22 -0
- package/dist/gate.js.map +1 -1
- package/dist/index.d.ts +14 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -14
- package/dist/index.js.map +1 -1
- package/dist/log-inclusion.d.ts +135 -0
- package/dist/log-inclusion.d.ts.map +1 -0
- package/dist/log-inclusion.js +127 -0
- package/dist/log-inclusion.js.map +1 -0
- package/dist/merchant-card.d.ts +18 -57
- package/dist/merchant-card.d.ts.map +1 -1
- package/dist/merchant-card.js +23 -108
- package/dist/merchant-card.js.map +1 -1
- package/dist/mpp-hook.d.ts +12 -39
- package/dist/mpp-hook.d.ts.map +1 -1
- package/dist/mpp-hook.js +13 -76
- package/dist/mpp-hook.js.map +1 -1
- package/dist/network.d.ts +3 -1
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js.map +1 -1
- package/dist/payment-decision.d.ts +263 -0
- package/dist/payment-decision.d.ts.map +1 -0
- package/dist/payment-decision.js +666 -0
- package/dist/payment-decision.js.map +1 -0
- package/dist/payto.d.ts +12 -1
- package/dist/payto.d.ts.map +1 -1
- package/dist/payto.js +32 -0
- package/dist/payto.js.map +1 -1
- package/dist/policy-runtime.d.ts +2 -15
- package/dist/policy-runtime.d.ts.map +1 -1
- package/dist/policy-runtime.js +16 -52
- package/dist/policy-runtime.js.map +1 -1
- package/dist/policy.d.ts +3 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +75 -61
- package/dist/policy.js.map +1 -1
- package/dist/resource-bind.d.ts.map +1 -1
- package/dist/resource-bind.js +0 -1
- package/dist/resource-bind.js.map +1 -1
- package/dist/seller-hook.d.ts.map +1 -1
- package/dist/seller-hook.js +32 -4
- package/dist/seller-hook.js.map +1 -1
- package/dist/spend-control.d.ts +30 -12
- package/dist/spend-control.d.ts.map +1 -1
- package/dist/spend-control.js +162 -93
- package/dist/spend-control.js.map +1 -1
- package/dist/spend-ledger-file.d.ts +3 -0
- package/dist/spend-ledger-file.d.ts.map +1 -1
- package/dist/spend-ledger-file.js +33 -1
- package/dist/spend-ledger-file.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/unsafe.d.ts +11 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +11 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/with-guard.d.ts.map +1 -1
- package/dist/with-guard.js +5 -7
- package/dist/with-guard.js.map +1 -1
- package/dist/wrap-fetch.d.ts.map +1 -1
- package/dist/wrap-fetch.js +5 -7
- package/dist/wrap-fetch.js.map +1 -1
- package/dist/x402-client-hook.d.ts +19 -53
- package/dist/x402-client-hook.d.ts.map +1 -1
- package/dist/x402-client-hook.js +59 -136
- package/dist/x402-client-hook.js.map +1 -1
- package/package.json +30 -16
- package/dist/cloudflare-x402.d.ts +0 -29
- package/dist/cloudflare-x402.d.ts.map +0 -1
- package/dist/cloudflare-x402.js +0 -31
- package/dist/cloudflare-x402.js.map +0 -1
- package/dist/foreign-key.d.ts +0 -19
- package/dist/foreign-key.d.ts.map +0 -1
- package/dist/foreign-key.js +0 -61
- package/dist/foreign-key.js.map +0 -1
- package/dist/paying-fetch.d.ts +0 -15
- package/dist/paying-fetch.d.ts.map +0 -1
- package/dist/paying-fetch.js +0 -67
- package/dist/paying-fetch.js.map +0 -1
- package/dist/policy-fetch.d.ts +0 -18
- package/dist/policy-fetch.d.ts.map +0 -1
- package/dist/policy-fetch.js +0 -77
- package/dist/policy-fetch.js.map +0 -1
- package/dist/record-leash-settle.d.ts +0 -20
- package/dist/record-leash-settle.d.ts.map +0 -1
- package/dist/record-leash-settle.js +0 -25
- package/dist/record-leash-settle.js.map +0 -1
- package/dist/wash-default.d.ts +0 -112
- package/dist/wash-default.d.ts.map +0 -1
- package/dist/wash-default.js +0 -229
- package/dist/wash-default.js.map +0 -1
package/QUICKSTART.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# twzrd-x402-gate — Quickstart (15 minutes, 0 USDC)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Refuses payment to a wash-flagged merchant **before your wallet signs**. Free intel, no
|
|
4
|
+
API key, no signup, no config — every `TWZRD_*` env var is an optional override. If intel
|
|
5
|
+
is unreachable the gate never *invents* a wash flag (the wash check fails open); a failed
|
|
6
|
+
preflight blocks the payment by default (`TWZRD_FAIL_OPEN=true` to allow).
|
|
6
7
|
|
|
7
|
-
**Pin:** `twzrd-x402-gate@0.9.
|
|
8
|
+
**Pin:** `twzrd-x402-gate@0.9.6` + stock PayAI client `x402-solana@3.0.0` (official
|
|
9
|
+
`beforePayment` seat). `@x402/core` Path E remains supported; refuse script is fallback.
|
|
8
10
|
|
|
9
11
|
## 1. Stock PayAI client (default seat — copy-paste)
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
|
-
npm install twzrd-x402-gate@0.9.
|
|
14
|
+
npm install twzrd-x402-gate@0.9.6 x402-solana@3.0.0
|
|
13
15
|
```
|
|
14
16
|
|
|
15
17
|
> **ESM-only.** The package ships `import` conditions only — a CommonJS
|
|
@@ -17,16 +19,6 @@ npm install twzrd-x402-gate@0.9.3 x402-solana@3.0.0
|
|
|
17
19
|
> fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Set `"type": "module"` in your
|
|
18
20
|
> package.json, use `.mjs`, or bundle ESM.
|
|
19
21
|
|
|
20
|
-
```typescript
|
|
21
|
-
import { createX402Client } from "x402-solana";
|
|
22
|
-
import { createTwzrdPayingClient } from "twzrd-x402-gate";
|
|
23
|
-
|
|
24
|
-
// was: createX402Client({ wallet })
|
|
25
|
-
const client = createX402Client(createTwzrdPayingClient({ wallet }));
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Or hook-only:
|
|
29
|
-
|
|
30
22
|
```typescript
|
|
31
23
|
import { createX402Client } from "x402-solana";
|
|
32
24
|
import { createTwzrdBeforePaymentHook } from "twzrd-x402-gate";
|
|
@@ -34,18 +26,17 @@ import { createTwzrdBeforePaymentHook } from "twzrd-x402-gate";
|
|
|
34
26
|
const client = createX402Client({
|
|
35
27
|
wallet,
|
|
36
28
|
network: "solana",
|
|
37
|
-
beforePayment: createTwzrdBeforePaymentHook(),
|
|
29
|
+
beforePayment: createTwzrdBeforePaymentHook({ refuseWashFlagged: true }),
|
|
38
30
|
});
|
|
39
31
|
```
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
Equivalent: `beforePayment: installTwzrdAutoGate("x402-solana", { refuseWashFlagged: true })`.
|
|
43
34
|
Then: `await client.fetch("https://merchant.example/paid");`
|
|
44
35
|
|
|
45
36
|
## 1b. Official `@x402/core` client (Path E)
|
|
46
37
|
|
|
47
38
|
```bash
|
|
48
|
-
npm install twzrd-x402-gate@0.9.
|
|
39
|
+
npm install twzrd-x402-gate@0.9.6 @x402/core @x402/fetch @x402/svm
|
|
49
40
|
```
|
|
50
41
|
|
|
51
42
|
```typescript
|
|
@@ -58,6 +49,33 @@ installTwzrdAutoGate(client, { refuseWashFlagged: true });
|
|
|
58
49
|
// then register schemes + wrapFetchWithPayment as usual
|
|
59
50
|
```
|
|
60
51
|
|
|
52
|
+
## 1c. PayKit (`createPayKitClient`) — Foundation #303
|
|
53
|
+
|
|
54
|
+
PayKit callers pass TWZRD as `onBeforeX402PaymentCreation`. No TWZRD branding
|
|
55
|
+
inside pay-kit itself. The option is on `solana-foundation/pay-kit#303` (and the
|
|
56
|
+
`twzrd-sol` fork); until Foundation merges, use the fork or wait.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { createPayKitClient } from "@solana/pay-kit";
|
|
60
|
+
import { createTwzrdPayKitBeforePaymentHook } from "twzrd-x402-gate";
|
|
61
|
+
|
|
62
|
+
const client = await createPayKitClient({
|
|
63
|
+
accept: ["x402"],
|
|
64
|
+
onBeforeX402PaymentCreation: createTwzrdPayKitBeforePaymentHook({
|
|
65
|
+
refuseWashFlagged: true,
|
|
66
|
+
}),
|
|
67
|
+
rpcUrl,
|
|
68
|
+
signer,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Equivalent: `onBeforeX402PaymentCreation: installTwzrdAutoGate("pay-kit", { refuseWashFlagged: true })`.
|
|
73
|
+
The hook is the official `@x402/core` context shape (same evaluator as Path E).
|
|
74
|
+
`@solana/pay-kit` is optional — this package does not hard-depend on it.
|
|
75
|
+
The factory itself does not read `TWZRD_AUTO_GATE`; use the AutoGate seat if you
|
|
76
|
+
want the env kill switch re-read per call. You cannot `installTwzrdAutoGate(client)`
|
|
77
|
+
after `createPayKitClient` — PayKit only accepts the hook at construction.
|
|
78
|
+
|
|
61
79
|
## 2. Prove it blocked something (spends nothing)
|
|
62
80
|
|
|
63
81
|
```bash
|
|
@@ -69,6 +87,9 @@ npm run x402-solana-before-payment-proof
|
|
|
69
87
|
|
|
70
88
|
# @x402/core Path E proof (onBeforePaymentCreation)
|
|
71
89
|
npm run autogate-block-proof
|
|
90
|
+
|
|
91
|
+
# PayKit seat (fake createPayKitClient — no unpublished @solana/pay-kit)
|
|
92
|
+
npm run pay-kit-before-payment
|
|
72
93
|
```
|
|
73
94
|
|
|
74
95
|
That JSON is your receipt: a bad merchant intercepted with 0 USDC at risk.
|
|
@@ -121,7 +142,7 @@ payWrap as `x402Fetch`.
|
|
|
121
142
|
|
|
122
143
|
| Knob | Effect |
|
|
123
144
|
|------|--------|
|
|
124
|
-
| `TWZRD_AUTO_GATE=0` | Kill switch — gate fully off, payments proceed unguarded |
|
|
145
|
+
| `TWZRD_AUTO_GATE=0` | Kill switch — gate fully off, payments proceed unguarded. Read per call on the x402-client / x402-solana / pay-kit / MPP seats; the fetch (payWrap) seat resolves it once when the fetch is composed, in both directions — rebuild the fetch to change it. |
|
|
125
146
|
| `refuseWashFlagged: false` | Stop refusing wash-flagged merchants (default `true`) |
|
|
126
147
|
| `gateOnCanSpend: true` | Opt-in hard cap: also block when `can_spend=false` (default `false`) |
|
|
127
148
|
|
|
@@ -129,42 +150,9 @@ Everything else (thresholds, wash caps, fail posture, settle guard): [README](./
|
|
|
129
150
|
|
|
130
151
|
## What this will NOT do
|
|
131
152
|
|
|
132
|
-
- **No Base/EVM reputation.** Non-Solana networks get an explicit `unknown`
|
|
133
|
-
|
|
153
|
+
- **No Base/EVM reputation.** Non-Solana networks get an explicit `unknown`
|
|
154
|
+
(observed; no Solana preflight) unless you set
|
|
155
|
+
`TWZRD_UNSUPPORTED_NETWORK_MODE=strict`. Observe is not a wash bypass —
|
|
156
|
+
`wash_flagged` still refuses before sign.
|
|
134
157
|
- **No delivery guarantee.** It screens the merchant before you pay, nothing after.
|
|
135
158
|
- **Not a wallet.** It never holds keys or signs — it only decides if your signer runs.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
## Pay Kit before-payment hook (upstream PR pending)
|
|
139
|
-
|
|
140
|
-
`solana-foundation/pay-kit#303` is open as of 2026-09-07. This adapter targets
|
|
141
|
-
that PR's `onBeforeX402PaymentCreation` option; a released Pay Kit client must
|
|
142
|
-
expose that option before this integration can enforce policy.
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { createPayKitClient } from "@solana/pay-kit";
|
|
146
|
-
import { installTwzrdAutoGate } from "twzrd-x402-gate";
|
|
147
|
-
|
|
148
|
-
const client = await createPayKitClient({
|
|
149
|
-
accept: ["x402"],
|
|
150
|
-
rpcUrl,
|
|
151
|
-
signer,
|
|
152
|
-
onBeforeX402PaymentCreation: installTwzrdAutoGate("pay-kit", {
|
|
153
|
-
refuseWashFlagged: true,
|
|
154
|
-
}),
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
The adapter returns the official x402 context hook and reuses the shared
|
|
159
|
-
before-payment evaluator. It adds no Pay Kit dependency. Supply it at client
|
|
160
|
-
construction; passing the constructed Pay Kit client to AutoGate is unsupported.
|
|
161
|
-
This hook covers x402 payment creation, not Pay Kit's MPP path.
|
|
162
|
-
|
|
163
|
-
`createTwzrdPayKitBeforePaymentHook(options)` exposes the same evaluator directly.
|
|
164
|
-
The AutoGate form reads environment kill switches on every call; the direct
|
|
165
|
-
factory does not. Calling AutoGate installs protection by default, whereas
|
|
166
|
-
ClawRouter's integration loads AutoGate only after explicit opt-in.
|
|
167
|
-
|
|
168
|
-
Source-checkout verification: `npx tsx test/pay-kit-before-payment.test.ts`.
|
|
169
|
-
The test covers a fake Pay Kit host and the real x402 client with a fake scheme;
|
|
170
|
-
it does not establish released Pay Kit compatibility or external use.
|