twzrd-x402-gate 0.10.0 → 0.10.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/QUICKSTART.md +35 -3
- package/README.md +98 -6
- package/bin/twzrd-evidence-bundle.js +10 -3
- package/dist/adoption-proof.d.ts +8 -0
- package/dist/adoption-proof.d.ts.map +1 -1
- package/dist/adoption-proof.js +13 -2
- package/dist/adoption-proof.js.map +1 -1
- package/dist/auto-gate.d.ts +35 -2
- package/dist/auto-gate.d.ts.map +1 -1
- package/dist/auto-gate.js +94 -16
- package/dist/auto-gate.js.map +1 -1
- package/dist/cloudflare-base.d.ts +49 -0
- package/dist/cloudflare-base.d.ts.map +1 -0
- package/dist/cloudflare-base.js +113 -0
- package/dist/cloudflare-base.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/doctor.d.ts.map +1 -1
- package/dist/doctor.js +24 -2
- package/dist/doctor.js.map +1 -1
- 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 +50 -0
- package/dist/evidence-bundle.d.ts.map +1 -1
- package/dist/evidence-bundle.js +95 -14
- package/dist/evidence-bundle.js.map +1 -1
- package/dist/evidence-verify.d.ts +145 -0
- package/dist/evidence-verify.d.ts.map +1 -0
- package/dist/evidence-verify.js +784 -0
- package/dist/evidence-verify.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- 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/network.d.ts +3 -1
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js.map +1 -1
- 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.d.ts.map +1 -1
- package/dist/policy.js +90 -44
- package/dist/policy.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.map +1 -1
- package/dist/spend-control.js +132 -63
- 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 +3 -2
- package/dist/types.d.ts.map +1 -1
- 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 +38 -0
- package/dist/x402-client-hook.d.ts.map +1 -1
- package/dist/x402-client-hook.js +82 -4
- package/dist/x402-client-hook.js.map +1 -1
- package/package.json +17 -5
package/QUICKSTART.md
CHANGED
|
@@ -49,6 +49,33 @@ installTwzrdAutoGate(client, { refuseWashFlagged: true });
|
|
|
49
49
|
// then register schemes + wrapFetchWithPayment as usual
|
|
50
50
|
```
|
|
51
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
|
+
|
|
52
79
|
## 2. Prove it blocked something (spends nothing)
|
|
53
80
|
|
|
54
81
|
```bash
|
|
@@ -60,6 +87,9 @@ npm run x402-solana-before-payment-proof
|
|
|
60
87
|
|
|
61
88
|
# @x402/core Path E proof (onBeforePaymentCreation)
|
|
62
89
|
npm run autogate-block-proof
|
|
90
|
+
|
|
91
|
+
# PayKit seat (fake createPayKitClient — no unpublished @solana/pay-kit)
|
|
92
|
+
npm run pay-kit-before-payment
|
|
63
93
|
```
|
|
64
94
|
|
|
65
95
|
That JSON is your receipt: a bad merchant intercepted with 0 USDC at risk.
|
|
@@ -112,7 +142,7 @@ payWrap as `x402Fetch`.
|
|
|
112
142
|
|
|
113
143
|
| Knob | Effect |
|
|
114
144
|
|------|--------|
|
|
115
|
-
| `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. |
|
|
116
146
|
| `refuseWashFlagged: false` | Stop refusing wash-flagged merchants (default `true`) |
|
|
117
147
|
| `gateOnCanSpend: true` | Opt-in hard cap: also block when `can_spend=false` (default `false`) |
|
|
118
148
|
|
|
@@ -120,7 +150,9 @@ Everything else (thresholds, wash caps, fail posture, settle guard): [README](./
|
|
|
120
150
|
|
|
121
151
|
## What this will NOT do
|
|
122
152
|
|
|
123
|
-
- **No Base/EVM reputation.** Non-Solana networks get an explicit `unknown`
|
|
124
|
-
|
|
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.
|
|
125
157
|
- **No delivery guarantee.** It screens the merchant before you pay, nothing after.
|
|
126
158
|
- **Not a wallet.** It never holds keys or signs — it only decides if your signer runs.
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ installTwzrdAutoGate(client, { refuseWashFlagged: true });
|
|
|
57
57
|
**Intercept proof (0 USDC, wash seller never reaches signer):**
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
cd
|
|
60
|
+
cd twzrd-x402-gate && npm run autogate-block-proof # needs network: live intel preflight
|
|
61
61
|
# writes block-proof-<run_id>.json (schema twzrd.autogate_block_proof.v1)
|
|
62
62
|
# public reason: TWZRD_TRUST_GATE_BLOCK: wash_flagged
|
|
63
63
|
```
|
|
@@ -102,6 +102,7 @@ server.onBeforeSettle(
|
|
|
102
102
|
| Default screen | free `GET /v1/intel/merchant_card/{payer}` via `twzrdPayerScreen()` |
|
|
103
103
|
| Screen/extract timeout | `timeoutMs: 3000` — on timeout, **continue** (fail-open) |
|
|
104
104
|
| Unresolved payer / null screen / screen error | **continue** unless `failOpen: false` |
|
|
105
|
+
| exact-SVM payload, no `@x402/svm` peer installed | reports `twzrd_svm_peer_missing` (warns once) and **continues** — without the peer, SVM payers are never screened; install it or set `failOpen: false` |
|
|
105
106
|
| Paid `/v1/intel/trust` | **not** default — inject a custom `screen` if you want it |
|
|
106
107
|
|
|
107
108
|
Payer identity prefers signed/encoded scheme fields (EIP-3009 `authorization.from`, Permit2
|
|
@@ -217,6 +218,31 @@ official x402 client receives 402
|
|
|
217
218
|
|
|
218
219
|
No AgentCash. No marketplace. No second probe. No TWZRD custody.
|
|
219
220
|
|
|
221
|
+
### PayKit (`@solana/pay-kit`)
|
|
222
|
+
|
|
223
|
+
Foundation [pay-kit#303](https://github.com/solana-foundation/pay-kit/pull/303)
|
|
224
|
+
exposes `onBeforeX402PaymentCreation` on `createPayKitClient` and registers it
|
|
225
|
+
on the internal x402Client. Pass TWZRD as that option — no TWZRD branding inside
|
|
226
|
+
pay-kit itself. This package does not hard-depend on unpublished `@solana/pay-kit`.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { createPayKitClient } from "@solana/pay-kit";
|
|
230
|
+
import { createTwzrdPayKitBeforePaymentHook } from "twzrd-x402-gate";
|
|
231
|
+
|
|
232
|
+
const client = await createPayKitClient({
|
|
233
|
+
accept: ["x402"],
|
|
234
|
+
onBeforeX402PaymentCreation: createTwzrdPayKitBeforePaymentHook({
|
|
235
|
+
refuseWashFlagged: true,
|
|
236
|
+
}),
|
|
237
|
+
rpcUrl,
|
|
238
|
+
signer,
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Equivalent: `onBeforeX402PaymentCreation: installTwzrdAutoGate("pay-kit", { refuseWashFlagged: true })`.
|
|
243
|
+
Same official `@x402/core` context hook as Path E. Abort returns
|
|
244
|
+
`{ abort: true, reason }`; PayKit throws before `signTransactions`.
|
|
245
|
+
|
|
220
246
|
### MCP (`@x402/mcp`)
|
|
221
247
|
|
|
222
248
|
Wire `twzrdOnPaymentRequested` / prefer `onPaymentRequired` + `onBeforePayment` per
|
|
@@ -457,16 +483,22 @@ Library: `import { safeFetch } from "twzrd-x402-gate/safe-fetch"`.
|
|
|
457
483
|
|
|
458
484
|
## Quickstart: `installTwzrdAutoGate` (default-on)
|
|
459
485
|
|
|
460
|
-
Canonical entry point (design: `docs/strategy/install-autogate-design.md`). One name,
|
|
486
|
+
Canonical entry point (design: `docs/strategy/install-autogate-design.md`). One name, five adapters:
|
|
461
487
|
|
|
462
488
|
| Call | Adapter |
|
|
463
489
|
|------|---------|
|
|
464
490
|
| `installTwzrdAutoGate(payWrap, opts?)` | Fetch: guard raw fetch → pay client |
|
|
465
491
|
| `installTwzrdAutoGate(x402Client, opts?)` | Official x402 `onBeforePaymentCreation` |
|
|
492
|
+
| `installTwzrdAutoGate("x402-solana", opts)` | PayAI `beforePayment` on `createX402Client` |
|
|
493
|
+
| `installTwzrdAutoGate("pay-kit", opts)` | PayKit `onBeforeX402PaymentCreation` (Foundation #303) |
|
|
466
494
|
| `installTwzrdAutoGate("mpp", opts)` | MPP `onChallenge` (returns handler) |
|
|
467
495
|
|
|
468
496
|
Aliases: `installTwzrdX402ClientHook`, `createTwzrdMppOnChallenge` remain; docs prefer AutoGate.
|
|
469
497
|
Kill switch: `TWZRD_GATE_ENABLED=false` or `TWZRD_AUTO_GATE=0`. Uninstall x402 installs with `uninstallTwzrdAutoGate(client)`.
|
|
498
|
+
The env switch is read **per call** on the x402-client, x402-solana, pay-kit and MPP seats, so flipping it moves an already-installed
|
|
499
|
+
gate in both directions. The **fetch / payWrap** seat is the exception: it resolves the switch once, when the fetch is composed,
|
|
500
|
+
so a fetch built while the switch was off stays ungated after you clear it — rebuild the fetch. `options.disabled: true` is a
|
|
501
|
+
permanent install-time opt-out everywhere and no env change revives it.
|
|
470
502
|
|
|
471
503
|
|
|
472
504
|
`installTwzrdAutoGate` is the one-liner form of "guard the raw fetch, then hand it to your
|
|
@@ -510,13 +542,66 @@ The gate **recognizes** multi-chain 402s but only **reputation-scores Solana mai
|
|
|
510
542
|
| Network | Reputation scored? | Default policy (`unsupportedNetworkMode`) |
|
|
511
543
|
|---------|-------------------|-------------------------------------------|
|
|
512
544
|
| Solana mainnet | Yes — free preflight + merchant_card | allow/block from intel |
|
|
513
|
-
| Base / other EVM (`eip155:*`) | **No** | `observe` (default): `decision=unknown`, `policyAction=allow`, telemetry `unsupported_network_seen` |
|
|
545
|
+
| Base / other EVM (`eip155:*`) | **No** Solana preflight | `observe` (default): `decision=unknown`, `policyAction=allow`, telemetry `unsupported_network_seen`. **Wash still runs** — `wash_flagged` refuses before sign. |
|
|
514
546
|
| Base / EVM in `strict` mode | No | `policyAction=block` before sign |
|
|
515
547
|
|
|
516
548
|
This is intentional: Base listing abundance ≠ Solana behavioral history. Unsupported is never
|
|
517
549
|
represented as a TWZRD trust `allow`. Set `TWZRD_UNSUPPORTED_NETWORK_MODE=strict` (or
|
|
518
550
|
`{ unsupportedNetworkMode: "strict" }`) to hard-block unscored networks.
|
|
519
551
|
|
|
552
|
+
`requireReceipt` (Path A) follows the same line: `hard` receipts apply to **scored networks
|
|
553
|
+
only** — on an unscored network there is no receipt to buy, so the decision carries
|
|
554
|
+
`receiptSkipped: "unscored_network"` and continues. Use `strict` mode to fail closed there.
|
|
555
|
+
|
|
556
|
+
`requireLogInclusion` sits one step further: a captured Path A receipt does not **count** as
|
|
557
|
+
trust until its leaf is proven included in the Receipt Transparency log under a key you
|
|
558
|
+
pinned ([spec](../docs/transparency-log.md)). A valid signature proves authorship and
|
|
559
|
+
integrity; only the log proves the issuer showed everyone the same answer. The log is **live**
|
|
560
|
+
(v0.1 domain, genesis 2026-09-03), and a paid response carries its proof **inline** as
|
|
561
|
+
`log_inclusion` — the audit path plus the signed head it targets — once the leaf is merged, so
|
|
562
|
+
the usual case verifies **offline** with nothing but your pinned key. The gate takes no
|
|
563
|
+
dependency on the log verifier — you wire it; it receives the receipt *and* the whole paid
|
|
564
|
+
response, and `twzrd-log-verifier`'s results fit the verdict shape with no adapter:
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
import { verifyLogInclusion, verifyReceiptInLog } from "twzrd-log-verifier"; // not yet on npm — see its README
|
|
568
|
+
|
|
569
|
+
// Today the log serves a single signing key (the receipt issuer key); pin it out of band.
|
|
570
|
+
// When v0.2 ships a key directory, pass that here instead — same call.
|
|
571
|
+
const PIN = "Ak5SQwHpuQAqU7ty7ZWX7qgF39A9yi72c22KNn8sHzvS";
|
|
572
|
+
|
|
573
|
+
await evaluate_x402_resource(url, requirements, {
|
|
574
|
+
requireReceipt: true,
|
|
575
|
+
x402Fetch,
|
|
576
|
+
requireLogInclusion: {
|
|
577
|
+
verifier: async (_receipt, ctx) =>
|
|
578
|
+
ctx.logInclusion
|
|
579
|
+
? verifyLogInclusion(ctx.response, PIN) // offline: no round-trip
|
|
580
|
+
: verifyReceiptInLog({ baseUrl: "https://intel.twzrd.xyz", receipt: ctx.response, trusted: PIN }), // fetch; 404 ⇒ pending
|
|
581
|
+
// hard: true — an unproven receipt denies spend (default)
|
|
582
|
+
// onPending: "deny" — a leaf not merged yet is unprovable at pay time; "allow"
|
|
583
|
+
// tolerates the one-anchor-period merge window (default "deny")
|
|
584
|
+
// refuseTofu: true — never accept keys the log advertised about itself (default)
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
The receipt is returned either way (`result.receipt`) — you paid for it. What changes is
|
|
590
|
+
`approved`: a denial sets `logInclusionDenied: true`, `policyAction: "block"`, and a reason of
|
|
591
|
+
`twzrd_log_inclusion_failed | _pending | _tofu_refused | _error`; `result.logInclusion` carries
|
|
592
|
+
the verdict (`key_id`, `leaf_index`, `tree_size`, `pending`, `tofu`). A verifier that throws
|
|
593
|
+
denies under `hard` — a broken or unreachable verifier must not wave receipts through. So does a
|
|
594
|
+
Path A attempt that yields no receipt at all (non-OK response, thrown fetch, `x402Fetch` not
|
|
595
|
+
wired): an outage on the receipt endpoint must never produce a *better* outcome than an empty
|
|
596
|
+
receipt body. Path A that your `requireReceipt` threshold never attempted is out of scope — this
|
|
597
|
+
knob gates receipts, it does not override your threshold.
|
|
598
|
+
|
|
599
|
+
Two things to know today: a leaf is merged within one anchor period, so a receipt paid for
|
|
600
|
+
*just now* may not yet carry `log_inclusion` — the fetch fallback above then reports `pending`,
|
|
601
|
+
and `onPending` decides. And nothing is **anchored** on Solana yet (`anchor_authority` is null),
|
|
602
|
+
so inclusion currently proves *what the log committed to*, not yet *when* — the anchor is what
|
|
603
|
+
makes backdating detectable.
|
|
604
|
+
|
|
520
605
|
Dual-chain accepts still prefer the Solana entry for scoring (same as payment clients that
|
|
521
606
|
prefer Solana when available).
|
|
522
607
|
|
|
@@ -797,7 +882,9 @@ Deterministic install→transcript path for operators (no wallet, no USDC):
|
|
|
797
882
|
npm run adoption-proof -- --integration demo-autogate-proof --run-id 00000000-0000-4000-8000-000000000001
|
|
798
883
|
```
|
|
799
884
|
|
|
800
|
-
Emits `twzrd.gate_adoption_transcript.v1` JSON: block path aborts with `signerInvocations: 0`, allow path emits decision, attribution headers stamped on mocked preflight. Full acceptance criteria (what counts as `EXTERNAL_RUN` vs dogfood)
|
|
885
|
+
Emits `twzrd.gate_adoption_transcript.v1` JSON: block path aborts with `signerInvocations: 0`, allow path emits decision, attribution headers stamped on mocked preflight. Full acceptance criteria (what counts as `EXTERNAL_RUN` vs dogfood), and the
|
|
886
|
+
harness's own limits: [`docs/strategy/gate-adoption-operator-proof.md`](../docs/strategy/gate-adoption-operator-proof.md)
|
|
887
|
+
in this repo — the same path the transcript's `acceptanceDoc` field cites.
|
|
801
888
|
|
|
802
889
|
## Run attribution (optional, for integration correlation)
|
|
803
890
|
|
|
@@ -841,8 +928,13 @@ If you're composing `withTwzrdGuard` manually instead, pass the raw (non-paying)
|
|
|
841
928
|
`POST /v1/intel/preflight` is the **free** `ReadinessCard` for the pre-spend decision.
|
|
842
929
|
The gate path only ever calls free endpoints — the preflight plus, by default
|
|
843
930
|
(`refuseWashFlagged: true`), the free merchant_card wash check. Paid intel
|
|
844
|
-
(`quickCheck`, `autoReceipt`) is opt-in
|
|
845
|
-
|
|
931
|
+
(`quickCheck`, `autoReceipt`) is otherwise opt-in, with one documented
|
|
932
|
+
exception (QUICKSTART 3b): on the fetch / payWrap seat, wiring a paying fetch
|
|
933
|
+
auto-enables buyer Path A, so a proceeding `warn` settles the $0.001 quick
|
|
934
|
+
tier ($0.05 at material size) through your wallet with no further flag —
|
|
935
|
+
opt out with `escalateOnWarn: false`, `requireReceipt: false`, or by leaving
|
|
936
|
+
`x402Fetch` unwired. The merchant-facing payment still waits on the free
|
|
937
|
+
preflight's verdict.
|
|
846
938
|
|
|
847
939
|
## License
|
|
848
940
|
|
|
@@ -12,15 +12,22 @@ import { dirname, join } from "node:path";
|
|
|
12
12
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
13
|
|
|
14
14
|
const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
15
|
-
|
|
15
|
+
// --verify re-checks an ALREADY PUBLISHED bundle. Offline and deterministic,
|
|
16
|
+
// so a foreign operator reaches the same verdict TWZRD would.
|
|
17
|
+
const verify = process.argv.includes("--verify");
|
|
18
|
+
const dist = join(pkgRoot, "dist", verify ? "evidence-verify.js" : "evidence-bundle.js");
|
|
16
19
|
|
|
17
20
|
if (!existsSync(dist)) {
|
|
18
21
|
console.error("twzrd-evidence-bundle: run `npm run build` in twzrd-x402-gate or install the published package");
|
|
19
22
|
process.exit(2);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
const
|
|
23
|
-
|
|
25
|
+
const mod = await import(pathToFileURL(dist).href);
|
|
26
|
+
if (verify) {
|
|
27
|
+
const code = await mod.mainVerify(process.argv.slice(2).filter((a) => a !== "--verify"));
|
|
28
|
+
process.exit(code);
|
|
29
|
+
}
|
|
30
|
+
await mod.main(process.argv.slice(2)).catch((err) => {
|
|
24
31
|
console.error(err instanceof Error ? err.message : err);
|
|
25
32
|
process.exit(1);
|
|
26
33
|
});
|
package/dist/adoption-proof.d.ts
CHANGED
|
@@ -92,6 +92,14 @@ export type RunGateAdoptionProofOptions = {
|
|
|
92
92
|
lineage?: GateAdoptionLineage;
|
|
93
93
|
};
|
|
94
94
|
export declare function isInternalIntegration(integration: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* AUDIT FIX (finding B): lineage may only TIGHTEN. isInternalIntegration()
|
|
97
|
+
* was a default that any explicit `lineage` overrode, so a twzrd-/ci- id could
|
|
98
|
+
* emit external_candidate with ok:true. An internal id is dogfood regardless
|
|
99
|
+
* of what the caller (or a hand-edited transcript) says; only a non-internal
|
|
100
|
+
* id may carry external_candidate, and it may still self-declare dogfood.
|
|
101
|
+
*/
|
|
102
|
+
export declare function resolveLineage(integration: string, requested?: GateAdoptionLineage): GateAdoptionLineage;
|
|
95
103
|
/**
|
|
96
104
|
* Run the deterministic no-spend adoption proof.
|
|
97
105
|
* Never contacts a wallet; never spends USDC. Preflight is mocked.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adoption-proof.d.ts","sourceRoot":"","sources":["../src/adoption-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,0BAA0B,EAAG,mCAA4C,CAAC;AAEvF,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,sBAAsB,4CAA4C,CAAC;AAChF,eAAO,MAAM,uBAAuB,kDAAkD,CAAC;AAEvF,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,oBAAoB,CAAC;IAC3B,oBAAoB,EAAE,wBAAwB,CAAC;IAC/C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAA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M,EACnB,SAAS,CAAC,EAAE,mBAAmB,GAC9B,mBAAmB,CAGrB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,GAAE,2BAAgC,GACrC,OAAO,CAAC,sBAAsB,CAAC,CAoLjC;AAED,2EAA2E;AAC3E,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBlF"}
|
package/dist/adoption-proof.js
CHANGED
|
@@ -96,6 +96,18 @@ export function isInternalIntegration(integration) {
|
|
|
96
96
|
i.includes("ci-") ||
|
|
97
97
|
i === "gate-adoption-proof");
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* AUDIT FIX (finding B): lineage may only TIGHTEN. isInternalIntegration()
|
|
101
|
+
* was a default that any explicit `lineage` overrode, so a twzrd-/ci- id could
|
|
102
|
+
* emit external_candidate with ok:true. An internal id is dogfood regardless
|
|
103
|
+
* of what the caller (or a hand-edited transcript) says; only a non-internal
|
|
104
|
+
* id may carry external_candidate, and it may still self-declare dogfood.
|
|
105
|
+
*/
|
|
106
|
+
export function resolveLineage(integration, requested) {
|
|
107
|
+
if (isInternalIntegration(integration))
|
|
108
|
+
return "dogfood";
|
|
109
|
+
return requested === "dogfood" ? "dogfood" : "external_candidate";
|
|
110
|
+
}
|
|
99
111
|
/**
|
|
100
112
|
* Run the deterministic no-spend adoption proof.
|
|
101
113
|
* Never contacts a wallet; never spends USDC. Preflight is mocked.
|
|
@@ -106,8 +118,7 @@ export async function runGateAdoptionProof(opts = {}) {
|
|
|
106
118
|
(typeof crypto !== "undefined" && "randomUUID" in crypto
|
|
107
119
|
? crypto.randomUUID()
|
|
108
120
|
: `run-${Date.now()}`);
|
|
109
|
-
const lineage = opts.lineage
|
|
110
|
-
(isInternalIntegration(integration) ? "dogfood" : "external_candidate");
|
|
121
|
+
const lineage = resolveLineage(integration, opts.lineage);
|
|
111
122
|
const clientHeader = `twzrd-x402-gate/${CLIENT_VERSION}`;
|
|
112
123
|
const steps = [];
|
|
113
124
|
// ── block path: can_spend false → abort, signer must stay 0 ─────────────
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adoption-proof.js","sourceRoot":"","sources":["../src/adoption-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,0BAA0B,GAK3B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,0BAA0B,GAAG,mCAA4C,CAAC;AAEvF,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,6CAA6C,CAAC;AACnF,MAAM,CAAC,MAAM,sBAAsB,GAAG,yCAAyC,CAAC;AAChF,MAAM,CAAC,MAAM,uBAAuB,GAAG,+CAA+C,CAAC;AAkFvF,SAAS,UAAU;IAIjB,IAAI,IAIS,CAAC;IACd,MAAM,MAAM,GAAmB;QAC7B,uBAAuB,CAAC,CAAC;YACvB,IAAI,GAAG,CAAC,CAAC;YACT,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IACF,OAAO;QACL,MAAM;QACN,KAAK,CAAC,IAAI,CAAC,GAAG;YACZ,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,QAAoC,EAAE,QAAiB;IAC5E,OAAO;QACL,cAAc,EAAE;YACd,QAAQ;YACR,SAAS,EAAE,QAAQ;YACnB,WAAW,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;YACxD,aAAa,EAAE,qBAAqB;SACrC;QACD,YAAY,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,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,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,QAAQ,GACZ,OAAO,OAAO,KAAK,WAAW;IAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACf,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAEnD,IAAI,QAAQ,EAAE,CAAC;IACb,IAAI,EAAE,CAAC,IAAI,CACT,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,CAAC,GAAG,EAAE,EAAE;QACN,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/auto-gate.d.ts
CHANGED
|
@@ -3,19 +3,34 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design: docs/strategy/install-autogate-design.md (#1586).
|
|
5
5
|
*
|
|
6
|
-
* One name across
|
|
6
|
+
* One name across five adapters:
|
|
7
7
|
* 1. Fetch / payWrap — guard raw fetch, then hand to x402 payer
|
|
8
8
|
* 2. x402 client — onBeforePaymentCreation (@x402/core Path E)
|
|
9
9
|
* 3. x402-solana seat — beforePayment on createX402Client (PayAI 2.1.0+)
|
|
10
10
|
* 4. MPP — onChallenge via createTwzrdMppOnChallenge
|
|
11
|
+
* 5. PayKit seat — onBeforeX402PaymentCreation on createPayKitClient
|
|
12
|
+
* (Foundation pay-kit #303; optional / duck-typed)
|
|
11
13
|
*
|
|
12
14
|
* Default ON. Kill switch (any):
|
|
13
15
|
* TWZRD_AUTO_GATE=0|false
|
|
14
16
|
* TWZRD_GATE_ENABLED=0|false
|
|
15
17
|
* options.disabled: true
|
|
18
|
+
*
|
|
19
|
+
* Kill-switch timing, which differs by kind and is deliberate:
|
|
20
|
+
* - The ENV switches are re-read PER CALL on the MPP, x402-solana,
|
|
21
|
+
* pay-kit and x402-client adapters, so flipping one takes effect on
|
|
22
|
+
* already-installed hooks. It is a running switch, not only a deploy-time one.
|
|
23
|
+
* - `options.disabled: true` is an install-time opt-out and is permanent for
|
|
24
|
+
* that install: nothing is constructed and no later env change revives it.
|
|
25
|
+
* - EXCEPTION, adapter 1: the fetch / payWrap adapter still resolves the
|
|
26
|
+
* switch once, at install, because it composes fetch wrappers rather than
|
|
27
|
+
* dispatching per call. This is permanent in BOTH directions: setting
|
|
28
|
+
* TWZRD_AUTO_GATE=0 afterwards does not un-gate an already-composed fetch,
|
|
29
|
+
* and — the direction that matters — a fetch composed WHILE the switch was
|
|
30
|
+
* off stays ungated after it is cleared. Rebuild it either way.
|
|
16
31
|
*/
|
|
17
32
|
import { type TwzrdGuardOptions } from "./with-guard.js";
|
|
18
|
-
import { type BeforePaymentCreationResult, type InstallX402ClientHookOptions, type X402ClientLike, type X402SelectedRequirements, type X402SolanaBeforePaymentContext } from "./x402-client-hook.js";
|
|
33
|
+
import { type BeforePaymentCreationContext, type BeforePaymentCreationResult, type InstallX402ClientHookOptions, type X402ClientLike, type X402SelectedRequirements, type X402SolanaBeforePaymentContext } from "./x402-client-hook.js";
|
|
19
34
|
import { type MppOnChallengeHelpers, type MppOnChallengeOptions, type MppChallenge } from "./mpp-hook.js";
|
|
20
35
|
/**
|
|
21
36
|
* Takes a guarded (pre-pay-checked) fetch and returns the fetch your agent actually
|
|
@@ -78,6 +93,24 @@ export declare function installTwzrdAutoGate(adapter: "mpp", options: InstallAut
|
|
|
78
93
|
* });
|
|
79
94
|
*/
|
|
80
95
|
export declare function installTwzrdAutoGate(adapter: "x402-solana", options?: InstallAutoGateX402Options): (requirements: X402SelectedRequirements & Record<string, unknown>, context?: X402SolanaBeforePaymentContext) => Promise<BeforePaymentCreationResult>;
|
|
96
|
+
/**
|
|
97
|
+
* PayKit seat (Foundation pay-kit #303): returns the official `@x402/core`
|
|
98
|
+
* `BeforePaymentCreationHook` for `createPayKitClient({
|
|
99
|
+
* onBeforeX402PaymentCreation,
|
|
100
|
+
* })`. Same evaluator as `createTwzrdPayKitBeforePaymentHook`. No hard
|
|
101
|
+
* dependency on `@solana/pay-kit`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const client = await createPayKitClient({
|
|
105
|
+
* accept: ["x402"],
|
|
106
|
+
* onBeforeX402PaymentCreation: installTwzrdAutoGate("pay-kit", {
|
|
107
|
+
* refuseWashFlagged: true,
|
|
108
|
+
* }),
|
|
109
|
+
* rpcUrl,
|
|
110
|
+
* signer,
|
|
111
|
+
* });
|
|
112
|
+
*/
|
|
113
|
+
export declare function installTwzrdAutoGate(adapter: "pay-kit", options?: InstallAutoGateX402Options): (context: BeforePaymentCreationContext) => Promise<BeforePaymentCreationResult>;
|
|
81
114
|
/**
|
|
82
115
|
* Disable a prior installTwzrdAutoGate on an x402 client (soft uninstall).
|
|
83
116
|
* Fetch compositions cannot be uninstalled — rebuild with disabled:true instead.
|
package/dist/auto-gate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-gate.d.ts","sourceRoot":"","sources":["../src/auto-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auto-gate.d.ts","sourceRoot":"","sources":["../src/auto-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAIL,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,cAAc,EACnB,KAAK,wBAAw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;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,0BAA0B,GACnC,CACD,YAAY,EAAE,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,CAAC,EAAE,8BAA8B,KACrC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAE1C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,EAClB,OAAO,CAAC,EAAE,0BAA0B,GACnC,CAAC,OAAO,EAAE,4BAA4B,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAmJnF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAWnE"}
|
package/dist/auto-gate.js
CHANGED
|
@@ -3,20 +3,38 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design: docs/strategy/install-autogate-design.md (#1586).
|
|
5
5
|
*
|
|
6
|
-
* One name across
|
|
6
|
+
* One name across five adapters:
|
|
7
7
|
* 1. Fetch / payWrap — guard raw fetch, then hand to x402 payer
|
|
8
8
|
* 2. x402 client — onBeforePaymentCreation (@x402/core Path E)
|
|
9
9
|
* 3. x402-solana seat — beforePayment on createX402Client (PayAI 2.1.0+)
|
|
10
10
|
* 4. MPP — onChallenge via createTwzrdMppOnChallenge
|
|
11
|
+
* 5. PayKit seat — onBeforeX402PaymentCreation on createPayKitClient
|
|
12
|
+
* (Foundation pay-kit #303; optional / duck-typed)
|
|
11
13
|
*
|
|
12
14
|
* Default ON. Kill switch (any):
|
|
13
15
|
* TWZRD_AUTO_GATE=0|false
|
|
14
16
|
* TWZRD_GATE_ENABLED=0|false
|
|
15
17
|
* options.disabled: true
|
|
18
|
+
*
|
|
19
|
+
* Kill-switch timing, which differs by kind and is deliberate:
|
|
20
|
+
* - The ENV switches are re-read PER CALL on the MPP, x402-solana,
|
|
21
|
+
* pay-kit and x402-client adapters, so flipping one takes effect on
|
|
22
|
+
* already-installed hooks. It is a running switch, not only a deploy-time one.
|
|
23
|
+
* - `options.disabled: true` is an install-time opt-out and is permanent for
|
|
24
|
+
* that install: nothing is constructed and no later env change revives it.
|
|
25
|
+
* - EXCEPTION, adapter 1: the fetch / payWrap adapter still resolves the
|
|
26
|
+
* switch once, at install, because it composes fetch wrappers rather than
|
|
27
|
+
* dispatching per call. This is permanent in BOTH directions: setting
|
|
28
|
+
* TWZRD_AUTO_GATE=0 afterwards does not un-gate an already-composed fetch,
|
|
29
|
+
* and — the direction that matters — a fetch composed WHILE the switch was
|
|
30
|
+
* off stays ungated after it is cleared. Rebuild it either way.
|
|
16
31
|
*/
|
|
17
32
|
import { withTwzrdGuard } from "./with-guard.js";
|
|
18
|
-
import { createTwzrdBeforePaymentHook, installTwzrdX402ClientHook, } from "./x402-client-hook.js";
|
|
33
|
+
import { createTwzrdBeforePaymentHook, createTwzrdPayKitBeforePaymentHook, installTwzrdX402ClientHook, } from "./x402-client-hook.js";
|
|
19
34
|
import { createTwzrdMppOnChallenge, } from "./mpp-hook.js";
|
|
35
|
+
/** All installs on a client, oldest first. A second install used to REPLACE the
|
|
36
|
+
* entry, so uninstall only reached the newest and the older install's hook kept
|
|
37
|
+
* gating with its own `disabled: false`. */
|
|
20
38
|
const clientInstalls = new WeakMap();
|
|
21
39
|
/** True when env or options ask to skip the gate entirely. */
|
|
22
40
|
export function isTwzrdAutoGateDisabled(options) {
|
|
@@ -42,39 +60,96 @@ export function installTwzrdAutoGate(target, options) {
|
|
|
42
60
|
// ── MPP ──────────────────────────────────────────────────────────────
|
|
43
61
|
if (target === "mpp") {
|
|
44
62
|
const mppOpts = options;
|
|
45
|
-
|
|
63
|
+
// `options.disabled` is an install-time decision and stays permanent.
|
|
64
|
+
if (mppOpts?.disabled === true) {
|
|
46
65
|
return async (_challenge, helpers) => helpers.createCredential();
|
|
47
66
|
}
|
|
48
|
-
|
|
67
|
+
// AUDIT FIX: the env kill switch used to be read ONCE here, so a hook built
|
|
68
|
+
// before TWZRD_AUTO_GATE=0 kept gating forever while the x402-client adapter
|
|
69
|
+
// honoured the same variable per call. Re-read it per call so one documented
|
|
70
|
+
// switch means the same thing on every adapter.
|
|
71
|
+
const gated = createTwzrdMppOnChallenge(mppOpts);
|
|
72
|
+
return async (challenge, helpers) => isTwzrdAutoGateDisabled(mppOpts) ? helpers.createCredential() : gated(challenge, helpers);
|
|
49
73
|
}
|
|
50
74
|
// ── PayAI x402-solana beforePayment ────────────────────────────────
|
|
51
75
|
if (target === "x402-solana") {
|
|
52
76
|
const solOpts = options;
|
|
53
|
-
if (
|
|
77
|
+
if (solOpts?.disabled === true) {
|
|
78
|
+
return async () => undefined;
|
|
79
|
+
}
|
|
80
|
+
// AUDIT FIX: same as the MPP seat — the env kill switch is re-read per call.
|
|
81
|
+
const gated = createTwzrdBeforePaymentHook(solOpts);
|
|
82
|
+
return async (requirements, context) => isTwzrdAutoGateDisabled(solOpts) ? undefined : gated(requirements, context);
|
|
83
|
+
}
|
|
84
|
+
// ── PayKit onBeforeX402PaymentCreation (official @x402/core context) ─
|
|
85
|
+
if (target === "pay-kit") {
|
|
86
|
+
const payKitOpts = options;
|
|
87
|
+
if (payKitOpts?.disabled === true) {
|
|
54
88
|
return async () => undefined;
|
|
55
89
|
}
|
|
56
|
-
|
|
90
|
+
const gated = createTwzrdPayKitBeforePaymentHook(payKitOpts);
|
|
91
|
+
return async (context) => isTwzrdAutoGateDisabled(payKitOpts) ? undefined : gated(context);
|
|
57
92
|
}
|
|
58
93
|
// ── x402 client ──────────────────────────────────────────────────────
|
|
59
94
|
if (isX402ClientLike(target)) {
|
|
60
95
|
const x402Opts = options;
|
|
61
|
-
|
|
96
|
+
// AUDIT FIX: this used to short-circuit on the FULL check, env included, so
|
|
97
|
+
// a client installed while TWZRD_AUTO_GATE=0 registered nothing and could
|
|
98
|
+
// never be re-armed by clearing the variable — a permanent fail-open in the
|
|
99
|
+
// exact window an operator uses the switch. Only the install-time opt-out
|
|
100
|
+
// short-circuits now; the wrapped registrar below re-reads the env per call,
|
|
101
|
+
// so an env-off install is inert while the switch is set and gates once it
|
|
102
|
+
// clears. Trade-off: a paymentControl misconfig now throws at install even
|
|
103
|
+
// under the kill switch, i.e. fails fast instead of silently passing through.
|
|
104
|
+
if (x402Opts?.disabled === true) {
|
|
62
105
|
return target;
|
|
63
106
|
}
|
|
64
107
|
if (clientInstalls.has(target)) {
|
|
65
108
|
console.warn("[twzrd-x402-gate] installTwzrdAutoGate: client already gated; dual install may double-evaluate. Call uninstallTwzrdAutoGate first.");
|
|
66
109
|
}
|
|
67
110
|
const state = { disabled: false };
|
|
68
|
-
clientInstalls.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
const states = clientInstalls.get(target);
|
|
112
|
+
if (states)
|
|
113
|
+
states.push(state);
|
|
114
|
+
else
|
|
115
|
+
clientInstalls.set(target, [state]);
|
|
116
|
+
// Wrap the registrar ONLY for TWZRD's own registration below, then restore
|
|
117
|
+
// it. AUDIT FIX: leaving the patch in place gated every hook the host
|
|
118
|
+
// registered later behind TWZRD's kill switch / uninstall — "gate off"
|
|
119
|
+
// silently became "all host policy off".
|
|
120
|
+
const ownProp = Object.prototype.hasOwnProperty.call(target, "onBeforePaymentCreation");
|
|
121
|
+
const originalProp = target.onBeforePaymentCreation;
|
|
122
|
+
const originalRegister = originalProp.bind(target);
|
|
123
|
+
const patched = ((hook) => originalRegister(async (context) => {
|
|
72
124
|
if (state.disabled || isTwzrdAutoGateDisabled()) {
|
|
73
125
|
return undefined; // proceed unguarded
|
|
74
126
|
}
|
|
75
127
|
return hook(context);
|
|
76
128
|
}));
|
|
77
|
-
|
|
129
|
+
target.onBeforePaymentCreation = patched;
|
|
130
|
+
try {
|
|
131
|
+
installTwzrdX402ClientHook(target, x402Opts);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
if (ownProp)
|
|
135
|
+
target.onBeforePaymentCreation = originalProp;
|
|
136
|
+
else
|
|
137
|
+
delete target.onBeforePaymentCreation;
|
|
138
|
+
// If the registrar is an accessor pair on the prototype, the patch above
|
|
139
|
+
// went through its SETTER, so no own property was ever created and the
|
|
140
|
+
// `delete` was a no-op — the patched registrar would survive. Assigning
|
|
141
|
+
// back drives the setter to the original.
|
|
142
|
+
//
|
|
143
|
+
// The test is `=== patched`, NOT `!== originalProp`. The looser form fired
|
|
144
|
+
// on any shape whose reads do not round-trip — a Proxy with a dynamic get
|
|
145
|
+
// trap can never satisfy it, so the assignment materialised an own
|
|
146
|
+
// property that permanently shadowed the trap. It also masked the
|
|
147
|
+
// `if (ownProp)` arm above by re-assigning whatever that arm failed to
|
|
148
|
+
// restore, which made the arm untestable. Only ever undo OUR patch.
|
|
149
|
+
if (target.onBeforePaymentCreation === patched) {
|
|
150
|
+
target.onBeforePaymentCreation = originalProp;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
78
153
|
return target;
|
|
79
154
|
}
|
|
80
155
|
// ── Fetch / payWrap ──────────────────────────────────────────────────
|
|
@@ -90,7 +165,7 @@ export function installTwzrdAutoGate(target, options) {
|
|
|
90
165
|
const x402Fetch = fetchOpts?.x402Fetch ?? target(raw);
|
|
91
166
|
return target(withTwzrdGuard(raw, { ...fetchOpts, x402Fetch }));
|
|
92
167
|
}
|
|
93
|
-
throw new TypeError('[twzrd-x402-gate] installTwzrdAutoGate: expected a PayWrap function, an x402 client with onBeforePaymentCreation, or the string "mpp" / "x402-solana"');
|
|
168
|
+
throw new TypeError('[twzrd-x402-gate] installTwzrdAutoGate: expected a PayWrap function, an x402 client with onBeforePaymentCreation, or the string "mpp" / "x402-solana" / "pay-kit"');
|
|
94
169
|
}
|
|
95
170
|
/**
|
|
96
171
|
* Disable a prior installTwzrdAutoGate on an x402 client (soft uninstall).
|
|
@@ -98,9 +173,12 @@ export function installTwzrdAutoGate(target, options) {
|
|
|
98
173
|
* Process-wide kill: TWZRD_GATE_ENABLED=false or TWZRD_AUTO_GATE=0.
|
|
99
174
|
*/
|
|
100
175
|
export function uninstallTwzrdAutoGate(client) {
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
176
|
+
const states = clientInstalls.get(client);
|
|
177
|
+
if (states?.length) {
|
|
178
|
+
// Every install, not just the newest: each wrapped hook closes over its own
|
|
179
|
+
// state, so missing one leaves that install still gating after uninstall.
|
|
180
|
+
for (const state of states)
|
|
181
|
+
state.disabled = true;
|
|
104
182
|
return;
|
|
105
183
|
}
|
|
106
184
|
console.warn("[twzrd-x402-gate] uninstallTwzrdAutoGate: no install state for this client (noop).");
|
package/dist/auto-gate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-gate.js","sourceRoot":"","sources":["../src/auto-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auto-gate.js","sourceRoot":"","sources":["../src/auto-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,cAAc,EAA0B,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACL,4BAA4B,EAC5B,kCAAkC,EAClC,0BAA0B,GAO3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yBAAyB,GAI1B,MAAM,eAAe,CAAC;AAoCvB;;6CAE6C;AAC7C,MAAM,cAAc,GAAG,IAAI,OAAO,EAAgC,CAAC;AAEnE,8DAA8D;AAC9D,MAAM,UAAU,uBAAuB,CAAC,OAAgC;IACtE,IAAI,OAAO,EAAE,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IACzC,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC5C,IAAI,IAAI,KAAK,GAAG,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