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.
Files changed (142) hide show
  1. package/QUICKSTART.md +45 -57
  2. package/README.md +230 -293
  3. package/bin/twzrd-bounty-preflight.js +63 -0
  4. package/bin/twzrd-evidence-bundle.js +33 -0
  5. package/bin/twzrd-payment-decision.js +25 -0
  6. package/dist/adoption-proof.d.ts +9 -0
  7. package/dist/adoption-proof.d.ts.map +1 -1
  8. package/dist/adoption-proof.js +15 -3
  9. package/dist/adoption-proof.js.map +1 -1
  10. package/dist/auto-gate.d.ts +32 -2
  11. package/dist/auto-gate.d.ts.map +1 -1
  12. package/dist/auto-gate.js +85 -16
  13. package/dist/auto-gate.js.map +1 -1
  14. package/dist/bounty-preflight-cli.d.ts +25 -0
  15. package/dist/bounty-preflight-cli.d.ts.map +1 -0
  16. package/dist/bounty-preflight-cli.js +155 -0
  17. package/dist/bounty-preflight-cli.js.map +1 -0
  18. package/dist/bounty-preflight.d.ts +140 -0
  19. package/dist/bounty-preflight.d.ts.map +1 -0
  20. package/dist/bounty-preflight.js +208 -0
  21. package/dist/bounty-preflight.js.map +1 -0
  22. package/dist/config.d.ts.map +1 -1
  23. package/dist/config.js +3 -2
  24. package/dist/config.js.map +1 -1
  25. package/dist/consumer-adjacency.d.ts +79 -0
  26. package/dist/consumer-adjacency.d.ts.map +1 -0
  27. package/dist/consumer-adjacency.js +236 -0
  28. package/dist/consumer-adjacency.js.map +1 -0
  29. package/dist/decision-ledger-file.d.ts +49 -0
  30. package/dist/decision-ledger-file.d.ts.map +1 -0
  31. package/dist/decision-ledger-file.js +95 -0
  32. package/dist/decision-ledger-file.js.map +1 -0
  33. package/dist/decision-token.d.ts +23 -1
  34. package/dist/decision-token.d.ts.map +1 -1
  35. package/dist/decision-token.js +44 -14
  36. package/dist/decision-token.js.map +1 -1
  37. package/dist/directory.d.ts +35 -0
  38. package/dist/directory.d.ts.map +1 -0
  39. package/dist/directory.js +95 -0
  40. package/dist/directory.js.map +1 -0
  41. package/dist/evaluate.d.ts +20 -0
  42. package/dist/evaluate.d.ts.map +1 -1
  43. package/dist/evaluate.js +71 -0
  44. package/dist/evaluate.js.map +1 -1
  45. package/dist/evidence-bundle.d.ts +139 -0
  46. package/dist/evidence-bundle.d.ts.map +1 -0
  47. package/dist/evidence-bundle.js +213 -0
  48. package/dist/evidence-bundle.js.map +1 -0
  49. package/dist/gate.d.ts +13 -0
  50. package/dist/gate.d.ts.map +1 -1
  51. package/dist/gate.js +22 -0
  52. package/dist/gate.js.map +1 -1
  53. package/dist/index.d.ts +14 -16
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +20 -14
  56. package/dist/index.js.map +1 -1
  57. package/dist/log-inclusion.d.ts +135 -0
  58. package/dist/log-inclusion.d.ts.map +1 -0
  59. package/dist/log-inclusion.js +127 -0
  60. package/dist/log-inclusion.js.map +1 -0
  61. package/dist/merchant-card.d.ts +18 -57
  62. package/dist/merchant-card.d.ts.map +1 -1
  63. package/dist/merchant-card.js +23 -108
  64. package/dist/merchant-card.js.map +1 -1
  65. package/dist/mpp-hook.d.ts +12 -39
  66. package/dist/mpp-hook.d.ts.map +1 -1
  67. package/dist/mpp-hook.js +13 -76
  68. package/dist/mpp-hook.js.map +1 -1
  69. package/dist/network.d.ts +3 -1
  70. package/dist/network.d.ts.map +1 -1
  71. package/dist/network.js.map +1 -1
  72. package/dist/payment-decision.d.ts +263 -0
  73. package/dist/payment-decision.d.ts.map +1 -0
  74. package/dist/payment-decision.js +666 -0
  75. package/dist/payment-decision.js.map +1 -0
  76. package/dist/payto.d.ts +12 -1
  77. package/dist/payto.d.ts.map +1 -1
  78. package/dist/payto.js +32 -0
  79. package/dist/payto.js.map +1 -1
  80. package/dist/policy-runtime.d.ts +2 -15
  81. package/dist/policy-runtime.d.ts.map +1 -1
  82. package/dist/policy-runtime.js +16 -52
  83. package/dist/policy-runtime.js.map +1 -1
  84. package/dist/policy.d.ts +3 -1
  85. package/dist/policy.d.ts.map +1 -1
  86. package/dist/policy.js +75 -61
  87. package/dist/policy.js.map +1 -1
  88. package/dist/resource-bind.d.ts.map +1 -1
  89. package/dist/resource-bind.js +0 -1
  90. package/dist/resource-bind.js.map +1 -1
  91. package/dist/seller-hook.d.ts.map +1 -1
  92. package/dist/seller-hook.js +32 -4
  93. package/dist/seller-hook.js.map +1 -1
  94. package/dist/spend-control.d.ts +30 -12
  95. package/dist/spend-control.d.ts.map +1 -1
  96. package/dist/spend-control.js +162 -93
  97. package/dist/spend-control.js.map +1 -1
  98. package/dist/spend-ledger-file.d.ts +3 -0
  99. package/dist/spend-ledger-file.d.ts.map +1 -1
  100. package/dist/spend-ledger-file.js +33 -1
  101. package/dist/spend-ledger-file.js.map +1 -1
  102. package/dist/types.d.ts +7 -4
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/unsafe.d.ts +11 -0
  105. package/dist/unsafe.d.ts.map +1 -0
  106. package/dist/unsafe.js +11 -0
  107. package/dist/unsafe.js.map +1 -0
  108. package/dist/with-guard.d.ts.map +1 -1
  109. package/dist/with-guard.js +5 -7
  110. package/dist/with-guard.js.map +1 -1
  111. package/dist/wrap-fetch.d.ts.map +1 -1
  112. package/dist/wrap-fetch.js +5 -7
  113. package/dist/wrap-fetch.js.map +1 -1
  114. package/dist/x402-client-hook.d.ts +19 -53
  115. package/dist/x402-client-hook.d.ts.map +1 -1
  116. package/dist/x402-client-hook.js +59 -136
  117. package/dist/x402-client-hook.js.map +1 -1
  118. package/package.json +30 -16
  119. package/dist/cloudflare-x402.d.ts +0 -29
  120. package/dist/cloudflare-x402.d.ts.map +0 -1
  121. package/dist/cloudflare-x402.js +0 -31
  122. package/dist/cloudflare-x402.js.map +0 -1
  123. package/dist/foreign-key.d.ts +0 -19
  124. package/dist/foreign-key.d.ts.map +0 -1
  125. package/dist/foreign-key.js +0 -61
  126. package/dist/foreign-key.js.map +0 -1
  127. package/dist/paying-fetch.d.ts +0 -15
  128. package/dist/paying-fetch.d.ts.map +0 -1
  129. package/dist/paying-fetch.js +0 -67
  130. package/dist/paying-fetch.js.map +0 -1
  131. package/dist/policy-fetch.d.ts +0 -18
  132. package/dist/policy-fetch.d.ts.map +0 -1
  133. package/dist/policy-fetch.js +0 -77
  134. package/dist/policy-fetch.js.map +0 -1
  135. package/dist/record-leash-settle.d.ts +0 -20
  136. package/dist/record-leash-settle.d.ts.map +0 -1
  137. package/dist/record-leash-settle.js +0 -25
  138. package/dist/record-leash-settle.js.map +0 -1
  139. package/dist/wash-default.d.ts +0 -112
  140. package/dist/wash-default.d.ts.map +0 -1
  141. package/dist/wash-default.js +0 -229
  142. 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
- **Product:** replace naked `createX402Client({ wallet })` with a client that
4
- **refuses wash before sign**. Free `merchant_card`, no API key. Intel down →
5
- **fail-open** (never invents wash). No Path A in the default path.
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.3` + `x402-solana@3.0.0`.
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.3 x402-solana@3.0.0
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
- Default engine = wash only. Full 0.8 preflight/Path A: `{ engine: "full" }`.
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.3 @x402/core @x402/fetch @x402/svm
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` (payment
133
- allowed, observed) unless you set `TWZRD_UNSUPPORTED_NETWORK_MODE=strict`.
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.