@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/README.md +54 -0
- package/dist/clients.d.ts +5 -1
- package/dist/clients.js +29 -6
- package/dist/identity.d.ts +35 -0
- package/dist/identity.js +96 -0
- package/dist/identityMiddleware.d.ts +50 -0
- package/dist/identityMiddleware.js +247 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +16 -1
- package/dist/middleware.js +80 -67
- package/dist/operatorSdk.js +21 -0
- package/dist/types.d.ts +63 -1
- package/dist/types.js +2 -2
- package/docs/AGENT-READY-APIS.md +62 -7
- package/docs/API-REFERENCE.md +121 -9
- package/docs/DASHBOARD.md +14 -3
- package/docs/E2E-MIDDLEWARE-INTEGRATION.md +221 -0
- package/docs/ERRORS.md +95 -10
- package/docs/IDENTITY.md +12 -2
- package/docs/PROVIDER-IDENTITY.md +277 -0
- package/docs/QUICKSTART.md +8 -0
- package/docs/README.md +9 -0
- package/docs/SDK-REFERENCE.md +80 -6
- package/docs/TRUST-MODEL.md +20 -0
- package/docs/llms.txt +17 -3
- package/package.json +2 -2
package/docs/API-REFERENCE.md
CHANGED
|
@@ -12,6 +12,120 @@ Endpoints are organized into three groups:
|
|
|
12
12
|
|
|
13
13
|
## Trust Evaluation Endpoints
|
|
14
14
|
|
|
15
|
+
### POST /operator/identity/verify
|
|
16
|
+
|
|
17
|
+
Normalize and verify a provider-backed agent identity proof. This endpoint is
|
|
18
|
+
provider-independent. SDK 1.3 exposes it as `verifyAgentIdentity()` and provides
|
|
19
|
+
dedicated middleware for `x-valiron-identity-*` proof headers. The ANS adapter
|
|
20
|
+
and provider credentials run inside Valiron's hosted service.
|
|
21
|
+
|
|
22
|
+
An empty body returns `identityStatus: "anonymous"`. Supplying an agent ID with
|
|
23
|
+
an incomplete or failed proof returns HTTP 200 with `identityStatus: "claimed"`
|
|
24
|
+
and a machine-readable `failureReason`. Only a validated authority binding,
|
|
25
|
+
fresh signature, and unused nonce return `identityStatus: "verified"`.
|
|
26
|
+
|
|
27
|
+
#### Request body
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"provider": "ans",
|
|
32
|
+
"agentId": "ans://v1.0.0.sales-agent.acme.com",
|
|
33
|
+
"signature": "BASE64URL_OR_0xHEX_SIGNATURE",
|
|
34
|
+
"timestamp": "2026-09-04T12:00:00.000Z",
|
|
35
|
+
"nonce": "nonce-0123456789abcdef",
|
|
36
|
+
"requestDigest": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
37
|
+
"keyId": "optional-provider-key-id",
|
|
38
|
+
"policy": {
|
|
39
|
+
"anonymous": "challenge",
|
|
40
|
+
"claimed": "block",
|
|
41
|
+
"verified": "allow",
|
|
42
|
+
"minReputationScore": 65,
|
|
43
|
+
"belowMinimumScore": "limit",
|
|
44
|
+
"mediumRisk": "limit",
|
|
45
|
+
"highRisk": "block"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Field | Type | Required | Description |
|
|
51
|
+
| --- | --- | --- | --- |
|
|
52
|
+
| `provider` | string | for a claimed identity | Registered resolver name. `ans` is implemented; DNS, DID, and API-key adapters are future integrations |
|
|
53
|
+
| `agentId` | string | no | Provider identity. Omit it to classify the request as anonymous |
|
|
54
|
+
| `signature` | string | for verification | Base64/base64url or `0x`-hex signature unless the resolver defines a provider-specific proof |
|
|
55
|
+
| `timestamp` | ISO timestamp | for verification | Signed time; default acceptance window is five minutes |
|
|
56
|
+
| `nonce` | string | for verification | 16–256 URL-safe characters; atomically claimed to prevent replay |
|
|
57
|
+
| `requestDigest` | string | for verification | `sha256:` plus 64 hexadecimal characters for the protected request bytes |
|
|
58
|
+
| `keyId` | string | no | Selects one provider-resolved verification key |
|
|
59
|
+
| `policy` | object | no | Per-status and per-risk actions. Every action must be `allow`, `limit`, `challenge`, or `block` |
|
|
60
|
+
|
|
61
|
+
The signature covers the exact canonical payload documented in
|
|
62
|
+
[PROVIDER-IDENTITY.md](./PROVIDER-IDENTITY.md#low-level-verification-request).
|
|
63
|
+
SDK identity gates calculate `requestDigest` from the exact received request
|
|
64
|
+
bytes rather than trusting a digest header.
|
|
65
|
+
|
|
66
|
+
#### Response — verified
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"agentId": "ans://v1.0.0.sales-agent.acme.com",
|
|
71
|
+
"provider": "ans",
|
|
72
|
+
"organization": "Acme Corp",
|
|
73
|
+
"identityStatus": "verified",
|
|
74
|
+
"humanIdentified": false,
|
|
75
|
+
"stableIdentityId": "identity:ans:<sha256>",
|
|
76
|
+
"credentialId": "7b93c61c-e261-488c-89a3-f948119be0a0",
|
|
77
|
+
"credentialVersion": "1.0.0",
|
|
78
|
+
"verifiedAt": "2026-09-04T12:00:00.000Z",
|
|
79
|
+
"reputationScore": 82,
|
|
80
|
+
"riskLevel": "low",
|
|
81
|
+
"policyDecision": {
|
|
82
|
+
"action": "allow",
|
|
83
|
+
"reason": "identity_verified"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For ANS, `stableIdentityId` is derived from `agentHost`, so reputation and
|
|
89
|
+
activity remain continuous across versioned registrations. `credentialId` is
|
|
90
|
+
the Registry Authority UUID and `credentialVersion` is the resolved version.
|
|
91
|
+
|
|
92
|
+
#### Response — claimed, resolver unavailable
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"agentId": "ans://v1.0.0.sales-agent.acme.com",
|
|
97
|
+
"provider": "ans",
|
|
98
|
+
"organization": null,
|
|
99
|
+
"identityStatus": "claimed",
|
|
100
|
+
"humanIdentified": false,
|
|
101
|
+
"stableIdentityId": null,
|
|
102
|
+
"verifiedAt": null,
|
|
103
|
+
"failureReason": "resolver_unavailable",
|
|
104
|
+
"reputationScore": null,
|
|
105
|
+
"riskLevel": "unknown",
|
|
106
|
+
"policyDecision": {
|
|
107
|
+
"action": "challenge",
|
|
108
|
+
"reason": "resolver_unavailable"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
This response occurs when the requested provider is not registered. For ANS it
|
|
114
|
+
also occurs when the deployment does not have the required ANS credentials and
|
|
115
|
+
trusted CA configuration.
|
|
116
|
+
|
|
117
|
+
#### Error responses
|
|
118
|
+
|
|
119
|
+
| Status | Error | Meaning |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| 400 | `invalid_identity_policy` | A policy is not an object, an action is unsupported, or `minReputationScore` is outside 0–100 |
|
|
122
|
+
| 503 | `identity_verification_unavailable` | Valiron could not safely resolve identity or atomically claim replay state |
|
|
123
|
+
|
|
124
|
+
See [Provider-Backed Identity Errors](./ERRORS.md#provider-backed-identity-errors)
|
|
125
|
+
for all `failureReason` values and retry guidance.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
15
129
|
### GET /operator/agent/:agentId
|
|
16
130
|
|
|
17
131
|
Retrieve the complete trust profile for an agent.
|
|
@@ -976,9 +1090,8 @@ Create a hosted agent-ready API wrapper. Requires JWT.
|
|
|
976
1090
|
"paymentNetwork": "eip155:8453",
|
|
977
1091
|
"payoutAddress": "0xYourReceivingWallet",
|
|
978
1092
|
"trustEnabled": false,
|
|
979
|
-
"upstreamAuthType": "
|
|
980
|
-
"
|
|
981
|
-
"upstreamAuthSecret": "Bearer upstream-secret"
|
|
1093
|
+
"upstreamAuthType": "hmac",
|
|
1094
|
+
"upstreamAuthSecret": "replace-with-a-unique-shared-secret"
|
|
982
1095
|
}
|
|
983
1096
|
```
|
|
984
1097
|
|
|
@@ -994,9 +1107,9 @@ Create a hosted agent-ready API wrapper. Requires JWT.
|
|
|
994
1107
|
| `paymentNetwork` | string | no | Payment network. Use `eip155:8453` or `eip155:84532` for x402, and `tempo:4217` or `tempo:42431` for MPP. |
|
|
995
1108
|
| `payoutAddress` | string | no | Receiving wallet for paid x402 wrappers. Required if no platform default receiving address is configured. |
|
|
996
1109
|
| `trustEnabled` | boolean | no | When true, the wrapper requires Valiron agent identity headers and checks trust before forwarding. |
|
|
997
|
-
| `upstreamAuthType` | string | no | `none` or `
|
|
998
|
-
| `upstreamAuthHeader` | string | no | Header name
|
|
999
|
-
| `upstreamAuthSecret` | string |
|
|
1110
|
+
| `upstreamAuthType` | string | no | `none`, `bearer`, `api_key`, or `hmac`. Defaults to `none`. Use `hmac` for a public origin that must reject direct requests. |
|
|
1111
|
+
| `upstreamAuthHeader` | string | no | Header name for `api_key` or `hmac`; defaults to `x-api-key` and `x-valiron-signature` respectively. Ignored by `bearer`. |
|
|
1112
|
+
| `upstreamAuthSecret` | string | required when auth is enabled | Shared secret, stored encrypted at rest. For `hmac`, your origin uses it to verify the signature and `x-valiron-timestamp`. |
|
|
1000
1113
|
|
|
1001
1114
|
---
|
|
1002
1115
|
|
|
@@ -1016,7 +1129,7 @@ Public agent-facing wrapper URL. This endpoint is created by `POST /operator/end
|
|
|
1016
1129
|
https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/{path}
|
|
1017
1130
|
```
|
|
1018
1131
|
|
|
1019
|
-
The wrapper matches the operator ID, path, and HTTP method to an active endpoint config. It can enforce payment, optional trust checks, rate limits, SSRF protection, upstream auth injection, and request forwarding.
|
|
1132
|
+
The wrapper matches the operator ID, path, and HTTP method to an active endpoint config. It can enforce payment, optional trust checks, rate limits, SSRF protection, upstream auth injection, and request forwarding. These controls apply only to traffic sent to this wrapper URL. Protect a public upstream with `hmac` auth and reject direct, unsigned origin traffic. See [API Scaffolding](./AGENT-READY-APIS.md#recommended-production-pattern-hmac-origin-verification).
|
|
1020
1133
|
|
|
1021
1134
|
#### Caller Headers
|
|
1022
1135
|
|
|
@@ -1025,8 +1138,7 @@ The wrapper matches the operator ID, path, and HTTP method to an active endpoint
|
|
|
1025
1138
|
| `X-PAYMENT` | paid x402 retry | x402 payment payload returned by an x402-capable client. |
|
|
1026
1139
|
| `Authorization: Payment ...` | paid MPP retry | MPP payment authorization header. |
|
|
1027
1140
|
| `x-agent-id` | if trust enabled | ERC-8004 agent ID. |
|
|
1028
|
-
| `x-agent-address` |
|
|
1029
|
-
| `x-agent-session` | key agents | Session token from key-based challenge-response. |
|
|
1141
|
+
| `x-agent-address` | not supported by hosted trust wrappers | Use SDK middleware in your own backend when you need key/address identity support. |
|
|
1030
1142
|
|
|
1031
1143
|
#### Free Wrapper Response
|
|
1032
1144
|
|
package/docs/DASHBOARD.md
CHANGED
|
@@ -114,8 +114,9 @@ This product is appropriate when an API must be callable by autonomous agents wi
|
|
|
114
114
|
1. Open **Make API Agent-Ready**.
|
|
115
115
|
2. Click **Make API Agent-Ready**.
|
|
116
116
|
3. Enter your upstream API details and payment settings.
|
|
117
|
-
4.
|
|
118
|
-
5.
|
|
117
|
+
4. Configure upstream authentication to protect your origin.
|
|
118
|
+
5. Save the wrapper.
|
|
119
|
+
6. Distribute only the generated wrapper URL to agent clients:
|
|
119
120
|
|
|
120
121
|
```text
|
|
121
122
|
https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/{path}
|
|
@@ -129,6 +130,12 @@ When an agent calls the wrapper:
|
|
|
129
130
|
4. Valiron appends the wrapper path to `targetUrl`, forwards the request, and adds Valiron metadata headers.
|
|
130
131
|
5. Valiron returns the upstream response and records analytics.
|
|
131
132
|
|
|
133
|
+
> **Origin protection is required for a public upstream.** Valiron can enforce
|
|
134
|
+
> payment, trust, rate limits, and logging only for calls made to the wrapper
|
|
135
|
+
> URL. A call sent directly to your upstream does not pass through Valiron. Use
|
|
136
|
+
> HMAC upstream auth and reject missing or invalid signatures at your origin;
|
|
137
|
+
> do not rely on the presence of `x-valiron-*` metadata headers.
|
|
138
|
+
|
|
132
139
|
### Wrapper fields
|
|
133
140
|
|
|
134
141
|
| Field | Required | Description |
|
|
@@ -142,7 +149,7 @@ When an agent calls the wrapper:
|
|
|
142
149
|
| Payout wallet | No | Required for paid x402 wrappers unless a platform default receiving address is configured. |
|
|
143
150
|
| Require Valiron trust | No | When enabled, callers must provide agent identity headers and pass the trust threshold. |
|
|
144
151
|
| Rate limit (req/min) | No | Max requests per minute per agent (null = unlimited) |
|
|
145
|
-
| Upstream auth |
|
|
152
|
+
| Upstream auth | Required for a public origin | `hmac` recommended. Your origin verifies the signature and timestamp before serving the request. |
|
|
146
153
|
| Description | No | What this endpoint does |
|
|
147
154
|
|
|
148
155
|
**Removing a wrapper** performs a soft-delete. The wrapper stops matching new calls but historical logs remain available.
|
|
@@ -330,6 +337,10 @@ API Scaffolding is a separate product that provides a hosted, agent-facing wrapp
|
|
|
330
337
|
4. Test the generated `/wrap/{operatorId}/{path}` URL.
|
|
331
338
|
5. Monitor calls in Analytics and Logs.
|
|
332
339
|
|
|
340
|
+
For hosted wrappers, also verify that a direct request to the upstream origin
|
|
341
|
+
returns `401` or `403`, while a wrapper request is visible in call logs. See
|
|
342
|
+
[API Scaffolding origin protection](./AGENT-READY-APIS.md#origin-lockdown-checklist).
|
|
343
|
+
|
|
333
344
|
For deployments requiring full backend control, protect the API directly with Valiron middleware using `createValironGate()` or `ValironOperator.paywall()`.
|
|
334
345
|
|
|
335
346
|
For full hosted wrapper docs, see [AGENT-READY-APIS.md](./AGENT-READY-APIS.md).
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# End-to-End Valiron Middleware Integration
|
|
2
|
+
|
|
3
|
+
This guide helps API teams integrate Valiron middleware from the first incoming
|
|
4
|
+
agent request through the downstream action they want to take. Start with the
|
|
5
|
+
agent identity, choose the trust signals that match your policy, then use the
|
|
6
|
+
gate result to protect an endpoint, vary access, attach pricing context, or
|
|
7
|
+
record the decision.
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
Incoming request
|
|
11
|
+
-> identify the agent
|
|
12
|
+
-> evaluate selected trust signals
|
|
13
|
+
-> receive an allow/deny decision, score, tier, and route
|
|
14
|
+
-> apply your API policy
|
|
15
|
+
-> serve, limit, sandbox, price, or deny
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Before you start
|
|
19
|
+
|
|
20
|
+
1. Create an operator account in the [Dashboard](./DASHBOARD.md).
|
|
21
|
+
2. Copy an operator API key (`val_op_...`) if you will use Pro trust signals,
|
|
22
|
+
operator usage logging, or hosted products.
|
|
23
|
+
3. Install the SDK:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @valiron/sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
4. Choose the identity format your agent callers will send.
|
|
30
|
+
|
|
31
|
+
## 1. Identify every agent
|
|
32
|
+
|
|
33
|
+
The standard gate automatically handles on-chain and key-based identities.
|
|
34
|
+
Provider-backed identity uses the dedicated identity gate because its proof is
|
|
35
|
+
bound to each exact request body:
|
|
36
|
+
|
|
37
|
+
| Agent type | Header | Value | Setup |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| ERC-8004 EVM agent | `x-agent-id` | ERC-8004 token ID | Agent is registered on-chain |
|
|
40
|
+
| Solana agent | `x-agent-id` | Metaplex Core asset pubkey or supported indexed ID | Use `chain: "solana"` |
|
|
41
|
+
| Local, Web2, or non-ERC-8004 agent | `x-agent-address` | Persistent Ethereum-style address | Complete [key-based challenge-response](https://www.valiron.co/auth.md) first |
|
|
42
|
+
| ANS or another provider-backed identity | `x-valiron-identity-*` | Canonical provider ID, signature, timestamp, and nonce | Sign with `createAgentIdentityProof()` |
|
|
43
|
+
|
|
44
|
+
Do not send a local agent name to `x-agent-id`. Key-based agents must prove
|
|
45
|
+
ownership of their persistent address before they can pass an identity-aware
|
|
46
|
+
policy.
|
|
47
|
+
|
|
48
|
+
> **Hosted wrapper note:** Valiron-hosted API Scaffolding currently requires
|
|
49
|
+
> `x-agent-id` when its trust check is enabled. Use the SDK middleware in your
|
|
50
|
+
> own backend for a policy that accepts either identity path.
|
|
51
|
+
|
|
52
|
+
> **Provider-backed identity:** use the dedicated `createValironIdentityGate`,
|
|
53
|
+
> `valironIdentityFastifyPlugin`, `createValironIdentityNextMiddleware`, or
|
|
54
|
+
> `valironIdentityGateCheck` exports documented in
|
|
55
|
+
> [PROVIDER-IDENTITY.md](./PROVIDER-IDENTITY.md). Do not send an ANS name through
|
|
56
|
+
> `x-agent-id`. Valiron hosts the ANS credentials and trusted CA bundle.
|
|
57
|
+
|
|
58
|
+
## 2. Choose trust signals
|
|
59
|
+
|
|
60
|
+
Pass `trustSignals` to the middleware configuration. Start with the default
|
|
61
|
+
baseline, then add signals only when they are meaningful for the action you are
|
|
62
|
+
protecting.
|
|
63
|
+
|
|
64
|
+
| Signal | What it contributes | Availability |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `8004` | Registry-backed on-chain identity and reputation | All plans |
|
|
67
|
+
| `sandbox` | Behavioral evaluation and route readiness | All plans |
|
|
68
|
+
| `world` | World ID proof-of-personhood linkage | Pro |
|
|
69
|
+
| `self` | Self eligible-human verification | Pro |
|
|
70
|
+
| `icebreaker` | Human-to-agent attestation | Pro |
|
|
71
|
+
| `wallet` | Explainable wallet-history risk, confidence, and hard flags | Pro |
|
|
72
|
+
|
|
73
|
+
For example, a high-value endpoint might require on-chain reputation,
|
|
74
|
+
behavioral evidence, and wallet intelligence:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { ValironSDK, createValironGate } from "@valiron/sdk";
|
|
78
|
+
|
|
79
|
+
const valiron = new ValironSDK({
|
|
80
|
+
apiKey: process.env.VALIRON_API_KEY,
|
|
81
|
+
chain: "base",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const trustGate = createValironGate({
|
|
85
|
+
sdk: valiron,
|
|
86
|
+
trustSignals: ["8004", "sandbox", "wallet"],
|
|
87
|
+
minScore: 80,
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If a wallet-history provider is unavailable or a network is unsupported, its
|
|
92
|
+
result is neutral and excluded from the composite score rather than treated as
|
|
93
|
+
malicious. See [Trust Model](./TRUST-MODEL.md) for the complete signal model.
|
|
94
|
+
|
|
95
|
+
## 3. Choose the downstream behavior
|
|
96
|
+
|
|
97
|
+
The middleware attaches a normalized result to the request after a successful
|
|
98
|
+
check. It includes `allow`, `score`, `tier`, `riskLevel`, `route`, and the
|
|
99
|
+
resolved `agentId`, regardless of which supported identity header the agent
|
|
100
|
+
used.
|
|
101
|
+
|
|
102
|
+
Choose the behavior that fits the endpoint:
|
|
103
|
+
|
|
104
|
+
| Goal | Use the decision for |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| Trust gate | Allow trusted agents and return a denial before your handler runs |
|
|
107
|
+
| Graduated access | Serve full access for `prod`, apply limits for `prod_throttled`, and use test data for sandbox routes |
|
|
108
|
+
| Trust-aware pricing | Read the result in your handler and apply your own price or entitlement policy |
|
|
109
|
+
| Monetized endpoint logging | Use `ValironOperator.paywall()` to gate access, attach a configured per-call price, and record usage |
|
|
110
|
+
| Agent profile lookup | Retrieve a profile when your product needs to display or review trust evidence |
|
|
111
|
+
| Predictive risk | Use dashboard/API forecasts as an additional operational signal; do not replace the runtime gate with a forecast |
|
|
112
|
+
| Audit and operations | Capture the result in your logs or use dashboard call logs and evaluation history |
|
|
113
|
+
|
|
114
|
+
Valiron does not itself settle a payment or choose a dynamic price table. It
|
|
115
|
+
provides the verified trust context that your payment and application policy
|
|
116
|
+
can use.
|
|
117
|
+
|
|
118
|
+
## 4. Put the gate in front of your handler
|
|
119
|
+
|
|
120
|
+
Here is a complete Express example that supports both agent identity paths and
|
|
121
|
+
uses the route decision for graduated access:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import express from "express";
|
|
125
|
+
import { ValironSDK, createValironGate } from "@valiron/sdk";
|
|
126
|
+
|
|
127
|
+
const app = express();
|
|
128
|
+
const valiron = new ValironSDK({
|
|
129
|
+
apiKey: process.env.VALIRON_API_KEY,
|
|
130
|
+
chain: "base",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
app.use("/api/research", createValironGate({
|
|
134
|
+
sdk: valiron,
|
|
135
|
+
trustSignals: ["8004", "sandbox", "wallet"],
|
|
136
|
+
minScore: 65,
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
app.get("/api/research", (req, res) => {
|
|
140
|
+
const trust = (req as typeof req & { valiron: {
|
|
141
|
+
route: "prod" | "prod_throttled" | "sandbox" | "sandbox_only";
|
|
142
|
+
score: number;
|
|
143
|
+
tier: string;
|
|
144
|
+
} }).valiron;
|
|
145
|
+
|
|
146
|
+
if (trust.route === "prod_throttled") {
|
|
147
|
+
res.set("X-Rate-Limit-Policy", "reduced");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (trust.route === "sandbox") {
|
|
151
|
+
return res.json({ mode: "sandbox", results: [] });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return res.json({
|
|
155
|
+
mode: "production",
|
|
156
|
+
trust: { score: trust.score, tier: trust.tier },
|
|
157
|
+
results: [/* your production response */],
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
app.listen(3000);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The middleware checks `x-agent-id` first, then `x-agent-address`. If there is
|
|
165
|
+
no supported identity, the agent is denied. If an agent is pending its first
|
|
166
|
+
behavioral evaluation, it receives a retryable denial while sandbox evaluation
|
|
167
|
+
runs.
|
|
168
|
+
|
|
169
|
+
## 5. Add a pricing or payment policy
|
|
170
|
+
|
|
171
|
+
For a server-side endpoint with a fixed price and usage logging, use the
|
|
172
|
+
operator SDK. It gates the route, makes the decision available as
|
|
173
|
+
`req.valiron`, and records the configured price only for successful allowed
|
|
174
|
+
calls.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { ValironOperator } from "@valiron/sdk";
|
|
178
|
+
|
|
179
|
+
const operator = new ValironOperator({
|
|
180
|
+
apiKey: process.env.VALIRON_API_KEY!,
|
|
181
|
+
chain: "base",
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
app.use("/api/premium", operator.paywall({
|
|
185
|
+
pricePerCall: 0.05,
|
|
186
|
+
minTrustScore: 65,
|
|
187
|
+
trustSignals: ["8004", "sandbox", "wallet"],
|
|
188
|
+
}));
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
If your payment provider supports multiple prices, select the price in your
|
|
192
|
+
handler from `req.valiron.tier`, `score`, or `route`. Keep payment settlement
|
|
193
|
+
in that provider; use Valiron first to decide whether the caller is eligible
|
|
194
|
+
to reach it.
|
|
195
|
+
|
|
196
|
+
## 6. Test the complete request path
|
|
197
|
+
|
|
198
|
+
Test each case before production:
|
|
199
|
+
|
|
200
|
+
1. A registered agent using `x-agent-id`.
|
|
201
|
+
2. A verified key-based agent using `x-agent-address`.
|
|
202
|
+
3. A request without either identity header.
|
|
203
|
+
4. An agent below your `minScore`.
|
|
204
|
+
5. A new agent pending sandbox evaluation.
|
|
205
|
+
6. A production-eligible agent on every protected route.
|
|
206
|
+
7. A paid or priced request, verifying that trust denial happens before your
|
|
207
|
+
payment or application handler.
|
|
208
|
+
|
|
209
|
+
Use the [Dashboard Playground](./DASHBOARD.md#api-playground) to inspect
|
|
210
|
+
decisions and the Dashboard's call logs to review outcome, latency, price, and
|
|
211
|
+
trust context after launch.
|
|
212
|
+
|
|
213
|
+
## Next steps
|
|
214
|
+
|
|
215
|
+
- [Quickstart](./QUICKSTART.md) — protect a first endpoint quickly
|
|
216
|
+
- [SDK Reference](./SDK-REFERENCE.md#middleware) — Express, Fastify, Next.js,
|
|
217
|
+
and generic middleware APIs
|
|
218
|
+
- [Identity](./IDENTITY.md) — registry and key-based identity details
|
|
219
|
+
- [Trust Model](./TRUST-MODEL.md) — signals, tiers, and routes
|
|
220
|
+
- [API Scaffolding](./AGENT-READY-APIS.md) — hosted x402/MPP wrappers for an
|
|
221
|
+
existing API
|
package/docs/ERRORS.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
Common error scenarios, status codes, and guidance on how to handle them.
|
|
4
4
|
|
|
5
|
+
## Read an error before retrying
|
|
6
|
+
|
|
7
|
+
Every SDK failure is a `ValironError`. Its stable `code` is for program logic; its `message` is safe to show in developer logs; and `details` provides the recovery information that was available from the API.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { ValironError } from "@valiron/sdk";
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
await valiron.getAgentProfile("99999");
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error instanceof ValironError) {
|
|
16
|
+
console.error({
|
|
17
|
+
code: error.code,
|
|
18
|
+
status: error.statusCode,
|
|
19
|
+
message: error.message,
|
|
20
|
+
nextStep: error.details?.action,
|
|
21
|
+
requestId: error.details?.requestId,
|
|
22
|
+
docs: error.details?.docsUrl,
|
|
23
|
+
retryAfterMs: error.details?.retryAfterMs,
|
|
24
|
+
serverDetails: error.details?.details,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
HTTP errors from SDK calls and trust-gate responses use these fields where applicable:
|
|
31
|
+
|
|
32
|
+
| Field | Purpose |
|
|
33
|
+
|--------|---------|
|
|
34
|
+
| `code` | Stable, machine-readable category such as `MISSING_AGENT_IDENTITY` or `TRUST_GATE_DENIED` |
|
|
35
|
+
| `message` | Human-readable explanation of what happened |
|
|
36
|
+
| `action` / `details.action` | Concrete next debugging or recovery step |
|
|
37
|
+
| `docsUrl` / `details.docsUrl` | Relevant documentation section |
|
|
38
|
+
| `requestId` / `details.requestId` | Include with a timestamp in a support request |
|
|
39
|
+
| `retryAfterMs` | Minimum delay before retrying, when retrying is appropriate |
|
|
40
|
+
|
|
41
|
+
Treat `code` as the contract; wording may be refined over time.
|
|
42
|
+
|
|
5
43
|
## HTTP Status Codes
|
|
6
44
|
|
|
7
45
|
| Status | Meaning | Action |
|
|
@@ -28,12 +66,11 @@ const valiron = new ValironSDK();
|
|
|
28
66
|
try {
|
|
29
67
|
const profile = await valiron.getAgentProfile("99999");
|
|
30
68
|
} catch (error) {
|
|
31
|
-
if (error.
|
|
69
|
+
if (error instanceof ValironError && error.statusCode === 404) {
|
|
32
70
|
// Agent not registered — register via ERC-8004 first
|
|
33
|
-
} else if (error.
|
|
71
|
+
} else if (error instanceof ValironError && error.statusCode === 429) {
|
|
34
72
|
// Rate limited — wait and retry
|
|
35
|
-
|
|
36
|
-
await sleep(parseInt(retryAfter || "5") * 1000);
|
|
73
|
+
await sleep(error.details?.retryAfterMs ?? 5_000);
|
|
37
74
|
} else {
|
|
38
75
|
// Unexpected error — log and retry with backoff
|
|
39
76
|
console.error(error.message);
|
|
@@ -52,10 +89,11 @@ async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
|
|
|
52
89
|
return await fn();
|
|
53
90
|
} catch (error) {
|
|
54
91
|
// Never retry auth errors
|
|
55
|
-
|
|
92
|
+
const status = error instanceof ValironError ? error.statusCode : undefined;
|
|
93
|
+
if (status === 401 || status === 403) throw error;
|
|
56
94
|
|
|
57
95
|
// Never retry client errors (except 429)
|
|
58
|
-
if (
|
|
96
|
+
if (status && status >= 400 && status < 500 && status !== 429) throw error;
|
|
59
97
|
|
|
60
98
|
if (attempt === maxRetries) throw error;
|
|
61
99
|
|
|
@@ -177,14 +215,51 @@ SOLANA_RPC_URL=https://your-private-rpc.example.com
|
|
|
177
215
|
|
|
178
216
|
All Valiron middleware (Express, Fastify, Next.js, generic) returns consistent error responses:
|
|
179
217
|
|
|
180
|
-
| Status | When |
|
|
218
|
+
| Status | Code | When | What to do |
|
|
181
219
|
|--------|------|------|
|
|
182
|
-
| 401 | No
|
|
183
|
-
| 403 | Agent
|
|
184
|
-
|
|
|
220
|
+
| 401 | `MISSING_AGENT_IDENTITY` | No identity header | Send one supported identity header: `x-agent-id` or `x-agent-address` |
|
|
221
|
+
| 403 | `TRUST_GATE_DENIED` | Agent did not meet the configured policy | Inspect `score`, `tier`, `route`, and `reasons`; do not blindly retry |
|
|
222
|
+
| 403 | `AGENT_EVALUATION_PENDING` | New identity is sandbox-evaluating | Keep the same identity and retry after `retryAfterMs` |
|
|
223
|
+
| 503 | `TRUST_GATE_UNAVAILABLE` | Trust evaluation could not complete | Fail closed; retry shortly and inspect the logged `cause` |
|
|
224
|
+
|
|
225
|
+
Each response includes `message`, `action`, and `docsUrl`; denials retain the trust result fields so an application can make a deliberate fallback decision.
|
|
185
226
|
|
|
186
227
|
> **Fail-closed:** When the Valiron service is unreachable, middleware returns 503 — it never fails open and never allows unverified agents through.
|
|
187
228
|
|
|
229
|
+
## Provider-Backed Identity Errors
|
|
230
|
+
|
|
231
|
+
Provider identity proof failures are classifications, not transport failures:
|
|
232
|
+
the SDK and `POST /operator/identity/verify` return
|
|
233
|
+
HTTP 200 with `identityStatus: "claimed"` and one of these `failureReason`
|
|
234
|
+
values.
|
|
235
|
+
|
|
236
|
+
Dedicated identity middleware maps policy actions to HTTP responses: `challenge`
|
|
237
|
+
to 401, `block` to 403, and `limit` to 429. `IDENTITY_RAW_BODY_REQUIRED` is a
|
|
238
|
+
local HTTP 400 response when Express or Fastify parsed a body without retaining
|
|
239
|
+
its exact bytes. `IDENTITY_GATE_UNAVAILABLE` is a fail-closed HTTP 503.
|
|
240
|
+
|
|
241
|
+
| Failure reason | Meaning | Action |
|
|
242
|
+
| --- | --- | --- |
|
|
243
|
+
| `provider_missing` | An agent ID was supplied without a provider | Send the resolver provider name |
|
|
244
|
+
| `resolver_unavailable` | No adapter is registered for the provider | For ANS, configure credentials and a trusted CA bundle; never treat the claim as verified |
|
|
245
|
+
| `proof_incomplete` | Signature, timestamp, nonce, or digest is missing | Construct and sign the complete proof |
|
|
246
|
+
| `request_digest_invalid` | Digest is not `sha256:` plus 64 hex characters | Recalculate and format the SHA-256 digest |
|
|
247
|
+
| `nonce_invalid` | Nonce is shorter than 16 characters or contains unsupported characters | Generate a 16–256 character URL-safe nonce |
|
|
248
|
+
| `timestamp_invalid` | Timestamp cannot be parsed | Send an ISO-8601 timestamp |
|
|
249
|
+
| `timestamp_out_of_window` | Timestamp is outside the default five-minute window | Sign a fresh request; do not reuse the old proof |
|
|
250
|
+
| `resolution_failed` | Provider resolution threw an error | Retry only if the provider failure is transient |
|
|
251
|
+
| `identity_not_found` | Provider has no acceptable matching identity; ANS also uses this when strict lifecycle, certificate, or Transparency Log checks fail | Correct the ID or repair the provider registration outside Valiron |
|
|
252
|
+
| `provider_mismatch` | Resolved record belongs to a different provider | Reject the proof and inspect resolver configuration |
|
|
253
|
+
| `ownership_chain_unverified` | Provider authority or organization/domain binding did not validate | Do not grant verified access |
|
|
254
|
+
| `public_key_not_found` | No verification key matched the optional key ID | Refresh provider metadata or use an active key ID |
|
|
255
|
+
| `signature_invalid` | Signature encoding is invalid | Send base64/base64url or `0x`-hex as required by the resolver |
|
|
256
|
+
| `signature_verification_failed` | Proof does not match a resolved key or provider verifier | Reject the proof and sign the exact canonical payload |
|
|
257
|
+
| `replay_detected` | This identity and nonce were already accepted | Generate a fresh nonce and signature |
|
|
258
|
+
|
|
259
|
+
Malformed policies return HTTP 400 with `invalid_identity_policy`. A replay
|
|
260
|
+
store or other safe-verification failure returns HTTP 503 with
|
|
261
|
+
`identity_verification_unavailable`; the endpoint fails closed.
|
|
262
|
+
|
|
188
263
|
## Proxy Gateway Errors
|
|
189
264
|
|
|
190
265
|
| Status | When | Action |
|
|
@@ -194,6 +269,16 @@ All Valiron middleware (Express, Fastify, Next.js, generic) returns consistent e
|
|
|
194
269
|
| 403 | SSRF blocked | The `targetUrl` resolves to a private IP, localhost, or metadata endpoint |
|
|
195
270
|
| 503 | Origin server unreachable | Your upstream API base URL is down or timed out |
|
|
196
271
|
|
|
272
|
+
## Hosted Wrapper Errors
|
|
273
|
+
|
|
274
|
+
| Status | Code | When | Action |
|
|
275
|
+
|--------|------|------|--------|
|
|
276
|
+
| 400 | `MISSING_AGENT_IDENTITY` | A trust-enabled hosted wrapper did not receive `x-agent-id` | Hosted wrappers currently require `x-agent-id`; use SDK middleware for key/address identity support |
|
|
277
|
+
| 404 | `WRAPPER_NOT_FOUND` | Operator ID, path, method, or endpoint activation does not match | Verify all four values in the dashboard |
|
|
278
|
+
| 413 | `WRAPPER_BODY_TOO_LARGE` | Body exceeds the wrapper limit | Send a smaller request or use an external input reference |
|
|
279
|
+
| 429 | `WRAPPER_RATE_LIMITED` | Endpoint rate limit reached | Honor `retryAfter` and use exponential backoff |
|
|
280
|
+
| 502 / 504 | `WRAPPER_UPSTREAM_REQUEST_FAILED` / `WRAPPER_UPSTREAM_TIMEOUT` | The target API failed or was too slow | Check upstream URL/auth; include `requestId` and timestamp when escalating |
|
|
281
|
+
|
|
197
282
|
## Key-Based Agent Errors
|
|
198
283
|
|
|
199
284
|
| Status | When | Action |
|
package/docs/IDENTITY.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
# Agent Identity:
|
|
1
|
+
# Agent Identity: On-Chain, Key-Based, and Provider-Backed Agents
|
|
2
2
|
|
|
3
|
-
Valiron supports
|
|
3
|
+
Valiron supports on-chain, key-based, and provider-backed middleware identity
|
|
4
|
+
paths:
|
|
4
5
|
|
|
5
6
|
| Agent type | Use this identifier | Request header | Lookup path |
|
|
6
7
|
|------------|---------------------|----------------|-------------|
|
|
7
8
|
| ERC-8004 / on-chain EVM agent | ERC-8004 token ID | `x-agent-id` | `/operator/agent/:agentId` |
|
|
8
9
|
| Solana 8004 agent | Metaplex Core asset pubkey or indexed ID | `x-agent-id` | `/operator/agent/:agentId?chain=solana` |
|
|
9
10
|
| Local, Web2, or non-ERC-8004 agent | Persistent Ethereum-style agent address | `x-agent-address` | `/operator/key/:agentAddress` |
|
|
11
|
+
| ANS, DNS, DID, API-key, or future provider identity | Provider-canonical ID | `x-valiron-identity-*` proof headers | SDK identity gate or `/operator/identity/verify` |
|
|
10
12
|
|
|
11
13
|
Use `/operator/agent/:agentId` only for registry-backed on-chain agents. Local and Web2 agents should generate or reuse a persistent keypair, prove ownership through Valiron's challenge-response flow, and then use their `x-agent-address` for trust checks.
|
|
12
14
|
|
|
15
|
+
The provider-backed framework normalizes identity into `anonymous`, `claimed`,
|
|
16
|
+
or `verified`, performs freshness and replay checks, and can return an
|
|
17
|
+
`allow`, `limit`, `challenge`, or `block` policy action. SDK 1.3 includes
|
|
18
|
+
signing helpers and dedicated provider identity gates; Valiron hosts the ANS
|
|
19
|
+
credentials and trusted CA bundle. See
|
|
20
|
+
[Provider-Backed Agent Identity](./PROVIDER-IDENTITY.md) for the exact request,
|
|
21
|
+
signature payload, SDK integration, response, and current ANS boundary.
|
|
22
|
+
|
|
13
23
|
## Wallet as a Trust Input
|
|
14
24
|
|
|
15
25
|
When a Pro policy selects `trustSignals: ["wallet"]`, Valiron evaluates the wallet associated with the chosen identity path. ERC-8004 and Solana agents use the wallet resolved from their registry identity; key-based agents use their verified persistent agent address. Wallet intelligence does not establish identity by itself—it is an additional economic-history signal applied after Valiron has a wallet address.
|