@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
package/dist/types.d.ts
CHANGED
|
@@ -102,6 +102,25 @@ export interface WalletProfile {
|
|
|
102
102
|
localReputation: LocalReputation | null;
|
|
103
103
|
routing: RoutingExplanation;
|
|
104
104
|
chain: ChainContext;
|
|
105
|
+
/** How the wallet was resolved to an agentId. */
|
|
106
|
+
resolutionSource?: "redis" | "subgraph" | "cache" | "none";
|
|
107
|
+
timestamp: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Response from `GET /operator/resolve-wallet/:wallet`
|
|
111
|
+
*
|
|
112
|
+
* Lightweight wallet → agentId resolution without the full trust profile.
|
|
113
|
+
*/
|
|
114
|
+
export type ResolutionSource = "redis" | "subgraph" | "cache" | "none";
|
|
115
|
+
export interface WalletResolution {
|
|
116
|
+
wallet: string;
|
|
117
|
+
agentId: string | null;
|
|
118
|
+
/** How the wallet was resolved. */
|
|
119
|
+
source: ResolutionSource;
|
|
120
|
+
/** Chain ID of the resolved agent (from subgraph), if available */
|
|
121
|
+
chainId?: number | null;
|
|
122
|
+
/** Agent name (from subgraph), if available */
|
|
123
|
+
agentName?: string | null;
|
|
105
124
|
timestamp: string;
|
|
106
125
|
}
|
|
107
126
|
/**
|
|
@@ -117,6 +136,26 @@ export interface SandboxResult {
|
|
|
117
136
|
chain: ChainContext;
|
|
118
137
|
message: string;
|
|
119
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Response from `GET /operator/agent/:agentId/snapshot`
|
|
141
|
+
*
|
|
142
|
+
* Opaque behavioral snapshot hash for hash-chain commitments.
|
|
143
|
+
* Contains no raw metrics — only the deterministic hash, the previous
|
|
144
|
+
* hash in the chain, and metadata.
|
|
145
|
+
*/
|
|
146
|
+
export interface AgentSnapshotSummary {
|
|
147
|
+
agentId: string;
|
|
148
|
+
/** Deterministic SHA-256 hash of the behavioral evaluation. Opaque — cannot be reversed to raw metrics. */
|
|
149
|
+
snapshotHash: string;
|
|
150
|
+
/** Hash of the prior snapshot, or "0x0" for the first evaluation. */
|
|
151
|
+
previousHash: string;
|
|
152
|
+
/** IPFS CID of the encrypted full snapshot data, or null if unavailable. */
|
|
153
|
+
encryptedDataUri: string | null;
|
|
154
|
+
/** ISO 8601 timestamp of when the evaluation was performed. */
|
|
155
|
+
timestamp: string | null;
|
|
156
|
+
/** Total number of interactions in the evaluation window. */
|
|
157
|
+
interactionCount: number;
|
|
158
|
+
}
|
|
120
159
|
/** Options for `gate()` call. */
|
|
121
160
|
export interface GateOptions {
|
|
122
161
|
/** Minimum Valiron score to allow (default: 65 = BA tier). */
|
|
@@ -144,6 +183,8 @@ export interface GateResult {
|
|
|
144
183
|
sandboxRan: boolean;
|
|
145
184
|
/** Whether cached results were used. */
|
|
146
185
|
cached: boolean;
|
|
186
|
+
/** Whether the score is from a micro-sandbox (fast, limited coverage). When true, a full deep test is running in the background and will update the cached score. */
|
|
187
|
+
provisional?: boolean;
|
|
147
188
|
}
|
|
148
189
|
/** Options that can be passed to individual SDK method calls. */
|
|
149
190
|
export interface CallOptions {
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
Base URL: `https://valiron-edge-proxy.onrender.com`
|
|
4
|
+
|
|
5
|
+
All endpoints are under the `/operator/` path prefix.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## GET /operator/agent/:agentId
|
|
10
|
+
|
|
11
|
+
Retrieve the complete trust profile for an agent.
|
|
12
|
+
|
|
13
|
+
### Parameters
|
|
14
|
+
|
|
15
|
+
| Parameter | Location | Type | Required | Description |
|
|
16
|
+
|-----------|----------|------|----------|-------------|
|
|
17
|
+
| `agentId` | path | string | yes | ERC-8004 token ID |
|
|
18
|
+
| `chain` | query | string | no | Network override (default: ethereum) |
|
|
19
|
+
|
|
20
|
+
### Response — 200 OK
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"agentId": "25459",
|
|
25
|
+
"identity": {
|
|
26
|
+
"agentId": "25459",
|
|
27
|
+
"wallet": "0x52ce...",
|
|
28
|
+
"tokenUri": "data:application/json;base64,...",
|
|
29
|
+
"name": "Agent Name",
|
|
30
|
+
"image": "https://...",
|
|
31
|
+
"description": "Agent description",
|
|
32
|
+
"endpoints": {
|
|
33
|
+
"agentWallet": "eip155:1:0x...",
|
|
34
|
+
"api": "https://api.example.com"
|
|
35
|
+
},
|
|
36
|
+
"trustModels": ["reputation_on_chain", "behavioral_sandbox"]
|
|
37
|
+
},
|
|
38
|
+
"onchainReputation": {
|
|
39
|
+
"feedbackCount": 12,
|
|
40
|
+
"averageScore": 92.5
|
|
41
|
+
},
|
|
42
|
+
"routing": {
|
|
43
|
+
"finalRoute": "prod",
|
|
44
|
+
"meetsThreshold": true
|
|
45
|
+
},
|
|
46
|
+
"chain": {
|
|
47
|
+
"name": "ethereum",
|
|
48
|
+
"chainId": 1
|
|
49
|
+
},
|
|
50
|
+
"timestamp": "2026-03-23T12:00:00.000Z"
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Error Responses
|
|
55
|
+
|
|
56
|
+
| Status | Meaning |
|
|
57
|
+
|--------|---------|
|
|
58
|
+
| 404 | Agent not found in ERC-8004 registry |
|
|
59
|
+
| 500 | Internal server error |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## GET /operator/wallet/:wallet
|
|
64
|
+
|
|
65
|
+
Reverse-lookup a wallet address to get its trust profile.
|
|
66
|
+
|
|
67
|
+
### Parameters
|
|
68
|
+
|
|
69
|
+
| Parameter | Location | Type | Required | Description |
|
|
70
|
+
|-----------|----------|------|----------|-------------|
|
|
71
|
+
| `wallet` | path | string | yes | Ethereum address (0x...) |
|
|
72
|
+
| `chain` | query | string | no | Network override |
|
|
73
|
+
|
|
74
|
+
### Response — 200 OK
|
|
75
|
+
|
|
76
|
+
Same structure as `GET /operator/agent/:agentId`.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## GET /operator/resolve-wallet/:wallet
|
|
81
|
+
|
|
82
|
+
Lightweight wallet → agentId resolution. Returns just the agent ID and how it was resolved, without the full trust profile.
|
|
83
|
+
|
|
84
|
+
Resolution chain: Redis → Agent0 subgraph → null.
|
|
85
|
+
|
|
86
|
+
### Parameters
|
|
87
|
+
|
|
88
|
+
| Parameter | Location | Type | Required | Description |
|
|
89
|
+
|-----------|----------|------|----------|-------------|
|
|
90
|
+
| `wallet` | path | string | yes | Ethereum address (0x...) |
|
|
91
|
+
| `chain` | query | string | no | Network override (default: ethereum) |
|
|
92
|
+
|
|
93
|
+
### Response — 200 OK
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"wallet": "0x52ce...",
|
|
98
|
+
"agentId": "25459",
|
|
99
|
+
"source": "subgraph",
|
|
100
|
+
"chainId": 1,
|
|
101
|
+
"agentName": "MyAgent",
|
|
102
|
+
"timestamp": "2024-01-01T00:00:00.000Z"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## POST /operator/trigger-sandbox/:agentId
|
|
109
|
+
|
|
110
|
+
Execute real-time sandbox tests against an agent and compute a trust evaluation.
|
|
111
|
+
|
|
112
|
+
### Parameters
|
|
113
|
+
|
|
114
|
+
| Parameter | Location | Type | Required | Description |
|
|
115
|
+
|-----------|----------|------|----------|-------------|
|
|
116
|
+
| `agentId` | path | string | yes | ERC-8004 token ID |
|
|
117
|
+
| `chain` | query | string | no | Network override |
|
|
118
|
+
|
|
119
|
+
### Response — 200 OK
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"ok": true,
|
|
124
|
+
"agentId": "25459",
|
|
125
|
+
"wallet": "0x52ce...",
|
|
126
|
+
"tier": "AAA",
|
|
127
|
+
"riskLevel": "GREEN",
|
|
128
|
+
"meetsThreshold": true,
|
|
129
|
+
"testSummary": {
|
|
130
|
+
"totalRequests": 25,
|
|
131
|
+
"successCount": 18,
|
|
132
|
+
"rateLimitCount": 5,
|
|
133
|
+
"errorCount": 2,
|
|
134
|
+
"avgLatencyMs": 120
|
|
135
|
+
},
|
|
136
|
+
"chain": {
|
|
137
|
+
"name": "ethereum",
|
|
138
|
+
"chainId": 1
|
|
139
|
+
},
|
|
140
|
+
"message": "Sandbox evaluation complete"
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## POST /operator/gate/:agentId
|
|
147
|
+
|
|
148
|
+
Trust gate — combined on-chain reputation + sandbox check. Returns an allow/deny decision. Designed for protecting payment endpoints (x402, etc.).
|
|
149
|
+
|
|
150
|
+
### Parameters
|
|
151
|
+
|
|
152
|
+
| Parameter | Location | Type | Required | Description |
|
|
153
|
+
|-----------|----------|------|----------|-------------|
|
|
154
|
+
| `agentId` | path | string | yes | ERC-8004 token ID |
|
|
155
|
+
|
|
156
|
+
### Request Body
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"ttlMs": 86400000
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
| Field | Type | Default | Description |
|
|
165
|
+
|-------|------|---------|-------------|
|
|
166
|
+
| `ttlMs` | number | 86400000 | Cache TTL in milliseconds (default 24 hours) |
|
|
167
|
+
|
|
168
|
+
### Response — 200 OK
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"allow": true,
|
|
173
|
+
"tier": "AAA",
|
|
174
|
+
"riskLevel": "GREEN",
|
|
175
|
+
"meetsThreshold": true,
|
|
176
|
+
"route": "prod",
|
|
177
|
+
"agentId": "25459",
|
|
178
|
+
"wallet": "0x52ce...",
|
|
179
|
+
"chain": {
|
|
180
|
+
"name": "ethereum",
|
|
181
|
+
"chainId": 1
|
|
182
|
+
},
|
|
183
|
+
"sandboxRan": false,
|
|
184
|
+
"cached": true
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Decision Logic
|
|
189
|
+
|
|
190
|
+
1. If the agent meets the trust threshold → `allow: true`
|
|
191
|
+
2. If the agent does not meet the threshold → `allow: false`
|
|
192
|
+
3. Cached sandbox results are reused within the `ttlMs` window
|
|
193
|
+
4. If no cached result exists, sandbox tests run automatically
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## GET /operator/agent/:agentId/snapshot
|
|
198
|
+
|
|
199
|
+
Get the latest behavioral snapshot hash for an agent. Returns an opaque hash suitable for on-chain commitment systems.
|
|
200
|
+
|
|
201
|
+
### Parameters
|
|
202
|
+
|
|
203
|
+
| Parameter | Location | Type | Required | Description |
|
|
204
|
+
|-----------|----------|------|----------|-------------|
|
|
205
|
+
| `agentId` | path | string | yes | ERC-8004 token ID |
|
|
206
|
+
| `chain` | query | string | no | Network override |
|
|
207
|
+
|
|
208
|
+
### Response — 200 OK
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"agentId": "25459",
|
|
213
|
+
"snapshotHash": "0x3a7f2b...",
|
|
214
|
+
"previousHash": "0x0",
|
|
215
|
+
"encryptedDataUri": null,
|
|
216
|
+
"timestamp": "2026-04-01T12:00:00.000Z",
|
|
217
|
+
"interactionCount": 15
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Error Responses
|
|
222
|
+
|
|
223
|
+
| Status | Meaning |
|
|
224
|
+
|--------|---------|
|
|
225
|
+
| 400 | Invalid agentId |
|
|
226
|
+
| 404 | Agent not found or no snapshot available (trigger a sandbox evaluation first) |
|
|
227
|
+
| 500 | Internal server error |
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## POST /operator/webhooks/register
|
|
232
|
+
|
|
233
|
+
Register a webhook URL to receive `evaluation_complete` events whenever Valiron evaluates an agent.
|
|
234
|
+
|
|
235
|
+
### Request Body
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"event": "evaluation_complete",
|
|
240
|
+
"url": "https://your-endpoint.com/hooks/valiron",
|
|
241
|
+
"agentIds": [42, 43]
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
| Field | Type | Required | Description |
|
|
246
|
+
|-------|------|----------|-------------|
|
|
247
|
+
| `event` | string | yes | Must be `"evaluation_complete"` |
|
|
248
|
+
| `url` | string | yes | HTTPS endpoint to receive webhook POST requests |
|
|
249
|
+
| `agentIds` | number[] | no | Filter to specific agent IDs. Omit for all agents. |
|
|
250
|
+
|
|
251
|
+
### Response — 201 Created
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"id": "a1b2c3d4-...",
|
|
256
|
+
"event": "evaluation_complete",
|
|
257
|
+
"url": "https://your-endpoint.com/hooks/valiron",
|
|
258
|
+
"agentIds": [42, 43],
|
|
259
|
+
"createdAt": "2026-04-01T12:00:00.000Z"
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Webhook Payload
|
|
264
|
+
|
|
265
|
+
When an evaluation completes, Valiron POSTs the following to your registered URL:
|
|
266
|
+
|
|
267
|
+
```json
|
|
268
|
+
{
|
|
269
|
+
"event": "evaluation_complete",
|
|
270
|
+
"agentId": "25459",
|
|
271
|
+
"snapshotHash": "0x3a7f2b...",
|
|
272
|
+
"previousHash": "0x8b2c1a...",
|
|
273
|
+
"encryptedDataUri": null,
|
|
274
|
+
"timestamp": "2026-04-01T12:05:00.000Z",
|
|
275
|
+
"interactionCount": 16
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## GET /operator/health
|
|
282
|
+
|
|
283
|
+
Health check endpoint.
|
|
284
|
+
|
|
285
|
+
### Response — 200 OK
|
|
286
|
+
|
|
287
|
+
```json
|
|
288
|
+
{
|
|
289
|
+
"status": "ok",
|
|
290
|
+
"supportedChains": ["ethereum", "monad", "arbitrum", "base", ...],
|
|
291
|
+
"defaultChain": "ethereum"
|
|
292
|
+
}
|
|
293
|
+
```
|
package/docs/CHAINS.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Supported Chains
|
|
2
|
+
|
|
3
|
+
Valiron operates across 21 blockchain networks. The ERC-8004 contracts are deployed at the same addresses on every chain.
|
|
4
|
+
|
|
5
|
+
## Contract Addresses (all chains)
|
|
6
|
+
|
|
7
|
+
| Contract | Address |
|
|
8
|
+
|----------|---------|
|
|
9
|
+
| Identity Registry | `0x8004A169FB4a3325136EB29fA0ceB6D2e539a432` |
|
|
10
|
+
| Reputation Registry | `0x8004BAa17C55a88189AE136b182e5fdA19dE9b63` |
|
|
11
|
+
|
|
12
|
+
## Supported Networks
|
|
13
|
+
|
|
14
|
+
| Chain ID | Name | SDK Value |
|
|
15
|
+
|----------|------|-----------|
|
|
16
|
+
| — | Ethereum | `ethereum` |
|
|
17
|
+
| — | Monad | `monad` |
|
|
18
|
+
| — | Arbitrum | `arbitrum` |
|
|
19
|
+
| — | Base | `base` |
|
|
20
|
+
| — | Avalanche | `avalanche` |
|
|
21
|
+
| — | Celo | `celo` |
|
|
22
|
+
| — | Polygon | `polygon` |
|
|
23
|
+
| — | Linea | `linea` |
|
|
24
|
+
| — | Abstract | `abstract` |
|
|
25
|
+
| — | BSC (Binance Smart Chain) | `bsc` |
|
|
26
|
+
| — | Gnosis | `gnosis` |
|
|
27
|
+
| — | Goat | `goat` |
|
|
28
|
+
| — | Mantle | `mantle` |
|
|
29
|
+
| — | MegaETH | `megaeth` |
|
|
30
|
+
| — | Metis | `metis` |
|
|
31
|
+
| — | Optimism | `optimism` |
|
|
32
|
+
| — | Scroll | `scroll` |
|
|
33
|
+
| — | SKALE Base | `skale_base` |
|
|
34
|
+
| — | Soneium | `soneium` |
|
|
35
|
+
| — | Taiko | `taiko` |
|
|
36
|
+
| — | X Layer | `xlayer` |
|
|
37
|
+
|
|
38
|
+
## Specifying a Chain
|
|
39
|
+
|
|
40
|
+
### SDK
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// At initialization (default for all calls)
|
|
44
|
+
const valiron = new ValironSDK({ chain: "monad" });
|
|
45
|
+
|
|
46
|
+
// Per-call override
|
|
47
|
+
const route = await valiron.checkAgent("25459", { chain: "arbitrum" });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### HTTP API
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Query parameter
|
|
54
|
+
curl https://valiron-edge-proxy.onrender.com/operator/agent/25459?chain=monad
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Querying Supported Chains
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
curl https://valiron-edge-proxy.onrender.com/operator/health
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"status": "ok",
|
|
67
|
+
"supportedChains": ["ethereum", "monad", "arbitrum", ...],
|
|
68
|
+
"defaultChain": "ethereum"
|
|
69
|
+
}
|
|
70
|
+
```
|
package/docs/ERRORS.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Errors
|
|
2
|
+
|
|
3
|
+
Common error scenarios, status codes, and guidance on how to handle them.
|
|
4
|
+
|
|
5
|
+
## HTTP Status Codes
|
|
6
|
+
|
|
7
|
+
| Status | Meaning | Action |
|
|
8
|
+
|--------|---------|--------|
|
|
9
|
+
| 200 | Success | Process the response |
|
|
10
|
+
| 400 | Bad request | Check your request parameters |
|
|
11
|
+
| 401 | Unauthorized | Verify your API key or credentials. **Do not retry.** |
|
|
12
|
+
| 403 | Forbidden | You do not have access. **Do not retry.** |
|
|
13
|
+
| 404 | Not found | Agent ID does not exist in the ERC-8004 registry |
|
|
14
|
+
| 429 | Too many requests | **Stop immediately.** Honor the `Retry-After` header. |
|
|
15
|
+
| 500 | Internal server error | Retry with exponential backoff |
|
|
16
|
+
| 502 | Bad gateway | Retry after a short delay |
|
|
17
|
+
| 503 | Service unavailable | Retry after `Retry-After` header duration |
|
|
18
|
+
|
|
19
|
+
## SDK Error Handling
|
|
20
|
+
|
|
21
|
+
The SDK throws typed errors that you can catch:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
25
|
+
|
|
26
|
+
const valiron = new ValironSDK();
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const profile = await valiron.getAgentProfile("99999");
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error.status === 404) {
|
|
32
|
+
// Agent not registered — register via ERC-8004 first
|
|
33
|
+
} else if (error.status === 429) {
|
|
34
|
+
// Rate limited — wait and retry
|
|
35
|
+
const retryAfter = error.headers?.["retry-after"];
|
|
36
|
+
await sleep(parseInt(retryAfter || "5") * 1000);
|
|
37
|
+
} else {
|
|
38
|
+
// Unexpected error — log and retry with backoff
|
|
39
|
+
console.error(error.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Retry Strategy
|
|
45
|
+
|
|
46
|
+
When retrying requests, follow this pattern:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
|
|
50
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
51
|
+
try {
|
|
52
|
+
return await fn();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// Never retry auth errors
|
|
55
|
+
if (error.status === 401 || error.status === 403) throw error;
|
|
56
|
+
|
|
57
|
+
// Never retry client errors (except 429)
|
|
58
|
+
if (error.status >= 400 && error.status < 500 && error.status !== 429) throw error;
|
|
59
|
+
|
|
60
|
+
if (attempt === maxRetries) throw error;
|
|
61
|
+
|
|
62
|
+
// Exponential backoff: 1s, 2s, 4s
|
|
63
|
+
const delay = Math.pow(2, attempt) * 1000;
|
|
64
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Unreachable");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Usage
|
|
71
|
+
const profile = await withRetry(() => valiron.getAgentProfile("25459"));
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Common Issues
|
|
75
|
+
|
|
76
|
+
### "Agent not found" (404)
|
|
77
|
+
|
|
78
|
+
Your agent ID is not registered in the ERC-8004 Identity Registry on the specified chain. Ensure:
|
|
79
|
+
- The agent has been minted in the Identity Registry
|
|
80
|
+
- You are querying the correct chain (`?chain=monad`, etc.)
|
|
81
|
+
- The agent ID is the correct ERC-721 token ID (numeric string)
|
|
82
|
+
|
|
83
|
+
### "No behavioral data" (sandbox result is null)
|
|
84
|
+
|
|
85
|
+
The agent has not been evaluated in the sandbox yet. Trigger a sandbox test:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
await valiron.triggerSandboxTest("YOUR_AGENT_ID");
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Timeout errors
|
|
92
|
+
|
|
93
|
+
The default SDK timeout is 5 seconds. For sandbox tests (which run real evaluations), increase it:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const valiron = new ValironSDK({ timeout: 30000 }); // 30 seconds
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Chain mismatch
|
|
100
|
+
|
|
101
|
+
If your agent is registered on Monad but you query Ethereum (the default), it will return 404. Always specify the correct chain:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const valiron = new ValironSDK({ chain: "monad" });
|
|
105
|
+
```
|
package/docs/IDENTITY.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Identity (ERC-8004)
|
|
2
|
+
|
|
3
|
+
Valiron uses the ERC-8004 standard for on-chain AI agent identity. Each agent is represented by an ERC-721 token in the Identity Registry.
|
|
4
|
+
|
|
5
|
+
## How Identity Works
|
|
6
|
+
|
|
7
|
+
1. An agent owner mints an ERC-721 token in the Identity Registry
|
|
8
|
+
2. The token's `tokenURI` points to an Agent Registration File (ARF)
|
|
9
|
+
3. The ARF contains the agent's name, description, endpoints, and supported trust models
|
|
10
|
+
4. Valiron reads this on-chain data to identify and evaluate agents
|
|
11
|
+
|
|
12
|
+
## Agent Registration File (ARF) Format
|
|
13
|
+
|
|
14
|
+
The `tokenURI` must resolve to a JSON object with this structure:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"name": "Your Agent Name",
|
|
19
|
+
"image": "https://example.com/agent-avatar.png",
|
|
20
|
+
"description": "A brief description of what your agent does.",
|
|
21
|
+
"endpoints": {
|
|
22
|
+
"agentWallet": "eip155:1:0xYourWalletAddress",
|
|
23
|
+
"api": "https://your-agent-api.example.com"
|
|
24
|
+
},
|
|
25
|
+
"supportedTrust": [
|
|
26
|
+
"reputation_on_chain",
|
|
27
|
+
"behavioral_sandbox"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### ARF Fields
|
|
33
|
+
|
|
34
|
+
| Field | Type | Required | Description |
|
|
35
|
+
|-------|------|----------|-------------|
|
|
36
|
+
| `name` | string | yes | Human-readable agent name |
|
|
37
|
+
| `image` | string | no | URL to agent avatar/image |
|
|
38
|
+
| `description` | string | no | Brief description of agent purpose |
|
|
39
|
+
| `endpoints.agentWallet` | string | yes | CAIP-10 formatted wallet address |
|
|
40
|
+
| `endpoints.api` | string | no | Agent's API endpoint URL |
|
|
41
|
+
| `supportedTrust` | string[] | no | Trust models the agent supports |
|
|
42
|
+
|
|
43
|
+
### Supported Trust Models
|
|
44
|
+
|
|
45
|
+
- `reputation_on_chain` — Agent participates in on-chain feedback
|
|
46
|
+
- `behavioral_sandbox` — Agent can be evaluated via sandbox testing
|
|
47
|
+
|
|
48
|
+
### ARF Hosting
|
|
49
|
+
|
|
50
|
+
The ARF can be hosted as:
|
|
51
|
+
- **Data URI**: `data:application/json;base64,eyJuYW1lIjoi...` (inline, gas-efficient)
|
|
52
|
+
- **IPFS**: `ipfs://bafybeig...` (permanent, decentralized)
|
|
53
|
+
- **HTTPS URL**: `https://example.com/agent.json` (mutable, centralized)
|
|
54
|
+
|
|
55
|
+
## Contract Addresses
|
|
56
|
+
|
|
57
|
+
The Identity Registry contract address is the same across all supported networks:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Identity Registry: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Reading Identity On-Chain
|
|
64
|
+
|
|
65
|
+
### Using viem (direct contract call)
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { createPublicClient, http } from "viem";
|
|
69
|
+
import { mainnet } from "viem/chains";
|
|
70
|
+
|
|
71
|
+
const client = createPublicClient({
|
|
72
|
+
chain: mainnet,
|
|
73
|
+
transport: http(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Get token owner
|
|
77
|
+
const owner = await client.readContract({
|
|
78
|
+
address: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
|
|
79
|
+
abi: [{ name: "ownerOf", type: "function", inputs: [{ type: "uint256" }], outputs: [{ type: "address" }], stateMutability: "view" }],
|
|
80
|
+
functionName: "ownerOf",
|
|
81
|
+
args: [25459n],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Get agent metadata
|
|
85
|
+
const tokenUri = await client.readContract({
|
|
86
|
+
address: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
|
|
87
|
+
abi: [{ name: "tokenURI", type: "function", inputs: [{ type: "uint256" }], outputs: [{ type: "string" }], stateMutability: "view" }],
|
|
88
|
+
functionName: "tokenURI",
|
|
89
|
+
args: [25459n],
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Using Valiron SDK
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { ValironSDK } from "@valiron/sdk";
|
|
97
|
+
|
|
98
|
+
const valiron = new ValironSDK();
|
|
99
|
+
const profile = await valiron.getAgentProfile("25459");
|
|
100
|
+
|
|
101
|
+
console.log(profile.identity.name);
|
|
102
|
+
console.log(profile.identity.wallet);
|
|
103
|
+
console.log(profile.identity.endpoints);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## On-Chain Reputation (Feedback)
|
|
107
|
+
|
|
108
|
+
The Reputation Registry stores feedback submitted by other agents and operators.
|
|
109
|
+
|
|
110
|
+
### Contract Address
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
Reputation Registry: 0x8004BAa17C55a88189AE136b182e5fdA19dE9b63
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Submitting Feedback
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
giveFeedback(
|
|
120
|
+
agentId: uint256, // Target agent's token ID
|
|
121
|
+
value: int128, // Score (typically 0-100)
|
|
122
|
+
valueDecimals: uint8, // Decimal places in value
|
|
123
|
+
tag1: string, // Category tag #1
|
|
124
|
+
tag2: string, // Category tag #2
|
|
125
|
+
endpoint: string, // API endpoint tested
|
|
126
|
+
feedbackURI: string, // IPFS CID or URL to full feedback JSON
|
|
127
|
+
feedbackHash: bytes32 // SHA-256 hash of feedback for verification
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Reading Feedback
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Get all feedback for an agent
|
|
135
|
+
readAllFeedback(agentId, clientAddresses, tag1, tag2, includeRevoked)
|
|
136
|
+
|
|
137
|
+
// Get specific feedback entry
|
|
138
|
+
readFeedback(agentId, clientAddress, feedbackIndex)
|
|
139
|
+
|
|
140
|
+
// Get all clients who provided feedback
|
|
141
|
+
getClients(agentId)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Impact on Trust Score
|
|
145
|
+
|
|
146
|
+
- **5+ feedbacks with average ≥ 90**: +10 bonus to Valiron score
|
|
147
|
+
- **5+ feedbacks with average ≥ 80**: +5 bonus
|
|
148
|
+
- **1–4 feedbacks with average ≥ 80**: +3 bonus
|
|
149
|
+
- **5+ feedbacks with average ≥ 80**: Grants direct `prod` routing (bypasses sandbox)
|