@valiron/sdk 2.0.0 → 2.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.
Files changed (38) hide show
  1. package/README.md +12 -0
  2. package/bin/valiron-card.mjs +211 -0
  3. package/dist/card.d.ts +565 -0
  4. package/dist/card.js +722 -0
  5. package/dist/clients.js +2 -2
  6. package/dist/edge.d.ts +87 -0
  7. package/dist/edge.js +164 -0
  8. package/dist/edgeGate.d.ts +146 -0
  9. package/dist/edgeGate.js +230 -0
  10. package/dist/edgeGateVerify.d.ts +146 -0
  11. package/dist/edgeGateVerify.js +243 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/middleware.d.ts +2 -0
  15. package/dist/middleware.js +6 -3
  16. package/dist/operatorSdk.d.ts +8 -0
  17. package/dist/operatorSdk.js +8 -0
  18. package/docs/API-REFERENCE.md +59 -80
  19. package/docs/CLOUDFLARE-GATE-MIDDLEWARE.md +196 -0
  20. package/docs/CRAWLER-PROTECTION.md +509 -25
  21. package/docs/DASHBOARD.md +72 -214
  22. package/docs/E2E-MIDDLEWARE-INTEGRATION.md +9 -46
  23. package/docs/ERRORS.md +3 -11
  24. package/docs/PROVIDER-IDENTITY.md +1 -1
  25. package/docs/QUICKSTART.md +7 -22
  26. package/docs/README.md +10 -9
  27. package/docs/SDK-REFERENCE.md +51 -7
  28. package/docs/SECURITY-UPGRADE-2026-10-31.md +3 -3
  29. package/docs/llms.txt +19 -14
  30. package/examples/cloudflare-gate-worker/README.md +198 -0
  31. package/examples/cloudflare-gate-worker/package.json +20 -0
  32. package/examples/cloudflare-gate-worker/worker.ts +309 -0
  33. package/examples/cloudflare-gate-worker/wrangler.toml +46 -0
  34. package/examples/cloudflare-worker/package.json +8 -0
  35. package/examples/cloudflare-worker/worker.ts +495 -0
  36. package/examples/cloudflare-worker/wrangler.toml +57 -0
  37. package/package.json +34 -4
  38. package/docs/AGENT-READY-APIS.md +0 -294
@@ -1,294 +0,0 @@
1
- # API Scaffolding
2
-
3
- API Scaffolding is a separate Valiron product for exposing existing HTTPS APIs through hosted, agent-facing URLs. It can add x402 or MPP payment handling, optional Valiron trust checks, rate limits, upstream forwarding, and usage logs without requiring immediate SDK middleware integration.
4
-
5
- Use this flow when Valiron should host the payment and optional trust layer for an existing HTTPS API:
6
-
7
- ```text
8
- Agent or client
9
- -> Valiron-hosted wrapper URL
10
- -> x402 or MPP payment check
11
- -> optional Valiron trust check
12
- -> provider's existing API
13
- -> response returned through Valiron
14
- ```
15
-
16
- > **Important: protect the origin.** A hosted wrapper evaluates and logs only
17
- > requests sent to its Valiron URL. It is not a network firewall in front of a
18
- > separately public API origin. If callers can reach your origin directly, they
19
- > can bypass the wrapper's payment, trust, rate-limit, and analytics path.
20
- > Publish the generated wrapper URL as the agent-facing URL and configure your
21
- > origin to accept only authenticated requests from Valiron.
22
-
23
- The wrapper is intentionally narrow: Valiron forwards valid HTTP requests to an existing upstream API. It does not need direct database access, internal service access, or provider infrastructure credentials beyond the optional upstream auth secret needed to call the API.
24
-
25
- ## When To Use This
26
-
27
- Use API Scaffolding when:
28
-
29
- - You already have an HTTPS API and want to sell per-call access to agents.
30
- - You want x402 or MPP payment challenges without implementing those protocols yourself.
31
- - You want Valiron trust checks before paid traffic reaches your API.
32
- - You need a no-code or low-code path from an existing API to an agent-compatible endpoint.
33
-
34
- Use the SDK middleware instead when:
35
-
36
- - You want payments to be handled entirely by your own server.
37
- - You need custom payment terms, subscriptions, account billing, or business-specific authorization.
38
- - Valiron should run directly in the API backend as the primary trust and policy enforcement layer.
39
-
40
- ## Provider Setup
41
-
42
- Providers configure one wrapper per public endpoint.
43
-
44
- | Field | Required | Description |
45
- |-------|----------|-------------|
46
- | Public path | Yes | Path callers use on Valiron, for example `/weather`. |
47
- | HTTP method | Yes | `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, or `HEAD`. |
48
- | Upstream base URL | Yes | Existing HTTPS API base URL, for example `https://api.example.com`. |
49
- | Price per call | Yes | USD amount charged for paid requests. Use `0` for a free wrapper. |
50
- | Payment protocol | Yes | `x402` or `MPP`. |
51
- | Payment network | Yes | x402: `eip155:8453` or `eip155:84532`; MPP: `tempo:4217` or `tempo:42431`. |
52
- | Payout wallet | Paid only | EVM address receiving payment. |
53
- | Upstream auth | Required to prevent origin bypass | Auth Valiron adds when forwarding to your upstream. Use `hmac` for a public origin. |
54
- | Rate limit | No | Max requests per minute per client. |
55
- | Trust check | No | Whether callers must pass Valiron agent trust evaluation before forwarding. |
56
-
57
- Example existing API:
58
-
59
- ```text
60
- GET https://api.example.com/weather
61
- ```
62
-
63
- Example Valiron URL:
64
-
65
- ```text
66
- GET https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/weather
67
- ```
68
-
69
- Valiron preserves query strings and appends the public wrapper path to the upstream base URL. If your upstream base URL is `https://api.example.com/v1` and your public path is `/weather`, Valiron forwards to:
70
-
71
- ```text
72
- https://api.example.com/v1/weather
73
- ```
74
-
75
- ## Dashboard Flow
76
-
77
- 1. Open [valiron.co/dashboard](https://www.valiron.co/dashboard).
78
- 2. Choose **API Scaffolding → Endpoints & testing**.
79
- 3. Click **Make API Agent-Ready**.
80
- 4. Enter the upstream URL, public path, method, price, protocol, network, and payout wallet.
81
- 5. Choose whether Valiron trust checks are required.
82
- 6. Configure upstream authentication. For a public origin, choose `hmac` and
83
- store the same secret in your origin's verification middleware.
84
- 7. Create the wrapper.
85
- 8. Distribute only the generated Valiron URL to agent clients or API customers.
86
- 9. Verify that a direct request to your origin is rejected and a request to the
87
- wrapper is recorded in Valiron call logs.
88
-
89
- Create, list, and deactivate wrappers in the dashboard.
90
-
91
- ## Calling A Wrapper
92
-
93
- Call the generated URL directly:
94
-
95
- ```bash
96
- curl -i https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/weather
97
- ```
98
-
99
- For a free wrapper, Valiron forwards immediately and returns the upstream response with Valiron wrapper headers:
100
-
101
- ```text
102
- x-valiron-wrapper-id: ...
103
- x-valiron-payment-protocol: free
104
- x-valiron-trust-enabled: false
105
- ```
106
-
107
- For a paid x402 wrapper without payment, Valiron returns `402` and an x402 payment challenge:
108
-
109
- ```text
110
- HTTP/1.1 402 Payment Required
111
- x-payment-required: ...
112
- ```
113
-
114
- For a paid MPP wrapper without payment, Valiron returns `402` and an MPP challenge:
115
-
116
- ```text
117
- HTTP/1.1 402 Payment Required
118
- WWW-Authenticate: Payment ...
119
- ```
120
-
121
- ## x402 Paid Client
122
-
123
- Use an x402-capable client to retry with payment. The example below uses:
124
-
125
- - `@x402/fetch`
126
- - `@x402/core/client`
127
- - `@x402/evm/exact/client`
128
- - `viem/accounts`
129
-
130
- Minimal client shape:
131
-
132
- ```typescript
133
- import { wrapFetchWithPayment } from "@x402/fetch";
134
- import { x402Client } from "@x402/core/client";
135
- import { ExactEvmScheme } from "@x402/evm/exact/client";
136
- import { privateKeyToAccount } from "viem/accounts";
137
-
138
- const account = privateKeyToAccount(process.env.BUYER_PRIVATE_KEY as `0x${string}`);
139
-
140
- const client = new x402Client();
141
- client.register("eip155:*", new ExactEvmScheme(account));
142
-
143
- const fetchWithPayment = wrapFetchWithPayment(fetch, client);
144
-
145
- const response = await fetchWithPayment(
146
- "https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/weather",
147
- { method: "GET", headers: { "x-agent-id": "25459" } }
148
- );
149
-
150
- console.log(response.status);
151
- console.log(await response.text());
152
- ```
153
-
154
- The buyer wallet must hold the required token on the selected x402 network. For Base mainnet, the default production path expects USDC on Base.
155
-
156
- ## MPP Paid Client
157
-
158
- Valiron MPP support uses the official `mppx` SDK with the Tempo `charge` intent.
159
-
160
- Server behavior:
161
-
162
- - Unpaid request returns `402`.
163
- - Response includes `WWW-Authenticate: Payment ...`.
164
- - Paid request includes `Authorization: Payment ...`.
165
- - Successful paid response includes `Payment-Receipt`.
166
-
167
- Recommended testnet client flow:
168
-
169
- ```bash
170
- pnpm exec mppx account create
171
- pnpm exec mppx https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/research
172
- ```
173
-
174
- Use `tempo:42431` for Tempo testnet and `tempo:4217` for Tempo mainnet.
175
-
176
- Default Tempo currencies from `mppx`:
177
-
178
- | Network | Chain ID | Default currency |
179
- |---------|----------|------------------|
180
- | Tempo mainnet | `4217` | USDC (`0x20C000000000000000000000b9537d11c60E8b50`) |
181
- | Tempo testnet | `42431` | pathUSD (`0x20c0000000000000000000000000000000000000`) |
182
-
183
- ## Optional Trust Checks
184
-
185
- When `trustEnabled` is `false`, Valiron only handles payment, rate limiting, upstream auth, and forwarding.
186
-
187
- When `trustEnabled` is `true`, callers must identify the agent:
188
-
189
- ```text
190
- x-agent-id: 25459
191
- ```
192
-
193
- Valiron evaluates the agent before forwarding. If the agent is denied, the upstream API is not called.
194
-
195
- Use trust checks when:
196
-
197
- - You want to block risky agents even if they can pay.
198
- - You want route decisions and call logs tied to agent IDs.
199
- - You plan to vary pricing, limits, or access based on trust tiers.
200
-
201
- Use payment-only wrappers when:
202
-
203
- - You want the lowest-friction paid endpoint.
204
- - You do not need agent identity yet.
205
- - You are testing x402 or MPP integration.
206
-
207
- ## Upstream Auth
208
-
209
- Valiron stores the configured secret encrypted and injects or derives it only
210
- when forwarding a request that has reached the wrapper. This is how your origin
211
- distinguishes an authenticated wrapper request from a direct public request.
212
-
213
- For a public API origin, configure upstream authentication before announcing or
214
- indexing the wrapper. Otherwise, a caller can send traffic directly to the
215
- origin and bypass Valiron entirely. `none` is appropriate only when the origin
216
- is already inaccessible to untrusted callers or bypass is intentionally
217
- acceptable.
218
-
219
- Supported auth modes:
220
-
221
- | Mode | Behavior |
222
- |------|----------|
223
- | `none` | No upstream auth is added. |
224
- | `bearer` | Adds `Authorization: Bearer <secret>`. |
225
- | `api_key` | Adds the secret to the configured header name. |
226
- | `hmac` | Signs the request using the secret and adds signature headers. |
227
-
228
- The calling agent never sees your upstream secret.
229
-
230
- ### Recommended production pattern: HMAC origin verification
231
-
232
- Choose `hmac` for an origin that is publicly reachable. Valiron sends:
233
-
234
- ```text
235
- x-valiron-signature: sha256=<hex HMAC>
236
- x-valiron-timestamp: <Unix seconds>
237
- ```
238
-
239
- Your origin must reject requests when the signature is missing, invalid, or too
240
- old. Verify the signature against the request method, public wrapper path, raw
241
- body SHA-256, and timestamp with the shared secret configured on the wrapper.
242
- Use constant-time signature comparison and a short timestamp window to reduce
243
- replay risk.
244
-
245
- Do **not** treat headers such as `x-valiron-wrapper-id`,
246
- `x-valiron-payment-protocol`, or `x-valiron-trust-enabled` as proof that a
247
- request came through Valiron. They are request metadata, not a credential, and
248
- can be forged by a caller that reaches your origin directly.
249
-
250
- ### Origin-lockdown checklist
251
-
252
- Before production:
253
-
254
- 1. Set `upstreamAuthType` to `hmac` and configure a unique secret.
255
- 2. Deploy origin middleware that verifies the HMAC and timestamp before the API
256
- handler runs.
257
- 3. Make the Valiron `/wrap/{operatorId}/{path}` URL the only public URL in
258
- agent discovery metadata, examples, and client configuration.
259
- 4. Send a direct request to the origin without the signature and confirm a
260
- `401` or `403` response.
261
- 5. Send a request through the wrapper and confirm the expected payment/trust
262
- result and a corresponding Valiron call-log entry.
263
-
264
- ## Security Defaults
265
-
266
- In production, Valiron wrappers:
267
-
268
- - Require HTTPS upstream URLs.
269
- - Block localhost, private IP ranges, link-local IPs, metadata hosts, and internal hostnames.
270
- - Resolve upstream DNS and block private resolved IPs.
271
- - Strip hop-by-hop and sensitive inbound headers before forwarding.
272
- - Do not forward inbound `Authorization`, `Cookie`, `x-payment`, or `payment-signature` headers to the upstream.
273
- - Add Valiron wrapper metadata headers to forwarded requests.
274
- - Apply per-endpoint rate limits.
275
- - Enforce request body size limits.
276
- - Time out slow upstream calls.
277
-
278
- ## Current Limits
279
-
280
- The first wrapper release supports:
281
-
282
- - Per-call x402 payments.
283
- - Per-call MPP Tempo charge payments.
284
- - Free wrappers.
285
- - Optional trust checks.
286
- - Optional upstream auth injection.
287
- - Per-endpoint rate limits.
288
-
289
- It does not yet support:
290
-
291
- - MPP sessions or subscriptions.
292
- - Multi-upstream routing.
293
- - Cross-protocol fallback on a single endpoint.
294
- - Non-HTTPS production upstreams.