@valiron/sdk 1.4.0 → 2.0.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.
@@ -21,9 +21,11 @@ export interface ValironGateConfig {
21
21
  * Defaults to reading `x-agent-address` header (falls back to `x-agent-key-hash`).
22
22
  */
23
23
  extractAgentAddress?: (req: any) => string | null;
24
+ /** Required: verify a fresh cryptographic proof bound to this identity, method, URL and raw body; enforce replay protection. */
25
+ verifyRequest?: (request: any, identifier: string) => Promise<boolean>;
24
26
  /** Minimum Valiron score to allow (default: 65). */
25
27
  minScore?: number;
26
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
28
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
27
29
  trustSignals?: TrustSignal[];
28
30
  /**
29
31
  * Client-side profile cache TTL in ms.
@@ -58,15 +60,16 @@ export interface ValironGateConfig {
58
60
  * ```typescript
59
61
  * import { ValironSDK, createValironGate } from '@valiron/sdk';
60
62
  *
61
- * const valiron = new ValironSDK({ chain: 'monad' });
63
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
62
64
  *
63
65
  * // Apply before your x402 / payment handler
64
66
  * // Works with both on-chain (x-agent-id) and key-based (x-agent-address) agents
65
- * app.use('/api/paid', createValironGate({ sdk: valiron }));
67
+ * app.use('/api/paid', createValironGate({ sdk: valiron, verifyRequest: verifyAgentRequest }));
66
68
  *
67
69
  * // Custom threshold + cache TTL
68
70
  * app.use('/api/premium', createValironGate({
69
71
  * sdk: valiron,
72
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
70
73
  * minScore: 85,
71
74
  * cacheTtlMs: 60_000, // 60s client-side cache
72
75
  * }));
@@ -77,6 +80,7 @@ export declare function createValironGate(config: ValironGateConfig): (req: any,
77
80
  * Configuration for the Fastify Valiron trust gate plugin.
78
81
  */
79
82
  export interface ValironFastifyConfig {
83
+ verifyRequest?: ValironGateConfig["verifyRequest"];
80
84
  /** Configured ValironSDK instance. */
81
85
  sdk: ValironSDK;
82
86
  /**
@@ -91,7 +95,7 @@ export interface ValironFastifyConfig {
91
95
  extractAgentAddress?: (req: any) => string | null;
92
96
  /** Minimum Valiron score to allow (default: 65). */
93
97
  minScore?: number;
94
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
98
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
95
99
  trustSignals?: TrustSignal[];
96
100
  /**
97
101
  * Client-side profile cache TTL in ms (default: 30000).
@@ -122,7 +126,7 @@ export interface ValironFastifyConfig {
122
126
  * import { ValironSDK, valironFastifyPlugin } from '@valiron/sdk';
123
127
  *
124
128
  * const app = Fastify();
125
- * const valiron = new ValironSDK({ chain: 'monad' });
129
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
126
130
  *
127
131
  * // Gate all routes
128
132
  * app.register(valironFastifyPlugin, { sdk: valiron });
@@ -130,6 +134,7 @@ export interface ValironFastifyConfig {
130
134
  * // Or gate a specific prefix
131
135
  * app.register(valironFastifyPlugin, {
132
136
  * sdk: valiron,
137
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
133
138
  * prefix: '/api',
134
139
  * minScore: 85,
135
140
  * });
@@ -140,6 +145,7 @@ export declare function valironFastifyPlugin(fastify: any, opts: ValironFastifyC
140
145
  * Configuration for the Next.js Valiron gate.
141
146
  */
142
147
  export interface ValironNextConfig {
148
+ verifyRequest?: (request: Request, identifier: string) => Promise<boolean>;
143
149
  /** Configured ValironSDK instance. */
144
150
  sdk: ValironSDK;
145
151
  /**
@@ -154,7 +160,7 @@ export interface ValironNextConfig {
154
160
  extractAgentAddress?: (req: Request) => string | null;
155
161
  /** Minimum Valiron score to allow (default: 65). */
156
162
  minScore?: number;
157
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
163
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
158
164
  trustSignals?: TrustSignal[];
159
165
  /**
160
166
  * Client-side profile cache TTL in ms (default: 30000).
@@ -180,10 +186,11 @@ export interface ValironNextConfig {
180
186
  * // middleware.ts (Next.js project root)
181
187
  * import { ValironSDK, createValironNextMiddleware } from '@valiron/sdk';
182
188
  *
183
- * const valiron = new ValironSDK({ chain: 'monad' });
189
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
184
190
  *
185
191
  * const valironMiddleware = createValironNextMiddleware({
186
192
  * sdk: valiron,
193
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
187
194
  * paths: ['/api/paid'],
188
195
  * minScore: 65,
189
196
  * });
@@ -232,7 +239,7 @@ export interface ValironGateCheckResult {
232
239
  * import { Hono } from 'hono';
233
240
  * import { ValironSDK, valironGateCheck } from '@valiron/sdk';
234
241
  *
235
- * const valiron = new ValironSDK({ chain: 'monad' });
242
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
236
243
  * const app = new Hono();
237
244
  *
238
245
  * app.use('/api/*', async (c, next) => {
@@ -269,8 +276,10 @@ export declare function valironGateCheck(sdk: ValironSDK, opts: {
269
276
  agentId?: string | null;
270
277
  /** Key-based agent hash (web2). Checked if agentId is not provided. */
271
278
  agentAddress?: string | null;
279
+ /** Verify ownership and request binding before every decision, including cache hits. */
280
+ verifyRequest?: (identifier: string) => Promise<boolean>;
272
281
  minScore?: number;
273
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
282
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
274
283
  trustSignals?: TrustSignal[];
275
284
  /**
276
285
  * Client-side profile cache TTL in ms (default: 30000).
@@ -236,11 +236,21 @@ function emitGateTelemetry(sdk, payload) {
236
236
  async function runGateCheck(config, req, cache) {
237
237
  const minScore = config.minScore ?? 65;
238
238
  const cacheTtl = config.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
239
+ const claimed = (config.extractAgentId || defaultExtractAgentId)(req) || (config.extractAgentAddress || defaultExtractAgentAddress)(req);
240
+ if (claimed) {
241
+ try {
242
+ if (!config.verifyRequest || !await config.verifyRequest(req, claimed))
243
+ return { agentId: claimed, ownershipRequired: true };
244
+ }
245
+ catch (error) {
246
+ return { agentId: claimed, error };
247
+ }
248
+ }
239
249
  // 1. Try on-chain agent ID (ERC-8004 / Solana)
240
250
  const extractAgentId = config.extractAgentId || defaultExtractAgentId;
241
251
  const agentId = extractAgentId(req);
242
252
  if (agentId) {
243
- const agentCacheKey = cacheKeyFor(agentId, config.trustSignals);
253
+ const agentCacheKey = cacheKeyFor(agentId, config.trustSignals) + ":" + minScore;
244
254
  // Check client-side cache first
245
255
  if (cacheTtl > 0) {
246
256
  const cached = cache.getCached(agentCacheKey, cacheTtl);
@@ -248,9 +258,8 @@ async function runGateCheck(config, req, cache) {
248
258
  return { agentId, result: cached.result, pendingEvaluation: cached.pendingEvaluation };
249
259
  }
250
260
  try {
251
- // Use getAgentProfile() which hits the PUBLIC /operator/agent/ endpoint.
252
- // The old gate() call used POST /operator/gate/ which is protected by
253
- // agent challenge-response auth and fails from server contexts.
261
+ // Read the authenticated profile after the local caller verifier passes.
262
+ // Hosted gate() calls instead require a registry-owner request signature.
254
263
  const profile = await config.sdk.getAgentProfile(agentId, {
255
264
  trustSignals: normalizeTrustSignals(config.trustSignals),
256
265
  });
@@ -276,7 +285,7 @@ async function runGateCheck(config, req, cache) {
276
285
  const extractAddress = config.extractAgentAddress || defaultExtractAgentAddress;
277
286
  const agentAddr = extractAddress(req);
278
287
  if (agentAddr) {
279
- const agentCacheKey = cacheKeyFor(agentAddr, config.trustSignals);
288
+ const agentCacheKey = cacheKeyFor(agentAddr, config.trustSignals) + ":" + minScore;
280
289
  // Check client-side cache first
281
290
  if (cacheTtl > 0) {
282
291
  const cached = cache.getCached(agentCacheKey, cacheTtl);
@@ -323,15 +332,16 @@ async function runGateCheck(config, req, cache) {
323
332
  * ```typescript
324
333
  * import { ValironSDK, createValironGate } from '@valiron/sdk';
325
334
  *
326
- * const valiron = new ValironSDK({ chain: 'monad' });
335
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
327
336
  *
328
337
  * // Apply before your x402 / payment handler
329
338
  * // Works with both on-chain (x-agent-id) and key-based (x-agent-address) agents
330
- * app.use('/api/paid', createValironGate({ sdk: valiron }));
339
+ * app.use('/api/paid', createValironGate({ sdk: valiron, verifyRequest: verifyAgentRequest }));
331
340
  *
332
341
  * // Custom threshold + cache TTL
333
342
  * app.use('/api/premium', createValironGate({
334
343
  * sdk: valiron,
344
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
335
345
  * minScore: 85,
336
346
  * cacheTtlMs: 60_000, // 60s client-side cache
337
347
  * }));
@@ -344,7 +354,7 @@ function createValironGate(config) {
344
354
  const cache = createProfileCache();
345
355
  async function valironGateHandler(req, res, next) {
346
356
  const startedAt = Date.now();
347
- const { agentId, result, error, pendingEvaluation } = await runGateCheck(frozen, req, cache);
357
+ const { agentId, result, error, pendingEvaluation, ownershipRequired } = await runGateCheck(frozen, req, cache);
348
358
  const latencyMs = Date.now() - startedAt;
349
359
  const minScore = frozen.minScore ?? 65;
350
360
  const agentType = agentId
@@ -361,6 +371,8 @@ function createValironGate(config) {
361
371
  });
362
372
  return res.status(401).json(missingIdentityBody());
363
373
  }
374
+ if (ownershipRequired)
375
+ return res.status(401).json({ code: "AGENT_OWNERSHIP_REQUIRED", error: "Fresh request-bound identity proof required" });
364
376
  if (error) {
365
377
  emitGateTelemetry(frozen.sdk, {
366
378
  framework: "express",
@@ -426,7 +438,7 @@ function createValironGate(config) {
426
438
  * import { ValironSDK, valironFastifyPlugin } from '@valiron/sdk';
427
439
  *
428
440
  * const app = Fastify();
429
- * const valiron = new ValironSDK({ chain: 'monad' });
441
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
430
442
  *
431
443
  * // Gate all routes
432
444
  * app.register(valironFastifyPlugin, { sdk: valiron });
@@ -434,6 +446,7 @@ function createValironGate(config) {
434
446
  * // Or gate a specific prefix
435
447
  * app.register(valironFastifyPlugin, {
436
448
  * sdk: valiron,
449
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
437
450
  * prefix: '/api',
438
451
  * minScore: 85,
439
452
  * });
@@ -442,9 +455,11 @@ function createValironGate(config) {
442
455
  async function valironFastifyPlugin(fastify, opts) {
443
456
  const gateConfig = {
444
457
  sdk: opts.sdk,
458
+ verifyRequest: opts.verifyRequest,
445
459
  extractAgentId: opts.extractAgentId,
446
460
  extractAgentAddress: opts.extractAgentAddress,
447
461
  minScore: opts.minScore,
462
+ trustSignals: opts.trustSignals,
448
463
  cacheTtlMs: opts.cacheTtlMs,
449
464
  onAllow: opts.onAllow,
450
465
  };
@@ -465,7 +480,7 @@ async function valironFastifyPlugin(fastify, opts) {
465
480
  return;
466
481
  }
467
482
  const startedAt = Date.now();
468
- const { agentId, result, error, pendingEvaluation } = await runGateCheck(gateConfig, request, cache);
483
+ const { agentId, result, error, pendingEvaluation, ownershipRequired } = await runGateCheck(gateConfig, request, cache);
469
484
  const latencyMs = Date.now() - startedAt;
470
485
  const minScore = opts.minScore ?? 65;
471
486
  const agentType = agentId
@@ -482,6 +497,8 @@ async function valironFastifyPlugin(fastify, opts) {
482
497
  });
483
498
  return reply.status(401).send(missingIdentityBody());
484
499
  }
500
+ if (ownershipRequired)
501
+ return reply.status(401).send({ code: "AGENT_OWNERSHIP_REQUIRED", error: "Fresh request-bound identity proof required" });
485
502
  if (error) {
486
503
  emitGateTelemetry(opts.sdk, {
487
504
  framework: "fastify",
@@ -537,10 +554,11 @@ async function valironFastifyPlugin(fastify, opts) {
537
554
  * // middleware.ts (Next.js project root)
538
555
  * import { ValironSDK, createValironNextMiddleware } from '@valiron/sdk';
539
556
  *
540
- * const valiron = new ValironSDK({ chain: 'monad' });
557
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
541
558
  *
542
559
  * const valironMiddleware = createValironNextMiddleware({
543
560
  * sdk: valiron,
561
+ * verifyRequest: verifyAgentRequest, // application-owned request signature verifier
544
562
  * paths: ['/api/paid'],
545
563
  * minScore: 65,
546
564
  * });
@@ -583,6 +601,8 @@ function createValironNextMiddleware(config) {
583
601
  return Response.json(missingIdentityBody(), { status: 401 });
584
602
  }
585
603
  const cacheTtl = config.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
604
+ if (!config.verifyRequest || !await config.verifyRequest(request, agentId || agentAddr))
605
+ return Response.json({ code: "AGENT_OWNERSHIP_REQUIRED" }, { status: 401 });
586
606
  const effectiveMinScore = minScore ?? 65;
587
607
  try {
588
608
  let result;
@@ -590,7 +610,7 @@ function createValironNextMiddleware(config) {
590
610
  const identifier = agentId || agentAddr;
591
611
  // Check client-side cache first
592
612
  if (cacheTtl > 0) {
593
- const cached = cache.getCached(identifier, cacheTtl);
613
+ const cached = cache.getCached(cacheKeyFor(identifier, trustSignals) + ":" + effectiveMinScore, cacheTtl);
594
614
  if (cached) {
595
615
  emitGateTelemetry(sdk, {
596
616
  framework: "next",
@@ -637,7 +657,7 @@ function createValironNextMiddleware(config) {
637
657
  }
638
658
  }
639
659
  if (cacheTtl > 0)
640
- cache.setCache(identifier, result, pendingEvaluation || undefined);
660
+ cache.setCache(cacheKeyFor(identifier, trustSignals) + ":" + effectiveMinScore, result, pendingEvaluation || undefined);
641
661
  emitGateTelemetry(sdk, {
642
662
  framework: "next",
643
663
  agentType: agentId ? "onchain" : "key",
@@ -685,7 +705,7 @@ function createValironNextMiddleware(config) {
685
705
  * import { Hono } from 'hono';
686
706
  * import { ValironSDK, valironGateCheck } from '@valiron/sdk';
687
707
  *
688
- * const valiron = new ValironSDK({ chain: 'monad' });
708
+ * const valiron = new ValironSDK({ apiKey: process.env.VALIRON_API_KEY, chain: 'monad' });
689
709
  * const app = new Hono();
690
710
  *
691
711
  * app.use('/api/*', async (c, next) => {
@@ -738,13 +758,18 @@ async function valironGateCheck(sdk, opts) {
738
758
  body: missingIdentityBody(),
739
759
  };
740
760
  }
761
+ if (!opts.verifyRequest || !await opts.verifyRequest(identifier))
762
+ return {
763
+ hasAgent: true, agentId: identifier, ok: false, allow: false, status: 401,
764
+ body: { code: "AGENT_OWNERSHIP_REQUIRED", error: "Fresh request-bound identity proof required" },
765
+ };
741
766
  const effectiveMinScore = minScore ?? 65;
742
767
  const cacheTtl = opts.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
743
768
  // Get or create a per-SDK cache instance
744
769
  const cache = getGateCheckCache(sdk);
745
770
  // Check client-side cache first
746
771
  if (cacheTtl > 0) {
747
- const cached = cache.getCached(identifier, cacheTtl);
772
+ const cached = cache.getCached(cacheKeyFor(identifier, trustSignals) + ":" + effectiveMinScore, cacheTtl);
748
773
  if (cached) {
749
774
  emitGateTelemetry(sdk, {
750
775
  framework: "generic",
@@ -804,7 +829,7 @@ async function valironGateCheck(sdk, opts) {
804
829
  }
805
830
  }
806
831
  if (cacheTtl > 0)
807
- cache.setCache(identifier, result, pendingEvaluation || undefined);
832
+ cache.setCache(cacheKeyFor(identifier, trustSignals) + ":" + effectiveMinScore, result, pendingEvaluation || undefined);
808
833
  emitGateTelemetry(sdk, {
809
834
  framework: "generic",
810
835
  agentType: agentId ? "onchain" : "key",
@@ -1,9 +1,12 @@
1
1
  import { ValironSDK } from "./index.js";
2
+ import type { ValironGateConfig } from "./middleware.js";
2
3
  import type { SupportedChain, TrustSignal } from "./types.js";
3
4
  /**
4
5
  * Configuration for the Valiron Operator SDK.
5
6
  */
6
7
  export interface ValironOperatorConfig {
8
+ /** Explicit opt-in to aggregate API usage telemetry; raw IP/UA/path are never sent. */
9
+ analytics?: boolean;
7
10
  /** Operator API key (val_op_xxxx) — obtained from valiron.co/dashboard. */
8
11
  apiKey: string;
9
12
  /** Default blockchain (default: 'ethereum'). */
@@ -19,11 +22,13 @@ export interface ValironOperatorConfig {
19
22
  * Configuration for the paywall middleware.
20
23
  */
21
24
  export interface PaywallConfig {
25
+ /** Required for admission: verify a fresh request-bound proof and reject replay before cache access. */
26
+ verifyRequest?: ValironGateConfig["verifyRequest"];
22
27
  /** Price per API call in USDC. */
23
28
  pricePerCall: number;
24
29
  /** Minimum trust score to allow (default: 45). */
25
30
  minTrustScore?: number;
26
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
31
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
27
32
  trustSignals?: TrustSignal[];
28
33
  /**
29
34
  * Server-side gate result TTL in ms (default: 86400000 = 24h).
@@ -55,11 +60,12 @@ export interface PaywallConfig {
55
60
  * });
56
61
  *
57
62
  * // Express: one line to monetize an endpoint
58
- * app.use('/api/inference', operator.paywall({ pricePerCall: 0.05 }));
63
+ * app.use('/api/inference', operator.paywall({ pricePerCall: 0.05, verifyRequest: verifyAgentRequest }));
59
64
  *
60
65
  * // Fastify: register as plugin
61
66
  * app.register(operator.fastifyPaywall({
62
67
  * pricePerCall: 0.10,
68
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
63
69
  * prefix: '/api',
64
70
  * }));
65
71
  * ```
@@ -68,6 +74,7 @@ export declare class ValironOperator {
68
74
  private sdk;
69
75
  private apiKey;
70
76
  private debug;
77
+ private analytics;
71
78
  private endpoint;
72
79
  constructor(config: ValironOperatorConfig);
73
80
  private buildAnalyticsUrl;
@@ -87,6 +94,7 @@ export declare class ValironOperator {
87
94
  * ```typescript
88
95
  * app.use('/api/inference', operator.paywall({
89
96
  * pricePerCall: 0.05,
97
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
90
98
  * minTrustScore: 45,
91
99
  * }));
92
100
  *
@@ -105,6 +113,7 @@ export declare class ValironOperator {
105
113
  * ```typescript
106
114
  * app.register(operator.fastifyPaywall({
107
115
  * pricePerCall: 0.10,
116
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
108
117
  * prefix: '/api',
109
118
  * minTrustScore: 65,
110
119
  * }));
@@ -15,11 +15,12 @@ const middleware_js_1 = require("./middleware.js");
15
15
  * });
16
16
  *
17
17
  * // Express: one line to monetize an endpoint
18
- * app.use('/api/inference', operator.paywall({ pricePerCall: 0.05 }));
18
+ * app.use('/api/inference', operator.paywall({ pricePerCall: 0.05, verifyRequest: verifyAgentRequest }));
19
19
  *
20
20
  * // Fastify: register as plugin
21
21
  * app.register(operator.fastifyPaywall({
22
22
  * pricePerCall: 0.10,
23
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
23
24
  * prefix: '/api',
24
25
  * }));
25
26
  * ```
@@ -30,6 +31,7 @@ class ValironOperator {
30
31
  throw new Error("Invalid operator API key — must start with 'val_op_'");
31
32
  }
32
33
  this.apiKey = config.apiKey;
34
+ this.analytics = config.analytics === true;
33
35
  this.debug = config.debug || false;
34
36
  this.endpoint = config.endpoint || "https://valiron-edge-proxy.onrender.com";
35
37
  this.sdk = new index_js_1.ValironSDK({
@@ -44,20 +46,19 @@ class ValironOperator {
44
46
  return new URL("/operator/analytics/ingest", this.endpoint).toString();
45
47
  }
46
48
  recordUsage(entry) {
49
+ if (!this.analytics)
50
+ return;
47
51
  const trustSignals = this.normalizeTrustSignals(entry.trustSignals);
48
52
  const body = {
49
53
  agent_id: entry.agentId || undefined,
50
54
  agent_label: entry.agentLabel || undefined,
51
55
  session_id: entry.sessionId || undefined,
52
56
  chain: entry.chain || undefined,
53
- path: entry.path,
57
+ path: "/redacted",
54
58
  method: entry.method,
55
59
  status_code: entry.statusCode,
56
60
  price_charged: entry.priceCharged,
57
61
  response_ms: entry.responseMs,
58
- user_agent: entry.userAgent || undefined,
59
- ip_address: entry.ipAddress || undefined,
60
- error_message: entry.errorMessage || undefined,
61
62
  trust_signals: trustSignals,
62
63
  trust_signal_count: trustSignals.length,
63
64
  scoring_mode: trustSignals.length ? trustSignals.join("+") : undefined,
@@ -77,6 +78,8 @@ class ValironOperator {
77
78
  };
78
79
  void fetch(this.buildAnalyticsUrl(), {
79
80
  method: "POST",
81
+ redirect: "error",
82
+ signal: AbortSignal.timeout(5000),
80
83
  headers: {
81
84
  "Content-Type": "application/json",
82
85
  Authorization: `Bearer ${this.apiKey}`,
@@ -99,8 +102,7 @@ class ValironOperator {
99
102
  return req.originalUrl || req.url || req.path || "/";
100
103
  }
101
104
  expressIp(req) {
102
- const forwarded = this.extractHeader(req, "x-forwarded-for")?.split(",")[0]?.trim();
103
- return forwarded || this.extractHeader(req, "x-real-ip") || req.ip || req.socket?.remoteAddress || null;
105
+ return req.ip || req.socket?.remoteAddress || null;
104
106
  }
105
107
  fastifyPath(req) {
106
108
  return req.url || req.routerPath || "/";
@@ -118,6 +120,7 @@ class ValironOperator {
118
120
  * ```typescript
119
121
  * app.use('/api/inference', operator.paywall({
120
122
  * pricePerCall: 0.05,
123
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
121
124
  * minTrustScore: 45,
122
125
  * }));
123
126
  *
@@ -133,6 +136,7 @@ class ValironOperator {
133
136
  sdk: this.sdk,
134
137
  minScore: config.minTrustScore ?? 45,
135
138
  trustSignals: config.trustSignals,
139
+ verifyRequest: config.verifyRequest,
136
140
  cacheTtlMs: config.cacheTtlMs ?? config.ttlMs,
137
141
  onDeny: config.onDeny,
138
142
  onAllow: (req, result) => {
@@ -208,6 +212,7 @@ class ValironOperator {
208
212
  * ```typescript
209
213
  * app.register(operator.fastifyPaywall({
210
214
  * pricePerCall: 0.10,
215
+ * verifyRequest: verifyAgentRequest, // application-owned verifier
211
216
  * prefix: '/api',
212
217
  * minTrustScore: 65,
213
218
  * }));
@@ -218,6 +223,7 @@ class ValironOperator {
218
223
  sdk: this.sdk,
219
224
  minScore: config.minTrustScore ?? 45,
220
225
  trustSignals: config.trustSignals,
226
+ verifyRequest: config.verifyRequest,
221
227
  cacheTtlMs: config.cacheTtlMs ?? config.ttlMs,
222
228
  prefix: config.prefix,
223
229
  onDeny: config.onDeny,
package/dist/types.d.ts CHANGED
@@ -21,6 +21,9 @@ export interface AgentIdentityProof {
21
21
  timestamp?: string;
22
22
  nonce?: string;
23
23
  requestDigest?: string;
24
+ audience?: string;
25
+ method?: string;
26
+ url?: string;
24
27
  keyId?: string;
25
28
  }
26
29
  /** Proof fields transported with an HTTP request. The receiving gate computes requestDigest itself. */
@@ -269,7 +272,7 @@ export interface GateOptions {
269
272
  minScore?: number;
270
273
  /** TTL in ms for cached sandbox results. Stale results trigger re-testing (default: 86400000 = 24 h). */
271
274
  ttlMs?: number;
272
- /** Customer-selected scoring signals. Free plans support 8004+sandbox; Pro adds world+self+icebreaker+wallet. */
275
+ /** Customer-selected scoring signals. Free includes 8004, sandbox, world, self, and wallet; Pro adds icebreaker (Social Graph). */
273
276
  trustSignals?: TrustSignal[];
274
277
  /** Override the blockchain network for this call. */
275
278
  chain?: SupportedChain;
@@ -545,7 +548,7 @@ export interface KeyAgentProfile {
545
548
  riskLevel: RiskLevel | null;
546
549
  /** Route decision */
547
550
  route: RouteDecision | null;
548
- /** Redacted in public HTTP profiles; use getKeyAgentIcebreaker with a Pro key. */
551
+ /** Redacted in authenticated summary profiles; use getKeyAgentIcebreaker with a Pro key. */
549
552
  icebreaker: IcebreakerOwnership | null;
550
553
  /** Human-readable trust explanation */
551
554
  reasons: string[];
@@ -586,11 +589,18 @@ export interface TelemetryConfig {
586
589
  onEvent?: (event: TelemetryEventBase & Record<string, unknown>) => void;
587
590
  }
588
591
  export interface ValironConfig {
592
+ /** Sign a fresh owner proof for each POST; keys remain in the caller's wallet/key manager. */
593
+ signRequest?: (request: {
594
+ method: "POST";
595
+ url: string;
596
+ body: string;
597
+ chain?: SupportedChain;
598
+ }) => Promise<Record<string, string>>;
589
599
  /**
590
600
  * Your Valiron API key.
591
601
  *
592
- * Optional for public identity/trust summaries. Required for sandbox runs;
593
- * paid signals, enriched profiles, proxy calls, and webhooks also require Pro.
602
+ * Required for hosted profile/status reads, trust gates and sandbox runs;
603
+ * only Social Graph (Icebreaker) requires Pro. Crawler Protection is included on Free.
594
604
  */
595
605
  apiKey?: string;
596
606
  /**