@valiron/sdk 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/clients.d.ts +3 -1
- package/dist/clients.js +38 -14
- 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/operatorSdk.js +21 -0
- package/dist/telemetry.js +30 -10
- package/dist/types.d.ts +46 -1
- package/docs/AGENT-READY-APIS.md +62 -7
- package/docs/API-REFERENCE.md +146 -9
- package/docs/DASHBOARD.md +27 -5
- package/docs/E2E-MIDDLEWARE-INTEGRATION.md +10 -2
- package/docs/ERRORS.md +34 -0
- package/docs/IDENTITY.md +12 -2
- package/docs/PROVIDER-IDENTITY.md +277 -0
- package/docs/QUICKSTART.md +11 -3
- package/docs/README.md +8 -0
- package/docs/SDK-REFERENCE.md +78 -1
- package/docs/TRUST-MODEL.md +20 -0
- package/docs/llms.txt +17 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,6 +49,39 @@ No API key is required for basic read operations. Pro trust signals and `getWall
|
|
|
49
49
|
|
|
50
50
|
Use `x-agent-id` for ERC-8004/Solana agents. Use `x-agent-address` plus Valiron challenge-response for local, Web2, or non-ERC-8004 agents. Agents can follow the hosted identity skill at https://www.valiron.co/auth.md.
|
|
51
51
|
|
|
52
|
+
Provider-backed identities such as ANS use signed `x-valiron-identity-*`
|
|
53
|
+
headers. SDK 1.3 provides `createAgentIdentityProof()` for agents,
|
|
54
|
+
`verifyAgentIdentity()` for low-level verification, and dedicated Express,
|
|
55
|
+
Fastify, Next.js, and generic identity gates. Valiron hosts the ANS credentials
|
|
56
|
+
and trusted CA bundle; SDK users do not configure them. See the
|
|
57
|
+
[provider-backed identity guide](https://valiron.co/docs/agents/PROVIDER-IDENTITY.md)
|
|
58
|
+
for the signing and middleware quickstart.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import {
|
|
62
|
+
agentIdentityProofHeaders,
|
|
63
|
+
createAgentIdentityProof,
|
|
64
|
+
createValironIdentityGate,
|
|
65
|
+
} from "@valiron/sdk";
|
|
66
|
+
|
|
67
|
+
// Agent: sign the exact bytes it will send.
|
|
68
|
+
const body = JSON.stringify({ operation: "quote" });
|
|
69
|
+
const proof = await createAgentIdentityProof({
|
|
70
|
+
provider: "ans",
|
|
71
|
+
agentId: "ans://v1.0.0.sales-agent.acme.com",
|
|
72
|
+
body,
|
|
73
|
+
sign: (payload) => agentKey.sign(payload),
|
|
74
|
+
});
|
|
75
|
+
await fetch(apiUrl, { method: "POST", body, headers: agentIdentityProofHeaders(proof) });
|
|
76
|
+
|
|
77
|
+
// API owner: capture raw bytes, then enforce the returned identity policy.
|
|
78
|
+
app.use(express.json({ verify: (req: any, _res, bytes) => { req.rawBody = Buffer.from(bytes); } }));
|
|
79
|
+
app.post("/quote", createValironIdentityGate({
|
|
80
|
+
sdk: valiron,
|
|
81
|
+
policy: { anonymous: "challenge", claimed: "block", verified: "allow" },
|
|
82
|
+
}), handler);
|
|
83
|
+
```
|
|
84
|
+
|
|
52
85
|
## Error diagnostics
|
|
53
86
|
|
|
54
87
|
SDK failures are `ValironError` instances. Handle the stable `code` programmatically and log `details.action`, `details.requestId`, `details.docsUrl`, and `details.retryAfterMs` to make recovery explicit.
|
|
@@ -95,6 +128,7 @@ Full SDK reference, API docs, trust model, and integration guides:
|
|
|
95
128
|
- **[API Reference](https://valiron.co/docs/agents/API-REFERENCE.md)** — HTTP endpoints
|
|
96
129
|
- **[Quickstart](https://valiron.co/docs/agents/QUICKSTART.md)** — get started in 2 minutes
|
|
97
130
|
- **[End-to-End Middleware Integration](https://valiron.co/docs/agents/E2E-MIDDLEWARE-INTEGRATION.md)** — identity, trust signals, downstream policy, and testing
|
|
131
|
+
- **[Provider-Backed Identity](https://valiron.co/docs/agents/PROVIDER-IDENTITY.md)** — resolver foundation, proof format, replay handling, policy actions, and ANS adapter status
|
|
98
132
|
- **[Error Guide](https://valiron.co/docs#error-handling)** — codes, recovery actions, retries, and wrapper diagnostics
|
|
99
133
|
- **[llms.txt](https://valiron.co/llms.txt)** — compact reference for LLM/agent integration
|
|
100
134
|
- **Install agent skill**: `npx @valiron/skill`
|
package/dist/clients.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValironConfig, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, WalletRiskSnapshot, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, CallOptions, KeyAgentChallenge, KeyAgentProfile, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, ProxyRequest, ProxyResponse } from "./types";
|
|
1
|
+
import { ValironConfig, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, WalletRiskSnapshot, SandboxResult, KeyAgentSandboxResult, GateResult, GateOptions, CallOptions, KeyAgentChallenge, KeyAgentProfile, WorldIdStatus, WorldIdAgentProfile, SelfAgentProfile, SelfProofPayload, SelfSessionRequest, SelfSessionResponse, SelfStatus, AgentIdentityProof, AgentIdentityPolicy, AgentIdentityVerificationResult, ProxyRequest, ProxyResponse } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* HTTP client for the Valiron Operator API.
|
|
4
4
|
*
|
|
@@ -187,6 +187,8 @@ export declare class ValironClient {
|
|
|
187
187
|
* `GET /operator/self/profile/:agentId`
|
|
188
188
|
*/
|
|
189
189
|
getSelfProfile(agentId: string, options?: CallOptions): Promise<SelfAgentProfile>;
|
|
190
|
+
/** Verify a provider-backed identity proof and evaluate the supplied policy. */
|
|
191
|
+
verifyAgentIdentity(proof?: AgentIdentityProof, policy?: AgentIdentityPolicy): Promise<AgentIdentityVerificationResult>;
|
|
190
192
|
/** Flush any pending telemetry events and clean up resources. */
|
|
191
193
|
dispose(): Promise<void>;
|
|
192
194
|
/** Emit an SDK telemetry event from higher-level helpers. */
|
package/dist/clients.js
CHANGED
|
@@ -260,6 +260,10 @@ class ValironClient {
|
|
|
260
260
|
async getSelfProfile(agentId, options) {
|
|
261
261
|
return this.get(`/operator/self/profile/${agentId}`, this.resolveChain(options));
|
|
262
262
|
}
|
|
263
|
+
/** Verify a provider-backed identity proof and evaluate the supplied policy. */
|
|
264
|
+
async verifyAgentIdentity(proof = {}, policy) {
|
|
265
|
+
return this.post("/operator/identity/verify", policy ? { ...proof, policy } : proof);
|
|
266
|
+
}
|
|
263
267
|
/** Flush any pending telemetry events and clean up resources. */
|
|
264
268
|
async dispose() {
|
|
265
269
|
await this.telemetry.dispose();
|
|
@@ -307,27 +311,29 @@ class ValironClient {
|
|
|
307
311
|
const controller = new AbortController();
|
|
308
312
|
const timeoutMs = this.getTimeoutForPath(path);
|
|
309
313
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
310
|
-
const start =
|
|
314
|
+
const start = performance.now();
|
|
315
|
+
let responseStatus;
|
|
311
316
|
try {
|
|
312
317
|
const response = await fetch(url.toString(), {
|
|
313
318
|
method: "GET",
|
|
314
319
|
headers: this.buildHeaders(),
|
|
315
320
|
signal: controller.signal,
|
|
316
321
|
});
|
|
317
|
-
|
|
318
|
-
const durationMs = Date.now() - start;
|
|
322
|
+
responseStatus = response.status;
|
|
319
323
|
const methodName = this.extractMethodName(path);
|
|
320
324
|
if (!response.ok) {
|
|
321
325
|
const body = await response
|
|
322
326
|
.json()
|
|
323
327
|
.catch(() => ({ message: response.statusText }));
|
|
328
|
+
clearTimeout(timeoutId);
|
|
329
|
+
const durationMs = Math.round(performance.now() - start);
|
|
324
330
|
this.telemetry.emit("sdk_call", {
|
|
325
331
|
method: methodName,
|
|
326
332
|
chain: chain || "server_default",
|
|
327
333
|
duration_ms: durationMs,
|
|
328
334
|
success: false,
|
|
329
335
|
http_status: response.status,
|
|
330
|
-
error_code: "API_ERROR",
|
|
336
|
+
error_code: typeof body.code === "string" ? body.code : "API_ERROR",
|
|
331
337
|
retries: 0,
|
|
332
338
|
timeout_count: 0,
|
|
333
339
|
abort_count: 0,
|
|
@@ -336,6 +342,8 @@ class ValironClient {
|
|
|
336
342
|
throw this.createApiError(response, body, path, "GET");
|
|
337
343
|
}
|
|
338
344
|
const data = await response.json();
|
|
345
|
+
clearTimeout(timeoutId);
|
|
346
|
+
const durationMs = Math.round(performance.now() - start);
|
|
339
347
|
this.telemetry.emit("sdk_call", {
|
|
340
348
|
method: methodName,
|
|
341
349
|
chain: chain || "server_default",
|
|
@@ -353,7 +361,7 @@ class ValironClient {
|
|
|
353
361
|
}
|
|
354
362
|
catch (error) {
|
|
355
363
|
clearTimeout(timeoutId);
|
|
356
|
-
const durationMs =
|
|
364
|
+
const durationMs = Math.round(performance.now() - start);
|
|
357
365
|
const methodName = this.extractMethodName(path);
|
|
358
366
|
if (error.name === "AbortError") {
|
|
359
367
|
this.telemetry.emit("sdk_call", {
|
|
@@ -372,18 +380,22 @@ class ValironClient {
|
|
|
372
380
|
}
|
|
373
381
|
if (error instanceof types_1.ValironError)
|
|
374
382
|
throw error;
|
|
383
|
+
const errorCode = responseStatus === undefined ? "NETWORK_ERROR" : "RESPONSE_ERROR";
|
|
375
384
|
this.telemetry.emit("sdk_call", {
|
|
376
385
|
method: methodName,
|
|
377
386
|
chain: chain || "server_default",
|
|
378
387
|
duration_ms: durationMs,
|
|
379
388
|
success: false,
|
|
380
|
-
|
|
389
|
+
http_status: responseStatus,
|
|
390
|
+
error_code: errorCode,
|
|
381
391
|
retries: 0,
|
|
382
392
|
timeout_count: 0,
|
|
383
393
|
abort_count: 0,
|
|
384
394
|
});
|
|
385
395
|
this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
|
|
386
|
-
throw new types_1.ValironError(
|
|
396
|
+
throw new types_1.ValironError(responseStatus === undefined
|
|
397
|
+
? `Could not reach Valiron: ${error.message || "network error"}`
|
|
398
|
+
: `Could not read Valiron's response: ${error.message || "response error"}`, errorCode, responseStatus, { method: "GET", path, action: "Check your endpoint URL, network egress, and DNS configuration before retrying." });
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
401
|
async post(path, body, chain) {
|
|
@@ -396,7 +408,8 @@ class ValironClient {
|
|
|
396
408
|
const controller = new AbortController();
|
|
397
409
|
const timeoutMs = this.getTimeoutForPath(path);
|
|
398
410
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
399
|
-
const start =
|
|
411
|
+
const start = performance.now();
|
|
412
|
+
let responseStatus;
|
|
400
413
|
try {
|
|
401
414
|
const headers = this.buildHeaders();
|
|
402
415
|
const hasBody = body !== undefined && body !== null;
|
|
@@ -408,20 +421,21 @@ class ValironClient {
|
|
|
408
421
|
body: hasBody ? JSON.stringify(body) : undefined,
|
|
409
422
|
signal: controller.signal,
|
|
410
423
|
});
|
|
411
|
-
|
|
412
|
-
const durationMs = Date.now() - start;
|
|
424
|
+
responseStatus = response.status;
|
|
413
425
|
const methodName = this.extractMethodName(path);
|
|
414
426
|
if (!response.ok) {
|
|
415
427
|
const respBody = await response
|
|
416
428
|
.json()
|
|
417
429
|
.catch(() => ({ message: response.statusText }));
|
|
430
|
+
clearTimeout(timeoutId);
|
|
431
|
+
const durationMs = Math.round(performance.now() - start);
|
|
418
432
|
this.telemetry.emit("sdk_call", {
|
|
419
433
|
method: methodName,
|
|
420
434
|
chain: chain || "server_default",
|
|
421
435
|
duration_ms: durationMs,
|
|
422
436
|
success: false,
|
|
423
437
|
http_status: response.status,
|
|
424
|
-
error_code: "API_ERROR",
|
|
438
|
+
error_code: typeof respBody.code === "string" ? respBody.code : "API_ERROR",
|
|
425
439
|
retries: 0,
|
|
426
440
|
timeout_count: 0,
|
|
427
441
|
abort_count: 0,
|
|
@@ -430,6 +444,8 @@ class ValironClient {
|
|
|
430
444
|
throw this.createApiError(response, respBody, path, "POST");
|
|
431
445
|
}
|
|
432
446
|
const data = await response.json();
|
|
447
|
+
clearTimeout(timeoutId);
|
|
448
|
+
const durationMs = Math.round(performance.now() - start);
|
|
433
449
|
this.telemetry.emit("sdk_call", {
|
|
434
450
|
method: methodName,
|
|
435
451
|
chain: chain || "server_default",
|
|
@@ -447,7 +463,7 @@ class ValironClient {
|
|
|
447
463
|
}
|
|
448
464
|
catch (error) {
|
|
449
465
|
clearTimeout(timeoutId);
|
|
450
|
-
const durationMs =
|
|
466
|
+
const durationMs = Math.round(performance.now() - start);
|
|
451
467
|
const methodName = this.extractMethodName(path);
|
|
452
468
|
if (error.name === "AbortError") {
|
|
453
469
|
this.telemetry.emit("sdk_call", {
|
|
@@ -466,23 +482,31 @@ class ValironClient {
|
|
|
466
482
|
}
|
|
467
483
|
if (error instanceof types_1.ValironError)
|
|
468
484
|
throw error;
|
|
485
|
+
const errorCode = responseStatus === undefined ? "NETWORK_ERROR" : "RESPONSE_ERROR";
|
|
469
486
|
this.telemetry.emit("sdk_call", {
|
|
470
487
|
method: methodName,
|
|
471
488
|
chain: chain || "server_default",
|
|
472
489
|
duration_ms: durationMs,
|
|
473
490
|
success: false,
|
|
474
|
-
|
|
491
|
+
http_status: responseStatus,
|
|
492
|
+
error_code: errorCode,
|
|
475
493
|
retries: 0,
|
|
476
494
|
timeout_count: 0,
|
|
477
495
|
abort_count: 0,
|
|
478
496
|
});
|
|
479
497
|
this.telemetry.recordLatency(methodName, chain || "server_default", durationMs);
|
|
480
|
-
throw new types_1.ValironError(
|
|
498
|
+
throw new types_1.ValironError(responseStatus === undefined
|
|
499
|
+
? `Could not reach Valiron: ${error.message || "network error"}`
|
|
500
|
+
: `Could not read Valiron's response: ${error.message || "response error"}`, errorCode, responseStatus, { method: "POST", path, action: "Check your endpoint URL, network egress, and DNS configuration before retrying." });
|
|
481
501
|
}
|
|
482
502
|
}
|
|
483
503
|
extractMethodName(path) {
|
|
504
|
+
if (/^\/operator\/agent\/[^/]+\/snapshot(?:\?|$)/.test(path))
|
|
505
|
+
return "getAgentSnapshot";
|
|
484
506
|
if (path.startsWith("/operator/agent/"))
|
|
485
507
|
return "getAgentProfile";
|
|
508
|
+
if (path === "/operator/identity/verify")
|
|
509
|
+
return "verifyAgentIdentity";
|
|
486
510
|
if (path.startsWith("/operator/resolve-wallet/"))
|
|
487
511
|
return "resolveWallet";
|
|
488
512
|
if (path.startsWith("/operator/wallet-risk/"))
|
package/dist/identity.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AgentIdentityProof, AgentIdentityTransportProof } from "./types";
|
|
1
2
|
export interface ChallengeResponse {
|
|
2
3
|
/** The challenge nonce that was signed */
|
|
3
4
|
challenge: string;
|
|
@@ -6,6 +7,25 @@ export interface ChallengeResponse {
|
|
|
6
7
|
/** The agent's Ethereum address */
|
|
7
8
|
agentAddress: string;
|
|
8
9
|
}
|
|
10
|
+
export type AgentIdentityBody = string | Uint8Array | ArrayBuffer | null | undefined;
|
|
11
|
+
export interface CreateAgentIdentityProofInput {
|
|
12
|
+
provider: string;
|
|
13
|
+
agentId: string;
|
|
14
|
+
body?: AgentIdentityBody;
|
|
15
|
+
/** Sign the exact UTF-8 payload with the private key bound to the provider identity. */
|
|
16
|
+
sign: (payload: string) => string | Uint8Array | Promise<string | Uint8Array>;
|
|
17
|
+
timestamp?: string;
|
|
18
|
+
nonce?: string;
|
|
19
|
+
keyId?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const AGENT_IDENTITY_HEADERS: {
|
|
22
|
+
readonly provider: "x-valiron-identity-provider";
|
|
23
|
+
readonly agentId: "x-valiron-identity-agent-id";
|
|
24
|
+
readonly signature: "x-valiron-identity-signature";
|
|
25
|
+
readonly timestamp: "x-valiron-identity-timestamp";
|
|
26
|
+
readonly nonce: "x-valiron-identity-nonce";
|
|
27
|
+
readonly keyId: "x-valiron-identity-key-id";
|
|
28
|
+
};
|
|
9
29
|
/** Validate that a string looks like an Ethereum address (0x + 40 hex chars). */
|
|
10
30
|
export declare function isValidAddress(address: string): boolean;
|
|
11
31
|
/**
|
|
@@ -14,3 +34,18 @@ export declare function isValidAddress(address: string): boolean;
|
|
|
14
34
|
* @returns A 32-byte hex-encoded nonce
|
|
15
35
|
*/
|
|
16
36
|
export declare function generateChallenge(): string;
|
|
37
|
+
/** Calculate the digest Valiron binds to the signed request proof. */
|
|
38
|
+
export declare function sha256RequestDigest(body?: AgentIdentityBody): string;
|
|
39
|
+
/** Build the canonical payload understood by Valiron's provider identity verifier. */
|
|
40
|
+
export declare function buildAgentIdentitySigningPayload(input: {
|
|
41
|
+
agentId: string;
|
|
42
|
+
timestamp: string;
|
|
43
|
+
nonce: string;
|
|
44
|
+
requestDigest: string;
|
|
45
|
+
}): string;
|
|
46
|
+
/** Create a signed proof for one exact request body. Private keys remain with the agent. */
|
|
47
|
+
export declare function createAgentIdentityProof(input: CreateAgentIdentityProofInput): Promise<AgentIdentityProof>;
|
|
48
|
+
/** Convert a proof into transport headers. requestDigest is intentionally omitted and recomputed by the API gate. */
|
|
49
|
+
export declare function agentIdentityProofHeaders(proof: AgentIdentityProof): Record<string, string>;
|
|
50
|
+
/** Read provider identity proof fields from Fetch Headers or Node-style request headers. */
|
|
51
|
+
export declare function agentIdentityProofFromHeaders(headers: unknown): AgentIdentityTransportProof;
|
package/dist/identity.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGENT_IDENTITY_HEADERS = void 0;
|
|
3
4
|
exports.isValidAddress = isValidAddress;
|
|
4
5
|
exports.generateChallenge = generateChallenge;
|
|
6
|
+
exports.sha256RequestDigest = sha256RequestDigest;
|
|
7
|
+
exports.buildAgentIdentitySigningPayload = buildAgentIdentitySigningPayload;
|
|
8
|
+
exports.createAgentIdentityProof = createAgentIdentityProof;
|
|
9
|
+
exports.agentIdentityProofHeaders = agentIdentityProofHeaders;
|
|
10
|
+
exports.agentIdentityProofFromHeaders = agentIdentityProofFromHeaders;
|
|
5
11
|
const crypto_1 = require("crypto");
|
|
12
|
+
exports.AGENT_IDENTITY_HEADERS = {
|
|
13
|
+
provider: "x-valiron-identity-provider",
|
|
14
|
+
agentId: "x-valiron-identity-agent-id",
|
|
15
|
+
signature: "x-valiron-identity-signature",
|
|
16
|
+
timestamp: "x-valiron-identity-timestamp",
|
|
17
|
+
nonce: "x-valiron-identity-nonce",
|
|
18
|
+
keyId: "x-valiron-identity-key-id",
|
|
19
|
+
};
|
|
6
20
|
// ─── Validation Helpers ─────────────────────────────────────────────────────
|
|
7
21
|
/** Validate that a string looks like an Ethereum address (0x + 40 hex chars). */
|
|
8
22
|
function isValidAddress(address) {
|
|
@@ -17,3 +31,85 @@ function isValidAddress(address) {
|
|
|
17
31
|
function generateChallenge() {
|
|
18
32
|
return (0, crypto_1.randomBytes)(32).toString("hex");
|
|
19
33
|
}
|
|
34
|
+
/** Calculate the digest Valiron binds to the signed request proof. */
|
|
35
|
+
function sha256RequestDigest(body) {
|
|
36
|
+
const bytes = body == null
|
|
37
|
+
? Buffer.alloc(0)
|
|
38
|
+
: typeof body === "string"
|
|
39
|
+
? Buffer.from(body, "utf8")
|
|
40
|
+
: body instanceof ArrayBuffer
|
|
41
|
+
? Buffer.from(body)
|
|
42
|
+
: Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
43
|
+
return `sha256:${(0, crypto_1.createHash)("sha256").update(bytes).digest("hex")}`;
|
|
44
|
+
}
|
|
45
|
+
/** Build the canonical payload understood by Valiron's provider identity verifier. */
|
|
46
|
+
function buildAgentIdentitySigningPayload(input) {
|
|
47
|
+
return [
|
|
48
|
+
"valiron-agent-request-v1",
|
|
49
|
+
`agent-id:${input.agentId}`,
|
|
50
|
+
`timestamp:${input.timestamp}`,
|
|
51
|
+
`nonce:${input.nonce}`,
|
|
52
|
+
`request-digest:${input.requestDigest.toLowerCase()}`,
|
|
53
|
+
].join("\n");
|
|
54
|
+
}
|
|
55
|
+
/** Create a signed proof for one exact request body. Private keys remain with the agent. */
|
|
56
|
+
async function createAgentIdentityProof(input) {
|
|
57
|
+
const timestamp = input.timestamp ?? new Date().toISOString();
|
|
58
|
+
const nonce = input.nonce ?? (0, crypto_1.randomBytes)(24).toString("base64url");
|
|
59
|
+
const requestDigest = sha256RequestDigest(input.body);
|
|
60
|
+
const signed = await input.sign(buildAgentIdentitySigningPayload({
|
|
61
|
+
agentId: input.agentId,
|
|
62
|
+
timestamp,
|
|
63
|
+
nonce,
|
|
64
|
+
requestDigest,
|
|
65
|
+
}));
|
|
66
|
+
const signature = typeof signed === "string" ? signed : Buffer.from(signed).toString("base64url");
|
|
67
|
+
return {
|
|
68
|
+
provider: input.provider,
|
|
69
|
+
agentId: input.agentId,
|
|
70
|
+
signature,
|
|
71
|
+
timestamp,
|
|
72
|
+
nonce,
|
|
73
|
+
requestDigest,
|
|
74
|
+
...(input.keyId ? { keyId: input.keyId } : {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Convert a proof into transport headers. requestDigest is intentionally omitted and recomputed by the API gate. */
|
|
78
|
+
function agentIdentityProofHeaders(proof) {
|
|
79
|
+
const headers = {};
|
|
80
|
+
if (proof.provider)
|
|
81
|
+
headers[exports.AGENT_IDENTITY_HEADERS.provider] = proof.provider;
|
|
82
|
+
if (proof.agentId)
|
|
83
|
+
headers[exports.AGENT_IDENTITY_HEADERS.agentId] = proof.agentId;
|
|
84
|
+
if (proof.signature)
|
|
85
|
+
headers[exports.AGENT_IDENTITY_HEADERS.signature] = proof.signature;
|
|
86
|
+
if (proof.timestamp)
|
|
87
|
+
headers[exports.AGENT_IDENTITY_HEADERS.timestamp] = proof.timestamp;
|
|
88
|
+
if (proof.nonce)
|
|
89
|
+
headers[exports.AGENT_IDENTITY_HEADERS.nonce] = proof.nonce;
|
|
90
|
+
if (proof.keyId)
|
|
91
|
+
headers[exports.AGENT_IDENTITY_HEADERS.keyId] = proof.keyId;
|
|
92
|
+
return headers;
|
|
93
|
+
}
|
|
94
|
+
/** Read provider identity proof fields from Fetch Headers or Node-style request headers. */
|
|
95
|
+
function agentIdentityProofFromHeaders(headers) {
|
|
96
|
+
const read = (name) => {
|
|
97
|
+
if (headers && typeof headers.get === "function") {
|
|
98
|
+
return headers.get(name) ?? undefined;
|
|
99
|
+
}
|
|
100
|
+
if (!headers || typeof headers !== "object")
|
|
101
|
+
return undefined;
|
|
102
|
+
const value = headers[name];
|
|
103
|
+
if (Array.isArray(value))
|
|
104
|
+
return typeof value[0] === "string" ? value[0] : undefined;
|
|
105
|
+
return typeof value === "string" ? value : undefined;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
provider: read(exports.AGENT_IDENTITY_HEADERS.provider),
|
|
109
|
+
agentId: read(exports.AGENT_IDENTITY_HEADERS.agentId),
|
|
110
|
+
signature: read(exports.AGENT_IDENTITY_HEADERS.signature),
|
|
111
|
+
timestamp: read(exports.AGENT_IDENTITY_HEADERS.timestamp),
|
|
112
|
+
nonce: read(exports.AGENT_IDENTITY_HEADERS.nonce),
|
|
113
|
+
keyId: read(exports.AGENT_IDENTITY_HEADERS.keyId),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ValironSDK } from "./index";
|
|
2
|
+
import { type AgentIdentityBody } from "./identity";
|
|
3
|
+
import type { AgentIdentityPolicy, AgentIdentityPolicyAction, AgentIdentityTransportProof, AgentIdentityVerificationResult } from "./types";
|
|
4
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
export interface ValironIdentityGateConfig {
|
|
6
|
+
sdk: ValironSDK;
|
|
7
|
+
/** Policy evaluated by Valiron after identity and reputation checks. */
|
|
8
|
+
policy?: AgentIdentityPolicy;
|
|
9
|
+
/** Override transport-header extraction. */
|
|
10
|
+
extractProof?: (request: any) => AgentIdentityTransportProof;
|
|
11
|
+
/**
|
|
12
|
+
* Return the exact raw request bytes. Required for body-bearing Express and
|
|
13
|
+
* Fastify requests unless `request.rawBody` has already been populated.
|
|
14
|
+
*/
|
|
15
|
+
getRawBody?: (request: any) => MaybePromise<AgentIdentityBody>;
|
|
16
|
+
onAllow?: (request: any, result: AgentIdentityVerificationResult) => void;
|
|
17
|
+
onDeny?: (request: any, response: any, result: AgentIdentityVerificationResult) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface ValironIdentityFastifyConfig extends ValironIdentityGateConfig {
|
|
20
|
+
/** URL prefix to protect. Omit to protect every route in the plugin scope. */
|
|
21
|
+
prefix?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ValironIdentityNextConfig {
|
|
24
|
+
sdk: ValironSDK;
|
|
25
|
+
policy?: AgentIdentityPolicy;
|
|
26
|
+
paths?: string[];
|
|
27
|
+
extractProof?: (request: Request) => AgentIdentityTransportProof;
|
|
28
|
+
}
|
|
29
|
+
export interface ValironIdentityGateCheckResult {
|
|
30
|
+
hasClaim: boolean;
|
|
31
|
+
ok: boolean;
|
|
32
|
+
allow: boolean;
|
|
33
|
+
action?: AgentIdentityPolicyAction;
|
|
34
|
+
identity?: AgentIdentityVerificationResult;
|
|
35
|
+
status: number;
|
|
36
|
+
body?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/** Framework-independent provider identity policy check. */
|
|
39
|
+
export declare function valironIdentityGateCheck(sdk: ValironSDK, input?: {
|
|
40
|
+
proof?: AgentIdentityTransportProof;
|
|
41
|
+
body?: AgentIdentityBody;
|
|
42
|
+
policy?: AgentIdentityPolicy;
|
|
43
|
+
}): Promise<ValironIdentityGateCheckResult>;
|
|
44
|
+
/** Express/Connect middleware for ANS and other provider-backed identities. */
|
|
45
|
+
export declare function createValironIdentityGate(config: ValironIdentityGateConfig): (request: any, response: any, next: any) => void;
|
|
46
|
+
/** Fastify plugin for ANS and other provider-backed identities. */
|
|
47
|
+
export declare function valironIdentityFastifyPlugin(fastify: any, opts: ValironIdentityFastifyConfig): Promise<void>;
|
|
48
|
+
/** Next.js middleware for ANS and other provider-backed identities. */
|
|
49
|
+
export declare function createValironIdentityNextMiddleware(config: ValironIdentityNextConfig): (request: Request) => Promise<Response | undefined>;
|
|
50
|
+
export {};
|