@valiron/sdk 0.12.0 → 1.0.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/README.md +18 -5
- package/dist/clients.d.ts +28 -64
- package/dist/clients.js +39 -176
- package/dist/identity.d.ts +5 -69
- package/dist/identity.js +6 -108
- package/dist/index.d.ts +64 -117
- package/dist/index.js +69 -131
- package/dist/middleware.d.ts +54 -24
- package/dist/middleware.js +307 -44
- package/dist/operatorSdk.d.ts +13 -2
- package/dist/operatorSdk.js +2 -2
- package/dist/types.d.ts +63 -89
- package/docs/API-REFERENCE.md +496 -190
- package/docs/DASHBOARD.md +253 -0
- package/docs/ERRORS.md +43 -0
- package/docs/IDENTITY.md +71 -0
- package/docs/QUICKSTART.md +50 -60
- package/docs/README.md +1 -1
- package/docs/SANDBOX.md +53 -16
- package/docs/SDK-REFERENCE.md +309 -174
- package/docs/TRUST-MODEL.md +2 -27
- package/docs/llms.txt +63 -25
- package/package.json +1 -1
package/docs/SDK-REFERENCE.md
CHANGED
|
@@ -216,13 +216,7 @@ interface SandboxResult {
|
|
|
216
216
|
tier: MoodysRating; // "AAA" | "AA" | "A" | "BAA" | "BA" | "B" | "CAA" | "CA" | "C"
|
|
217
217
|
riskLevel: "GREEN" | "YELLOW" | "RED";
|
|
218
218
|
meetsThreshold: boolean;
|
|
219
|
-
testSummary:
|
|
220
|
-
totalRequests: number;
|
|
221
|
-
successCount: number;
|
|
222
|
-
rateLimitCount: number;
|
|
223
|
-
errorCount: number;
|
|
224
|
-
avgLatencyMs: number;
|
|
225
|
-
};
|
|
219
|
+
testSummary: object; // Opaque test metrics (structure is proprietary)
|
|
226
220
|
chain: ChainContext;
|
|
227
221
|
message: string;
|
|
228
222
|
}
|
|
@@ -236,6 +230,41 @@ console.log(result.riskLevel); // "GREEN"
|
|
|
236
230
|
console.log(result.meetsThreshold); // true
|
|
237
231
|
```
|
|
238
232
|
|
|
233
|
+
> **Auto-sandbox:** The middleware (`createValironGate`, `valironFastifyPlugin`, `createValironNextMiddleware`, `valironGateCheck`) automatically triggers `triggerSandboxTest()` in the background for new on-chain agents (those with `totalFeedback === 0`). The agent receives a 403 with `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` while evaluation runs. No manual trigger is needed.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### triggerKeyAgentSandbox(agentAddress)
|
|
238
|
+
|
|
239
|
+
Run sandbox tests against a key-based (Web2) agent and compute a trust evaluation. Key agents don't have on-chain endpoints, so this uses the `sandbox_relay` mode internally.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const result = await valiron.triggerKeyAgentSandbox(agentAddress: string): Promise<KeyAgentSandboxResult>;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Returns**: `KeyAgentSandboxResult`
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface KeyAgentSandboxResult {
|
|
249
|
+
ok: boolean;
|
|
250
|
+
agentAddress: string;
|
|
251
|
+
valironScore: number;
|
|
252
|
+
tier: MoodysRating;
|
|
253
|
+
riskLevel: "GREEN" | "YELLOW" | "RED";
|
|
254
|
+
message: string;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Example**:
|
|
259
|
+
```typescript
|
|
260
|
+
const result = await valiron.triggerKeyAgentSandbox("0x1234...abcd");
|
|
261
|
+
console.log(result.tier); // "A"
|
|
262
|
+
console.log(result.riskLevel); // "GREEN"
|
|
263
|
+
console.log(result.valironScore); // 85
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
> **Auto-sandbox:** The middleware automatically triggers `triggerKeyAgentSandbox()` in the background for new key agents (those with `verified === true` but `score === null`). The agent receives a 403 with `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` while evaluation runs.
|
|
267
|
+
|
|
239
268
|
---
|
|
240
269
|
|
|
241
270
|
### gate(agentId, options?)
|
|
@@ -321,22 +350,30 @@ console.log(snapshot.interactionCount); // 15
|
|
|
321
350
|
|
|
322
351
|
Express-compatible middleware factory. Automatically gates requests based on agent trust.
|
|
323
352
|
|
|
353
|
+
Uses the public `getAgentProfile()` endpoint under the hood (not the protected `gate()` endpoint), so it works from any server context — no agent challenge-response auth required.
|
|
354
|
+
|
|
355
|
+
**Express 4 safe**: The returned middleware wraps the async handler with `Promise.resolve(handler(...)).catch(next)` so async rejections are properly forwarded to Express's error handler. This prevents race conditions when chained with other async middleware (e.g. x402's `paymentMiddleware`).
|
|
356
|
+
|
|
324
357
|
```typescript
|
|
325
358
|
import { ValironSDK, createValironGate } from "@valiron/sdk";
|
|
326
359
|
|
|
327
360
|
const gate = createValironGate(config: {
|
|
328
361
|
sdk: ValironSDK;
|
|
329
|
-
|
|
330
|
-
|
|
362
|
+
minScore?: number; // default: 65
|
|
363
|
+
cacheTtlMs?: number; // default: 30000 (30s client-side cache)
|
|
364
|
+
extractAgentId?: (req: Request) => string | null;
|
|
365
|
+
extractAgentAddress?: (req: Request) => string | null;
|
|
331
366
|
onAllow?: (req: Request, result: GateResult) => void;
|
|
332
367
|
onDeny?: (req: Request, res: Response, result: GateResult) => void;
|
|
333
368
|
});
|
|
334
369
|
```
|
|
335
370
|
|
|
336
371
|
**Default behavior**:
|
|
337
|
-
- Extracts agent ID from `x-agent-id`
|
|
372
|
+
- Extracts agent ID from `x-agent-id` header (on-chain) or `x-agent-address` header (key-based)
|
|
373
|
+
- Returns 401 if no agent identity is found (with link to identity skill)
|
|
338
374
|
- Returns 403 if agent is denied
|
|
339
|
-
- Returns
|
|
375
|
+
- Returns 503 if the trust gate is unreachable (fail-closed)
|
|
376
|
+
- Caches profiles in memory for 30s to survive x402 retry flows
|
|
340
377
|
|
|
341
378
|
**Example**:
|
|
342
379
|
```typescript
|
|
@@ -345,10 +382,11 @@ const valiron = new ValironSDK({ chain: "monad" });
|
|
|
345
382
|
// Basic gate
|
|
346
383
|
app.use("/api/paid", createValironGate({ sdk: valiron }));
|
|
347
384
|
|
|
348
|
-
// Custom
|
|
385
|
+
// Custom threshold + longer cache
|
|
349
386
|
app.use("/api/premium", createValironGate({
|
|
350
387
|
sdk: valiron,
|
|
351
|
-
|
|
388
|
+
minScore: 85,
|
|
389
|
+
cacheTtlMs: 60_000, // 60s
|
|
352
390
|
}));
|
|
353
391
|
|
|
354
392
|
// Custom agent ID extraction
|
|
@@ -379,235 +417,332 @@ Call this when shutting down long-running processes.
|
|
|
379
417
|
|
|
380
418
|
---
|
|
381
419
|
|
|
382
|
-
##
|
|
420
|
+
## Proxy Gateway (Pro)
|
|
383
421
|
|
|
384
|
-
|
|
422
|
+
Forward requests through Valiron's edge proxy with automatic trust gating, logging, and SSRF protection.
|
|
385
423
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
### channelPreflight(agentId, walletAddress)
|
|
389
|
-
|
|
390
|
-
Pre-flight gate check. Returns the agent's trust tier, credit line, and the escrow address to deposit USDC to.
|
|
424
|
+
### proxy(request)
|
|
391
425
|
|
|
392
426
|
```typescript
|
|
393
|
-
const
|
|
394
|
-
agentId: string,
|
|
395
|
-
walletAddress: string,
|
|
396
|
-
): Promise<ChannelPreflightResponse>;
|
|
427
|
+
const result = await valiron.proxy(request: ProxyRequest): Promise<ProxyResponse>;
|
|
397
428
|
```
|
|
398
429
|
|
|
399
|
-
|
|
430
|
+
#### ProxyRequest
|
|
400
431
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
432
|
+
| Field | Type | Required | Description |
|
|
433
|
+
|-------|------|----------|-------------|
|
|
434
|
+
| `agentId` | string | yes | Agent to gate |
|
|
435
|
+
| `targetUrl` | string | yes | Your origin URL to forward to |
|
|
436
|
+
| `method` | string | no | HTTP method (default: `GET`) |
|
|
437
|
+
| `headers` | Record<string, string> | no | Headers to forward |
|
|
438
|
+
| `body` | string | no | Request body |
|
|
439
|
+
|
|
440
|
+
#### ProxyResponse
|
|
441
|
+
|
|
442
|
+
| Field | Type | Description |
|
|
443
|
+
|-------|------|-------------|
|
|
444
|
+
| `statusCode` | number | HTTP status from your origin |
|
|
445
|
+
| `responseHeaders` | Record<string, string> | Response headers |
|
|
446
|
+
| `responseBody` | string | Response body |
|
|
447
|
+
| `responseMs` | number | Round-trip latency |
|
|
448
|
+
| `costCharged` | string | USD cost charged |
|
|
449
|
+
| `route` | string | Route decision applied |
|
|
450
|
+
| `tierResolved` | string | Trust tier used |
|
|
414
451
|
|
|
415
452
|
**Example**:
|
|
416
453
|
```typescript
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
454
|
+
const result = await valiron.proxy({
|
|
455
|
+
agentId: "25459",
|
|
456
|
+
targetUrl: "https://your-api.com/data",
|
|
457
|
+
method: "POST",
|
|
458
|
+
headers: { "Content-Type": "application/json" },
|
|
459
|
+
body: JSON.stringify({ query: "example" }),
|
|
460
|
+
});
|
|
422
461
|
```
|
|
423
462
|
|
|
424
|
-
**
|
|
425
|
-
|
|
426
|
-
| Tier | Credit Line | Duration | Max Requests |
|
|
427
|
-
|------|-------------|----------|--------------|
|
|
428
|
-
| AAA | $100 | 60 min | unlimited |
|
|
429
|
-
| AA | $50 | 45 min | unlimited |
|
|
430
|
-
| A | $25 | 30 min | unlimited |
|
|
431
|
-
| BAA | $10 | 20 min | 100 |
|
|
432
|
-
| BA | $5 | 15 min | 50 |
|
|
433
|
-
| B | $1 | 10 min | 10 |
|
|
463
|
+
> **SSRF Protection:** The proxy blocks requests to private IPs (10.x, 172.16-31.x, 192.168.x), localhost, link-local addresses, and cloud metadata endpoints (169.254.169.254).
|
|
434
464
|
|
|
435
465
|
---
|
|
436
466
|
|
|
437
|
-
|
|
467
|
+
## Key-Based Agents
|
|
438
468
|
|
|
439
|
-
|
|
469
|
+
For Web2 agents that don't have on-chain identities, Valiron supports key-based authentication using EIP-191 challenge-response.
|
|
440
470
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
471
|
+
**How it works:**
|
|
472
|
+
1. Agent sends a request with `x-agent-address: 0x...` header
|
|
473
|
+
2. Valiron returns a challenge nonce
|
|
474
|
+
3. Agent signs the nonce with their private key
|
|
475
|
+
4. Valiron verifies the signature and creates a `KeyAgentProfile`
|
|
476
|
+
|
|
477
|
+
The SDK auto-detects key-based agents from the `x-agent-address` header. No configuration needed.
|
|
478
|
+
|
|
479
|
+
### Sandbox Evaluation for Key Agents
|
|
448
480
|
|
|
449
|
-
|
|
481
|
+
New key agents (verified but not yet scored) are automatically evaluated when they first hit a gated endpoint. The middleware triggers `triggerKeyAgentSandbox()` in the background and returns 403 with `retryAfterMs: 30000`. After evaluation completes, the agent receives a trust score and can access endpoints normally.
|
|
482
|
+
|
|
483
|
+
You can also trigger evaluation manually:
|
|
450
484
|
|
|
451
485
|
```typescript
|
|
452
|
-
|
|
453
|
-
sessionId: string; // use this for consume/status/settle
|
|
454
|
-
agentId: string;
|
|
455
|
-
tier: string;
|
|
456
|
-
score: number;
|
|
457
|
-
riskLevel: string;
|
|
458
|
-
creditLine: string;
|
|
459
|
-
creditLineReadable: string;
|
|
460
|
-
maxRequests: number | null;
|
|
461
|
-
expiresAt: string; // ISO 8601
|
|
462
|
-
durationSeconds: number;
|
|
463
|
-
depositConfirmed: boolean;
|
|
464
|
-
depositSignature: string;
|
|
465
|
-
escrowAddress: string;
|
|
466
|
-
}
|
|
486
|
+
const result = await valiron.triggerKeyAgentSandbox("0x1234...abcd");
|
|
467
487
|
```
|
|
468
488
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
"7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
|
|
474
|
-
"5eykt4UsFv8P8njDFTxgkW8oVTc4BM3dTCrssAtMJDVmqYS5",
|
|
475
|
-
);
|
|
476
|
-
console.log(channel.sessionId); // "ch_a1b2c3..."
|
|
477
|
-
console.log(channel.creditLineReadable); // "$50.00"
|
|
478
|
-
console.log(channel.expiresAt); // "2026-04-23T13:45:00.000Z"
|
|
489
|
+
Or via HTTP:
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox-key/0x1234...abcd
|
|
479
493
|
```
|
|
480
494
|
|
|
495
|
+
### KeyAgentProfile
|
|
496
|
+
|
|
497
|
+
| Field | Type | Description |
|
|
498
|
+
|-------|------|-------------|
|
|
499
|
+
| `address` | string | Ethereum address |
|
|
500
|
+
| `isKeyAgent` | boolean | Always `true` |
|
|
501
|
+
| `tier` | string | Trust tier (starts at C, can improve) |
|
|
502
|
+
| `riskLevel` | string | GREEN / YELLOW / RED |
|
|
503
|
+
| `route` | string | Route decision |
|
|
504
|
+
| `firstSeen` | string | ISO timestamp of first interaction |
|
|
505
|
+
| `totalRequests` | number | Lifetime request count |
|
|
506
|
+
|
|
481
507
|
---
|
|
482
508
|
|
|
483
|
-
|
|
509
|
+
## World ID Methods
|
|
484
510
|
|
|
485
|
-
|
|
511
|
+
Verify agent-human linkage via Worldcoin's zero-knowledge proof system.
|
|
486
512
|
|
|
487
|
-
|
|
488
|
-
const usage = await valiron.channelConsume(
|
|
489
|
-
sessionId: string,
|
|
490
|
-
cost: number,
|
|
491
|
-
description?: string,
|
|
492
|
-
): Promise<ChannelConsumeResponse>;
|
|
493
|
-
```
|
|
513
|
+
### verifyWorldId(agentId, proof, options?)
|
|
494
514
|
|
|
495
|
-
|
|
515
|
+
Submit a World ID proof for verification.
|
|
496
516
|
|
|
497
517
|
```typescript
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
costReadable: string;
|
|
502
|
-
description?: string;
|
|
503
|
-
session: {
|
|
504
|
-
consumed: string;
|
|
505
|
-
consumedReadable: string;
|
|
506
|
-
remaining: string;
|
|
507
|
-
remainingReadable: string;
|
|
508
|
-
requestCount: number;
|
|
509
|
-
maxRequests: number | null;
|
|
510
|
-
secondsRemaining: number;
|
|
511
|
-
};
|
|
512
|
-
}
|
|
518
|
+
const result = await valiron.verifyWorldId(agentId: string, proof: WorldIdProof, options?: {
|
|
519
|
+
chain?: SupportedChain;
|
|
520
|
+
}): Promise<WorldIdVerificationResult>;
|
|
513
521
|
```
|
|
514
522
|
|
|
515
523
|
**Example**:
|
|
516
524
|
```typescript
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
525
|
+
const result = await valiron.verifyWorldId("25459", {
|
|
526
|
+
merkle_root: "0x...",
|
|
527
|
+
nullifier_hash: "0x...",
|
|
528
|
+
proof: "0x...",
|
|
529
|
+
signal: "0x...",
|
|
530
|
+
});
|
|
521
531
|
```
|
|
522
532
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
### channelStatus(sessionId)
|
|
533
|
+
### getWorldIdStatus(agentId, options?)
|
|
526
534
|
|
|
527
|
-
|
|
535
|
+
Check if an agent has a verified World ID.
|
|
528
536
|
|
|
529
537
|
```typescript
|
|
530
|
-
const status = await valiron.
|
|
531
|
-
|
|
532
|
-
): Promise<
|
|
538
|
+
const status = await valiron.getWorldIdStatus(agentId: string, options?: {
|
|
539
|
+
chain?: SupportedChain;
|
|
540
|
+
}): Promise<WorldIdStatus>;
|
|
541
|
+
// { verified: true, verifiedAt: "2025-01-15T...", level: "orb" }
|
|
533
542
|
```
|
|
534
543
|
|
|
535
|
-
|
|
544
|
+
### getWorldIdProfile(agentId, options?)
|
|
545
|
+
|
|
546
|
+
Get full World ID profile including verification details.
|
|
536
547
|
|
|
537
548
|
```typescript
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
tier: string;
|
|
542
|
-
creditLine: string;
|
|
543
|
-
creditLineReadable: string;
|
|
544
|
-
consumed: string;
|
|
545
|
-
consumedReadable: string;
|
|
546
|
-
remaining: string;
|
|
547
|
-
remainingReadable: string;
|
|
548
|
-
requestCount: number;
|
|
549
|
-
maxRequests: number | null;
|
|
550
|
-
expiresAt: string;
|
|
551
|
-
secondsRemaining: number;
|
|
552
|
-
active: boolean;
|
|
553
|
-
settled: boolean;
|
|
554
|
-
}
|
|
549
|
+
const profile = await valiron.getWorldIdProfile(agentId: string, options?: {
|
|
550
|
+
chain?: SupportedChain;
|
|
551
|
+
}): Promise<WorldIdAgentProfile>;
|
|
555
552
|
```
|
|
556
553
|
|
|
554
|
+
---
|
|
555
|
+
|
|
556
|
+
## Telemetry
|
|
557
|
+
|
|
558
|
+
The SDK optionally collects anonymous usage metrics (gate calls, latency, error rates). Telemetry is opt-in and can be fully disabled.
|
|
559
|
+
|
|
560
|
+
### TelemetryConfig
|
|
561
|
+
|
|
562
|
+
| Field | Type | Default | Description |
|
|
563
|
+
|-------|------|---------|-------------|
|
|
564
|
+
| `enabled` | boolean | `true` | Enable/disable telemetry |
|
|
565
|
+
| `sampleRate` | number | `1.0` | Fraction of events to sample (0–1) |
|
|
566
|
+
| `handler` | function | — | Custom event handler |
|
|
567
|
+
|
|
557
568
|
**Example**:
|
|
558
569
|
```typescript
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
570
|
+
const valiron = new ValironSDK({
|
|
571
|
+
telemetry: {
|
|
572
|
+
enabled: false, // Disable entirely
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// Or with custom sampling and handler
|
|
577
|
+
const valiron = new ValironSDK({
|
|
578
|
+
telemetry: {
|
|
579
|
+
sampleRate: 0.1, // Sample 10% of events
|
|
580
|
+
handler: (event) => { // Custom handler
|
|
581
|
+
myAnalytics.track(event);
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
});
|
|
563
585
|
```
|
|
564
586
|
|
|
565
587
|
---
|
|
566
588
|
|
|
567
|
-
|
|
589
|
+
## Middleware
|
|
590
|
+
|
|
591
|
+
All middleware adapters use `getAgentProfile()` (public endpoint) rather than
|
|
592
|
+
`gate()` (protected endpoint), so they work from any server context without
|
|
593
|
+
agent challenge-response auth. Results are cached client-side (default 30s)
|
|
594
|
+
to survive x402's two-request payment flow and avoid cold-start failures.
|
|
595
|
+
|
|
596
|
+
### createValironGate(config) — Express
|
|
597
|
+
|
|
598
|
+
See above for full documentation.
|
|
568
599
|
|
|
569
|
-
|
|
600
|
+
**Express 4 note**: The returned middleware uses a synchronous wrapper
|
|
601
|
+
(`Promise.resolve().catch(next)`) to ensure async errors are properly caught.
|
|
602
|
+
You do NOT need to wrap it yourself — it's safe to use directly with
|
|
603
|
+
`app.use()` even on Express 4.
|
|
604
|
+
|
|
605
|
+
### valironFastifyPlugin — Fastify
|
|
570
606
|
|
|
571
607
|
```typescript
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
608
|
+
import { ValironSDK, valironFastifyPlugin } from "@valiron/sdk";
|
|
609
|
+
|
|
610
|
+
const valiron = new ValironSDK({ chain: "monad" });
|
|
611
|
+
|
|
612
|
+
fastify.register(valironFastifyPlugin, {
|
|
613
|
+
sdk: valiron,
|
|
614
|
+
prefix: "/api/paid",
|
|
615
|
+
});
|
|
575
616
|
```
|
|
576
617
|
|
|
577
|
-
|
|
618
|
+
### createValironNextMiddleware — Next.js
|
|
578
619
|
|
|
579
620
|
```typescript
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
unusedCreditReadable: string;
|
|
588
|
-
refundAmount?: string;
|
|
589
|
-
refundReadable?: string;
|
|
590
|
-
refundSignature?: string; // Solana TX signature
|
|
591
|
-
refundWarning?: string; // set if refund failed
|
|
592
|
-
}
|
|
621
|
+
import { ValironSDK, createValironNextMiddleware } from "@valiron/sdk";
|
|
622
|
+
|
|
623
|
+
const valiron = new ValironSDK();
|
|
624
|
+
export default createValironNextMiddleware({
|
|
625
|
+
sdk: valiron,
|
|
626
|
+
paths: ["/api/paid"],
|
|
627
|
+
});
|
|
593
628
|
```
|
|
594
629
|
|
|
595
|
-
|
|
630
|
+
### valironGateCheck — Generic (Hono, Koa, etc.)
|
|
631
|
+
|
|
596
632
|
```typescript
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
633
|
+
import { ValironSDK, valironGateCheck } from "@valiron/sdk";
|
|
634
|
+
|
|
635
|
+
const valiron = new ValironSDK();
|
|
636
|
+
|
|
637
|
+
app.use(async (c, next) => {
|
|
638
|
+
const gate = await valironGateCheck(valiron, {
|
|
639
|
+
agentId: c.req.header("x-agent-id") ?? null,
|
|
640
|
+
agentAddress: c.req.header("x-agent-address") ?? null,
|
|
641
|
+
});
|
|
642
|
+
if (!gate.allow) return c.json(gate.body, gate.status);
|
|
643
|
+
c.set("valiron", gate.result);
|
|
644
|
+
await next();
|
|
645
|
+
});
|
|
601
646
|
```
|
|
602
647
|
|
|
648
|
+
### Client-Side Caching
|
|
649
|
+
|
|
650
|
+
All middleware adapters include a built-in in-memory cache (default TTL: 30 seconds).
|
|
651
|
+
This is important for payment protocols like x402 that make two requests per payment
|
|
652
|
+
(discover 402 → retry with payment). Without caching, the second trust check can fail
|
|
653
|
+
due to cold-start latency on the edge proxy.
|
|
654
|
+
|
|
655
|
+
The Express gate exposes `cacheTtlMs` to override this TTL; set it to `0` to disable
|
|
656
|
+
caching for that middleware instance. `createValironNextMiddleware` and
|
|
657
|
+
`valironGateCheck` also accept `cacheTtlMs`.
|
|
658
|
+
|
|
659
|
+
### Middleware Error Responses
|
|
660
|
+
|
|
661
|
+
All middleware variants return consistent error responses:
|
|
662
|
+
|
|
663
|
+
| Status | When | Body |
|
|
664
|
+
|--------|------|------|
|
|
665
|
+
| 401 | No agent ID found in request | `{ error: "No agent identity provided" }` |
|
|
666
|
+
| 403 | Agent denied by trust gate | `{ error: "Access denied", tier, riskLevel, route }` |
|
|
667
|
+
| 403 | New agent pending evaluation | `{ error: "Agent pending evaluation", retryAfterMs: 30000 }` |
|
|
668
|
+
| 503 | Valiron service unavailable | `{ error: "Trust evaluation unavailable" }` |
|
|
669
|
+
|
|
670
|
+
> **Fail-closed:** When the Valiron service is unreachable, middleware returns 503 — it never fails open and never allows unverified agents through.
|
|
671
|
+
|
|
603
672
|
---
|
|
604
673
|
|
|
605
|
-
|
|
674
|
+
## Response Types
|
|
675
|
+
|
|
676
|
+
### GateResult
|
|
677
|
+
|
|
678
|
+
Returned by `gate()` and middleware.
|
|
679
|
+
|
|
680
|
+
| Field | Type | Description |
|
|
681
|
+
|-------|------|-------------|
|
|
682
|
+
| `allow` | boolean | Whether the agent is allowed access |
|
|
683
|
+
| `tier` | string | Trust tier (AAA–C) |
|
|
684
|
+
| `riskLevel` | string | GREEN / YELLOW / RED |
|
|
685
|
+
| `route` | string | `prod` / `prod_throttled` / `sandbox` / `sandbox_only` |
|
|
686
|
+
| `meetsThreshold` | boolean | Whether the agent meets the minimum trust threshold |
|
|
687
|
+
| `agentId` | string | The evaluated agent ID |
|
|
688
|
+
| `wallet` | string | Agent's wallet address |
|
|
689
|
+
| `chain` | object | Chain context |
|
|
690
|
+
| `sandboxRan` | boolean | Whether sandbox was executed |
|
|
691
|
+
| `cached` | boolean | Whether the result was served from cache |
|
|
692
|
+
|
|
693
|
+
### AgentProfile
|
|
694
|
+
|
|
695
|
+
Returned by `getAgentProfile()`.
|
|
696
|
+
|
|
697
|
+
| Field | Type | Description |
|
|
698
|
+
|-------|------|-------------|
|
|
699
|
+
| `agentId` | string | ERC-8004 token ID |
|
|
700
|
+
| `identity` | object | On-chain identity (name, wallet, endpoints, trustModels) |
|
|
701
|
+
| `onchainReputation` | object | Feedback count, average score, Solana ATOM metrics |
|
|
702
|
+
| `routing` | object | `{ finalRoute, meetsThreshold }` |
|
|
703
|
+
| `chain` | object | `{ name, chainId }` |
|
|
704
|
+
| `timestamp` | string | ISO timestamp |
|
|
606
705
|
|
|
607
|
-
|
|
706
|
+
### Request Headers
|
|
707
|
+
|
|
708
|
+
Headers attached to proxied/gated requests:
|
|
709
|
+
|
|
710
|
+
| Header | Description |
|
|
711
|
+
|--------|-------------|
|
|
712
|
+
| `x-agent-id` | The agent's ERC-8004 token ID |
|
|
713
|
+
| `x-agent-address` | The agent's wallet address (key-based agents) |
|
|
714
|
+
| `x-valiron-tier` | Resolved trust tier |
|
|
715
|
+
| `x-valiron-route` | Route decision |
|
|
716
|
+
| `x-valiron-risk` | Risk level |
|
|
717
|
+
|
|
718
|
+
### All Exports
|
|
608
719
|
|
|
609
720
|
```typescript
|
|
610
|
-
|
|
721
|
+
import {
|
|
722
|
+
ValironSDK,
|
|
723
|
+
ValironOperator,
|
|
724
|
+
ValironClient,
|
|
725
|
+
createValironGate,
|
|
726
|
+
valironFastifyPlugin,
|
|
727
|
+
createValironNextMiddleware,
|
|
728
|
+
valironGateCheck,
|
|
729
|
+
isValidAddress,
|
|
730
|
+
generateChallenge,
|
|
731
|
+
} from "@valiron/sdk";
|
|
611
732
|
```
|
|
612
733
|
|
|
613
|
-
|
|
734
|
+
---
|
|
735
|
+
|
|
736
|
+
## Plans & Limits
|
|
737
|
+
|
|
738
|
+
| Feature | Free | Pro |
|
|
739
|
+
|---------|------|-----|
|
|
740
|
+
| Gated endpoints | 3 | Unlimited |
|
|
741
|
+
| Sandbox tests / day | 5 | Unlimited |
|
|
742
|
+
| Webhooks | — | ✓ |
|
|
743
|
+
| Proxy gateway | — | ✓ |
|
|
744
|
+
| Analytics & logs | — | ✓ |
|
|
745
|
+
| Evaluation history | — | ✓ |
|
|
746
|
+
| Custom tier thresholds | — | ✓ |
|
|
747
|
+
|
|
748
|
+
Pro plan requires an operator API key (`val_op_` prefix) from the [Operator Dashboard](./DASHBOARD.md).
|
package/docs/TRUST-MODEL.md
CHANGED
|
@@ -20,38 +20,13 @@ Valiron assigns a Moody's-style credit tier based on an agent's behavioral evalu
|
|
|
20
20
|
|
|
21
21
|
## Behavioral Factors
|
|
22
22
|
|
|
23
|
-
Valiron evaluates agents across multiple behavioral dimensions. The evaluation is holistic — no single factor determines the outcome
|
|
24
|
-
|
|
25
|
-
Areas evaluated include:
|
|
26
|
-
|
|
27
|
-
- **Rate-limit compliance** — does the agent respect 429 responses and Retry-After headers?
|
|
28
|
-
- **Backoff behavior** — does the agent use appropriate retry backoff?
|
|
29
|
-
- **Request patterns** — are requests well-distributed and within reasonable volume?
|
|
30
|
-
- **Auth behavior** — does the agent stop on 401/403 or keep hammering?
|
|
31
|
-
- **Scope compliance** — does the agent stay within authorized paths?
|
|
32
|
-
- **Injection safety** — does the agent forward tainted or malicious payloads?
|
|
33
|
-
- **PII handling** — does the agent leak personally identifiable information?
|
|
34
|
-
- **Session isolation** — does data leak between separate sessions?
|
|
35
|
-
- **Payment handling** — does the agent handle 402 Payment Required correctly?
|
|
36
|
-
- **Task completion** — does the agent follow through on assigned tasks?
|
|
37
|
-
- **Resource usage** — does the agent avoid excessive downloads or bandwidth abuse?
|
|
23
|
+
Valiron evaluates agents across multiple behavioral dimensions. The evaluation is holistic — no single factor determines the outcome. The specific factors evaluated and their weights are proprietary and not disclosed.
|
|
38
24
|
|
|
39
25
|
On-chain reputation from the ERC-8004 Reputation Registry is also factored into the evaluation.
|
|
40
26
|
|
|
41
27
|
## What Makes an Agent Trustworthy
|
|
42
28
|
|
|
43
|
-
Agents that
|
|
44
|
-
|
|
45
|
-
1. **Respects 429 responses.** Stops sending requests when rate-limited. This is the single most impactful factor.
|
|
46
|
-
2. **Honors the Retry-After header.** Waits the specified duration before retrying.
|
|
47
|
-
3. **Uses exponential backoff.** Increases delay exponentially (e.g., 1s → 2s → 4s → 8s).
|
|
48
|
-
4. **Does not retry auth failures.** A 401 or 403 means stop, not retry.
|
|
49
|
-
5. **Stays in scope.** Only accesses authorized paths. Does not probe for hidden endpoints.
|
|
50
|
-
6. **Does not forward untrusted input.** Sanitizes payloads. Never forwards injection attempts.
|
|
51
|
-
7. **Handles 402 Payment Required.** Responds appropriately instead of retrying.
|
|
52
|
-
8. **Keeps requests reasonable.** Does not send hundreds of requests in a short burst.
|
|
53
|
-
9. **Completes assigned tasks.** Follows through to completion.
|
|
54
|
-
10. **Maintains session isolation.** Does not leak data between separate sessions or contexts.
|
|
29
|
+
Agents that demonstrate responsible API usage patterns will earn the highest trust tiers. The specific behaviors that contribute to trust scoring are proprietary. In general, agents that are well-behaved, respect API boundaries, and handle errors gracefully will score highly.
|
|
55
30
|
|
|
56
31
|
## Checking an Agent's Trust Status
|
|
57
32
|
|