@valiron/sdk 1.1.1 → 1.2.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Official TypeScript SDK for **Valiron** — Trust & Reputation Middleware for API Protection
4
4
 
5
- Protect your API endpoints from bad or malicious AI agents. Valiron evaluates incoming agents using on-chain identity (ERC-8004/Solana), key-based identity for local/Web2 agents, behavioral sandbox testing, predictive risk forecasts, and Moody's-style credit ratings — so you can allow trusted agents and block risky ones automatically.
5
+ Protect your API endpoints from bad or malicious AI agents. Valiron evaluates incoming agents using on-chain identity (ERC-8004/Solana), key-based identity for local/Web2 agents, behavioral sandbox testing, optional wallet-history intelligence, predictive risk forecasts, and Moody's-style credit ratings — so you can allow trusted agents and block risky ones automatically.
6
6
 
7
7
  ## Installation
8
8
 
@@ -15,7 +15,10 @@ npm install @valiron/sdk
15
15
  ```typescript
16
16
  import { ValironSDK, createValironGate } from "@valiron/sdk";
17
17
 
18
- const valiron = new ValironSDK({ chain: "ethereum" });
18
+ const valiron = new ValironSDK({
19
+ chain: "ethereum",
20
+ apiKey: process.env.VALIRON_API_KEY, // required for Pro signals
21
+ });
19
22
 
20
23
  // Check if an on-chain agent is trusted
21
24
  const route = await valiron.checkAgent("AGENT_ID");
@@ -35,17 +38,35 @@ app.use("/api/paid", createValironGate({ sdk: valiron }));
35
38
  // Optional: choose endpoint-specific trust signals
36
39
  app.use("/api/paid", createValironGate({
37
40
  sdk: valiron,
38
- trustSignals: ["8004", "sandbox"], // Pro can add "world", "self", and "icebreaker"
41
+ trustSignals: ["8004", "sandbox"], // Pro can add "world", "self", "icebreaker", and "wallet"
39
42
  }));
40
43
 
41
44
  // Fastify, Next.js, and generic middleware also available
42
45
  // See SDK Reference for valironFastifyPlugin, createValironNextMiddleware, valironGateCheck
43
46
  ```
44
47
 
45
- No API key required for read operations.
48
+ No API key is required for basic read operations. Pro trust signals and `getWalletRisk()` require an operator API key.
46
49
 
47
50
  Use `x-agent-id` for ERC-8004/Solana agents. Use `x-agent-address` plus Valiron challenge-response for local, Web2, or non-ERC-8004 agents. Agents can follow the hosted identity skill at https://www.valiron.co/auth.md.
48
51
 
52
+ ## Error diagnostics
53
+
54
+ SDK failures are `ValironError` instances. Handle the stable `code` programmatically and log `details.action`, `details.requestId`, `details.docsUrl`, and `details.retryAfterMs` to make recovery explicit.
55
+
56
+ ```typescript
57
+ import { ValironError } from "@valiron/sdk";
58
+
59
+ try {
60
+ await valiron.getAgentProfile("AGENT_ID");
61
+ } catch (error) {
62
+ if (error instanceof ValironError) {
63
+ console.error(error.code, error.message, error.details?.action);
64
+ }
65
+ }
66
+ ```
67
+
68
+ Trust middleware returns the same fields in JSON responses. Its primary codes are `MISSING_AGENT_IDENTITY`, `TRUST_GATE_DENIED`, `AGENT_EVALUATION_PENDING`, and `TRUST_GATE_UNAVAILABLE`. See the [error guide](https://valiron.co/docs#error-handling) for retry rules and hosted-wrapper diagnostics.
69
+
49
70
  ### Additional Features
50
71
 
51
72
  - **Auto-Sandbox** — Middleware automatically evaluates new agents (on-chain and key-based) on their first gated request
@@ -54,6 +75,7 @@ Use `x-agent-id` for ERC-8004/Solana agents. Use `x-agent-address` plus Valiron
54
75
  - **Key-Based Agents** — Support Web2 agents via EIP-191 challenge-response (auto-detected, auto-sandboxed)
55
76
  - **World ID** — Verify agent-human linkage via Worldcoin proof-of-personhood
56
77
  - **Self** — Create Self Enterprise sessions and store signed eligible-human webhook results
78
+ - **Wallet Intelligence** (Pro) — Score bounded Alchemy/Helius wallet history with confidence and explainable reasons
57
79
  - **Telemetry** — Optional anonymous usage metrics (disable with `telemetry: { enabled: false }`)
58
80
 
59
81
  ### Cleanup
@@ -72,6 +94,8 @@ Full SDK reference, API docs, trust model, and integration guides:
72
94
  - **[SDK Reference](https://valiron.co/docs/agents/SDK-REFERENCE.md)** — all methods, options, and response types
73
95
  - **[API Reference](https://valiron.co/docs/agents/API-REFERENCE.md)** — HTTP endpoints
74
96
  - **[Quickstart](https://valiron.co/docs/agents/QUICKSTART.md)** — get started in 2 minutes
97
+ - **[End-to-End Middleware Integration](https://valiron.co/docs/agents/E2E-MIDDLEWARE-INTEGRATION.md)** — identity, trust signals, downstream policy, and testing
98
+ - **[Error Guide](https://valiron.co/docs#error-handling)** — codes, recovery actions, retries, and wrapper diagnostics
75
99
  - **[llms.txt](https://valiron.co/llms.txt)** — compact reference for LLM/agent integration
76
100
  - **Install agent skill**: `npx @valiron/skill`
77
101
 
package/dist/clients.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ValironConfig, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, CallOptions, KeyAgentChallenge, KeyAgentProfile, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, ProxyRequest, ProxyResponse } from "./types";
1
+ import { ValironConfig, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, WalletRiskSnapshot, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, CallOptions, KeyAgentChallenge, KeyAgentProfile, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, ProxyRequest, ProxyResponse } from "./types";
2
2
  /**
3
3
  * HTTP client for the Valiron Operator API.
4
4
  *
@@ -34,6 +34,8 @@ export declare class ValironClient {
34
34
  * `GET /operator/wallet/:wallet`
35
35
  */
36
36
  getWalletProfile(wallet: string, options?: CallOptions): Promise<WalletProfile>;
37
+ /** Get an explainable wallet-history risk assessment. Pro plans only. */
38
+ getWalletRisk(wallet: string, options?: CallOptions): Promise<WalletRiskSnapshot>;
37
39
  /**
38
40
  * Resolve a wallet address to an ERC-8004 agent ID.
39
41
  *
@@ -190,6 +192,8 @@ export declare class ValironClient {
190
192
  /** Emit an SDK telemetry event from higher-level helpers. */
191
193
  emitTelemetry(event: string, payload: Record<string, unknown>): void;
192
194
  private buildHeaders;
195
+ /** Preserve safe server diagnostics instead of collapsing every non-2xx response into API_ERROR. */
196
+ private createApiError;
193
197
  private get;
194
198
  private post;
195
199
  private extractMethodName;
package/dist/clients.js CHANGED
@@ -60,6 +60,7 @@ class ValironClient {
60
60
  world_included: options?.trustSignals?.includes("world"),
61
61
  icebreaker_included: options?.trustSignals?.includes("icebreaker"),
62
62
  self_included: options?.trustSignals?.includes("self"),
63
+ wallet_included: options?.trustSignals?.includes("wallet"),
63
64
  });
64
65
  return profile;
65
66
  }
@@ -80,6 +81,10 @@ class ValironClient {
80
81
  }
81
82
  return profile;
82
83
  }
84
+ /** Get an explainable wallet-history risk assessment. Pro plans only. */
85
+ async getWalletRisk(wallet, options) {
86
+ return this.get(`/operator/wallet-risk/${wallet}`, this.resolveChain(options));
87
+ }
83
88
  /**
84
89
  * Resolve a wallet address to an ERC-8004 agent ID.
85
90
  *
@@ -273,6 +278,25 @@ class ValironClient {
273
278
  }
274
279
  return headers;
275
280
  }
281
+ /** Preserve safe server diagnostics instead of collapsing every non-2xx response into API_ERROR. */
282
+ createApiError(response, body, path, method) {
283
+ const message = (typeof body.message === "string" && body.message) ||
284
+ (typeof body.error === "string" && body.error) ||
285
+ `Request failed: ${response.statusText}`;
286
+ const requestId = response.headers.get("x-request-id") || response.headers.get("x-vercel-id") || undefined;
287
+ const retryAfterSeconds = Number(response.headers.get("retry-after"));
288
+ const bodyRetryAfterMs = typeof body.retryAfterMs === "number" ? body.retryAfterMs : undefined;
289
+ const details = {
290
+ method,
291
+ path,
292
+ requestId,
293
+ details: body.details,
294
+ action: typeof body.action === "string" ? body.action : typeof body.hint === "string" ? body.hint : undefined,
295
+ docsUrl: typeof body.docsUrl === "string" ? body.docsUrl : typeof body.identitySkill === "string" ? body.identitySkill : undefined,
296
+ retryAfterMs: bodyRetryAfterMs ?? (Number.isFinite(retryAfterSeconds) ? retryAfterSeconds * 1000 : undefined),
297
+ };
298
+ return new types_1.ValironError(message, typeof body.code === "string" ? body.code : "API_ERROR", response.status, details);
299
+ }
276
300
  async get(path, chain) {
277
301
  const url = new URL(path, this.endpoint);
278
302
  if (chain)
@@ -309,7 +333,7 @@ class ValironClient {
309
333
  abort_count: 0,
310
334
  });
311
335
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
312
- throw new types_1.ValironError(body.error || body.message || `Request failed: ${response.statusText}`, "API_ERROR", response.status);
336
+ throw this.createApiError(response, body, path, "GET");
313
337
  }
314
338
  const data = await response.json();
315
339
  this.telemetry.emit("sdk_call", {
@@ -344,7 +368,7 @@ class ValironClient {
344
368
  timeout_ms: timeoutMs,
345
369
  });
346
370
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
347
- throw new types_1.ValironError(`Request timeout after ${timeoutMs}ms`, "TIMEOUT_ERROR");
371
+ throw new types_1.ValironError(`Valiron did not respond within ${timeoutMs}ms. Retry the request, increase timeout, or check the service status.`, "TIMEOUT_ERROR", undefined, { method: "GET", path, action: "Retry with a longer timeout or inspect the Valiron service status.", retryAfterMs: 1000 });
348
372
  }
349
373
  if (error instanceof types_1.ValironError)
350
374
  throw error;
@@ -359,7 +383,7 @@ class ValironClient {
359
383
  abort_count: 0,
360
384
  });
361
385
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
362
- throw new types_1.ValironError(error.message || "Network error", "NETWORK_ERROR");
386
+ throw new types_1.ValironError(`Could not reach Valiron: ${error.message || "network error"}`, "NETWORK_ERROR", undefined, { method: "GET", path, action: "Check your endpoint URL, network egress, and DNS configuration before retrying." });
363
387
  }
364
388
  }
365
389
  async post(path, body, chain) {
@@ -403,7 +427,7 @@ class ValironClient {
403
427
  abort_count: 0,
404
428
  });
405
429
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
406
- throw new types_1.ValironError(respBody.error || respBody.message || `Request failed: ${response.statusText}`, "API_ERROR", response.status);
430
+ throw this.createApiError(response, respBody, path, "POST");
407
431
  }
408
432
  const data = await response.json();
409
433
  this.telemetry.emit("sdk_call", {
@@ -438,7 +462,7 @@ class ValironClient {
438
462
  timeout_ms: timeoutMs,
439
463
  });
440
464
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
441
- throw new types_1.ValironError(`Request timeout after ${timeoutMs}ms`, "TIMEOUT_ERROR");
465
+ throw new types_1.ValironError(`Valiron did not respond within ${timeoutMs}ms. Retry the request, increase timeout, or check the service status.`, "TIMEOUT_ERROR", undefined, { method: "POST", path, action: "Retry with a longer timeout or inspect the Valiron service status.", retryAfterMs: 1000 });
442
466
  }
443
467
  if (error instanceof types_1.ValironError)
444
468
  throw error;
@@ -453,7 +477,7 @@ class ValironClient {
453
477
  abort_count: 0,
454
478
  });
455
479
  this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
456
- throw new types_1.ValironError(error.message || "Network error", "NETWORK_ERROR");
480
+ throw new types_1.ValironError(`Could not reach Valiron: ${error.message || "network error"}`, "NETWORK_ERROR", undefined, { method: "POST", path, action: "Check your endpoint URL, network egress, and DNS configuration before retrying." });
457
481
  }
458
482
  }
459
483
  extractMethodName(path) {
@@ -461,6 +485,8 @@ class ValironClient {
461
485
  return "getAgentProfile";
462
486
  if (path.startsWith("/operator/resolve-wallet/"))
463
487
  return "resolveWallet";
488
+ if (path.startsWith("/operator/wallet-risk/"))
489
+ return "getWalletRisk";
464
490
  if (path.startsWith("/operator/wallet/"))
465
491
  return "getWalletProfile";
466
492
  if (path.startsWith("/operator/trigger-sandbox/"))
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ValironConfig, CallOptions, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, RouteDecision, KeyAgentProfile, KeyAgentChallenge, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, ProxyRequest, ProxyResponse } from "./types";
1
+ import { ValironConfig, CallOptions, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, WalletRiskSnapshot, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, RouteDecision, KeyAgentProfile, KeyAgentChallenge, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, ProxyRequest, ProxyResponse } from "./types";
2
2
  /**
3
3
  * Valiron SDK – Official TypeScript SDK for the Trust Layer for Agentic Economy
4
4
  *
@@ -97,6 +97,11 @@ export declare class ValironSDK {
97
97
  * ```
98
98
  */
99
99
  getWalletProfile(wallet: string, options?: CallOptions): Promise<WalletProfile>;
100
+ /**
101
+ * Analyze the on-chain history of a wallet and return an explainable score,
102
+ * confidence, feature summary, and any hard-risk flags.
103
+ */
104
+ getWalletRisk(wallet: string, options?: CallOptions): Promise<WalletRiskSnapshot>;
100
105
  /**
101
106
  * Resolve a wallet address to an ERC-8004 agent ID.
102
107
  *
package/dist/index.js CHANGED
@@ -122,6 +122,13 @@ class ValironSDK {
122
122
  async getWalletProfile(wallet, options) {
123
123
  return this.client.getWalletProfile(wallet, options);
124
124
  }
125
+ /**
126
+ * Analyze the on-chain history of a wallet and return an explainable score,
127
+ * confidence, feature summary, and any hard-risk flags.
128
+ */
129
+ async getWalletRisk(wallet, options) {
130
+ return this.client.getWalletRisk(wallet, options);
131
+ }
125
132
  /**
126
133
  * Resolve a wallet address to an ERC-8004 agent ID.
127
134
  *
@@ -23,7 +23,7 @@ export interface ValironGateConfig {
23
23
  extractAgentAddress?: (req: any) => string | null;
24
24
  /** Minimum Valiron score to allow (default: 65). */
25
25
  minScore?: number;
26
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker. */
26
+ /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
27
27
  trustSignals?: TrustSignal[];
28
28
  /**
29
29
  * Client-side profile cache TTL in ms.
@@ -91,7 +91,7 @@ export interface ValironFastifyConfig {
91
91
  extractAgentAddress?: (req: any) => string | null;
92
92
  /** Minimum Valiron score to allow (default: 65). */
93
93
  minScore?: number;
94
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker. */
94
+ /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
95
95
  trustSignals?: TrustSignal[];
96
96
  /**
97
97
  * Client-side profile cache TTL in ms (default: 30000).
@@ -154,7 +154,7 @@ export interface ValironNextConfig {
154
154
  extractAgentAddress?: (req: Request) => string | null;
155
155
  /** Minimum Valiron score to allow (default: 65). */
156
156
  minScore?: number;
157
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker. */
157
+ /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
158
158
  trustSignals?: TrustSignal[];
159
159
  /**
160
160
  * Client-side profile cache TTL in ms (default: 30000).
@@ -270,7 +270,7 @@ export declare function valironGateCheck(sdk: ValironSDK, opts: {
270
270
  /** Key-based agent hash (web2). Checked if agentId is not provided. */
271
271
  agentAddress?: string | null;
272
272
  minScore?: number;
273
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker. */
273
+ /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
274
274
  trustSignals?: TrustSignal[];
275
275
  /**
276
276
  * Client-side profile cache TTL in ms (default: 30000).
@@ -156,6 +156,57 @@ function bucketScore(score) {
156
156
  return "71-90";
157
157
  return "91+";
158
158
  }
159
+ const IDENTITY_SETUP_URL = "https://www.valiron.co/auth.md";
160
+ const ERROR_GUIDE_URL = "https://valiron.co/docs#error-handling";
161
+ function missingIdentityBody() {
162
+ return {
163
+ code: "MISSING_AGENT_IDENTITY",
164
+ error: "Missing agent identity",
165
+ message: "Provide x-agent-id for a registered agent or x-agent-address for a verified key-based agent.",
166
+ action: "Create or verify an agent identity, then retry this request with exactly one supported identity header.",
167
+ docsUrl: IDENTITY_SETUP_URL,
168
+ identitySkill: IDENTITY_SETUP_URL,
169
+ };
170
+ }
171
+ function unavailableGateBody(error) {
172
+ const cause = error instanceof Error ? error.message : undefined;
173
+ return {
174
+ code: "TRUST_GATE_UNAVAILABLE",
175
+ error: "Trust gate unavailable — request denied (fail-closed)",
176
+ message: "Valiron could not complete the trust evaluation, so this request was not allowed through.",
177
+ action: "Retry shortly. If it persists, verify your Valiron endpoint and include the request timestamp plus this cause in a support request.",
178
+ docsUrl: ERROR_GUIDE_URL,
179
+ ...(cause ? { cause } : {}),
180
+ };
181
+ }
182
+ function pendingEvaluationBody(result) {
183
+ return {
184
+ code: "AGENT_EVALUATION_PENDING",
185
+ error: "Agent pending evaluation",
186
+ message: "This newly identified agent is being sandbox-evaluated before it can access this endpoint.",
187
+ action: "Retry after the evaluation completes. Do not create a new identity; keep using the same agent identifier.",
188
+ docsUrl: ERROR_GUIDE_URL,
189
+ retryAfterMs: 30000,
190
+ pendingEvaluation: true,
191
+ ...result,
192
+ };
193
+ }
194
+ function deniedGateBody(result, minScore) {
195
+ return {
196
+ code: "TRUST_GATE_DENIED",
197
+ error: "Agent blocked by Valiron trust gate",
198
+ message: `The agent did not satisfy this endpoint's trust policy (minimum score: ${minScore}).`,
199
+ action: "Inspect route, tier, score, and reasons below. Use a sandbox route if offered, or improve the agent's trust signals before retrying.",
200
+ docsUrl: ERROR_GUIDE_URL,
201
+ ...result,
202
+ };
203
+ }
204
+ function logGateFailure(framework, agentId, error) {
205
+ console.error(`[Valiron middleware] ${framework} trust evaluation failed`, {
206
+ agentId: agentId || "missing",
207
+ error: error instanceof Error ? error.message : String(error),
208
+ });
209
+ }
159
210
  function emitGateTelemetry(sdk, payload) {
160
211
  if (typeof sdk.emitTelemetry !== "function")
161
212
  return;
@@ -177,6 +228,7 @@ function emitGateTelemetry(sdk, payload) {
177
228
  world_included: signals?.includes("world"),
178
229
  icebreaker_included: signals?.includes("icebreaker"),
179
230
  self_included: signals?.includes("self"),
231
+ wallet_included: signals?.includes("wallet"),
180
232
  status: payload.status || "ok",
181
233
  latency_ms: payload.latencyMs,
182
234
  });
@@ -307,11 +359,7 @@ function createValironGate(config) {
307
359
  status: "missing_identity",
308
360
  latencyMs,
309
361
  });
310
- return res.status(401).json({
311
- error: "Missing agent identity",
312
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
313
- identitySkill: "https://valiron.co/auth.md",
314
- });
362
+ return res.status(401).json(missingIdentityBody());
315
363
  }
316
364
  if (error) {
317
365
  emitGateTelemetry(frozen.sdk, {
@@ -322,9 +370,8 @@ function createValironGate(config) {
322
370
  status: "error",
323
371
  latencyMs,
324
372
  });
325
- return res.status(503).json({
326
- error: "Trust gate unavailable \u2014 request denied (fail-closed)",
327
- });
373
+ logGateFailure("express", agentId, error);
374
+ return res.status(503).json(unavailableGateBody(error));
328
375
  }
329
376
  emitGateTelemetry(frozen.sdk, {
330
377
  framework: "express",
@@ -349,20 +396,12 @@ function createValironGate(config) {
349
396
  }
350
397
  // New agent with no reputation — sandbox test triggered in background
351
398
  if (pendingEvaluation) {
352
- return res.status(403).json({
353
- error: "Agent pending evaluation",
354
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
355
- retryAfterMs: 30000,
356
- ...result,
357
- });
399
+ return res.status(403).json(pendingEvaluationBody(result));
358
400
  }
359
401
  if (config.onDeny) {
360
402
  return config.onDeny(req, res, result);
361
403
  }
362
- return res.status(403).json({
363
- error: "Agent blocked by Valiron trust gate",
364
- ...result,
365
- });
404
+ return res.status(403).json(deniedGateBody(result, minScore));
366
405
  }
367
406
  // Wrap with Promise.catch(next) for Express 4 async safety.
368
407
  // Express 4 does NOT await async middleware, so without this wrapper
@@ -441,11 +480,7 @@ async function valironFastifyPlugin(fastify, opts) {
441
480
  status: "missing_identity",
442
481
  latencyMs,
443
482
  });
444
- return reply.status(401).send({
445
- error: "Missing agent identity",
446
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
447
- identitySkill: "https://valiron.co/auth.md",
448
- });
483
+ return reply.status(401).send(missingIdentityBody());
449
484
  }
450
485
  if (error) {
451
486
  emitGateTelemetry(opts.sdk, {
@@ -456,9 +491,8 @@ async function valironFastifyPlugin(fastify, opts) {
456
491
  status: "error",
457
492
  latencyMs,
458
493
  });
459
- return reply.status(503).send({
460
- error: "Trust gate unavailable \u2014 request denied (fail-closed)",
461
- });
494
+ logGateFailure("fastify", agentId, error);
495
+ return reply.status(503).send(unavailableGateBody(error));
462
496
  }
463
497
  emitGateTelemetry(opts.sdk, {
464
498
  framework: "fastify",
@@ -483,20 +517,12 @@ async function valironFastifyPlugin(fastify, opts) {
483
517
  }
484
518
  // New agent with no reputation — sandbox test triggered in background
485
519
  if (pendingEvaluation) {
486
- return reply.status(403).send({
487
- error: "Agent pending evaluation",
488
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
489
- retryAfterMs: 30000,
490
- ...result,
491
- });
520
+ return reply.status(403).send(pendingEvaluationBody(result));
492
521
  }
493
522
  if (opts.onDeny) {
494
523
  return opts.onDeny(request, reply, result);
495
524
  }
496
- return reply.status(403).send({
497
- error: "Agent blocked by Valiron trust gate",
498
- ...result,
499
- });
525
+ return reply.status(403).send(deniedGateBody(result, minScore));
500
526
  });
501
527
  }
502
528
  /**
@@ -554,11 +580,7 @@ function createValironNextMiddleware(config) {
554
580
  status: "missing_identity",
555
581
  latencyMs: Date.now() - startedAt,
556
582
  });
557
- return Response.json({
558
- error: "Missing agent identity",
559
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
560
- identitySkill: "https://valiron.co/auth.md",
561
- }, { status: 401 });
583
+ return Response.json(missingIdentityBody(), { status: 401 });
562
584
  }
563
585
  const cacheTtl = config.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
564
586
  const effectiveMinScore = minScore ?? 65;
@@ -587,7 +609,9 @@ function createValironNextMiddleware(config) {
587
609
  });
588
610
  if (cached.result.allow)
589
611
  return undefined;
590
- return Response.json({ error: "Agent blocked by Valiron trust gate", ...cached.result }, { status: 403 });
612
+ return Response.json(cached.pendingEvaluation
613
+ ? pendingEvaluationBody(cached.result)
614
+ : deniedGateBody(cached.result, effectiveMinScore), { status: 403 });
591
615
  }
592
616
  }
593
617
  if (agentId) {
@@ -633,16 +657,11 @@ function createValironNextMiddleware(config) {
633
657
  return undefined; // continue to route handler
634
658
  }
635
659
  if (pendingEvaluation) {
636
- return Response.json({
637
- error: "Agent pending evaluation",
638
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
639
- retryAfterMs: 30000,
640
- ...result,
641
- }, { status: 403 });
660
+ return Response.json(pendingEvaluationBody(result), { status: 403 });
642
661
  }
643
- return Response.json({ error: "Agent blocked by Valiron trust gate", ...result }, { status: 403 });
662
+ return Response.json(deniedGateBody(result, effectiveMinScore), { status: 403 });
644
663
  }
645
- catch {
664
+ catch (error) {
646
665
  emitGateTelemetry(sdk, {
647
666
  framework: "next",
648
667
  agentType: agentId ? "onchain" : "key",
@@ -651,7 +670,8 @@ function createValironNextMiddleware(config) {
651
670
  status: "error",
652
671
  latencyMs: Date.now() - startedAt,
653
672
  });
654
- return Response.json({ error: "Trust gate unavailable \u2014 request denied (fail-closed)" }, { status: 503 });
673
+ logGateFailure("next", agentId || agentAddr, error);
674
+ return Response.json(unavailableGateBody(error), { status: 503 });
655
675
  }
656
676
  };
657
677
  }
@@ -715,11 +735,7 @@ async function valironGateCheck(sdk, opts) {
715
735
  agentId: null,
716
736
  ok: false,
717
737
  status: 401,
718
- body: {
719
- error: "Missing agent identity",
720
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
721
- identitySkill: "https://valiron.co/auth.md",
722
- },
738
+ body: missingIdentityBody(),
723
739
  };
724
740
  }
725
741
  const effectiveMinScore = minScore ?? 65;
@@ -755,8 +771,10 @@ async function valironGateCheck(sdk, opts) {
755
771
  allow: false,
756
772
  result: cached.result,
757
773
  status: 403,
758
- body: { error: "Agent blocked by Valiron trust gate", ...cached.result,
759
- ...(cached.pendingEvaluation ? { pendingEvaluation: true, retryAfterMs: 30000 } : {}) },
774
+ pendingEvaluation: cached.pendingEvaluation || undefined,
775
+ body: cached.pendingEvaluation
776
+ ? pendingEvaluationBody(cached.result)
777
+ : deniedGateBody(cached.result, effectiveMinScore),
760
778
  };
761
779
  }
762
780
  }
@@ -814,12 +832,7 @@ async function valironGateCheck(sdk, opts) {
814
832
  result,
815
833
  status: 403,
816
834
  pendingEvaluation: true,
817
- body: {
818
- error: "Agent pending evaluation",
819
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
820
- retryAfterMs: 30000,
821
- ...result,
822
- },
835
+ body: pendingEvaluationBody(result),
823
836
  };
824
837
  }
825
838
  return {
@@ -829,10 +842,10 @@ async function valironGateCheck(sdk, opts) {
829
842
  allow: false,
830
843
  result,
831
844
  status: 403,
832
- body: { error: "Agent blocked by Valiron trust gate", ...result },
845
+ body: deniedGateBody(result, effectiveMinScore),
833
846
  };
834
847
  }
835
- catch {
848
+ catch (error) {
836
849
  emitGateTelemetry(sdk, {
837
850
  framework: "generic",
838
851
  agentType: agentId ? "onchain" : "key",
@@ -841,12 +854,13 @@ async function valironGateCheck(sdk, opts) {
841
854
  status: "error",
842
855
  latencyMs: Date.now() - startedAt,
843
856
  });
857
+ logGateFailure("generic", identifier, error);
844
858
  return {
845
859
  hasAgent: true,
846
860
  agentId: identifier,
847
861
  ok: false,
848
862
  status: 503,
849
- body: { error: "Trust gate unavailable \u2014 request denied (fail-closed)" },
863
+ body: unavailableGateBody(error),
850
864
  };
851
865
  }
852
866
  }
@@ -23,7 +23,7 @@ export interface PaywallConfig {
23
23
  pricePerCall: number;
24
24
  /** Minimum trust score to allow (default: 45). */
25
25
  minTrustScore?: number;
26
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker. */
26
+ /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
27
27
  trustSignals?: TrustSignal[];
28
28
  /**
29
29
  * Server-side gate result TTL in ms (default: 86400000 = 24h).
@@ -66,6 +66,7 @@ class ValironOperator {
66
66
  world_included: trustSignals.includes("world"),
67
67
  icebreaker_included: trustSignals.includes("icebreaker"),
68
68
  self_included: trustSignals.includes("self"),
69
+ wallet_included: trustSignals.includes("wallet"),
69
70
  };
70
71
  void fetch(this.buildAnalyticsUrl(), {
71
72
  method: "POST",