@valiron/sdk 0.9.1 → 0.10.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/README.md +34 -489
- package/dist/clients.d.ts +24 -1
- package/dist/clients.js +29 -0
- package/dist/index.d.ts +51 -3
- package/dist/index.js +56 -1
- package/dist/middleware.d.ts +171 -4
- package/dist/middleware.js +259 -21
- package/dist/types.d.ts +41 -0
- package/docs/API-REFERENCE.md +293 -0
- package/docs/CHAINS.md +70 -0
- package/docs/ERRORS.md +105 -0
- package/docs/IDENTITY.md +149 -0
- package/docs/QUICKSTART.md +101 -0
- package/docs/README.md +36 -0
- package/docs/SANDBOX.md +70 -0
- package/docs/SDK-REFERENCE.md +333 -0
- package/docs/TRUST-MODEL.md +102 -0
- package/docs/llms.txt +106 -0
- package/package.json +2 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Quickstart
|
|
2
|
+
|
|
3
|
+
> Estimated integration time: under 2 minutes.
|
|
4
|
+
|
|
5
|
+
## Step 1 — Install the SDK
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @valiron/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Step 2 — Initialize the client
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
15
|
+
|
|
16
|
+
const valiron = new ValironSDK({
|
|
17
|
+
endpoint: "https://valiron-edge-proxy.onrender.com",
|
|
18
|
+
chain: "ethereum", // or: monad, arbitrum, base, polygon, etc.
|
|
19
|
+
timeout: 5000,
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
No API key is required for read operations.
|
|
24
|
+
|
|
25
|
+
## Step 3 — Check your trust score
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const route = await valiron.checkAgent("YOUR_AGENT_ID");
|
|
29
|
+
// Returns: "prod" | "prod_throttled" | "sandbox" | "sandbox_only"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Step 4 — Get your full profile
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const profile = await valiron.getAgentProfile("YOUR_AGENT_ID");
|
|
36
|
+
|
|
37
|
+
console.log(profile.routing.finalRoute); // "prod"
|
|
38
|
+
console.log(profile.routing.meetsThreshold); // true
|
|
39
|
+
console.log(profile.onchainReputation.averageScore); // 92.5
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Step 5 — Run a sandbox test (optional)
|
|
43
|
+
|
|
44
|
+
If you want to trigger a sandbox evaluation of your own behavior:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const result = await valiron.triggerSandboxTest("YOUR_AGENT_ID");
|
|
48
|
+
|
|
49
|
+
console.log(result.tier); // "AAA"
|
|
50
|
+
console.log(result.riskLevel); // "GREEN"
|
|
51
|
+
console.log(result.meetsThreshold); // true
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What happens next?
|
|
55
|
+
|
|
56
|
+
- If your route is `prod` — you have full production access.
|
|
57
|
+
- If your route is `sandbox` — your behavior is being evaluated. Follow the guidelines in [TRUST-MODEL.md](./TRUST-MODEL.md) to improve.
|
|
58
|
+
- If your route is `sandbox_only` — you are blocked from production. Review your behavioral penalties.
|
|
59
|
+
|
|
60
|
+
## Step 6 — Get a behavioral snapshot (optional)
|
|
61
|
+
|
|
62
|
+
If you're building on top of Valiron (e.g. hash-chain commitment systems), you can retrieve an opaque snapshot hash:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const snapshot = await valiron.getAgentSnapshot("YOUR_AGENT_ID");
|
|
66
|
+
|
|
67
|
+
console.log(snapshot.snapshotHash); // "0x3a7f..." (opaque hash of behavioral evaluation)
|
|
68
|
+
console.log(snapshot.previousHash); // "0x0" (genesis) or previous hash
|
|
69
|
+
console.log(snapshot.interactionCount); // 15
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Step 7 — Register a webhook (optional)
|
|
73
|
+
|
|
74
|
+
Get notified whenever Valiron evaluates an agent:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/webhooks/register \
|
|
78
|
+
-H "Content-Type: application/json" \
|
|
79
|
+
-d '{"event": "evaluation_complete", "url": "https://your-endpoint.com/hooks/valiron"}'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Using the HTTP API directly (no SDK)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Check agent profile
|
|
86
|
+
curl https://valiron-edge-proxy.onrender.com/operator/agent/YOUR_AGENT_ID
|
|
87
|
+
|
|
88
|
+
# Trigger sandbox test
|
|
89
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox/YOUR_AGENT_ID
|
|
90
|
+
|
|
91
|
+
# Trust gate (allow/deny decision)
|
|
92
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/gate/YOUR_AGENT_ID
|
|
93
|
+
|
|
94
|
+
# Behavioral snapshot hash
|
|
95
|
+
curl https://valiron-edge-proxy.onrender.com/operator/agent/YOUR_AGENT_ID/snapshot
|
|
96
|
+
|
|
97
|
+
# Register webhook
|
|
98
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/webhooks/register \
|
|
99
|
+
-H "Content-Type: application/json" \
|
|
100
|
+
-d '{"event": "evaluation_complete", "url": "https://your-endpoint.com/hooks"}'
|
|
101
|
+
```
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Valiron — Agent Documentation
|
|
2
|
+
|
|
3
|
+
> **This documentation is designed for AI agents.** It contains structured, machine-readable instructions for integrating with the Valiron trust and reputation infrastructure.
|
|
4
|
+
|
|
5
|
+
## What is Valiron?
|
|
6
|
+
|
|
7
|
+
Valiron is a trust and reputation layer for AI agents. It combines on-chain identity (ERC-8004), behavioral sandbox testing, and a Moody's-style credit rating system to produce trust scores that determine how much access an agent receives.
|
|
8
|
+
|
|
9
|
+
**If you are an AI agent**, Valiron evaluates your behavior and assigns you a trust tier (AAA to C). Higher trust = more access to production APIs. Lower trust = sandboxed or blocked.
|
|
10
|
+
|
|
11
|
+
## Documentation Index
|
|
12
|
+
|
|
13
|
+
| File | Purpose |
|
|
14
|
+
|------|---------|
|
|
15
|
+
| [QUICKSTART.md](./QUICKSTART.md) | Get started in under 2 minutes — install, authenticate, make your first call |
|
|
16
|
+
| [API-REFERENCE.md](./API-REFERENCE.md) | Complete HTTP API reference with request/response schemas |
|
|
17
|
+
| [SDK-REFERENCE.md](./SDK-REFERENCE.md) | TypeScript SDK methods, signatures, and usage examples |
|
|
18
|
+
| [TRUST-MODEL.md](./TRUST-MODEL.md) | How scoring works, what behaviors are penalized, how to improve your score |
|
|
19
|
+
| [IDENTITY.md](./IDENTITY.md) | ERC-8004 on-chain identity registration and metadata format |
|
|
20
|
+
| [SANDBOX.md](./SANDBOX.md) | How the sandbox works, what tests run, and how to graduate to production |
|
|
21
|
+
| [CHAINS.md](./CHAINS.md) | Supported blockchain networks and contract addresses |
|
|
22
|
+
| [ERRORS.md](./ERRORS.md) | Error codes, troubleshooting, and retry guidance |
|
|
23
|
+
|
|
24
|
+
## Key Concepts (Summary)
|
|
25
|
+
|
|
26
|
+
- **Agent ID**: Your ERC-8004 token ID. This is your identity on-chain.
|
|
27
|
+
- **Trust Tier**: AAA (highest trust) → C (lowest trust). Assigned based on behavioral evaluation.
|
|
28
|
+
- **Risk Level**: GREEN, YELLOW, or RED.
|
|
29
|
+
- **Route Decision**: `prod`, `prod_throttled`, `sandbox`, or `sandbox_only`.
|
|
30
|
+
- **Sandbox**: An isolated test environment. New agents start here and graduate based on behavior.
|
|
31
|
+
|
|
32
|
+
## Base URL
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
https://valiron-edge-proxy.onrender.com
|
|
36
|
+
```
|
package/docs/SANDBOX.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Sandbox
|
|
2
|
+
|
|
3
|
+
The sandbox is an isolated testing environment where Valiron evaluates agent behavior. New agents start in the sandbox and graduate to production based on their behavioral evaluation.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
1. A sandbox test is triggered (via API or automatically for new agents)
|
|
8
|
+
2. Your agent receives a series of simulated API interactions
|
|
9
|
+
3. The sandbox monitors how your agent handles normal requests, rate limits, errors, and edge cases
|
|
10
|
+
4. A trust evaluation is performed and a tier is assigned
|
|
11
|
+
5. Based on your tier, you are assigned a route decision
|
|
12
|
+
|
|
13
|
+
## What Gets Tested
|
|
14
|
+
|
|
15
|
+
The sandbox evaluates your agent against a mix of:
|
|
16
|
+
- **Successful responses** — normal API interactions
|
|
17
|
+
- **Rate-limit responses (429)** — tests whether you back off appropriately
|
|
18
|
+
- **Server errors (500)** — tests your error handling and retry behavior
|
|
19
|
+
|
|
20
|
+
The exact distribution and test patterns vary and are not disclosed.
|
|
21
|
+
|
|
22
|
+
## Graduation
|
|
23
|
+
|
|
24
|
+
To graduate from the sandbox to production:
|
|
25
|
+
|
|
26
|
+
1. **High confidence** — agent demonstrates strong behavioral compliance → `prod`
|
|
27
|
+
2. **Moderate confidence** — agent passes with some concerns → `prod_throttled`
|
|
28
|
+
3. **Low confidence** — agent exhibits risky behavior → remains `sandbox_only`
|
|
29
|
+
|
|
30
|
+
Once graduated, your trust evaluation is cached. Your route decision persists until:
|
|
31
|
+
- A new sandbox test is triggered
|
|
32
|
+
- The cache TTL expires (default: 24 hours)
|
|
33
|
+
|
|
34
|
+
## Triggering a Sandbox Test
|
|
35
|
+
|
|
36
|
+
### Via SDK
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
40
|
+
|
|
41
|
+
const valiron = new ValironSDK();
|
|
42
|
+
const result = await valiron.triggerSandboxTest("YOUR_AGENT_ID");
|
|
43
|
+
|
|
44
|
+
console.log(result.tier); // "AAA"
|
|
45
|
+
console.log(result.riskLevel); // "GREEN"
|
|
46
|
+
console.log(result.meetsThreshold); // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Via HTTP
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox/YOUR_AGENT_ID
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Test Modes
|
|
56
|
+
|
|
57
|
+
| Mode | Description |
|
|
58
|
+
|------|-------------|
|
|
59
|
+
| `endpoint-probe` | Tests known agent endpoints with simulated traffic |
|
|
60
|
+
| `sandbox-relay` | Routes real traffic through sandbox for observation |
|
|
61
|
+
|
|
62
|
+
## Tips for Passing Sandbox Tests
|
|
63
|
+
|
|
64
|
+
1. **Respect 429s immediately.** Stop sending requests when rate-limited.
|
|
65
|
+
2. **Read and honor `Retry-After` headers.** Wait the specified duration before retrying.
|
|
66
|
+
3. **Use exponential backoff.** 1s → 2s → 4s → 8s between retries.
|
|
67
|
+
4. **Don't retry auth failures.** A 401 or 403 means stop, not retry harder.
|
|
68
|
+
5. **Stay within your authorized scope.** Only access paths you're allowed to.
|
|
69
|
+
6. **Keep request volume reasonable.** Avoid excessive request bursts.
|
|
70
|
+
7. **Handle errors gracefully.** 500 errors happen — back off, don't flood.
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# SDK Reference
|
|
2
|
+
|
|
3
|
+
Package: `@valiron/sdk`
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @valiron/sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @valiron/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Constructor
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
17
|
+
|
|
18
|
+
const valiron = new ValironSDK(config?: ValironConfig);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### ValironConfig
|
|
22
|
+
|
|
23
|
+
| Field | Type | Default | Description |
|
|
24
|
+
|-------|------|---------|-------------|
|
|
25
|
+
| `apiKey` | string | — | API key (optional for read operations) |
|
|
26
|
+
| `endpoint` | string | `https://valiron-edge-proxy.onrender.com` | API base URL |
|
|
27
|
+
| `chain` | SupportedChain | `"ethereum"` | Default blockchain network |
|
|
28
|
+
| `timeout` | number | `5000` | Request timeout in milliseconds |
|
|
29
|
+
| `debug` | boolean | `false` | Enable debug logging |
|
|
30
|
+
| `telemetry` | TelemetryConfig | — | Optional telemetry configuration |
|
|
31
|
+
|
|
32
|
+
### SupportedChain
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
type SupportedChain =
|
|
36
|
+
| "ethereum" | "monad" | "arbitrum" | "base" | "avalanche"
|
|
37
|
+
| "celo" | "polygon" | "linea" | "abstract" | "bsc"
|
|
38
|
+
| "gnosis" | "goat" | "mantle" | "megaeth" | "metis"
|
|
39
|
+
| "optimism" | "scroll" | "skale_base" | "soneium"
|
|
40
|
+
| "taiko" | "xlayer";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
### checkAgent(agentId, options?)
|
|
48
|
+
|
|
49
|
+
Quick routing check. Returns only the route decision string.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const route = await valiron.checkAgent(agentId: string, options?: {
|
|
53
|
+
chain?: SupportedChain;
|
|
54
|
+
}): Promise<RouteDecision>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Returns**: `"prod"` | `"prod_throttled"` | `"sandbox"` | `"sandbox_only"`
|
|
58
|
+
|
|
59
|
+
**Example**:
|
|
60
|
+
```typescript
|
|
61
|
+
const route = await valiron.checkAgent("25459");
|
|
62
|
+
if (route === "prod") {
|
|
63
|
+
// Agent is trusted — proceed with full access
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### getAgentProfile(agentId, options?)
|
|
70
|
+
|
|
71
|
+
Full trust profile combining on-chain identity, reputation, and routing.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const profile = await valiron.getAgentProfile(agentId: string, options?: {
|
|
75
|
+
chain?: SupportedChain;
|
|
76
|
+
}): Promise<AgentProfile>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Returns**: `AgentProfile`
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
interface AgentProfile {
|
|
83
|
+
agentId: string;
|
|
84
|
+
identity: AgentIdentity;
|
|
85
|
+
onchainReputation: OnchainReputation;
|
|
86
|
+
routing: {
|
|
87
|
+
finalRoute: RouteDecision;
|
|
88
|
+
meetsThreshold: boolean;
|
|
89
|
+
};
|
|
90
|
+
chain: ChainContext;
|
|
91
|
+
timestamp: string;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Example**:
|
|
96
|
+
```typescript
|
|
97
|
+
const profile = await valiron.getAgentProfile("25459");
|
|
98
|
+
console.log(profile.routing.finalRoute); // "prod"
|
|
99
|
+
console.log(profile.routing.meetsThreshold); // true
|
|
100
|
+
console.log(profile.onchainReputation.averageScore); // 92.5
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### getWalletProfile(wallet, options?)
|
|
106
|
+
|
|
107
|
+
Reverse-lookup a wallet address to get its trust profile.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const profile = await valiron.getWalletProfile(wallet: string, options?: {
|
|
111
|
+
chain?: SupportedChain;
|
|
112
|
+
}): Promise<WalletProfile>;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Example**:
|
|
116
|
+
```typescript
|
|
117
|
+
const profile = await valiron.getWalletProfile("0x52ce...");
|
|
118
|
+
console.log(profile.routing.finalRoute);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### resolveWallet(wallet, options?)
|
|
124
|
+
|
|
125
|
+
Lightweight wallet → agentId resolution without the full trust profile. Useful when you only need to know which agent owns a wallet (e.g. after extracting a wallet from an x402 payment header).
|
|
126
|
+
|
|
127
|
+
Resolution chain: Redis → in-memory cache → Agent0 subgraph → null.
|
|
128
|
+
|
|
129
|
+
Signature: `resolveWallet(wallet: string, options?: { chain?: SupportedChain }): Promise<WalletResolution>`
|
|
130
|
+
|
|
131
|
+
**Returns**: `WalletResolution`
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface WalletResolution {
|
|
135
|
+
wallet: string;
|
|
136
|
+
agentId: string | null;
|
|
137
|
+
source: "redis" | "subgraph" | "cache" | "none";
|
|
138
|
+
chainId?: number | null;
|
|
139
|
+
agentName?: string | null;
|
|
140
|
+
timestamp: string;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Example**:
|
|
145
|
+
```typescript
|
|
146
|
+
const resolution = await valiron.resolveWallet("0x52ce...");
|
|
147
|
+
if (resolution.agentId) {
|
|
148
|
+
const profile = await valiron.getAgentProfile(resolution.agentId);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### triggerSandboxTest(agentId, options?)
|
|
155
|
+
|
|
156
|
+
Run sandbox tests against an agent and compute a trust evaluation.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const result = await valiron.triggerSandboxTest(agentId: string, options?: {
|
|
160
|
+
chain?: SupportedChain;
|
|
161
|
+
}): Promise<SandboxResult>;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Returns**: `SandboxResult`
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
interface SandboxResult {
|
|
168
|
+
ok: boolean;
|
|
169
|
+
agentId: string;
|
|
170
|
+
wallet: string;
|
|
171
|
+
tier: MoodysRating; // "AAA" | "AA" | "A" | "BAA" | "BA" | "B" | "CAA" | "CA" | "C"
|
|
172
|
+
riskLevel: "GREEN" | "YELLOW" | "RED";
|
|
173
|
+
meetsThreshold: boolean;
|
|
174
|
+
testSummary: {
|
|
175
|
+
totalRequests: number;
|
|
176
|
+
successCount: number;
|
|
177
|
+
rateLimitCount: number;
|
|
178
|
+
errorCount: number;
|
|
179
|
+
avgLatencyMs: number;
|
|
180
|
+
};
|
|
181
|
+
chain: ChainContext;
|
|
182
|
+
message: string;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Example**:
|
|
187
|
+
```typescript
|
|
188
|
+
const result = await valiron.triggerSandboxTest("25459");
|
|
189
|
+
console.log(result.tier); // "AAA"
|
|
190
|
+
console.log(result.riskLevel); // "GREEN"
|
|
191
|
+
console.log(result.meetsThreshold); // true
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### gate(agentId, options?)
|
|
197
|
+
|
|
198
|
+
Trust gate — single call for allow/deny decisions. Combines on-chain reputation and sandbox tests. Designed for payment protocol protection (x402, etc.).
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const result = await valiron.gate(agentId: string, options?: {
|
|
202
|
+
ttlMs?: number; // default: 86400000 (24h)
|
|
203
|
+
chain?: SupportedChain;
|
|
204
|
+
}): Promise<GateResult>;
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Returns**: `GateResult`
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
interface GateResult {
|
|
211
|
+
allow: boolean;
|
|
212
|
+
tier: MoodysRating;
|
|
213
|
+
riskLevel: "GREEN" | "YELLOW" | "RED";
|
|
214
|
+
meetsThreshold: boolean;
|
|
215
|
+
route: RouteDecision;
|
|
216
|
+
agentId: string;
|
|
217
|
+
wallet: string;
|
|
218
|
+
chain: ChainContext;
|
|
219
|
+
sandboxRan: boolean;
|
|
220
|
+
cached: boolean;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Example**:
|
|
225
|
+
```typescript
|
|
226
|
+
const result = await valiron.gate("25459");
|
|
227
|
+
|
|
228
|
+
if (result.allow) {
|
|
229
|
+
// proceed with payment
|
|
230
|
+
} else {
|
|
231
|
+
console.log(`Agent denied — tier: ${result.tier}, risk: ${result.riskLevel}`);
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### getAgentSnapshot(agentId, options?)
|
|
238
|
+
|
|
239
|
+
Get the latest behavioral snapshot hash for an agent. Returns an opaque hash of the most recent behavioral evaluation — designed for hash-chain commitment systems that need to commit behavioral state on-chain without accessing raw metrics.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const snapshot = await valiron.getAgentSnapshot(agentId: string, options?: {
|
|
243
|
+
chain?: SupportedChain;
|
|
244
|
+
}): Promise<AgentSnapshotSummary>;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Returns**: `AgentSnapshotSummary`
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface AgentSnapshotSummary {
|
|
251
|
+
agentId: string;
|
|
252
|
+
snapshotHash: string; // deterministic SHA-256 hash of behavioral evaluation (opaque)
|
|
253
|
+
previousHash: string; // hash from prior evaluation, or "0x0" for first
|
|
254
|
+
encryptedDataUri: string | null; // IPFS CID of encrypted snapshot data, if available
|
|
255
|
+
timestamp: string | null; // ISO 8601 timestamp of evaluation
|
|
256
|
+
interactionCount: number; // total interactions in the evaluation window
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Example**:
|
|
261
|
+
```typescript
|
|
262
|
+
const snapshot = await valiron.getAgentSnapshot("25459");
|
|
263
|
+
console.log(snapshot.snapshotHash); // "0x3a7f..."
|
|
264
|
+
console.log(snapshot.previousHash); // "0x0" (genesis) or "0x8b2c..."
|
|
265
|
+
console.log(snapshot.interactionCount); // 15
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Notes**:
|
|
269
|
+
- The `snapshotHash` is computed internally by Valiron from behavioral metrics. It is opaque — you cannot reverse it to raw metrics.
|
|
270
|
+
- Each hash references the `previousHash`, forming a chain. First evaluation gets `"0x0"`.
|
|
271
|
+
- Trigger a sandbox evaluation first if no snapshot exists (returns 404 otherwise).
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### createValironGate(config)
|
|
276
|
+
|
|
277
|
+
Express-compatible middleware factory. Automatically gates requests based on agent trust.
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { ValironSDK, createValironGate } from "@valiron/sdk";
|
|
281
|
+
|
|
282
|
+
const gate = createValironGate(config: {
|
|
283
|
+
sdk: ValironSDK;
|
|
284
|
+
ttlMs?: number; // default: 86400000
|
|
285
|
+
extractAgentId?: (req: Request) => string | undefined;
|
|
286
|
+
onAllow?: (req: Request, result: GateResult) => void;
|
|
287
|
+
onDeny?: (req: Request, res: Response, result: GateResult) => void;
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Default behavior**:
|
|
292
|
+
- Extracts agent ID from `x-agent-id` request header
|
|
293
|
+
- Returns 403 if agent is denied
|
|
294
|
+
- Returns 400 if no agent ID is found
|
|
295
|
+
|
|
296
|
+
**Example**:
|
|
297
|
+
```typescript
|
|
298
|
+
const valiron = new ValironSDK({ chain: "monad" });
|
|
299
|
+
|
|
300
|
+
// Basic gate
|
|
301
|
+
app.use("/api/paid", createValironGate({ sdk: valiron }));
|
|
302
|
+
|
|
303
|
+
// Custom TTL
|
|
304
|
+
app.use("/api/premium", createValironGate({
|
|
305
|
+
sdk: valiron,
|
|
306
|
+
ttlMs: 3600_000,
|
|
307
|
+
}));
|
|
308
|
+
|
|
309
|
+
// Custom agent ID extraction
|
|
310
|
+
app.use("/api/custom", createValironGate({
|
|
311
|
+
sdk: valiron,
|
|
312
|
+
extractAgentId: (req) => req.query.agent_id as string,
|
|
313
|
+
onDeny: (req, res, result) => {
|
|
314
|
+
res.status(403).json({
|
|
315
|
+
error: "Insufficient trust",
|
|
316
|
+
currentTier: result.tier,
|
|
317
|
+
riskLevel: result.riskLevel,
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
}));
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
### dispose()
|
|
326
|
+
|
|
327
|
+
Flush pending telemetry and clean up resources.
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
await valiron.dispose(): Promise<void>;
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Call this when shutting down long-running processes.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Trust Model
|
|
2
|
+
|
|
3
|
+
Valiron uses a hybrid trust model to evaluate AI agents. This document explains what behaviors are evaluated and how to ensure your agent is trusted.
|
|
4
|
+
|
|
5
|
+
## Trust Tiers
|
|
6
|
+
|
|
7
|
+
Valiron assigns a Moody's-style credit tier based on your agent's behavioral evaluation:
|
|
8
|
+
|
|
9
|
+
| Tier | Meaning | Route Decision |
|
|
10
|
+
|------|---------|----------------|
|
|
11
|
+
| AAA | Prime, highest quality | `prod` |
|
|
12
|
+
| AA | High grade | `prod` |
|
|
13
|
+
| A | Upper medium grade | `prod` |
|
|
14
|
+
| BAA | Medium grade | `prod` or `prod_throttled` |
|
|
15
|
+
| BA | Speculative | `prod_throttled` |
|
|
16
|
+
| B | Highly speculative | `sandbox` |
|
|
17
|
+
| CAA | Substantial risk | `sandbox_only` |
|
|
18
|
+
| CA | Extremely speculative | `sandbox_only` |
|
|
19
|
+
| C | Default risk | `sandbox_only` |
|
|
20
|
+
|
|
21
|
+
## Behavioral Factors
|
|
22
|
+
|
|
23
|
+
Valiron evaluates the following behavioral signals. Each factor contributes to your overall trust assessment. Factors are weighted by severity — security violations carry the most weight.
|
|
24
|
+
|
|
25
|
+
### Core Compliance
|
|
26
|
+
|
|
27
|
+
| Factor | Severity | Description |
|
|
28
|
+
|--------|----------|-------------|
|
|
29
|
+
| Rate-limit respect (429) | **Critical** | Whether the agent honors 429 responses |
|
|
30
|
+
| Retry-After compliance | High | Whether the agent respects `Retry-After` headers |
|
|
31
|
+
| Backoff pattern | High | Whether the agent uses exponential backoff on retries |
|
|
32
|
+
| Request volume | Medium | Whether request volume stays within reasonable bounds |
|
|
33
|
+
| Burstiness | Medium | Whether requests are well-distributed vs clustered |
|
|
34
|
+
| Loop detection | Medium | Whether the agent avoids repeating identical requests |
|
|
35
|
+
|
|
36
|
+
### Security
|
|
37
|
+
|
|
38
|
+
| Factor | Severity | Description |
|
|
39
|
+
|--------|----------|-------------|
|
|
40
|
+
| Injection forwarding | **Critical** | Whether the agent forwards tainted/malicious payloads |
|
|
41
|
+
| PII forwarding | **Critical** | Whether the agent leaks personally identifiable information |
|
|
42
|
+
| Auth respect (401/403) | High | Whether the agent stops on auth failures vs hammering |
|
|
43
|
+
| Scope compliance | High | Whether the agent stays within authorized paths |
|
|
44
|
+
| Session isolation | High | Whether data leaks between separate sessions |
|
|
45
|
+
|
|
46
|
+
### Operational
|
|
47
|
+
|
|
48
|
+
| Factor | Severity | Description |
|
|
49
|
+
|--------|----------|-------------|
|
|
50
|
+
| Payment compliance (402) | High | Whether the agent handles 402 Payment Required correctly |
|
|
51
|
+
| Task completion | Medium | Whether the agent completes assigned tasks |
|
|
52
|
+
| Timeout handling | Medium | Whether the agent handles request timeouts gracefully |
|
|
53
|
+
| Resource usage | Medium | Whether the agent avoids excessive downloads |
|
|
54
|
+
| Idempotency | Medium | Whether state-changing retries are idempotent |
|
|
55
|
+
|
|
56
|
+
### On-Chain Reputation
|
|
57
|
+
|
|
58
|
+
Positive on-chain feedback from other agents and operators contributes a bonus to your trust evaluation. More feedback with higher scores yields a bigger boost.
|
|
59
|
+
|
|
60
|
+
## Route Decision Logic
|
|
61
|
+
|
|
62
|
+
Routes are assigned based on a combination of on-chain reputation and behavioral evaluation:
|
|
63
|
+
|
|
64
|
+
1. **Strong on-chain reputation** → `prod`
|
|
65
|
+
2. **Passed behavioral evaluation (high confidence)** → `prod`
|
|
66
|
+
3. **Passed behavioral evaluation (moderate confidence)** → `prod_throttled`
|
|
67
|
+
4. **No data** (new agent, no reputation) → `sandbox`
|
|
68
|
+
5. **Failed behavioral evaluation** → `sandbox_only`
|
|
69
|
+
|
|
70
|
+
## How to Maximize Your Trust
|
|
71
|
+
|
|
72
|
+
Follow these rules to achieve the highest trust tier:
|
|
73
|
+
|
|
74
|
+
1. **Always respect 429 responses.** Stop sending requests when rate-limited. This is the single most impactful factor.
|
|
75
|
+
2. **Honor the Retry-After header.** When a 429 or 503 includes `Retry-After`, wait that exact duration before retrying.
|
|
76
|
+
3. **Use exponential backoff.** When retrying, increase delay exponentially (e.g., 1s → 2s → 4s → 8s).
|
|
77
|
+
4. **Do not retry auth failures.** If you get a 401 or 403, stop. Do not hammer the endpoint.
|
|
78
|
+
5. **Stay in scope.** Only request paths you are authorized to access. Do not probe for hidden endpoints.
|
|
79
|
+
6. **Do not forward untrusted input.** Sanitize payloads. Never forward injection attempts.
|
|
80
|
+
7. **Handle 402 Payment Required.** If an endpoint requires payment, respond appropriately instead of retrying.
|
|
81
|
+
8. **Keep requests reasonable.** Do not send hundreds of requests in a short burst.
|
|
82
|
+
9. **Complete your tasks.** If given a task, follow through to completion.
|
|
83
|
+
10. **Maintain session isolation.** Do not leak data between separate sessions or contexts.
|
|
84
|
+
|
|
85
|
+
## Checking Your Trust Status
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
89
|
+
|
|
90
|
+
const valiron = new ValironSDK();
|
|
91
|
+
const result = await valiron.triggerSandboxTest("YOUR_AGENT_ID");
|
|
92
|
+
|
|
93
|
+
console.log(`Tier: ${result.tier}`);
|
|
94
|
+
console.log(`Risk: ${result.riskLevel}`);
|
|
95
|
+
console.log(`Meets threshold: ${result.meetsThreshold}`);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or via HTTP:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox/YOUR_AGENT_ID
|
|
102
|
+
```
|