@valiron/sdk 0.9.2 → 0.11.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 +39 -488
- 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 +52 -1
- package/docs/API-REFERENCE.md +112 -0
- package/docs/CHAINS.md +21 -1
- package/docs/QUICKSTART.md +30 -0
- package/docs/SDK-REFERENCE.md +76 -1
- package/docs/llms.txt +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,522 +14,73 @@ yarn add @valiron/sdk
|
|
|
14
14
|
pnpm add @valiron/sdk
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Quick Start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { ValironSDK } from '@valiron/sdk';
|
|
21
21
|
|
|
22
22
|
const valiron = new ValironSDK();
|
|
23
23
|
|
|
24
|
-
// Quick routing check
|
|
25
|
-
const route = await valiron.checkAgent('25459');
|
|
26
|
-
if (route === 'prod') {
|
|
27
|
-
// Allow full production access
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Query a Monad agent — per-call override
|
|
31
|
-
const monadRoute = await valiron.checkAgent('8348', { chain: 'monad' });
|
|
32
|
-
// You can also target other supported chains:
|
|
33
|
-
const baseRoute = await valiron.checkAgent('8348', { chain: 'base' });
|
|
34
|
-
const arbRoute = await valiron.checkAgent('8348', { chain: 'arbitrum' });
|
|
35
|
-
const avaxRoute = await valiron.checkAgent('1719', { chain: 'avalanche' });
|
|
36
|
-
const celoRoute = await valiron.checkAgent('123', { chain: 'celo' });
|
|
37
|
-
const polygonRoute = await valiron.checkAgent('2001', { chain: 'polygon' });
|
|
38
|
-
const lineaRoute = await valiron.checkAgent('3001', { chain: 'linea' });
|
|
39
|
-
|
|
40
|
-
// Or set the default chain at construction
|
|
41
|
-
const monadValiron = new ValironSDK({ chain: 'monad' });
|
|
42
|
-
const profile = await monadValiron.getAgentProfile('8348');
|
|
43
|
-
// or use base/arbitrum clients:
|
|
44
|
-
const baseValiron = new ValironSDK({ chain: 'base' });
|
|
45
|
-
const arbValiron = new ValironSDK({ chain: 'arbitrum' });
|
|
46
|
-
const avaxValiron = new ValironSDK({ chain: 'avalanche' });
|
|
47
|
-
const celoValiron = new ValironSDK({ chain: 'celo' });
|
|
48
|
-
const polygonValiron = new ValironSDK({ chain: 'polygon' });
|
|
49
|
-
const lineaValiron = new ValironSDK({ chain: 'linea' });
|
|
50
|
-
console.log(profile.routing.finalRoute); // 'prod'
|
|
51
|
-
console.log(profile.localReputation?.tier); // 'AAA'
|
|
52
|
-
console.log(profile.onchainReputation.averageScore); // 92.5
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
> **Note:** API key authentication is not yet enforced. The `apiKey` config
|
|
56
|
-
> field is reserved for future use.
|
|
57
|
-
|
|
58
|
-
## Core Concepts
|
|
59
|
-
|
|
60
|
-
### Route Decisions
|
|
61
|
-
|
|
62
|
-
The SDK returns one of four routing decisions:
|
|
63
|
-
|
|
64
|
-
| Route | Meaning |
|
|
65
|
-
|-------|--------|
|
|
66
|
-
| `prod` | Full access |
|
|
67
|
-
| `prod_throttled` | Rate-limited access |
|
|
68
|
-
| `sandbox` | Agent under evaluation |
|
|
69
|
-
| `sandbox_only` | Access denied |
|
|
70
|
-
|
|
71
|
-
### Trust Evaluation
|
|
72
|
-
|
|
73
|
-
Valiron evaluates agents using:
|
|
74
|
-
|
|
75
|
-
1. **On-chain Reputation** — ERC-8004 feedback submitted by other organizations
|
|
76
|
-
2. **Behavioral Analysis** — Proprietary sandbox evaluation of agent behavior
|
|
77
|
-
3. **Credit Rating** — Moody's-style scoring system (AAA to C)
|
|
78
|
-
|
|
79
|
-
### Architecture
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
Request → SDK.checkAgent() → Valiron Operator API → Route Decision → Your App
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## API Reference
|
|
86
|
-
|
|
87
|
-
### Constructor
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
new ValironSDK(config?: ValironConfig)
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
| Option | Type | Default | Description |
|
|
94
|
-
|--------|------|---------|-------------|
|
|
95
|
-
| `apiKey` | `string` | — | API key (reserved for future use) |
|
|
96
|
-
| `endpoint` | `string` | `https://valiron-edge-proxy.onrender.com` | API endpoint URL |
|
|
97
|
-
| `chain` | `'ethereum' \| 'monad' \| 'arbitrum' \| 'base' \| 'avalanche' \| 'celo' \| 'polygon' \| 'linea' \| 'abstract' \| 'bsc' \| 'gnosis' \| 'goat' \| 'mantle' \| 'megaeth' \| 'metis' \| 'optimism' \| 'scroll' \| 'skale_base' \| 'soneium' \| 'taiko' \| 'xlayer'` | `undefined` (server default) | Default blockchain network for all calls |
|
|
98
|
-
| `timeout` | `number` | `5000` | Request timeout (ms) |
|
|
99
|
-
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
### `checkAgent(agentId, options?): Promise<RouteDecision>`
|
|
104
|
-
|
|
105
|
-
Quick routing check — returns just the route decision string.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
24
|
+
// Quick routing check
|
|
108
25
|
const route = await valiron.checkAgent('25459');
|
|
109
26
|
// route: 'prod' | 'prod_throttled' | 'sandbox' | 'sandbox_only'
|
|
110
27
|
|
|
111
|
-
//
|
|
112
|
-
const monadRoute = await valiron.checkAgent('8348', { chain: 'monad' });
|
|
113
|
-
// Arbitrum or Base also supported
|
|
114
|
-
const baseRoute = await valiron.checkAgent('8348', { chain: 'base' });
|
|
115
|
-
const arbRoute = await valiron.checkAgent('8348', { chain: 'arbitrum' });
|
|
116
|
-
const avaxRoute = await valiron.checkAgent('1719', { chain: 'avalanche' });
|
|
117
|
-
const celoRoute = await valiron.checkAgent('123', { chain: 'celo' });
|
|
118
|
-
const polygonRoute = await valiron.checkAgent('2001', { chain: 'polygon' });
|
|
119
|
-
const lineaRoute = await valiron.checkAgent('3001', { chain: 'linea' });
|
|
120
|
-
// general helper: `valiron.checkAgent('id', { chain: 'base' })` works
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
### `getAgentProfile(agentId, options?): Promise<AgentProfile>`
|
|
126
|
-
|
|
127
|
-
Full trust profile combining on-chain identity, reputation, behavioral data, and routing.
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
28
|
+
// Full trust profile
|
|
130
29
|
const profile = await valiron.getAgentProfile('25459');
|
|
131
30
|
|
|
132
|
-
//
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
const baseProfile = await valiron.getAgentProfile('8348', { chain: 'base' });
|
|
136
|
-
const arbProfile = await valiron.getAgentProfile('8348', { chain: 'arbitrum' });
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**Response shape:**
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
{
|
|
143
|
-
agentId: string,
|
|
144
|
-
identity: {
|
|
145
|
-
agentId: string,
|
|
146
|
-
wallet: string,
|
|
147
|
-
tokenUri: string,
|
|
148
|
-
name: string,
|
|
149
|
-
image: string,
|
|
150
|
-
description: string,
|
|
151
|
-
endpoints: Record<string, string>,
|
|
152
|
-
trustModels: string[],
|
|
153
|
-
},
|
|
154
|
-
onchainReputation: {
|
|
155
|
-
count: string,
|
|
156
|
-
averageScore: number,
|
|
157
|
-
feedbackEntries: FeedbackEntry[],
|
|
158
|
-
totalFeedback: number,
|
|
159
|
-
},
|
|
160
|
-
localReputation: {
|
|
161
|
-
exists: boolean,
|
|
162
|
-
score: number,
|
|
163
|
-
tier: MoodysRating,
|
|
164
|
-
riskLevel: 'GREEN' | 'YELLOW' | 'RED',
|
|
165
|
-
graduated: boolean,
|
|
166
|
-
} | null,
|
|
167
|
-
routing: {
|
|
168
|
-
finalRoute: RouteDecision,
|
|
169
|
-
decision: string,
|
|
170
|
-
reasons: string[],
|
|
171
|
-
signals: {
|
|
172
|
-
onchain: { feedbackCount, averageScore, meetsThreshold },
|
|
173
|
-
local: { exists, graduated, tier, riskLevel },
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
timestamp: string,
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
---
|
|
181
|
-
|
|
182
|
-
### `getWalletProfile(wallet, options?): Promise<WalletProfile>`
|
|
183
|
-
|
|
184
|
-
Reverse-lookup a wallet address to get its trust profile.
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
const profile = await valiron.getWalletProfile('0x52ce…');
|
|
188
|
-
console.log(profile.routing.finalRoute);
|
|
189
|
-
|
|
190
|
-
// With chain override
|
|
191
|
-
const monadProfile = await valiron.getWalletProfile('0xABC…', { chain: 'monad' });
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
### `triggerSandboxTest(agentId, options?): Promise<SandboxResult>`
|
|
197
|
-
|
|
198
|
-
Run real sandbox tests against an agent and compute a Valiron score.
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
const result = await valiron.triggerSandboxTest('25459');
|
|
202
|
-
console.log(result.valironScore); // 95
|
|
203
|
-
console.log(result.tier); // 'AAA'
|
|
204
|
-
console.log(result.riskLevel); // 'GREEN'
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
31
|
+
// Trust gate for payment endpoints
|
|
32
|
+
const gate = await valiron.gate('25459');
|
|
33
|
+
if (gate.allow) { /* proceed */ }
|
|
208
34
|
|
|
209
|
-
|
|
35
|
+
// Behavioral snapshot (for hash-chain commitments)
|
|
36
|
+
const snapshot = await valiron.getAgentSnapshot('25459');
|
|
37
|
+
console.log(snapshot.snapshotHash); // '0xabc…'
|
|
38
|
+
console.log(snapshot.previousHash); // '0x0' (genesis)
|
|
210
39
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
console.log(result.allow); // true
|
|
216
|
-
console.log(result.score); // 95
|
|
217
|
-
console.log(result.tier); // 'AAA'
|
|
218
|
-
console.log(result.riskLevel); // 'GREEN'
|
|
219
|
-
console.log(result.sandboxRan); // true (first call) / false (cached)
|
|
220
|
-
|
|
221
|
-
// Custom threshold + TTL
|
|
222
|
-
const result2 = await valiron.gate('8348', {
|
|
223
|
-
minScore: 85, // require A tier or above
|
|
224
|
-
ttlMs: 3600_000, // re-test every hour
|
|
225
|
-
chain: 'monad', // chain override
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (result2.allow) {
|
|
229
|
-
// proceed to payment
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
| Option | Type | Default | Description |
|
|
234
|
-
|--------|------|---------|-------------|
|
|
235
|
-
| `minScore` | `number` | `65` | Minimum score to allow (0–110) |
|
|
236
|
-
| `ttlMs` | `number` | `86400000` | Cache TTL for sandbox results (ms) |
|
|
237
|
-
| `chain` | `SupportedChain` | constructor default | Blockchain network override |
|
|
238
|
-
|
|
239
|
-
**Response shape:**
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
{
|
|
243
|
-
allow: boolean, // allow or deny
|
|
244
|
-
score: number, // combined Valiron score
|
|
245
|
-
tier: MoodysRating, // 'AAA' | 'AA' | ... | 'C'
|
|
246
|
-
riskLevel: RiskLevel, // 'GREEN' | 'YELLOW' | 'RED'
|
|
247
|
-
route: RouteDecision, // 'prod' | 'prod_throttled' | 'sandbox' | 'sandbox_only'
|
|
248
|
-
agentId: string,
|
|
249
|
-
wallet: string,
|
|
250
|
-
sandboxRan: boolean, // whether sandbox was freshly executed
|
|
251
|
-
cached: boolean, // whether cached metrics were reused
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
> **`gate()` vs `checkAgent()`:** `checkAgent()` returns a route decision based on existing data. `gate()` actively runs sandbox tests (if stale/missing), computes a combined score, and returns a binary allow/deny decision — ideal for protecting payment endpoints.
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
### `createValironGate(config): Middleware`
|
|
260
|
-
|
|
261
|
-
Express-compatible middleware factory that wraps `gate()`. Drop it in front of your routes and it handles agent extraction, trust gating, and error responses automatically.
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
import { ValironSDK, createValironGate } from '@valiron/sdk';
|
|
265
|
-
|
|
266
|
-
const valiron = new ValironSDK({ chain: 'monad' });
|
|
267
|
-
|
|
268
|
-
// Basic — uses x-agent-id header, minScore 65, 24h TTL
|
|
269
|
-
app.use('/api/paid', createValironGate({ sdk: valiron }));
|
|
270
|
-
|
|
271
|
-
// Custom threshold and TTL
|
|
272
|
-
app.use('/api/premium', createValironGate({
|
|
273
|
-
sdk: valiron,
|
|
274
|
-
minScore: 85,
|
|
275
|
-
ttlMs: 3600_000,
|
|
276
|
-
}));
|
|
40
|
+
// Multichain — override per-call or at construction
|
|
41
|
+
const monadValiron = new ValironSDK({ chain: 'monad' });
|
|
42
|
+
await monadValiron.checkAgent('8348');
|
|
43
|
+
await valiron.checkAgent('8348', { chain: 'base' });
|
|
277
44
|
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log(`Allowed agent ${result.agentId} (score: ${result.score})`);
|
|
284
|
-
},
|
|
285
|
-
onDeny: (req, res, result) => {
|
|
286
|
-
res.status(403).json({
|
|
287
|
-
error: 'Insufficient trust score',
|
|
288
|
-
requiredTier: 'A',
|
|
289
|
-
currentTier: result.tier,
|
|
290
|
-
});
|
|
291
|
-
},
|
|
292
|
-
}));
|
|
45
|
+
// Solana — use chain: 'solana' with base-58 pubkey or sequential ID
|
|
46
|
+
const solanaValiron = new ValironSDK({ chain: 'solana' });
|
|
47
|
+
const profile = await solanaValiron.getAgentProfile('1226'); // sequential ID
|
|
48
|
+
console.log(profile.identity.name); // 'NoahScout_Bot.noah'
|
|
49
|
+
console.log(profile.onchainReputation.solana?.trustTier); // 'trusted'
|
|
293
50
|
```
|
|
294
51
|
|
|
295
|
-
|
|
296
|
-
|--------|------|---------|-------------|
|
|
297
|
-
| `sdk` | `ValironSDK` | *required* | Configured SDK instance |
|
|
298
|
-
| `extractAgentId` | `(req) => string \| null` | `req.headers['x-agent-id']` | How to get the agent ID |
|
|
299
|
-
| `minScore` | `number` | `65` | Minimum score to allow |
|
|
300
|
-
| `ttlMs` | `number` | `86400000` | Sandbox cache TTL (ms) |
|
|
301
|
-
| `onDeny` | `(req, res, result) => void` | 403 JSON response | Custom deny handler |
|
|
302
|
-
| `onAllow` | `(req, result) => void` | — | Hook after allow, before next() |
|
|
303
|
-
|
|
304
|
-
**Behavior:**
|
|
305
|
-
- On **allow**: sets `req.valiron` to the `GateResult` and calls `next()`
|
|
306
|
-
- On **deny**: returns 403 (or delegates to `onDeny`)
|
|
307
|
-
- On **missing agent ID**: returns 401
|
|
308
|
-
- On **error**: returns 503 (fail-closed)
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
|
|
312
|
-
## Multichain Support
|
|
313
|
-
|
|
314
|
-
Valiron supports multiple blockchain networks. Set the chain globally or per-call:
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
// Option A: Set default chain at construction
|
|
318
|
-
const valiron = new ValironSDK({ chain: 'monad' });
|
|
319
|
-
await valiron.getAgentProfile('8348'); // Uses Monad
|
|
320
|
-
|
|
321
|
-
// Option B: Override per-call (takes precedence over constructor default)
|
|
322
|
-
const valiron2 = new ValironSDK(); // No default chain
|
|
323
|
-
await valiron2.getAgentProfile('8348', { chain: 'monad' }); // Monad
|
|
324
|
-
await valiron2.getAgentProfile('25459', { chain: 'ethereum' }); // Ethereum
|
|
325
|
-
await valiron2.getAgentProfile('25459'); // Server default (ethereum)
|
|
52
|
+
## Methods
|
|
326
53
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
54
|
+
| Method | Returns | Description |
|
|
55
|
+
|--------|---------|-------------|
|
|
56
|
+
| `checkAgent(agentId, opts?)` | `RouteDecision` | Quick routing check |
|
|
57
|
+
| `getAgentProfile(agentId, opts?)` | `AgentProfile` | Full trust profile (identity + reputation + routing) |
|
|
58
|
+
| `getWalletProfile(wallet, opts?)` | `WalletProfile` | Reverse-lookup wallet → trust profile |
|
|
59
|
+
| `resolveWallet(wallet, opts?)` | `WalletResolution` | Lightweight wallet → agentId (Redis → cache → Agent0 subgraph) |
|
|
60
|
+
| `triggerSandboxTest(agentId, opts?)` | `SandboxResult` | Run sandbox tests, compute behavioral score |
|
|
61
|
+
| `gate(agentId, opts?)` | `GateResult` | Trust gate: reputation + sandbox → allow/deny |
|
|
62
|
+
| `getAgentSnapshot(agentId, opts?)` | `AgentSnapshotSummary` | Opaque behavioral snapshot hash for chain commitments |
|
|
63
|
+
| `createValironGate(config)` | Express middleware | Drop-in middleware wrapping `gate()` |
|
|
331
64
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
All SDK methods accept an optional `CallOptions` object with a `chain` field.
|
|
65
|
+
All methods accept an optional `{ chain }` override. See the [full documentation](https://valiron.co/docs) for response shapes, options, and examples.
|
|
335
66
|
|
|
336
67
|
## Telemetry
|
|
337
68
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
To **disable** telemetry:
|
|
69
|
+
Anonymous usage telemetry is collected by default (opt-out). No PII is collected.
|
|
341
70
|
|
|
342
71
|
```ts
|
|
343
|
-
const valiron = new ValironSDK({
|
|
344
|
-
telemetry: {
|
|
345
|
-
enabled: false,
|
|
346
|
-
},
|
|
347
|
-
});
|
|
348
|
-
```
|
|
72
|
+
const valiron = new ValironSDK({ telemetry: { enabled: false } });
|
|
349
73
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const valiron = new ValironSDK({
|
|
354
|
-
telemetry: {
|
|
355
|
-
appId: "my-app",
|
|
356
|
-
workspaceId: "ws_123",
|
|
357
|
-
env: "prod",
|
|
358
|
-
// Optional: custom ingest endpoint (defaults to `${endpoint}/telemetry/sdk`)
|
|
359
|
-
// endpoint: "https://my-collector.example.com/events",
|
|
360
|
-
},
|
|
74
|
+
// Customize
|
|
75
|
+
const valiron2 = new ValironSDK({
|
|
76
|
+
telemetry: { appId: 'my-app', env: 'prod' },
|
|
361
77
|
});
|
|
362
78
|
```
|
|
363
79
|
|
|
364
|
-
|
|
365
|
-
- `sdk_initialized`
|
|
366
|
-
- `sdk_call`
|
|
367
|
-
- `route_decision`
|
|
368
|
-
- `sdk_latency_stats` (p50/p95 by method+chain+sdk_version)
|
|
369
|
-
|
|
370
|
-
> Geography should be derived server-side from request IP (coarse country/region), not captured directly in SDK payloads.
|
|
371
|
-
|
|
372
|
-
---
|
|
373
|
-
|
|
374
|
-
## Integration Examples
|
|
375
|
-
|
|
376
|
-
### Express.js Middleware
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
import express from 'express';
|
|
380
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
381
|
-
|
|
382
|
-
const app = express();
|
|
383
|
-
const valiron = new ValironSDK();
|
|
384
|
-
|
|
385
|
-
app.use('/api/protected/*', async (req, res, next) => {
|
|
386
|
-
const agentId = req.headers['x-agent-id'] as string;
|
|
387
|
-
if (!agentId) return res.status(400).json({ error: 'Missing x-agent-id' });
|
|
388
|
-
|
|
389
|
-
const profile = await valiron.getAgentProfile(agentId);
|
|
390
|
-
const { finalRoute } = profile.routing;
|
|
391
|
-
|
|
392
|
-
if (finalRoute === 'prod' || finalRoute === 'prod_throttled') {
|
|
393
|
-
(req as any).valironProfile = profile;
|
|
394
|
-
return next();
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return res.status(403).json({
|
|
398
|
-
error: finalRoute === 'sandbox' ? 'Agent under evaluation' : 'Access denied',
|
|
399
|
-
message: profile.routing.decision,
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### Next.js Middleware
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
408
|
-
import { ValironSDK } from '@valiron/sdk';
|
|
409
|
-
|
|
410
|
-
const valiron = new ValironSDK();
|
|
411
|
-
|
|
412
|
-
export async function middleware(request: NextRequest) {
|
|
413
|
-
const agentId = request.headers.get('x-agent-id');
|
|
414
|
-
if (!agentId) {
|
|
415
|
-
return NextResponse.json({ error: 'Missing x-agent-id' }, { status: 400 });
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const route = await valiron.checkAgent(agentId);
|
|
419
|
-
|
|
420
|
-
if (route === 'prod' || route === 'prod_throttled') {
|
|
421
|
-
return NextResponse.next();
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return NextResponse.json({ error: 'Access denied' }, { status: 403 });
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export const config = { matcher: '/api/protected/:path*' };
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
### x402 Payment Integration
|
|
431
|
-
|
|
432
|
-
Valiron integrates with x402 payment-gated APIs (e.g., [Orthogonal](https://www.orth.sh/)). Use `createValironGate()` to verify trust before processing payments:
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
import express from 'express';
|
|
436
|
-
import { ValironSDK, createValironGate } from '@valiron/sdk';
|
|
437
|
-
|
|
438
|
-
const app = express();
|
|
439
|
-
const valiron = new ValironSDK({ chain: 'monad' });
|
|
440
|
-
|
|
441
|
-
// Trust gate sits in front of x402 payment flow
|
|
442
|
-
const trustGate = createValironGate({
|
|
443
|
-
sdk: valiron,
|
|
444
|
-
minScore: 65,
|
|
445
|
-
ttlMs: 24 * 60 * 60_000, // 24h
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// Payment handler runs AFTER trust gate passes
|
|
449
|
-
async function x402PaymentCheck(req: any, res: any, next: any) {
|
|
450
|
-
const paymentValid = await verifyPayment(req.headers['x-payment']);
|
|
451
|
-
if (!paymentValid) {
|
|
452
|
-
// Trust-based pricing — better agents pay less
|
|
453
|
-
const tier = req.valiron?.tier || 'B';
|
|
454
|
-
const pricing: Record<string, number> = {
|
|
455
|
-
AAA: 5, AA: 5, A: 8, BAA: 10, BA: 25, B: 50,
|
|
456
|
-
};
|
|
457
|
-
return res.status(402).json({
|
|
458
|
-
accepts: [{ scheme: 'exact', maxAmountRequired: pricing[tier] || 50, payTo: '0x…' }],
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
next();
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// Flow: Trust Gate → x402 Payment → Handler
|
|
465
|
-
app.get('/api/premium/data', trustGate, x402PaymentCheck, (req, res) => {
|
|
466
|
-
res.json({ data: 'Premium content', tier: (req as any).valiron.tier });
|
|
467
|
-
});
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
## Moody's Credit Rating Tiers
|
|
471
|
-
|
|
472
|
-
| Tier | Risk | Access Level |
|
|
473
|
-
|------|------|--------------|
|
|
474
|
-
| AAA | Prime | Full production |
|
|
475
|
-
| AA | High grade | Full production |
|
|
476
|
-
| A | Upper medium | Full production |
|
|
477
|
-
| BAA | Medium | Full production (monitored) |
|
|
478
|
-
| BA | Speculative | Throttled |
|
|
479
|
-
| B | Highly speculative | Throttled |
|
|
480
|
-
| CAA | Substantial risk | Sandbox only |
|
|
481
|
-
| CA | Extremely speculative | Sandbox only |
|
|
482
|
-
| C | Default risk | Sandbox only |
|
|
483
|
-
|
|
484
|
-
## TypeScript Types
|
|
485
|
-
|
|
486
|
-
The SDK is fully typed. Import types as needed:
|
|
487
|
-
|
|
488
|
-
```typescript
|
|
489
|
-
import {
|
|
490
|
-
ValironSDK,
|
|
491
|
-
SupportedChain,
|
|
492
|
-
CallOptions,
|
|
493
|
-
RouteDecision,
|
|
494
|
-
MoodysRating,
|
|
495
|
-
RiskLevel,
|
|
496
|
-
AgentProfile,
|
|
497
|
-
WalletProfile,
|
|
498
|
-
SandboxResult,
|
|
499
|
-
GateResult,
|
|
500
|
-
GateOptions,
|
|
501
|
-
AgentIdentity,
|
|
502
|
-
OnchainReputation,
|
|
503
|
-
LocalReputation,
|
|
504
|
-
RoutingExplanation,
|
|
505
|
-
FeedbackEntry,
|
|
506
|
-
ValironError,
|
|
507
|
-
ValironClient,
|
|
508
|
-
createValironGate,
|
|
509
|
-
ValironGateConfig,
|
|
510
|
-
} from '@valiron/sdk';
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
## Error Handling
|
|
514
|
-
|
|
515
|
-
```typescript
|
|
516
|
-
import { ValironError } from '@valiron/sdk';
|
|
517
|
-
|
|
518
|
-
try {
|
|
519
|
-
const profile = await valiron.getAgentProfile('123');
|
|
520
|
-
} catch (error) {
|
|
521
|
-
if (error instanceof ValironError) {
|
|
522
|
-
switch (error.code) {
|
|
523
|
-
case 'TIMEOUT_ERROR': // Request timed out
|
|
524
|
-
case 'NETWORK_ERROR': // Could not reach API
|
|
525
|
-
case 'API_ERROR': // Non-2xx response (check error.statusCode)
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
## Additional Resources
|
|
80
|
+
## Documentation
|
|
532
81
|
|
|
82
|
+
- [Full Documentation](https://valiron.co/docs) — interactive docs with all methods, examples, and dynamic pricing
|
|
83
|
+
- [llms.txt](https://valiron.co/llms.txt) — compact reference for LLM integration
|
|
533
84
|
- [ERC-8004 Standard](https://eips.ethereum.org/EIPS/eip-8004)
|
|
534
85
|
|
|
535
86
|
## Support
|
package/dist/clients.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValironConfig, AgentProfile, WalletProfile, SandboxResult, GateResult, GateOptions, CallOptions } from "./types";
|
|
1
|
+
import { ValironConfig, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, SandboxResult, GateResult, GateOptions, CallOptions } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* HTTP client for the Valiron Operator API.
|
|
4
4
|
*
|
|
@@ -27,9 +27,32 @@ export declare class ValironClient {
|
|
|
27
27
|
/**
|
|
28
28
|
* Get a trust profile by wallet address (reverse lookup).
|
|
29
29
|
*
|
|
30
|
+
* Resolution chain: Redis → Agent0 subgraph → null.
|
|
31
|
+
* If an agentId is resolved, returns the full trust profile.
|
|
32
|
+
*
|
|
30
33
|
* `GET /operator/wallet/:wallet`
|
|
31
34
|
*/
|
|
32
35
|
getWalletProfile(wallet: string, options?: CallOptions): Promise<WalletProfile>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve a wallet address to an ERC-8004 agent ID.
|
|
38
|
+
*
|
|
39
|
+
* Lightweight lookup — returns just the agentId and resolution source
|
|
40
|
+
* without fetching the full trust profile. Uses Redis first, then
|
|
41
|
+
* falls back to the Agent0 subgraph.
|
|
42
|
+
*
|
|
43
|
+
* `GET /operator/resolve-wallet/:wallet`
|
|
44
|
+
*/
|
|
45
|
+
resolveWallet(wallet: string, options?: CallOptions): Promise<WalletResolution>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the latest behavioral snapshot hash for an agent.
|
|
48
|
+
*
|
|
49
|
+
* Returns an opaque hash of the agent's most recent behavioral
|
|
50
|
+
* evaluation, plus the previous hash for chain continuity.
|
|
51
|
+
* Contains no raw metrics or proprietary data.
|
|
52
|
+
*
|
|
53
|
+
* `GET /operator/agent/:agentId/snapshot`
|
|
54
|
+
*/
|
|
55
|
+
getAgentSnapshot(agentId: string, options?: CallOptions): Promise<AgentSnapshotSummary>;
|
|
33
56
|
/**
|
|
34
57
|
* Trigger real sandbox testing for an agent.
|
|
35
58
|
*
|
package/dist/clients.js
CHANGED
|
@@ -57,6 +57,9 @@ class ValironClient {
|
|
|
57
57
|
/**
|
|
58
58
|
* Get a trust profile by wallet address (reverse lookup).
|
|
59
59
|
*
|
|
60
|
+
* Resolution chain: Redis → Agent0 subgraph → null.
|
|
61
|
+
* If an agentId is resolved, returns the full trust profile.
|
|
62
|
+
*
|
|
60
63
|
* `GET /operator/wallet/:wallet`
|
|
61
64
|
*/
|
|
62
65
|
async getWalletProfile(wallet, options) {
|
|
@@ -68,6 +71,30 @@ class ValironClient {
|
|
|
68
71
|
}
|
|
69
72
|
return profile;
|
|
70
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolve a wallet address to an ERC-8004 agent ID.
|
|
76
|
+
*
|
|
77
|
+
* Lightweight lookup — returns just the agentId and resolution source
|
|
78
|
+
* without fetching the full trust profile. Uses Redis first, then
|
|
79
|
+
* falls back to the Agent0 subgraph.
|
|
80
|
+
*
|
|
81
|
+
* `GET /operator/resolve-wallet/:wallet`
|
|
82
|
+
*/
|
|
83
|
+
async resolveWallet(wallet, options) {
|
|
84
|
+
return this.get(`/operator/resolve-wallet/${wallet}`, this.resolveChain(options));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the latest behavioral snapshot hash for an agent.
|
|
88
|
+
*
|
|
89
|
+
* Returns an opaque hash of the agent's most recent behavioral
|
|
90
|
+
* evaluation, plus the previous hash for chain continuity.
|
|
91
|
+
* Contains no raw metrics or proprietary data.
|
|
92
|
+
*
|
|
93
|
+
* `GET /operator/agent/:agentId/snapshot`
|
|
94
|
+
*/
|
|
95
|
+
async getAgentSnapshot(agentId, options) {
|
|
96
|
+
return this.get(`/operator/agent/${agentId}/snapshot`, this.resolveChain(options));
|
|
97
|
+
}
|
|
71
98
|
/**
|
|
72
99
|
* Trigger real sandbox testing for an agent.
|
|
73
100
|
*
|
|
@@ -297,6 +324,8 @@ class ValironClient {
|
|
|
297
324
|
extractMethodName(path) {
|
|
298
325
|
if (path.startsWith("/operator/agent/"))
|
|
299
326
|
return "getAgentProfile";
|
|
327
|
+
if (path.startsWith("/operator/resolve-wallet/"))
|
|
328
|
+
return "resolveWallet";
|
|
300
329
|
if (path.startsWith("/operator/wallet/"))
|
|
301
330
|
return "getWalletProfile";
|
|
302
331
|
if (path.startsWith("/operator/trigger-sandbox/"))
|