@reinconsole/gate 0.1.0
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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.cjs +864 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +561 -0
- package/dist/index.d.ts +561 -0
- package/dist/index.js +844 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rein contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @reinconsole/gate
|
|
2
|
+
|
|
3
|
+
The supply side of **[Rein](https://github.com/bugiiiii11/rein)** — vendor-side [x402](https://www.x402.org) monetization middleware. Price your routes once and every payment into your API is quoted, cross-checked, screened, rate-limited, settled, and receipted before your handler runs.
|
|
4
|
+
|
|
5
|
+
> **Status: v0.1 — early open-source infrastructure, live on testnet.** Verified live on Base Sepolia against the hosted x402.org facilitator. APIs may change before 1.0. See it running: [Rein console](https://reinconsole-production.up.railway.app/).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @reinconsole/gate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createGate, gateMiddleware, facilitatorClientRails } from '@reinconsole/gate';
|
|
17
|
+
|
|
18
|
+
const gate = createGate({
|
|
19
|
+
routes: [
|
|
20
|
+
{ path: '/api/answer', price: '0.05', description: 'one research answer' },
|
|
21
|
+
{ path: '/api/premium/*', method: 'POST', price: '0.25' },
|
|
22
|
+
],
|
|
23
|
+
rails: facilitatorClientRails(facilitator), // or mockFacilitatorRails(...) offline
|
|
24
|
+
payTo: '0xYourTreasury…',
|
|
25
|
+
network: 'base-sepolia',
|
|
26
|
+
asset: USDC_ADDRESS,
|
|
27
|
+
screen: { denyPayers: ['0xKnownMule…'] },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app.use(gateMiddleware(gate)); // Express, or wrap any node:http handler
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
In-process instead? `createGatedFetch(...)` turns the same gate into a `fetch`-shaped vendor for tests and agent loops.
|
|
34
|
+
|
|
35
|
+
## What it does that a bare 402 snippet doesn't
|
|
36
|
+
|
|
37
|
+
- **Quote consistency.** A presented payment must match the gate's own quote — scheme, network, amount, recipient — before any facilitator round-trip. Underpayment is refused at the door.
|
|
38
|
+
- **Payer screening.** Allow/deny lists plus a dynamic `screen.check` hook (reputation plugs in here — see [`@reinconsole/graph`](https://www.npmjs.com/package/@reinconsole/graph)'s `payerCheck`), checked *before* verify/settle, so a blocked payer costs you nothing.
|
|
39
|
+
- **Replay protection.** Each payment settles once; the slot is burned before the async legs, so two concurrent copies can't both pass.
|
|
40
|
+
- **Velocity caps + rate limiting.** Per-payer settled-spend caps (`maxPayments` / `maxAmount`) and a sliding-window presentation limiter (`maxAttempts` → 429 + `Retry-After`). Throttle refusals happen before the replay burn, so a held payment clears once the window slides.
|
|
41
|
+
- **Honest rails failures.** Provably-unsent transport failures are retried, then refused `rails_unavailable` with the replay slot released; an ambiguous settle refuses `settle_unknown` with the slot kept burned — the money may have moved, and the gate never guesses.
|
|
42
|
+
- **Receipts + revenue.** Every settlement becomes a `GateReceipt`; `gate.stats()` aggregates revenue by asset, route, and payer; `quoted` / `settled` / `refused` events stream on the bus.
|
|
43
|
+
- **x402 v2 dual-stack.** Accepts both payment dialects always; `advertiseV2` adds the v2 `PAYMENT-REQUIRED` header quote beside the v1 body; CAIP-2 and v1 network ids normalize in consistency checks.
|
|
44
|
+
- **Pluggable rails.** The same gate runs against the mock facilitator ([`@reinconsole/mock-rails`](https://www.npmjs.com/package/@reinconsole/mock-rails)) or the real hosted facilitator ([`@reinconsole/x402-rails`](https://www.npmjs.com/package/@reinconsole/x402-rails)) — a two-method structural seam.
|
|
45
|
+
|
|
46
|
+
MIT © Rein contributors · [Repository](https://github.com/bugiiiii11/rein) · [Issues](https://github.com/bugiiiii11/rein/issues)
|