@valiron/sdk 0.12.0 → 1.0.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.
@@ -23,8 +23,19 @@ export interface PaywallConfig {
23
23
  pricePerCall: number;
24
24
  /** Minimum trust score to allow (default: 45). */
25
25
  minTrustScore?: number;
26
- /** TTL for cached trust results in ms (default: 86400000 = 24h). */
26
+ /**
27
+ * Server-side gate result TTL in ms (default: 86400000 = 24h).
28
+ * @deprecated Use `cacheTtlMs` for client-side cache control.
29
+ * This field is kept for backward compatibility and
30
+ * maps to `cacheTtlMs` if `cacheTtlMs` is not set.
31
+ */
27
32
  ttlMs?: number;
33
+ /**
34
+ * Client-side profile cache TTL in ms (default: 30000 = 30s).
35
+ * Controls how long gate results are cached in memory to absorb
36
+ * x402 retry flows. Set to `0` to disable caching.
37
+ */
38
+ cacheTtlMs?: number;
28
39
  /** Custom handler when an agent is denied. */
29
40
  onDeny?: (req: any, res: any, result: any) => void;
30
41
  /** Hook called after an agent is allowed. */
@@ -76,7 +87,7 @@ export declare class ValironOperator {
76
87
  * });
77
88
  * ```
78
89
  */
79
- paywall(config: PaywallConfig): (req: any, res: any, next: any) => Promise<any>;
90
+ paywall(config: PaywallConfig): (req: any, res: any, next: any) => void;
80
91
  /**
81
92
  * Create a Fastify plugin that gates access + tracks usage.
82
93
  *
@@ -63,7 +63,7 @@ class ValironOperator {
63
63
  const gateConfig = {
64
64
  sdk: this.sdk,
65
65
  minScore: config.minTrustScore ?? 45,
66
- ttlMs: config.ttlMs,
66
+ cacheTtlMs: config.cacheTtlMs ?? config.ttlMs,
67
67
  onDeny: config.onDeny,
68
68
  onAllow: (req, result) => {
69
69
  // Enrich the gate result with pricing
@@ -98,7 +98,7 @@ class ValironOperator {
98
98
  const pluginConfig = {
99
99
  sdk: this.sdk,
100
100
  minScore: config.minTrustScore ?? 45,
101
- ttlMs: config.ttlMs,
101
+ cacheTtlMs: config.cacheTtlMs ?? config.ttlMs,
102
102
  prefix: config.prefix,
103
103
  onDeny: config.onDeny,
104
104
  onAllow: (req, result) => {
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * Matches the actual edge-proxy /operator/* endpoints
6
6
  */
7
7
  /** Blockchain networks supported by the Valiron Operator API. */
8
- export type SupportedChain = "ethereum" | "monad" | "arbitrum" | "base" | "avalanche" | "celo" | "polygon" | "linea" | "abstract" | "bsc" | "gnosis" | "goat" | "mantle" | "megaeth" | "metis" | "optimism" | "scroll" | "skale_base" | "soneium" | "taiko" | "xlayer" | "base_sepolia" | "ethereum_sepolia" | "abstract_testnet" | "arbitrum_sepolia" | "avalanche_testnet" | "bsc_testnet" | "celo_testnet" | "linea_sepolia" | "mantle_testnet" | "megaeth_testnet" | "metis_sepolia" | "optimism_sepolia" | "polygon_amoy" | "scroll_sepolia" | "skale_base_sepolia" | "soneium_minato" | "taiko_hoodi" | "xlayer_testnet" | "hedera_testnet" | "arc_testnet" | "world_chain" | "solana";
8
+ export type SupportedChain = "ethereum" | "monad" | "arbitrum" | "base" | "avalanche" | "celo" | "polygon" | "linea" | "abstract" | "bsc" | "gnosis" | "goat" | "mantle" | "megaeth" | "metis" | "optimism" | "scroll" | "skale_base" | "soneium" | "taiko" | "xlayer" | "base_sepolia" | "ethereum_sepolia" | "abstract_testnet" | "arbitrum_sepolia" | "avalanche_testnet" | "bsc_testnet" | "celo_testnet" | "linea_sepolia" | "mantle_testnet" | "megaeth_testnet" | "metis_sepolia" | "optimism_sepolia" | "polygon_amoy" | "scroll_sepolia" | "skale_base_sepolia" | "soneium_minato" | "taiko_hoodi" | "xlayer_testnet" | "hedera_testnet" | "arc_testnet" | "solana";
9
9
  export type RouteDecision = "prod" | "prod_throttled" | "sandbox" | "sandbox_only";
10
10
  export type RiskLevel = "GREEN" | "YELLOW" | "RED";
11
11
  export type MoodysRating = "AAA" | "AA" | "A" | "BAA" | "BA" | "B" | "CAA" | "CA" | "C";
@@ -152,6 +152,20 @@ export interface SandboxResult {
152
152
  chain: ChainContext;
153
153
  message: string;
154
154
  }
155
+ /**
156
+ * Response from `POST /operator/trigger-sandbox-key/:agentAddress`
157
+ *
158
+ * Same scoring as on-chain agents, but keyed by agent address instead of
159
+ * on-chain agent ID.
160
+ */
161
+ export interface KeyAgentSandboxResult {
162
+ ok: boolean;
163
+ agentAddress: string;
164
+ valironScore: number;
165
+ tier: MoodysRating;
166
+ riskLevel: RiskLevel;
167
+ message: string;
168
+ }
155
169
  /**
156
170
  * Response from `GET /operator/agent/:agentId/snapshot`
157
171
  *
@@ -203,15 +217,57 @@ export interface GateResult {
203
217
  provisional?: boolean;
204
218
  }
205
219
  /**
206
- * Response from `POST /operator/key/:agentKeyHash/challenge`
220
+ * Options for the proxy gateway request.
221
+ *
222
+ * `POST /proxy/:agentId`
223
+ */
224
+ export interface ProxyRequest {
225
+ /** The real API endpoint URL to forward the request to. */
226
+ target: string;
227
+ /** HTTP method to use (default: GET). */
228
+ method?: string;
229
+ /** Headers to forward to the target API. */
230
+ headers?: Record<string, string>;
231
+ /** Request body to forward (for POST, PUT, PATCH). */
232
+ body?: unknown;
233
+ /** Minimum trust score to allow (default: 65). */
234
+ minScore?: number;
235
+ }
236
+ /**
237
+ * Response from the proxy gateway.
238
+ *
239
+ * On success, contains the real API response wrapped with Valiron metadata.
240
+ * On deny (score below threshold), the SDK will throw — callers should
241
+ * catch the error and inspect the response body for gate details.
242
+ */
243
+ export interface ProxyResponse<T = unknown> {
244
+ /** Valiron gate evaluation result. */
245
+ _valiron: {
246
+ allow: boolean;
247
+ score: number;
248
+ tier: MoodysRating;
249
+ riskLevel: RiskLevel;
250
+ agentId: string;
251
+ wallet: string;
252
+ sandboxRan: boolean;
253
+ provisional: boolean;
254
+ cached: boolean;
255
+ };
256
+ /** HTTP status code from the real API. */
257
+ _apiStatus: number;
258
+ /** The real API response body. */
259
+ response: T;
260
+ }
261
+ /**
262
+ * Response from `POST /operator/key/:agentAddress/challenge`
207
263
  */
208
264
  export interface KeyAgentChallenge {
209
265
  /** Random nonce the agent must sign */
210
266
  challenge: string;
211
267
  /** ISO 8601 expiry timestamp for the challenge */
212
268
  expiresAt: string;
213
- /** The agent key hash this challenge was issued for */
214
- agentKeyHash: string;
269
+ /** The agent's Ethereum address (keccak256-derived) */
270
+ agentAddress: string;
215
271
  }
216
272
  /** Verification level from World ID */
217
273
  export type WorldIdVerificationLevel = "orb" | "device" | "phone";
@@ -291,11 +347,11 @@ export interface IcebreakerOwnership {
291
347
  /**
292
348
  * Trust profile for a key-based (non-ERC-8004) agent.
293
349
  *
294
- * Response from `POST /operator/key/verify` and `GET /operator/key/:agentKeyHash`
350
+ * Response from `POST /operator/key/verify` and `GET /operator/key/:agentAddress`
295
351
  */
296
352
  export interface KeyAgentProfile {
297
- /** SHA-256 hash of the agent's public key */
298
- agentKeyHash: string;
353
+ /** Ethereum address derived via keccak256 of the agent's secp256k1 public key */
354
+ agentAddress: string;
299
355
  /** Whether identity has been verified via challenge-response */
300
356
  verified: boolean;
301
357
  /** Behavioral score (0-110) — same scoring as ERC-8004 agents */
@@ -374,88 +430,6 @@ export interface ValironConfig {
374
430
  */
375
431
  telemetry?: TelemetryConfig;
376
432
  }
377
- /** Response from `POST /channel/preflight/:agentId` */
378
- export interface ChannelPreflightResponse {
379
- agentId: string;
380
- tier: string;
381
- score: number;
382
- riskLevel: string;
383
- creditLine: string;
384
- creditLineReadable: string;
385
- maxRequests: number | null;
386
- durationSeconds: number;
387
- escrowAddress: string;
388
- }
389
- /** Response from `POST /channel/open/:agentId` */
390
- export interface ChannelOpenResponse {
391
- sessionId: string;
392
- agentId: string;
393
- tier: string;
394
- score: number;
395
- riskLevel: string;
396
- creditLine: string;
397
- creditLineReadable: string;
398
- maxRequests: number | null;
399
- expiresAt: string;
400
- durationSeconds: number;
401
- depositConfirmed: boolean;
402
- depositSignature: string;
403
- escrowAddress: string;
404
- }
405
- /** Response from `POST /channel/consume/:sessionId` */
406
- export interface ChannelConsumeResponse {
407
- requestId: string;
408
- cost: string;
409
- costReadable: string;
410
- description?: string;
411
- session: {
412
- consumed: string;
413
- consumedReadable: string;
414
- remaining: string;
415
- remainingReadable: string;
416
- requestCount: number;
417
- maxRequests: number | null;
418
- secondsRemaining: number;
419
- };
420
- }
421
- /** Response from `GET /channel/status/:sessionId` */
422
- export interface ChannelStatusResponse {
423
- sessionId: string;
424
- agentId: string;
425
- tier: string;
426
- creditLine: string;
427
- creditLineReadable: string;
428
- consumed: string;
429
- consumedReadable: string;
430
- remaining: string;
431
- remainingReadable: string;
432
- requestCount: number;
433
- maxRequests: number | null;
434
- expiresAt: string;
435
- secondsRemaining: number;
436
- active: boolean;
437
- settled: boolean;
438
- }
439
- /** Response from `POST /channel/settle/:sessionId` */
440
- export interface ChannelSettlementResponse {
441
- sessionId: string;
442
- settled: boolean;
443
- totalConsumed: string;
444
- totalConsumedReadable: string;
445
- requestsServed: number;
446
- unusedCredit: string;
447
- unusedCreditReadable: string;
448
- refundAmount?: string;
449
- refundReadable?: string;
450
- refundSignature?: string;
451
- refundWarning?: string;
452
- }
453
- /** Response from `GET /channel/health` */
454
- export interface ChannelHealthResponse {
455
- status: string;
456
- service: string;
457
- escrowAddress: string | null;
458
- }
459
433
  export declare class ValironError extends Error {
460
434
  code: string;
461
435
  statusCode?: number | undefined;