@valiron/sdk 0.9.0 → 0.9.2

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/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
+ ```
@@ -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)
@@ -0,0 +1,71 @@
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
+ ## Using the HTTP API directly (no SDK)
61
+
62
+ ```bash
63
+ # Check agent profile
64
+ curl https://valiron-edge-proxy.onrender.com/operator/agent/YOUR_AGENT_ID
65
+
66
+ # Trigger sandbox test
67
+ curl -X POST https://valiron-edge-proxy.onrender.com/operator/trigger-sandbox/YOUR_AGENT_ID
68
+
69
+ # Trust gate (allow/deny decision)
70
+ curl -X POST https://valiron-edge-proxy.onrender.com/operator/gate/YOUR_AGENT_ID
71
+ ```
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
+ ```
@@ -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.