@valiron/sdk 1.2.0 → 1.3.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/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ValironOperator = exports.generateChallenge = exports.isValidAddress = exports.valironGateCheck = exports.createValironNextMiddleware = exports.valironFastifyPlugin = exports.createValironGate = exports.ValironClient = exports.ValironSDK = void 0;
17
+ exports.ValironOperator = exports.AGENT_IDENTITY_HEADERS = exports.agentIdentityProofFromHeaders = exports.agentIdentityProofHeaders = exports.createAgentIdentityProof = exports.buildAgentIdentitySigningPayload = exports.sha256RequestDigest = exports.generateChallenge = exports.isValidAddress = exports.valironIdentityGateCheck = exports.createValironIdentityNextMiddleware = exports.valironIdentityFastifyPlugin = exports.createValironIdentityGate = exports.valironGateCheck = exports.createValironNextMiddleware = exports.valironFastifyPlugin = exports.createValironGate = exports.ValironClient = exports.ValironSDK = void 0;
18
18
  const clients_1 = require("./clients");
19
19
  /**
20
20
  * Valiron SDK – Official TypeScript SDK for the Trust Layer for Agentic Economy
@@ -444,6 +444,10 @@ class ValironSDK {
444
444
  async getSelfProfile(agentId, options) {
445
445
  return this.client.getSelfProfile(agentId, options);
446
446
  }
447
+ /** Verify ANS or another provider-backed identity and evaluate an action policy. */
448
+ async verifyAgentIdentity(proof = {}, policy) {
449
+ return this.client.verifyAgentIdentity(proof, policy);
450
+ }
447
451
  /**
448
452
  * Flush any pending telemetry events and release resources.
449
453
  *
@@ -480,8 +484,19 @@ Object.defineProperty(exports, "createValironGate", { enumerable: true, get: fun
480
484
  Object.defineProperty(exports, "valironFastifyPlugin", { enumerable: true, get: function () { return middleware_1.valironFastifyPlugin; } });
481
485
  Object.defineProperty(exports, "createValironNextMiddleware", { enumerable: true, get: function () { return middleware_1.createValironNextMiddleware; } });
482
486
  Object.defineProperty(exports, "valironGateCheck", { enumerable: true, get: function () { return middleware_1.valironGateCheck; } });
487
+ var identityMiddleware_1 = require("./identityMiddleware");
488
+ Object.defineProperty(exports, "createValironIdentityGate", { enumerable: true, get: function () { return identityMiddleware_1.createValironIdentityGate; } });
489
+ Object.defineProperty(exports, "valironIdentityFastifyPlugin", { enumerable: true, get: function () { return identityMiddleware_1.valironIdentityFastifyPlugin; } });
490
+ Object.defineProperty(exports, "createValironIdentityNextMiddleware", { enumerable: true, get: function () { return identityMiddleware_1.createValironIdentityNextMiddleware; } });
491
+ Object.defineProperty(exports, "valironIdentityGateCheck", { enumerable: true, get: function () { return identityMiddleware_1.valironIdentityGateCheck; } });
483
492
  var identity_1 = require("./identity");
484
493
  Object.defineProperty(exports, "isValidAddress", { enumerable: true, get: function () { return identity_1.isValidAddress; } });
485
494
  Object.defineProperty(exports, "generateChallenge", { enumerable: true, get: function () { return identity_1.generateChallenge; } });
495
+ Object.defineProperty(exports, "sha256RequestDigest", { enumerable: true, get: function () { return identity_1.sha256RequestDigest; } });
496
+ Object.defineProperty(exports, "buildAgentIdentitySigningPayload", { enumerable: true, get: function () { return identity_1.buildAgentIdentitySigningPayload; } });
497
+ Object.defineProperty(exports, "createAgentIdentityProof", { enumerable: true, get: function () { return identity_1.createAgentIdentityProof; } });
498
+ Object.defineProperty(exports, "agentIdentityProofHeaders", { enumerable: true, get: function () { return identity_1.agentIdentityProofHeaders; } });
499
+ Object.defineProperty(exports, "agentIdentityProofFromHeaders", { enumerable: true, get: function () { return identity_1.agentIdentityProofFromHeaders; } });
500
+ Object.defineProperty(exports, "AGENT_IDENTITY_HEADERS", { enumerable: true, get: function () { return identity_1.AGENT_IDENTITY_HEADERS; } });
486
501
  var operatorSdk_1 = require("./operatorSdk");
487
502
  Object.defineProperty(exports, "ValironOperator", { enumerable: true, get: function () { return operatorSdk_1.ValironOperator; } });
@@ -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;
@@ -308,11 +359,7 @@ function createValironGate(config) {
308
359
  status: "missing_identity",
309
360
  latencyMs,
310
361
  });
311
- return res.status(401).json({
312
- error: "Missing agent identity",
313
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
314
- identitySkill: "https://valiron.co/auth.md",
315
- });
362
+ return res.status(401).json(missingIdentityBody());
316
363
  }
317
364
  if (error) {
318
365
  emitGateTelemetry(frozen.sdk, {
@@ -323,9 +370,8 @@ function createValironGate(config) {
323
370
  status: "error",
324
371
  latencyMs,
325
372
  });
326
- return res.status(503).json({
327
- error: "Trust gate unavailable \u2014 request denied (fail-closed)",
328
- });
373
+ logGateFailure("express", agentId, error);
374
+ return res.status(503).json(unavailableGateBody(error));
329
375
  }
330
376
  emitGateTelemetry(frozen.sdk, {
331
377
  framework: "express",
@@ -350,20 +396,12 @@ function createValironGate(config) {
350
396
  }
351
397
  // New agent with no reputation — sandbox test triggered in background
352
398
  if (pendingEvaluation) {
353
- return res.status(403).json({
354
- error: "Agent pending evaluation",
355
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
356
- retryAfterMs: 30000,
357
- ...result,
358
- });
399
+ return res.status(403).json(pendingEvaluationBody(result));
359
400
  }
360
401
  if (config.onDeny) {
361
402
  return config.onDeny(req, res, result);
362
403
  }
363
- return res.status(403).json({
364
- error: "Agent blocked by Valiron trust gate",
365
- ...result,
366
- });
404
+ return res.status(403).json(deniedGateBody(result, minScore));
367
405
  }
368
406
  // Wrap with Promise.catch(next) for Express 4 async safety.
369
407
  // Express 4 does NOT await async middleware, so without this wrapper
@@ -442,11 +480,7 @@ async function valironFastifyPlugin(fastify, opts) {
442
480
  status: "missing_identity",
443
481
  latencyMs,
444
482
  });
445
- return reply.status(401).send({
446
- error: "Missing agent identity",
447
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
448
- identitySkill: "https://valiron.co/auth.md",
449
- });
483
+ return reply.status(401).send(missingIdentityBody());
450
484
  }
451
485
  if (error) {
452
486
  emitGateTelemetry(opts.sdk, {
@@ -457,9 +491,8 @@ async function valironFastifyPlugin(fastify, opts) {
457
491
  status: "error",
458
492
  latencyMs,
459
493
  });
460
- return reply.status(503).send({
461
- error: "Trust gate unavailable \u2014 request denied (fail-closed)",
462
- });
494
+ logGateFailure("fastify", agentId, error);
495
+ return reply.status(503).send(unavailableGateBody(error));
463
496
  }
464
497
  emitGateTelemetry(opts.sdk, {
465
498
  framework: "fastify",
@@ -484,20 +517,12 @@ async function valironFastifyPlugin(fastify, opts) {
484
517
  }
485
518
  // New agent with no reputation — sandbox test triggered in background
486
519
  if (pendingEvaluation) {
487
- return reply.status(403).send({
488
- error: "Agent pending evaluation",
489
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
490
- retryAfterMs: 30000,
491
- ...result,
492
- });
520
+ return reply.status(403).send(pendingEvaluationBody(result));
493
521
  }
494
522
  if (opts.onDeny) {
495
523
  return opts.onDeny(request, reply, result);
496
524
  }
497
- return reply.status(403).send({
498
- error: "Agent blocked by Valiron trust gate",
499
- ...result,
500
- });
525
+ return reply.status(403).send(deniedGateBody(result, minScore));
501
526
  });
502
527
  }
503
528
  /**
@@ -555,11 +580,7 @@ function createValironNextMiddleware(config) {
555
580
  status: "missing_identity",
556
581
  latencyMs: Date.now() - startedAt,
557
582
  });
558
- return Response.json({
559
- error: "Missing agent identity",
560
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
561
- identitySkill: "https://valiron.co/auth.md",
562
- }, { status: 401 });
583
+ return Response.json(missingIdentityBody(), { status: 401 });
563
584
  }
564
585
  const cacheTtl = config.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
565
586
  const effectiveMinScore = minScore ?? 65;
@@ -588,7 +609,9 @@ function createValironNextMiddleware(config) {
588
609
  });
589
610
  if (cached.result.allow)
590
611
  return undefined;
591
- 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 });
592
615
  }
593
616
  }
594
617
  if (agentId) {
@@ -634,16 +657,11 @@ function createValironNextMiddleware(config) {
634
657
  return undefined; // continue to route handler
635
658
  }
636
659
  if (pendingEvaluation) {
637
- return Response.json({
638
- error: "Agent pending evaluation",
639
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
640
- retryAfterMs: 30000,
641
- ...result,
642
- }, { status: 403 });
660
+ return Response.json(pendingEvaluationBody(result), { status: 403 });
643
661
  }
644
- return Response.json({ error: "Agent blocked by Valiron trust gate", ...result }, { status: 403 });
662
+ return Response.json(deniedGateBody(result, effectiveMinScore), { status: 403 });
645
663
  }
646
- catch {
664
+ catch (error) {
647
665
  emitGateTelemetry(sdk, {
648
666
  framework: "next",
649
667
  agentType: agentId ? "onchain" : "key",
@@ -652,7 +670,8 @@ function createValironNextMiddleware(config) {
652
670
  status: "error",
653
671
  latencyMs: Date.now() - startedAt,
654
672
  });
655
- 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 });
656
675
  }
657
676
  };
658
677
  }
@@ -716,11 +735,7 @@ async function valironGateCheck(sdk, opts) {
716
735
  agentId: null,
717
736
  ok: false,
718
737
  status: 401,
719
- body: {
720
- error: "Missing agent identity",
721
- message: "Provide an x-agent-id or x-agent-address header. If you don't have an identity yet, see the Valiron Identity Skill.",
722
- identitySkill: "https://valiron.co/auth.md",
723
- },
738
+ body: missingIdentityBody(),
724
739
  };
725
740
  }
726
741
  const effectiveMinScore = minScore ?? 65;
@@ -756,8 +771,10 @@ async function valironGateCheck(sdk, opts) {
756
771
  allow: false,
757
772
  result: cached.result,
758
773
  status: 403,
759
- body: { error: "Agent blocked by Valiron trust gate", ...cached.result,
760
- ...(cached.pendingEvaluation ? { pendingEvaluation: true, retryAfterMs: 30000 } : {}) },
774
+ pendingEvaluation: cached.pendingEvaluation || undefined,
775
+ body: cached.pendingEvaluation
776
+ ? pendingEvaluationBody(cached.result)
777
+ : deniedGateBody(cached.result, effectiveMinScore),
761
778
  };
762
779
  }
763
780
  }
@@ -815,12 +832,7 @@ async function valironGateCheck(sdk, opts) {
815
832
  result,
816
833
  status: 403,
817
834
  pendingEvaluation: true,
818
- body: {
819
- error: "Agent pending evaluation",
820
- message: "This agent was recently registered and is being evaluated. Retry shortly.",
821
- retryAfterMs: 30000,
822
- ...result,
823
- },
835
+ body: pendingEvaluationBody(result),
824
836
  };
825
837
  }
826
838
  return {
@@ -830,10 +842,10 @@ async function valironGateCheck(sdk, opts) {
830
842
  allow: false,
831
843
  result,
832
844
  status: 403,
833
- body: { error: "Agent blocked by Valiron trust gate", ...result },
845
+ body: deniedGateBody(result, effectiveMinScore),
834
846
  };
835
847
  }
836
- catch {
848
+ catch (error) {
837
849
  emitGateTelemetry(sdk, {
838
850
  framework: "generic",
839
851
  agentType: agentId ? "onchain" : "key",
@@ -842,12 +854,13 @@ async function valironGateCheck(sdk, opts) {
842
854
  status: "error",
843
855
  latencyMs: Date.now() - startedAt,
844
856
  });
857
+ logGateFailure("generic", identifier, error);
845
858
  return {
846
859
  hasAgent: true,
847
860
  agentId: identifier,
848
861
  ok: false,
849
862
  status: 503,
850
- body: { error: "Trust gate unavailable \u2014 request denied (fail-closed)" },
863
+ body: unavailableGateBody(error),
851
864
  };
852
865
  }
853
866
  }
@@ -67,6 +67,13 @@ class ValironOperator {
67
67
  icebreaker_included: trustSignals.includes("icebreaker"),
68
68
  self_included: trustSignals.includes("self"),
69
69
  wallet_included: trustSignals.includes("wallet"),
70
+ decision: entry.decision,
71
+ error_code: entry.errorCode || undefined,
72
+ request_id: entry.requestId || undefined,
73
+ identity_type: entry.identityType,
74
+ trust_route: entry.trustRoute || undefined,
75
+ trust_tier: entry.trustTier || undefined,
76
+ trust_score: entry.trustScore ?? undefined,
70
77
  };
71
78
  void fetch(this.buildAnalyticsUrl(), {
72
79
  method: "POST",
@@ -171,6 +178,13 @@ class ValironOperator {
171
178
  ipAddress: this.expressIp(req),
172
179
  errorMessage,
173
180
  trustSignals: config.trustSignals,
181
+ decision: allowed ? "allowed" : statusCode === 503 ? "unavailable" : "denied",
182
+ errorCode: !allowed ? (statusCode === 503 ? "TRUST_GATE_UNAVAILABLE" : "TRUST_GATE_DENIED") : undefined,
183
+ requestId: this.extractHeader(req, "x-request-id"),
184
+ identityType: gate?.agentId ? "onchain" : this.extractHeader(req, "x-agent-address") ? "key" : "missing",
185
+ trustRoute: gate?.route,
186
+ trustTier: gate?.tier,
187
+ trustScore: gate?.score,
174
188
  });
175
189
  };
176
190
  if (typeof res.once === "function") {
@@ -256,6 +270,13 @@ class ValironOperator {
256
270
  ipAddress: request.ip || this.extractHeader(request, "x-forwarded-for")?.split(",")[0]?.trim() || null,
257
271
  errorMessage,
258
272
  trustSignals: config.trustSignals,
273
+ decision: allowed ? "allowed" : statusCode === 503 ? "unavailable" : "denied",
274
+ errorCode: !allowed ? (statusCode === 503 ? "TRUST_GATE_UNAVAILABLE" : "TRUST_GATE_DENIED") : undefined,
275
+ requestId: this.extractHeader(request, "x-request-id"),
276
+ identityType: gate?.agentId ? "onchain" : this.extractHeader(request, "x-agent-address") ? "key" : "missing",
277
+ trustRoute: gate?.route,
278
+ trustTier: gate?.tier,
279
+ trustScore: gate?.score,
259
280
  });
260
281
  });
261
282
  done();
package/dist/types.d.ts CHANGED
@@ -11,6 +11,50 @@ export type RiskLevel = "GREEN" | "YELLOW" | "RED";
11
11
  export type MoodysRating = "AAA" | "AA" | "A" | "BAA" | "BA" | "B" | "CAA" | "CA" | "C";
12
12
  export type TrustSignal = "8004" | "sandbox" | "world" | "icebreaker" | "self" | "wallet";
13
13
  export type WalletRiskLevel = "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
14
+ export type AgentIdentityStatus = "anonymous" | "claimed" | "verified";
15
+ export type AgentIdentityPolicyAction = "allow" | "limit" | "challenge" | "block";
16
+ /** Proof submitted to Valiron's provider-independent identity verifier. */
17
+ export interface AgentIdentityProof {
18
+ provider?: string;
19
+ agentId?: string;
20
+ signature?: string;
21
+ timestamp?: string;
22
+ nonce?: string;
23
+ requestDigest?: string;
24
+ keyId?: string;
25
+ }
26
+ /** Proof fields transported with an HTTP request. The receiving gate computes requestDigest itself. */
27
+ export type AgentIdentityTransportProof = Omit<AgentIdentityProof, "requestDigest">;
28
+ export interface AgentIdentityPolicy {
29
+ anonymous?: AgentIdentityPolicyAction;
30
+ claimed?: AgentIdentityPolicyAction;
31
+ verified?: AgentIdentityPolicyAction;
32
+ belowMinimumScore?: AgentIdentityPolicyAction;
33
+ minReputationScore?: number;
34
+ mediumRisk?: AgentIdentityPolicyAction;
35
+ highRisk?: AgentIdentityPolicyAction;
36
+ }
37
+ export interface AgentIdentityPolicyDecision {
38
+ action: AgentIdentityPolicyAction;
39
+ reason: string;
40
+ }
41
+ /** Normalized provider identity, Valiron reputation, and the caller-selected policy decision. */
42
+ export interface AgentIdentityVerificationResult {
43
+ agentId: string | null;
44
+ provider: string | null;
45
+ organization: string | null;
46
+ identityStatus: AgentIdentityStatus;
47
+ humanIdentified: false;
48
+ stableIdentityId: string | null;
49
+ credentialId?: string;
50
+ credentialVersion?: string;
51
+ externalTrust?: Record<string, unknown>;
52
+ verifiedAt: string | null;
53
+ failureReason?: string;
54
+ reputationScore: number | null;
55
+ riskLevel: "low" | "medium" | "high" | "unknown";
56
+ policyDecision: AgentIdentityPolicyDecision;
57
+ }
14
58
  export interface AgentIdentity {
15
59
  agentId: string;
16
60
  wallet: string;
@@ -562,8 +606,26 @@ export interface ValironConfig {
562
606
  */
563
607
  telemetry?: TelemetryConfig;
564
608
  }
609
+ /** Structured diagnostics attached to SDK failures for programmatic recovery. */
610
+ export interface ValironErrorDetails {
611
+ /** HTTP method used for the failed request, when applicable. */
612
+ method?: "GET" | "POST";
613
+ /** Valiron API path that failed. */
614
+ path?: string;
615
+ /** Server request ID, when the deployment supplies one. Include this in support requests. */
616
+ requestId?: string;
617
+ /** Safe server-provided explanation beyond the top-level message. */
618
+ details?: unknown;
619
+ /** Suggested next step supplied by Valiron. */
620
+ action?: string;
621
+ /** Documentation or setup URL relevant to the failure. */
622
+ docsUrl?: string;
623
+ /** Delay before retrying, when the operation is retryable. */
624
+ retryAfterMs?: number;
625
+ }
565
626
  export declare class ValironError extends Error {
566
627
  code: string;
567
628
  statusCode?: number | undefined;
568
- constructor(message: string, code: string, statusCode?: number | undefined);
629
+ details?: ValironErrorDetails | undefined;
630
+ constructor(message: string, code: string, statusCode?: number | undefined, details?: ValironErrorDetails | undefined);
569
631
  }
package/dist/types.js CHANGED
@@ -7,12 +7,12 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ValironError = void 0;
10
- // ─── Errors ─────────────────────────────────────────────────────────────────
11
10
  class ValironError extends Error {
12
- constructor(message, code, statusCode) {
11
+ constructor(message, code, statusCode, details) {
13
12
  super(message);
14
13
  this.code = code;
15
14
  this.statusCode = statusCode;
15
+ this.details = details;
16
16
  this.name = "ValironError";
17
17
  }
18
18
  }
@@ -13,6 +13,13 @@ Agent or client
13
13
  -> response returned through Valiron
14
14
  ```
15
15
 
16
+ > **Important: protect the origin.** A hosted wrapper evaluates and logs only
17
+ > requests sent to its Valiron URL. It is not a network firewall in front of a
18
+ > separately public API origin. If callers can reach your origin directly, they
19
+ > can bypass the wrapper's payment, trust, rate-limit, and analytics path.
20
+ > Publish the generated wrapper URL as the agent-facing URL and configure your
21
+ > origin to accept only authenticated requests from Valiron.
22
+
16
23
  The wrapper is intentionally narrow: Valiron forwards valid HTTP requests to an existing upstream API. It does not need direct database access, internal service access, or provider infrastructure credentials beyond the optional upstream auth secret needed to call the API.
17
24
 
18
25
  ## When To Use This
@@ -43,7 +50,7 @@ Providers configure one wrapper per public endpoint.
43
50
  | Payment protocol | Yes | `x402` or `MPP`. |
44
51
  | Payment network | Yes | x402: `eip155:8453` or `eip155:84532`; MPP: `tempo:4217` or `tempo:42431`. |
45
52
  | Payout wallet | Paid only | EVM address receiving payment. |
46
- | Upstream auth | No | Secret Valiron injects when forwarding to your upstream. |
53
+ | Upstream auth | Required to prevent origin bypass | Auth Valiron adds when forwarding to your upstream. Use `hmac` for a public origin. |
47
54
  | Rate limit | No | Max requests per minute per client. |
48
55
  | Trust check | No | Whether callers must pass Valiron agent trust evaluation before forwarding. |
49
56
 
@@ -72,9 +79,12 @@ https://api.example.com/v1/weather
72
79
  3. Click **Make API Agent-Ready**.
73
80
  4. Enter the upstream URL, public path, method, price, protocol, network, and payout wallet.
74
81
  5. Choose whether Valiron trust checks are required.
75
- 6. Configure upstream auth only if your API needs it.
82
+ 6. Configure upstream authentication. For a public origin, choose `hmac` and
83
+ store the same secret in your origin's verification middleware.
76
84
  7. Create the wrapper.
77
- 8. Distribute the generated Valiron URL to agent clients or API customers.
85
+ 8. Distribute only the generated Valiron URL to agent clients or API customers.
86
+ 9. Verify that a direct request to your origin is rejected and a request to the
87
+ wrapper is recorded in Valiron call logs.
78
88
 
79
89
  ## HTTP API Flow
80
90
 
@@ -117,7 +127,8 @@ curl -X POST https://valiron-edge-proxy.onrender.com/operator/endpoints \
117
127
  "paymentProtocol": "x402",
118
128
  "paymentNetwork": "eip155:8453",
119
129
  "trustEnabled": false,
120
- "upstreamAuthType": "none"
130
+ "upstreamAuthType": "hmac",
131
+ "upstreamAuthSecret": "replace-with-a-unique-shared-secret"
121
132
  }'
122
133
  ```
123
134
 
@@ -136,7 +147,8 @@ curl -X POST https://valiron-edge-proxy.onrender.com/operator/endpoints \
136
147
  "paymentNetwork": "eip155:8453",
137
148
  "payoutAddress": "0xYourPayoutWallet",
138
149
  "trustEnabled": false,
139
- "upstreamAuthType": "none"
150
+ "upstreamAuthType": "hmac",
151
+ "upstreamAuthSecret": "replace-with-a-unique-shared-secret"
140
152
  }'
141
153
  ```
142
154
 
@@ -155,7 +167,8 @@ curl -X POST https://valiron-edge-proxy.onrender.com/operator/endpoints \
155
167
  "paymentNetwork": "tempo:4217",
156
168
  "payoutAddress": "0xYourPayoutWallet",
157
169
  "trustEnabled": false,
158
- "upstreamAuthType": "none"
170
+ "upstreamAuthType": "hmac",
171
+ "upstreamAuthSecret": "replace-with-a-unique-shared-secret"
159
172
  }'
160
173
  ```
161
174
 
@@ -299,7 +312,15 @@ Use payment-only wrappers when:
299
312
 
300
313
  ## Upstream Auth
301
314
 
302
- If your existing API requires auth, Valiron stores the secret encrypted and injects it only when forwarding a valid request upstream.
315
+ Valiron stores the configured secret encrypted and injects or derives it only
316
+ when forwarding a request that has reached the wrapper. This is how your origin
317
+ distinguishes an authenticated wrapper request from a direct public request.
318
+
319
+ For a public API origin, configure upstream authentication before announcing or
320
+ indexing the wrapper. Otherwise, a caller can send traffic directly to the
321
+ origin and bypass Valiron entirely. `none` is appropriate only when the origin
322
+ is already inaccessible to untrusted callers or bypass is intentionally
323
+ acceptable.
303
324
 
304
325
  Supported auth modes:
305
326
 
@@ -312,6 +333,40 @@ Supported auth modes:
312
333
 
313
334
  The calling agent never sees your upstream secret.
314
335
 
336
+ ### Recommended production pattern: HMAC origin verification
337
+
338
+ Choose `hmac` for an origin that is publicly reachable. Valiron sends:
339
+
340
+ ```text
341
+ x-valiron-signature: sha256=<hex HMAC>
342
+ x-valiron-timestamp: <Unix seconds>
343
+ ```
344
+
345
+ Your origin must reject requests when the signature is missing, invalid, or too
346
+ old. Verify the signature against the request method, public wrapper path, raw
347
+ body SHA-256, and timestamp with the shared secret configured on the wrapper.
348
+ Use constant-time signature comparison and a short timestamp window to reduce
349
+ replay risk.
350
+
351
+ Do **not** treat headers such as `x-valiron-wrapper-id`,
352
+ `x-valiron-payment-protocol`, or `x-valiron-trust-enabled` as proof that a
353
+ request came through Valiron. They are request metadata, not a credential, and
354
+ can be forged by a caller that reaches your origin directly.
355
+
356
+ ### Origin-lockdown checklist
357
+
358
+ Before production:
359
+
360
+ 1. Set `upstreamAuthType` to `hmac` and configure a unique secret.
361
+ 2. Deploy origin middleware that verifies the HMAC and timestamp before the API
362
+ handler runs.
363
+ 3. Make the Valiron `/wrap/{operatorId}/{path}` URL the only public URL in
364
+ agent discovery metadata, examples, and client configuration.
365
+ 4. Send a direct request to the origin without the signature and confirm a
366
+ `401` or `403` response.
367
+ 5. Send a request through the wrapper and confirm the expected payment/trust
368
+ result and a corresponding Valiron call-log entry.
369
+
315
370
  Production requires `VALIRON_SECRET_ENCRYPTION_KEY` to store upstream auth secrets. Use a 32-byte hex key:
316
371
 
317
372
  ```bash