@valiron/sdk 0.11.1 → 0.12.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 +6 -0
- package/dist/clients.d.ts +113 -1
- package/dist/clients.js +228 -0
- package/dist/identity.d.ts +80 -0
- package/dist/identity.js +121 -0
- package/dist/index.d.ts +218 -1
- package/dist/index.js +229 -1
- package/dist/middleware.d.ts +30 -4
- package/dist/middleware.js +98 -27
- package/dist/operatorSdk.d.ts +103 -0
- package/dist/operatorSdk.js +128 -0
- package/dist/types.d.ts +200 -1
- package/docs/API-REFERENCE.md +254 -0
- package/docs/QUICKSTART.md +65 -0
- package/docs/README.md +1 -0
- package/docs/SDK-REFERENCE.md +235 -0
- package/docs/llms.txt +25 -0
- package/package.json +3 -2
package/dist/middleware.js
CHANGED
|
@@ -5,35 +5,83 @@ exports.valironFastifyPlugin = valironFastifyPlugin;
|
|
|
5
5
|
exports.createValironNextMiddleware = createValironNextMiddleware;
|
|
6
6
|
exports.valironGateCheck = valironGateCheck;
|
|
7
7
|
// ─── Shared gate logic ──────────────────────────────────────────────────────
|
|
8
|
-
function
|
|
9
|
-
// Works for Express, Fastify, Koa, raw Node http (object headers)
|
|
10
|
-
// and Fetch-based frameworks like Hono (Headers with .get())
|
|
8
|
+
function extractHeader(req, name) {
|
|
11
9
|
const headers = req?.headers ?? {};
|
|
12
10
|
let value = null;
|
|
13
11
|
if (headers && typeof headers.get === "function") {
|
|
14
|
-
value = headers.get(
|
|
12
|
+
value = headers.get(name);
|
|
15
13
|
}
|
|
16
14
|
else {
|
|
17
|
-
const raw = headers[
|
|
15
|
+
const raw = headers[name];
|
|
18
16
|
value = Array.isArray(raw) ? raw[0] : raw;
|
|
19
17
|
}
|
|
20
18
|
return value ?? null;
|
|
21
19
|
}
|
|
20
|
+
function defaultExtractAgentId(req) {
|
|
21
|
+
return extractHeader(req, "x-agent-id");
|
|
22
|
+
}
|
|
23
|
+
function defaultExtractAgentKeyHash(req) {
|
|
24
|
+
return extractHeader(req, "x-agent-key-hash");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalize a KeyAgentProfile into a GateResult so all middleware
|
|
28
|
+
* consumers get one consistent type regardless of agent kind.
|
|
29
|
+
*/
|
|
30
|
+
function keyProfileToGateResult(profile, minScore) {
|
|
31
|
+
const score = profile.score ?? 0;
|
|
32
|
+
const tier = (profile.tier ?? "C");
|
|
33
|
+
const riskLevel = (profile.riskLevel ?? "RED");
|
|
34
|
+
const route = (profile.route ?? "sandbox_only");
|
|
35
|
+
const allow = profile.verified && score >= minScore;
|
|
36
|
+
return {
|
|
37
|
+
allow,
|
|
38
|
+
score,
|
|
39
|
+
tier,
|
|
40
|
+
riskLevel,
|
|
41
|
+
route,
|
|
42
|
+
agentId: profile.agentKeyHash,
|
|
43
|
+
wallet: "",
|
|
44
|
+
chain: {
|
|
45
|
+
network: "web2",
|
|
46
|
+
rpcUrl: "",
|
|
47
|
+
identityRegistry: "",
|
|
48
|
+
reputationRegistry: "",
|
|
49
|
+
},
|
|
50
|
+
sandboxRan: false,
|
|
51
|
+
cached: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
22
54
|
async function runGateCheck(config, req) {
|
|
55
|
+
// 1. Try on-chain agent ID (ERC-8004 / Solana)
|
|
23
56
|
const extractAgentId = config.extractAgentId || defaultExtractAgentId;
|
|
24
57
|
const agentId = extractAgentId(req);
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
58
|
+
if (agentId) {
|
|
59
|
+
try {
|
|
60
|
+
const result = await config.sdk.gate(agentId, {
|
|
61
|
+
minScore: config.minScore,
|
|
62
|
+
ttlMs: config.ttlMs,
|
|
63
|
+
});
|
|
64
|
+
return { agentId, result };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return { agentId, error };
|
|
68
|
+
}
|
|
33
69
|
}
|
|
34
|
-
|
|
35
|
-
|
|
70
|
+
// 2. Fall back to key-based agent (web2)
|
|
71
|
+
const extractKeyHash = config.extractAgentKeyHash || defaultExtractAgentKeyHash;
|
|
72
|
+
const keyHash = extractKeyHash(req);
|
|
73
|
+
if (keyHash) {
|
|
74
|
+
try {
|
|
75
|
+
const profile = await config.sdk.getKeyAgentProfile(keyHash);
|
|
76
|
+
const result = keyProfileToGateResult(profile, config.minScore ?? 65);
|
|
77
|
+
return { agentId: keyHash, result };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return { agentId: keyHash, error };
|
|
81
|
+
}
|
|
36
82
|
}
|
|
83
|
+
// 3. No agent identity found
|
|
84
|
+
return { agentId: null };
|
|
37
85
|
}
|
|
38
86
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
39
87
|
// EXPRESS / CONNECT MIDDLEWARE
|
|
@@ -53,6 +101,7 @@ async function runGateCheck(config, req) {
|
|
|
53
101
|
* const valiron = new ValironSDK({ chain: 'monad' });
|
|
54
102
|
*
|
|
55
103
|
* // Apply before your x402 / payment handler
|
|
104
|
+
* // Works with both on-chain (x-agent-id) and key-based (x-agent-key-hash) agents
|
|
56
105
|
* app.use('/api/paid', createValironGate({ sdk: valiron }));
|
|
57
106
|
*
|
|
58
107
|
* // Custom threshold
|
|
@@ -70,7 +119,7 @@ function createValironGate(config) {
|
|
|
70
119
|
return async function valironGate(req, res, next) {
|
|
71
120
|
const { agentId, result, error } = await runGateCheck(frozen, req);
|
|
72
121
|
if (!agentId) {
|
|
73
|
-
return res.status(401).json({ error: "Missing agent id" });
|
|
122
|
+
return res.status(401).json({ error: "Missing agent identity (provide x-agent-id or x-agent-key-hash header)" });
|
|
74
123
|
}
|
|
75
124
|
if (error) {
|
|
76
125
|
return res.status(503).json({
|
|
@@ -123,6 +172,7 @@ async function valironFastifyPlugin(fastify, opts) {
|
|
|
123
172
|
const gateConfig = {
|
|
124
173
|
sdk: opts.sdk,
|
|
125
174
|
extractAgentId: opts.extractAgentId,
|
|
175
|
+
extractAgentKeyHash: opts.extractAgentKeyHash,
|
|
126
176
|
minScore: opts.minScore,
|
|
127
177
|
ttlMs: opts.ttlMs,
|
|
128
178
|
onAllow: opts.onAllow,
|
|
@@ -144,7 +194,7 @@ async function valironFastifyPlugin(fastify, opts) {
|
|
|
144
194
|
}
|
|
145
195
|
const { agentId, result, error } = await runGateCheck(gateConfig, request);
|
|
146
196
|
if (!agentId) {
|
|
147
|
-
return reply.status(401).send({ error: "Missing agent id" });
|
|
197
|
+
return reply.status(401).send({ error: "Missing agent identity (provide x-agent-id or x-agent-key-hash header)" });
|
|
148
198
|
}
|
|
149
199
|
if (error) {
|
|
150
200
|
return reply.status(503).send({
|
|
@@ -197,6 +247,8 @@ function createValironNextMiddleware(config) {
|
|
|
197
247
|
const { sdk, minScore, ttlMs, paths } = config;
|
|
198
248
|
const extractAgentId = config.extractAgentId ||
|
|
199
249
|
((req) => req.headers.get("x-agent-id"));
|
|
250
|
+
const extractKeyHash = config.extractAgentKeyHash ||
|
|
251
|
+
((req) => req.headers.get("x-agent-key-hash"));
|
|
200
252
|
return async function valironNextGate(request) {
|
|
201
253
|
// Skip paths not in scope
|
|
202
254
|
if (paths && paths.length > 0) {
|
|
@@ -205,12 +257,21 @@ function createValironNextMiddleware(config) {
|
|
|
205
257
|
return undefined; // pass through
|
|
206
258
|
}
|
|
207
259
|
}
|
|
260
|
+
// Try on-chain agent ID first, then key-based hash
|
|
208
261
|
const agentId = extractAgentId(request);
|
|
209
|
-
|
|
210
|
-
|
|
262
|
+
const keyHash = agentId ? null : extractKeyHash(request);
|
|
263
|
+
if (!agentId && !keyHash) {
|
|
264
|
+
return Response.json({ error: "Missing agent identity (provide x-agent-id or x-agent-key-hash header)" }, { status: 401 });
|
|
211
265
|
}
|
|
212
266
|
try {
|
|
213
|
-
|
|
267
|
+
let result;
|
|
268
|
+
if (agentId) {
|
|
269
|
+
result = await sdk.gate(agentId, { minScore, ttlMs });
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
const profile = await sdk.getKeyAgentProfile(keyHash);
|
|
273
|
+
result = keyProfileToGateResult(profile, minScore ?? 65);
|
|
274
|
+
}
|
|
214
275
|
if (result.allow) {
|
|
215
276
|
return undefined; // continue to route handler
|
|
216
277
|
}
|
|
@@ -237,6 +298,7 @@ function createValironNextMiddleware(config) {
|
|
|
237
298
|
* app.use('/api/*', async (c, next) => {
|
|
238
299
|
* const gate = await valironGateCheck(valiron, {
|
|
239
300
|
* agentId: c.req.header('x-agent-id') ?? null,
|
|
301
|
+
* agentKeyHash: c.req.header('x-agent-key-hash') ?? null,
|
|
240
302
|
* });
|
|
241
303
|
* if (!gate.allow) return c.json(gate.body, gate.status);
|
|
242
304
|
* c.set('valiron', gate.result);
|
|
@@ -250,6 +312,7 @@ function createValironNextMiddleware(config) {
|
|
|
250
312
|
* app.use(async (ctx, next) => {
|
|
251
313
|
* const gate = await valironGateCheck(valiron, {
|
|
252
314
|
* agentId: ctx.get('x-agent-id') || null,
|
|
315
|
+
* agentKeyHash: ctx.get('x-agent-key-hash') || null,
|
|
253
316
|
* });
|
|
254
317
|
* if (!gate.allow) {
|
|
255
318
|
* ctx.status = gate.status;
|
|
@@ -262,24 +325,32 @@ function createValironNextMiddleware(config) {
|
|
|
262
325
|
* ```
|
|
263
326
|
*/
|
|
264
327
|
async function valironGateCheck(sdk, opts) {
|
|
265
|
-
const { agentId, minScore, ttlMs } = opts;
|
|
266
|
-
|
|
328
|
+
const { agentId, agentKeyHash, minScore, ttlMs } = opts;
|
|
329
|
+
const identifier = agentId || agentKeyHash || null;
|
|
330
|
+
if (!identifier) {
|
|
267
331
|
return {
|
|
268
332
|
hasAgent: false,
|
|
269
333
|
agentId: null,
|
|
270
334
|
ok: false,
|
|
271
335
|
status: 401,
|
|
272
|
-
body: { error: "Missing agent
|
|
336
|
+
body: { error: "Missing agent identity" },
|
|
273
337
|
};
|
|
274
338
|
}
|
|
275
339
|
try {
|
|
276
|
-
|
|
340
|
+
let result;
|
|
341
|
+
if (agentId) {
|
|
342
|
+
result = await sdk.gate(agentId, { minScore, ttlMs });
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
const profile = await sdk.getKeyAgentProfile(agentKeyHash);
|
|
346
|
+
result = keyProfileToGateResult(profile, minScore ?? 65);
|
|
347
|
+
}
|
|
277
348
|
if (result.allow) {
|
|
278
|
-
return { hasAgent: true, agentId, ok: true, allow: true, result, status: 200 };
|
|
349
|
+
return { hasAgent: true, agentId: identifier, ok: true, allow: true, result, status: 200 };
|
|
279
350
|
}
|
|
280
351
|
return {
|
|
281
352
|
hasAgent: true,
|
|
282
|
-
agentId,
|
|
353
|
+
agentId: identifier,
|
|
283
354
|
ok: true,
|
|
284
355
|
allow: false,
|
|
285
356
|
result,
|
|
@@ -290,7 +361,7 @@ async function valironGateCheck(sdk, opts) {
|
|
|
290
361
|
catch {
|
|
291
362
|
return {
|
|
292
363
|
hasAgent: true,
|
|
293
|
-
agentId,
|
|
364
|
+
agentId: identifier,
|
|
294
365
|
ok: false,
|
|
295
366
|
status: 503,
|
|
296
367
|
body: { error: "Trust gate unavailable \u2014 request denied (fail-closed)" },
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ValironSDK } from "./index.js";
|
|
2
|
+
import type { SupportedChain } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the Valiron Operator SDK.
|
|
5
|
+
*/
|
|
6
|
+
export interface ValironOperatorConfig {
|
|
7
|
+
/** Operator API key (val_op_xxxx) — obtained from valiron.co/dashboard. */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/** Default blockchain (default: 'ethereum'). */
|
|
10
|
+
chain?: SupportedChain;
|
|
11
|
+
/** Edge proxy endpoint (default: production). */
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
/** Request timeout in ms (default: 5000). */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Enable debug logging (default: false). */
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for the paywall middleware.
|
|
20
|
+
*/
|
|
21
|
+
export interface PaywallConfig {
|
|
22
|
+
/** Price per API call in USDC. */
|
|
23
|
+
pricePerCall: number;
|
|
24
|
+
/** Minimum trust score to allow (default: 45). */
|
|
25
|
+
minTrustScore?: number;
|
|
26
|
+
/** TTL for cached trust results in ms (default: 86400000 = 24h). */
|
|
27
|
+
ttlMs?: number;
|
|
28
|
+
/** Custom handler when an agent is denied. */
|
|
29
|
+
onDeny?: (req: any, res: any, result: any) => void;
|
|
30
|
+
/** Hook called after an agent is allowed. */
|
|
31
|
+
onAllow?: (req: any, result: any) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Valiron Operator SDK — for API sellers who want to monetize their endpoints.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { ValironOperator } from '@valiron/sdk';
|
|
39
|
+
*
|
|
40
|
+
* const operator = new ValironOperator({
|
|
41
|
+
* apiKey: 'val_op_xxxx',
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Express: one line to monetize an endpoint
|
|
45
|
+
* app.use('/api/inference', operator.paywall({ pricePerCall: 0.05 }));
|
|
46
|
+
*
|
|
47
|
+
* // Fastify: register as plugin
|
|
48
|
+
* app.register(operator.fastifyPaywall({
|
|
49
|
+
* pricePerCall: 0.10,
|
|
50
|
+
* prefix: '/api',
|
|
51
|
+
* }));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class ValironOperator {
|
|
55
|
+
private sdk;
|
|
56
|
+
private apiKey;
|
|
57
|
+
private debug;
|
|
58
|
+
constructor(config: ValironOperatorConfig);
|
|
59
|
+
/**
|
|
60
|
+
* Create Express/Connect middleware that gates access + tracks usage.
|
|
61
|
+
*
|
|
62
|
+
* Extracts `X-Agent-Id` from request, runs trust gate, and attaches
|
|
63
|
+
* `req.valiron` with the gate result + pricing info.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* app.use('/api/inference', operator.paywall({
|
|
68
|
+
* pricePerCall: 0.05,
|
|
69
|
+
* minTrustScore: 45,
|
|
70
|
+
* }));
|
|
71
|
+
*
|
|
72
|
+
* app.post('/api/inference', (req, res) => {
|
|
73
|
+
* // req.valiron.allow === true (guaranteed by paywall)
|
|
74
|
+
* // req.valiron.pricePerCall === 0.05
|
|
75
|
+
* res.json({ result: 'inference output' });
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
paywall(config: PaywallConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a Fastify plugin that gates access + tracks usage.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* app.register(operator.fastifyPaywall({
|
|
86
|
+
* pricePerCall: 0.10,
|
|
87
|
+
* prefix: '/api',
|
|
88
|
+
* minTrustScore: 65,
|
|
89
|
+
* }));
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
fastifyPaywall(config: PaywallConfig & {
|
|
93
|
+
prefix?: string;
|
|
94
|
+
}): (fastify: any, opts: any, done: any) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Get the underlying ValironSDK instance for advanced usage.
|
|
97
|
+
*/
|
|
98
|
+
getSDK(): ValironSDK;
|
|
99
|
+
/**
|
|
100
|
+
* Flush telemetry and release resources.
|
|
101
|
+
*/
|
|
102
|
+
dispose(): Promise<void>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValironOperator = void 0;
|
|
4
|
+
const index_js_1 = require("./index.js");
|
|
5
|
+
const middleware_js_1 = require("./middleware.js");
|
|
6
|
+
/**
|
|
7
|
+
* Valiron Operator SDK — for API sellers who want to monetize their endpoints.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { ValironOperator } from '@valiron/sdk';
|
|
12
|
+
*
|
|
13
|
+
* const operator = new ValironOperator({
|
|
14
|
+
* apiKey: 'val_op_xxxx',
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Express: one line to monetize an endpoint
|
|
18
|
+
* app.use('/api/inference', operator.paywall({ pricePerCall: 0.05 }));
|
|
19
|
+
*
|
|
20
|
+
* // Fastify: register as plugin
|
|
21
|
+
* app.register(operator.fastifyPaywall({
|
|
22
|
+
* pricePerCall: 0.10,
|
|
23
|
+
* prefix: '/api',
|
|
24
|
+
* }));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class ValironOperator {
|
|
28
|
+
constructor(config) {
|
|
29
|
+
if (!config.apiKey?.startsWith("val_op_")) {
|
|
30
|
+
throw new Error("Invalid operator API key — must start with 'val_op_'");
|
|
31
|
+
}
|
|
32
|
+
this.apiKey = config.apiKey;
|
|
33
|
+
this.debug = config.debug || false;
|
|
34
|
+
this.sdk = new index_js_1.ValironSDK({
|
|
35
|
+
apiKey: config.apiKey,
|
|
36
|
+
chain: config.chain,
|
|
37
|
+
endpoint: config.endpoint,
|
|
38
|
+
timeout: config.timeout,
|
|
39
|
+
debug: config.debug,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create Express/Connect middleware that gates access + tracks usage.
|
|
44
|
+
*
|
|
45
|
+
* Extracts `X-Agent-Id` from request, runs trust gate, and attaches
|
|
46
|
+
* `req.valiron` with the gate result + pricing info.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* app.use('/api/inference', operator.paywall({
|
|
51
|
+
* pricePerCall: 0.05,
|
|
52
|
+
* minTrustScore: 45,
|
|
53
|
+
* }));
|
|
54
|
+
*
|
|
55
|
+
* app.post('/api/inference', (req, res) => {
|
|
56
|
+
* // req.valiron.allow === true (guaranteed by paywall)
|
|
57
|
+
* // req.valiron.pricePerCall === 0.05
|
|
58
|
+
* res.json({ result: 'inference output' });
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
paywall(config) {
|
|
63
|
+
const gateConfig = {
|
|
64
|
+
sdk: this.sdk,
|
|
65
|
+
minScore: config.minTrustScore ?? 45,
|
|
66
|
+
ttlMs: config.ttlMs,
|
|
67
|
+
onDeny: config.onDeny,
|
|
68
|
+
onAllow: (req, result) => {
|
|
69
|
+
// Enrich the gate result with pricing
|
|
70
|
+
result.pricePerCall = config.pricePerCall;
|
|
71
|
+
result.operatorApiKey = this.apiKey.slice(0, 15) + "...";
|
|
72
|
+
if (config.onAllow)
|
|
73
|
+
config.onAllow(req, result);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const middleware = (0, middleware_js_1.createValironGate)(gateConfig);
|
|
77
|
+
if (this.debug) {
|
|
78
|
+
return async (req, res, next) => {
|
|
79
|
+
console.log(`[ValironOperator] Gate check for ${req.headers?.["x-agent-id"] || "unknown"} @ $${config.pricePerCall}/call`);
|
|
80
|
+
return middleware(req, res, next);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return middleware;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a Fastify plugin that gates access + tracks usage.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* app.register(operator.fastifyPaywall({
|
|
91
|
+
* pricePerCall: 0.10,
|
|
92
|
+
* prefix: '/api',
|
|
93
|
+
* minTrustScore: 65,
|
|
94
|
+
* }));
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
fastifyPaywall(config) {
|
|
98
|
+
const pluginConfig = {
|
|
99
|
+
sdk: this.sdk,
|
|
100
|
+
minScore: config.minTrustScore ?? 45,
|
|
101
|
+
ttlMs: config.ttlMs,
|
|
102
|
+
prefix: config.prefix,
|
|
103
|
+
onDeny: config.onDeny,
|
|
104
|
+
onAllow: (req, result) => {
|
|
105
|
+
result.pricePerCall = config.pricePerCall;
|
|
106
|
+
result.operatorApiKey = this.apiKey.slice(0, 15) + "...";
|
|
107
|
+
if (config.onAllow)
|
|
108
|
+
config.onAllow(req, result);
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return (fastify, opts, done) => {
|
|
112
|
+
(0, middleware_js_1.valironFastifyPlugin)(fastify, { ...pluginConfig, ...opts }).then(() => done()).catch(done);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the underlying ValironSDK instance for advanced usage.
|
|
117
|
+
*/
|
|
118
|
+
getSDK() {
|
|
119
|
+
return this.sdk;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Flush telemetry and release resources.
|
|
123
|
+
*/
|
|
124
|
+
dispose() {
|
|
125
|
+
return this.sdk.dispose();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.ValironOperator = ValironOperator;
|
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" | "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" | "world_chain" | "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";
|
|
@@ -74,6 +74,10 @@ export interface RoutingSignals {
|
|
|
74
74
|
tier: string;
|
|
75
75
|
riskLevel: string;
|
|
76
76
|
};
|
|
77
|
+
worldId?: {
|
|
78
|
+
verified: boolean;
|
|
79
|
+
verificationLevel: string | null;
|
|
80
|
+
};
|
|
77
81
|
}
|
|
78
82
|
export interface RoutingExplanation {
|
|
79
83
|
finalRoute: RouteDecision;
|
|
@@ -99,6 +103,8 @@ export interface AgentProfile {
|
|
|
99
103
|
localReputation: LocalReputation | null;
|
|
100
104
|
routing: RoutingExplanation;
|
|
101
105
|
chain: ChainContext;
|
|
106
|
+
/** World ID proof-of-personhood verification status */
|
|
107
|
+
worldId?: WorldIdStatus;
|
|
102
108
|
timestamp: string;
|
|
103
109
|
}
|
|
104
110
|
/**
|
|
@@ -196,6 +202,117 @@ export interface GateResult {
|
|
|
196
202
|
/** Whether the score is from a micro-sandbox (fast, limited coverage). When true, a full deep test is running in the background and will update the cached score. */
|
|
197
203
|
provisional?: boolean;
|
|
198
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Response from `POST /operator/key/:agentKeyHash/challenge`
|
|
207
|
+
*/
|
|
208
|
+
export interface KeyAgentChallenge {
|
|
209
|
+
/** Random nonce the agent must sign */
|
|
210
|
+
challenge: string;
|
|
211
|
+
/** ISO 8601 expiry timestamp for the challenge */
|
|
212
|
+
expiresAt: string;
|
|
213
|
+
/** The agent key hash this challenge was issued for */
|
|
214
|
+
agentKeyHash: string;
|
|
215
|
+
}
|
|
216
|
+
/** Verification level from World ID */
|
|
217
|
+
export type WorldIdVerificationLevel = "orb" | "device" | "phone";
|
|
218
|
+
/**
|
|
219
|
+
* World ID verification status for an agent.
|
|
220
|
+
*
|
|
221
|
+
* Returned from `GET /operator/world-id/status/:agentId`
|
|
222
|
+
*/
|
|
223
|
+
export interface WorldIdStatus {
|
|
224
|
+
/** Whether the agent has a verified World ID human link */
|
|
225
|
+
verified: boolean;
|
|
226
|
+
/** Verification level (orb = biometric, device = passkey, phone = SMS) */
|
|
227
|
+
verificationLevel?: WorldIdVerificationLevel;
|
|
228
|
+
/** Nullifier hash — unique per (user, action, app) tuple */
|
|
229
|
+
nullifierHash?: string;
|
|
230
|
+
/** The agent ID this verification is linked to */
|
|
231
|
+
agentId?: string;
|
|
232
|
+
/** Network this verification is scoped to */
|
|
233
|
+
network?: string;
|
|
234
|
+
/** ISO 8601 timestamp of when verification occurred */
|
|
235
|
+
verifiedAt?: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Enriched human-agent trust profile combining World ID + Icebreaker.
|
|
239
|
+
*
|
|
240
|
+
* Response from `GET /operator/world-id/profile/:agentId`
|
|
241
|
+
*/
|
|
242
|
+
export interface WorldIdAgentProfile {
|
|
243
|
+
agentId: string;
|
|
244
|
+
/** World ID proof-of-personhood status */
|
|
245
|
+
worldId: WorldIdStatus;
|
|
246
|
+
/** Icebreaker background enrichment (LinkedIn, GitHub, etc.) */
|
|
247
|
+
icebreaker: {
|
|
248
|
+
attested: boolean;
|
|
249
|
+
owner?: string;
|
|
250
|
+
bio?: string;
|
|
251
|
+
verifiedHandles?: {
|
|
252
|
+
source: string;
|
|
253
|
+
handle: string;
|
|
254
|
+
}[];
|
|
255
|
+
organization?: string;
|
|
256
|
+
profileUrl?: string;
|
|
257
|
+
};
|
|
258
|
+
/** On-chain identity summary */
|
|
259
|
+
identity: {
|
|
260
|
+
wallet: string;
|
|
261
|
+
name: string;
|
|
262
|
+
} | null;
|
|
263
|
+
/** Aggregated human trust signals */
|
|
264
|
+
humanTrust: {
|
|
265
|
+
hasHumanLink: boolean;
|
|
266
|
+
hasBackground: boolean;
|
|
267
|
+
verificationLevel: WorldIdVerificationLevel | null;
|
|
268
|
+
};
|
|
269
|
+
reasons: string[];
|
|
270
|
+
timestamp: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Icebreaker ownership attestation linked to an agent key hash.
|
|
274
|
+
*/
|
|
275
|
+
export interface IcebreakerOwnership {
|
|
276
|
+
/** Whether an Icebreaker attestation was found */
|
|
277
|
+
attested: boolean;
|
|
278
|
+
/** The human owner's name or address */
|
|
279
|
+
owner?: string;
|
|
280
|
+
/** Human-readable bio or description */
|
|
281
|
+
description?: string;
|
|
282
|
+
/** Verified social handles (e.g. "github: alice", "x: @alice") */
|
|
283
|
+
verifiedHandles?: string[];
|
|
284
|
+
/** Workplace or organization affiliation, if verified */
|
|
285
|
+
organization?: string;
|
|
286
|
+
/** EAS attestation UID on Base */
|
|
287
|
+
attestationUid?: string;
|
|
288
|
+
/** Icebreaker profile URL for the agent's linked address */
|
|
289
|
+
profileUrl?: string;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Trust profile for a key-based (non-ERC-8004) agent.
|
|
293
|
+
*
|
|
294
|
+
* Response from `POST /operator/key/verify` and `GET /operator/key/:agentKeyHash`
|
|
295
|
+
*/
|
|
296
|
+
export interface KeyAgentProfile {
|
|
297
|
+
/** SHA-256 hash of the agent's public key */
|
|
298
|
+
agentKeyHash: string;
|
|
299
|
+
/** Whether identity has been verified via challenge-response */
|
|
300
|
+
verified: boolean;
|
|
301
|
+
/** Behavioral score (0-110) — same scoring as ERC-8004 agents */
|
|
302
|
+
score: number | null;
|
|
303
|
+
/** Moody's-style tier (AAA → C) */
|
|
304
|
+
tier: MoodysRating | null;
|
|
305
|
+
/** Risk level derived from tier */
|
|
306
|
+
riskLevel: RiskLevel | null;
|
|
307
|
+
/** Route decision */
|
|
308
|
+
route: RouteDecision | null;
|
|
309
|
+
/** Icebreaker ownership context (optional enrichment) */
|
|
310
|
+
icebreaker: IcebreakerOwnership | null;
|
|
311
|
+
/** Human-readable trust explanation */
|
|
312
|
+
reasons: string[];
|
|
313
|
+
/** ISO 8601 timestamp */
|
|
314
|
+
timestamp: string;
|
|
315
|
+
}
|
|
199
316
|
/** Options that can be passed to individual SDK method calls. */
|
|
200
317
|
export interface CallOptions {
|
|
201
318
|
/**
|
|
@@ -257,6 +374,88 @@ export interface ValironConfig {
|
|
|
257
374
|
*/
|
|
258
375
|
telemetry?: TelemetryConfig;
|
|
259
376
|
}
|
|
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
|
+
}
|
|
260
459
|
export declare class ValironError extends Error {
|
|
261
460
|
code: string;
|
|
262
461
|
statusCode?: number | undefined;
|