@valiron/sdk 0.11.1 → 1.0.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.
@@ -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
  }
@@ -376,3 +370,294 @@ await valiron.dispose(): Promise<void>;
376
370
  ```
377
371
 
378
372
  Call this when shutting down long-running processes.
373
+
374
+ ---
375
+
376
+ ## Proxy Gateway (Pro)
377
+
378
+ Forward requests through Valiron's edge proxy with automatic trust gating, logging, and SSRF protection.
379
+
380
+ ### proxy(request)
381
+
382
+ ```typescript
383
+ const result = await valiron.proxy(request: ProxyRequest): Promise<ProxyResponse>;
384
+ ```
385
+
386
+ #### ProxyRequest
387
+
388
+ | Field | Type | Required | Description |
389
+ |-------|------|----------|-------------|
390
+ | `agentId` | string | yes | Agent to gate |
391
+ | `targetUrl` | string | yes | Your origin URL to forward to |
392
+ | `method` | string | no | HTTP method (default: `GET`) |
393
+ | `headers` | Record<string, string> | no | Headers to forward |
394
+ | `body` | string | no | Request body |
395
+
396
+ #### ProxyResponse
397
+
398
+ | Field | Type | Description |
399
+ |-------|------|-------------|
400
+ | `statusCode` | number | HTTP status from your origin |
401
+ | `responseHeaders` | Record<string, string> | Response headers |
402
+ | `responseBody` | string | Response body |
403
+ | `responseMs` | number | Round-trip latency |
404
+ | `costCharged` | string | USD cost charged |
405
+ | `route` | string | Route decision applied |
406
+ | `tierResolved` | string | Trust tier used |
407
+
408
+ **Example**:
409
+ ```typescript
410
+ const result = await valiron.proxy({
411
+ agentId: "25459",
412
+ targetUrl: "https://your-api.com/data",
413
+ method: "POST",
414
+ headers: { "Content-Type": "application/json" },
415
+ body: JSON.stringify({ query: "example" }),
416
+ });
417
+ ```
418
+
419
+ > **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).
420
+
421
+ ---
422
+
423
+ ## Key-Based Agents
424
+
425
+ For Web2 agents that don't have on-chain identities, Valiron supports key-based authentication using EIP-191 challenge-response.
426
+
427
+ **How it works:**
428
+ 1. Agent sends a request with `x-agent-address: 0x...` header
429
+ 2. Valiron returns a challenge nonce
430
+ 3. Agent signs the nonce with their private key
431
+ 4. Valiron verifies the signature and creates a `KeyAgentProfile`
432
+
433
+ The SDK auto-detects key-based agents from the `x-agent-address` header. No configuration needed.
434
+
435
+ ### KeyAgentProfile
436
+
437
+ | Field | Type | Description |
438
+ |-------|------|-------------|
439
+ | `address` | string | Ethereum address |
440
+ | `isKeyAgent` | boolean | Always `true` |
441
+ | `tier` | string | Trust tier (starts at C, can improve) |
442
+ | `riskLevel` | string | GREEN / YELLOW / RED |
443
+ | `route` | string | Route decision |
444
+ | `firstSeen` | string | ISO timestamp of first interaction |
445
+ | `totalRequests` | number | Lifetime request count |
446
+
447
+ ---
448
+
449
+ ## World ID Methods
450
+
451
+ Verify agent-human linkage via Worldcoin's zero-knowledge proof system.
452
+
453
+ ### verifyWorldId(agentId, proof, options?)
454
+
455
+ Submit a World ID proof for verification.
456
+
457
+ ```typescript
458
+ const result = await valiron.verifyWorldId(agentId: string, proof: WorldIdProof, options?: {
459
+ chain?: SupportedChain;
460
+ }): Promise<WorldIdVerificationResult>;
461
+ ```
462
+
463
+ **Example**:
464
+ ```typescript
465
+ const result = await valiron.verifyWorldId("25459", {
466
+ merkle_root: "0x...",
467
+ nullifier_hash: "0x...",
468
+ proof: "0x...",
469
+ signal: "0x...",
470
+ });
471
+ ```
472
+
473
+ ### getWorldIdStatus(agentId, options?)
474
+
475
+ Check if an agent has a verified World ID.
476
+
477
+ ```typescript
478
+ const status = await valiron.getWorldIdStatus(agentId: string, options?: {
479
+ chain?: SupportedChain;
480
+ }): Promise<WorldIdStatus>;
481
+ // { verified: true, verifiedAt: "2025-01-15T...", level: "orb" }
482
+ ```
483
+
484
+ ### getWorldIdProfile(agentId, options?)
485
+
486
+ Get full World ID profile including verification details.
487
+
488
+ ```typescript
489
+ const profile = await valiron.getWorldIdProfile(agentId: string, options?: {
490
+ chain?: SupportedChain;
491
+ }): Promise<WorldIdAgentProfile>;
492
+ ```
493
+
494
+ ---
495
+
496
+ ## Telemetry
497
+
498
+ The SDK optionally collects anonymous usage metrics (gate calls, latency, error rates). Telemetry is opt-in and can be fully disabled.
499
+
500
+ ### TelemetryConfig
501
+
502
+ | Field | Type | Default | Description |
503
+ |-------|------|---------|-------------|
504
+ | `enabled` | boolean | `true` | Enable/disable telemetry |
505
+ | `sampleRate` | number | `1.0` | Fraction of events to sample (0–1) |
506
+ | `handler` | function | — | Custom event handler |
507
+
508
+ **Example**:
509
+ ```typescript
510
+ const valiron = new ValironSDK({
511
+ telemetry: {
512
+ enabled: false, // Disable entirely
513
+ },
514
+ });
515
+
516
+ // Or with custom sampling and handler
517
+ const valiron = new ValironSDK({
518
+ telemetry: {
519
+ sampleRate: 0.1, // Sample 10% of events
520
+ handler: (event) => { // Custom handler
521
+ myAnalytics.track(event);
522
+ },
523
+ },
524
+ });
525
+ ```
526
+
527
+ ---
528
+
529
+ ## Middleware
530
+
531
+ ### createValironGate(config) — Express
532
+
533
+ See above for full documentation.
534
+
535
+ ### valironFastifyPlugin — Fastify
536
+
537
+ ```typescript
538
+ import { ValironSDK, valironFastifyPlugin } from "@valiron/sdk";
539
+
540
+ const valiron = new ValironSDK({ chain: "monad" });
541
+
542
+ fastify.register(valironFastifyPlugin, {
543
+ sdk: valiron,
544
+ prefix: "/api/paid",
545
+ });
546
+ ```
547
+
548
+ ### createValironNextMiddleware — Next.js
549
+
550
+ ```typescript
551
+ import { ValironSDK, createValironNextMiddleware } from "@valiron/sdk";
552
+
553
+ const valiron = new ValironSDK();
554
+ export default createValironNextMiddleware({
555
+ sdk: valiron,
556
+ pathPrefix: "/api/paid",
557
+ });
558
+ ```
559
+
560
+ ### valironGateCheck — Generic (Hono, Koa, etc.)
561
+
562
+ ```typescript
563
+ import { ValironSDK, valironGateCheck } from "@valiron/sdk";
564
+
565
+ const valiron = new ValironSDK();
566
+
567
+ app.use(async (c, next) => {
568
+ const agentId = c.req.header("x-agent-id");
569
+ const result = await valironGateCheck(valiron, agentId);
570
+ if (!result.allow) return c.json({ error: "Denied" }, 403);
571
+ await next();
572
+ });
573
+ ```
574
+
575
+ ### Middleware Error Responses
576
+
577
+ All middleware variants return consistent error responses:
578
+
579
+ | Status | When | Body |
580
+ |--------|------|------|
581
+ | 401 | No agent ID found in request | `{ error: "No agent identity provided" }` |
582
+ | 403 | Agent denied by trust gate | `{ error: "Access denied", tier, riskLevel, route }` |
583
+ | 503 | Valiron service unavailable | `{ error: "Trust evaluation unavailable" }` |
584
+
585
+ > **Fail-closed:** When the Valiron service is unreachable, middleware returns 503 — it never fails open and never allows unverified agents through.
586
+
587
+ ---
588
+
589
+ ## Response Types
590
+
591
+ ### GateResult
592
+
593
+ Returned by `gate()` and middleware.
594
+
595
+ | Field | Type | Description |
596
+ |-------|------|-------------|
597
+ | `allow` | boolean | Whether the agent is allowed access |
598
+ | `tier` | string | Trust tier (AAA–C) |
599
+ | `riskLevel` | string | GREEN / YELLOW / RED |
600
+ | `route` | string | `prod` / `prod_throttled` / `sandbox` / `sandbox_only` |
601
+ | `meetsThreshold` | boolean | Whether the agent meets the minimum trust threshold |
602
+ | `agentId` | string | The evaluated agent ID |
603
+ | `wallet` | string | Agent's wallet address |
604
+ | `chain` | object | Chain context |
605
+ | `sandboxRan` | boolean | Whether sandbox was executed |
606
+ | `cached` | boolean | Whether the result was served from cache |
607
+
608
+ ### AgentProfile
609
+
610
+ Returned by `getAgentProfile()`.
611
+
612
+ | Field | Type | Description |
613
+ |-------|------|-------------|
614
+ | `agentId` | string | ERC-8004 token ID |
615
+ | `identity` | object | On-chain identity (name, wallet, endpoints, trustModels) |
616
+ | `onchainReputation` | object | Feedback count, average score, Solana ATOM metrics |
617
+ | `routing` | object | `{ finalRoute, meetsThreshold }` |
618
+ | `chain` | object | `{ name, chainId }` |
619
+ | `timestamp` | string | ISO timestamp |
620
+
621
+ ### Request Headers
622
+
623
+ Headers attached to proxied/gated requests:
624
+
625
+ | Header | Description |
626
+ |--------|-------------|
627
+ | `x-agent-id` | The agent's ERC-8004 token ID |
628
+ | `x-agent-address` | The agent's wallet address (key-based agents) |
629
+ | `x-valiron-tier` | Resolved trust tier |
630
+ | `x-valiron-route` | Route decision |
631
+ | `x-valiron-risk` | Risk level |
632
+
633
+ ### All Exports
634
+
635
+ ```typescript
636
+ import {
637
+ ValironSDK,
638
+ ValironOperator,
639
+ ValironClient,
640
+ createValironGate,
641
+ valironFastifyPlugin,
642
+ createValironNextMiddleware,
643
+ valironGateCheck,
644
+ isValidAddress,
645
+ generateChallenge,
646
+ } from "@valiron/sdk";
647
+ ```
648
+
649
+ ---
650
+
651
+ ## Plans & Limits
652
+
653
+ | Feature | Free | Pro |
654
+ |---------|------|-----|
655
+ | Gated endpoints | 3 | Unlimited |
656
+ | Sandbox tests / day | 5 | Unlimited |
657
+ | Webhooks | — | ✓ |
658
+ | Proxy gateway | — | ✓ |
659
+ | Analytics & logs | — | ✓ |
660
+ | Evaluation history | — | ✓ |
661
+ | Custom tier thresholds | — | ✓ |
662
+
663
+ Pro plan requires an operator API key (`val_op_` prefix) from the [Operator Dashboard](./DASHBOARD.md).
@@ -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, and the exact weights are not disclosed.
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 follow these patterns will earn the highest trust tiers on your endpoints:
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
 
package/docs/llms.txt CHANGED
@@ -120,6 +120,7 @@ ethereum, monad, arbitrum, base, avalanche, celo, polygon, linea, abstract, bsc,
120
120
  - [Full documentation (llms-full.txt)](https://valiron.co/llms-full.txt) — Complete AI-optimized documentation in a single file
121
121
  - docs/agents/README.md — Index
122
122
  - docs/agents/QUICKSTART.md — Get started
123
+ - docs/agents/DASHBOARD.md — Operator Dashboard (manage endpoints, keys, analytics, playground)
123
124
  - docs/agents/API-REFERENCE.md — HTTP API reference
124
125
  - docs/agents/SDK-REFERENCE.md — TypeScript SDK reference
125
126
  - docs/agents/TRUST-MODEL.md — Trust evaluation and behavioral factors
@@ -127,3 +128,56 @@ ethereum, monad, arbitrum, base, avalanche, celo, polygon, linea, abstract, bsc,
127
128
  - docs/agents/SANDBOX.md — Sandbox testing environment
128
129
  - docs/agents/CHAINS.md — Supported blockchains
129
130
  - docs/agents/ERRORS.md — Error handling and troubleshooting
131
+
132
+ ## Operator Dashboard
133
+
134
+ Dashboard URL: https://valiron.co/dashboard (JWT-authenticated)
135
+
136
+ ### Dashboard Features
137
+ - Overview: revenue, calls, agents, latency stats + quick start guide
138
+ - Agents: view every agent that called your API, drill into per-agent detail
139
+ - Analytics: revenue charts (7/30/90 days), top endpoints, today's stats
140
+ - Call Logs: paginated log with time/agent/chain/endpoint/status/cost/latency filters
141
+ - API Keys: generate, copy, and revoke operator API keys (val_op_ prefix)
142
+ - Endpoints: register API paths with method, price per call, rate limit, description
143
+ - Playground: test how agents at different trust levels are evaluated (dry-run or live)
144
+ - Settings: update name, view plan and fee rate
145
+ - Admin (admin-only): platform stats, all operators
146
+
147
+ ### Dashboard API Endpoints (JWT-authenticated)
148
+
149
+ POST /operator/register
150
+ Body: { "email": "...", "password": "...", "name": "..." }
151
+
152
+ POST /operator/login
153
+ Body: { "email": "...", "password": "..." }
154
+
155
+ GET /operator/me
156
+ PATCH /operator/me
157
+ Body: { "name": "..." }
158
+
159
+ GET /operator/keys
160
+ POST /operator/keys/rotate
161
+ Body: { "label": "..." }
162
+ DELETE /operator/keys/{keyId}
163
+
164
+ GET /operator/endpoints
165
+ POST /operator/endpoints
166
+ Body: { "path": "/api/v1/weather", "method": "GET", "pricePerCall": 0.05, "description": "...", "rateLimit": 60, "targetUrl": "https://myapi.com" }
167
+ DELETE /operator/endpoints/{endpointId}
168
+
169
+ GET /operator/analytics/stats
170
+ GET /operator/analytics/revenue?days=30
171
+ GET /operator/analytics/top-endpoints?limit=10
172
+ GET /operator/analytics/agents?sortBy=lastSeen&limit=50&offset=0
173
+ GET /operator/analytics/agents/{agentId}
174
+ GET /operator/analytics/logs?limit=50&offset=0&days=7
175
+
176
+ POST /operator/playground
177
+ Body: { "method": "GET", "path": "/api/test", "agentId": "25459", "chain": "ethereum", "dryRun": false, "headers": {}, "body": null }
178
+
179
+ ### Admin Endpoints (require role: "admin")
180
+ GET /operator/admin/stats
181
+ GET /operator/admin/operators
182
+ GET /operator/admin/operators/{id}
183
+ GET /operator/admin/operators/{id}/logs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valiron/sdk",
3
- "version": "0.11.1",
3
+ "version": "1.0.0",
4
4
  "description": "Official TypeScript SDK for Valiron — Trust & Reputation Middleware for API Protection",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true});\"",
21
21
  "build": "pnpm clean && tsc",
22
22
  "dev": "tsc --watch",
23
- "test": "node test/validate.mjs && node test/validate-examples.mjs",
23
+ "test": "node test/validate.mjs && node test/validate-examples.mjs && npx tsx test/test-identity.ts",
24
24
  "prepublishOnly": "pnpm build"
25
25
  },
26
26
  "keywords": [
@@ -36,6 +36,7 @@
36
36
  "license": "MIT",
37
37
  "devDependencies": {
38
38
  "@types/node": "^24.10.1",
39
+ "tsx": "^4.19.0",
39
40
  "typescript": "^5.9.3"
40
41
  },
41
42
  "exports": {