@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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValironConfig, CallOptions, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, SandboxResult, GateResult, GateOptions, RouteDecision } from "./types";
|
|
1
|
+
import { ValironConfig, CallOptions, AgentProfile, AgentSnapshotSummary, WalletProfile, WalletResolution, SandboxResult, GateResult, GateOptions, RouteDecision, KeyAgentProfile, KeyAgentChallenge, WorldIdStatus, WorldIdAgentProfile, ChannelPreflightResponse, ChannelOpenResponse, ChannelConsumeResponse, ChannelStatusResponse, ChannelSettlementResponse, ChannelHealthResponse } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Valiron SDK – Official TypeScript SDK for the Trust Layer for Agentic Economy
|
|
4
4
|
*
|
|
@@ -196,6 +196,219 @@ export declare class ValironSDK {
|
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
198
|
gate(agentId: string, options?: GateOptions): Promise<GateResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Get a challenge nonce for a key-based agent to prove identity.
|
|
201
|
+
*
|
|
202
|
+
* The agent must sign this challenge with its private key and
|
|
203
|
+
* return the signature via `verifyKeyAgent()`.
|
|
204
|
+
*
|
|
205
|
+
* @param agentKeyHash - SHA-256 hash of the agent's public key
|
|
206
|
+
* @returns Challenge nonce and expiry
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const { challenge } = await valiron.getKeyAgentChallenge('a3f8c1d2...');
|
|
211
|
+
* const response = signChallenge(challenge, keypair.privateKey, keypair.publicKey);
|
|
212
|
+
* const profile = await valiron.verifyKeyAgent(response);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
getKeyAgentChallenge(agentKeyHash: string): Promise<KeyAgentChallenge>;
|
|
216
|
+
/**
|
|
217
|
+
* Verify a key-based agent's identity via challenge-response.
|
|
218
|
+
*
|
|
219
|
+
* Proves the agent controls the private key corresponding to the
|
|
220
|
+
* public key. On success, returns the agent's trust profile.
|
|
221
|
+
*
|
|
222
|
+
* @param params - Challenge response with signature and public key
|
|
223
|
+
* @returns Agent trust profile (behavioral score + Icebreaker context if available)
|
|
224
|
+
*/
|
|
225
|
+
verifyKeyAgent(params: {
|
|
226
|
+
challenge: string;
|
|
227
|
+
signature: string;
|
|
228
|
+
publicKey: string;
|
|
229
|
+
agentKeyHash: string;
|
|
230
|
+
ethereumAddress?: string;
|
|
231
|
+
}): Promise<KeyAgentProfile>;
|
|
232
|
+
/**
|
|
233
|
+
* Get trust profile for a key-based agent by its key hash.
|
|
234
|
+
*
|
|
235
|
+
* Returns behavioral score and any Icebreaker ownership context.
|
|
236
|
+
* The agent must have been verified via challenge-response at least once.
|
|
237
|
+
*
|
|
238
|
+
* @param agentKeyHash - SHA-256 hash of the agent's public key
|
|
239
|
+
* @returns Agent trust profile
|
|
240
|
+
*/
|
|
241
|
+
getKeyAgentProfile(agentKeyHash: string): Promise<KeyAgentProfile>;
|
|
242
|
+
/**
|
|
243
|
+
* Verify a World ID proof linking a human to an agent.
|
|
244
|
+
*
|
|
245
|
+
* The human uses World ID (IDKit) to generate a zero-knowledge proof
|
|
246
|
+
* of personhood, which is then verified against the World ID API.
|
|
247
|
+
* On success, the agent is marked as human-linked. Links are immutable.
|
|
248
|
+
*
|
|
249
|
+
* @param agentId - The ERC-8004 agent ID
|
|
250
|
+
* @param proof - World ID proof payload from IDKit
|
|
251
|
+
* @param options - Optional overrides (e.g. `{ chain: 'world_chain' }`)
|
|
252
|
+
* @returns Verification result with updated World ID status
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const result = await valiron.verifyWorldId('25459', {
|
|
257
|
+
* proof: '0x...',
|
|
258
|
+
* merkle_root: '0x...',
|
|
259
|
+
* nullifier_hash: '0x...',
|
|
260
|
+
* verification_level: 'orb',
|
|
261
|
+
* });
|
|
262
|
+
* console.log(result.worldId.verified); // true
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
verifyWorldId(agentId: string, proof: {
|
|
266
|
+
proof: string;
|
|
267
|
+
merkle_root: string;
|
|
268
|
+
nullifier_hash: string;
|
|
269
|
+
verification_level: "orb" | "device" | "phone";
|
|
270
|
+
}, options?: CallOptions): Promise<{
|
|
271
|
+
ok: boolean;
|
|
272
|
+
agentId: string;
|
|
273
|
+
worldId: WorldIdStatus;
|
|
274
|
+
timestamp: string;
|
|
275
|
+
}>;
|
|
276
|
+
/**
|
|
277
|
+
* Get World ID verification status for an agent.
|
|
278
|
+
*
|
|
279
|
+
* @param agentId - The ERC-8004 agent ID
|
|
280
|
+
* @param options - Optional overrides (e.g. `{ chain: 'base' }`)
|
|
281
|
+
* @returns World ID status including verification level and timestamp
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const { worldId } = await valiron.getWorldIdStatus('25459');
|
|
286
|
+
* if (worldId.verified) {
|
|
287
|
+
* console.log(`Verified via ${worldId.verificationLevel}`);
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
getWorldIdStatus(agentId: string, options?: CallOptions): Promise<{
|
|
292
|
+
agentId: string;
|
|
293
|
+
worldId: WorldIdStatus;
|
|
294
|
+
timestamp: string;
|
|
295
|
+
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Get enriched human-agent trust profile combining World ID + Icebreaker.
|
|
298
|
+
*
|
|
299
|
+
* World ID provides the human-agent link (proof-of-personhood),
|
|
300
|
+
* while Icebreaker provides background enrichment (LinkedIn, GitHub, etc.).
|
|
301
|
+
*
|
|
302
|
+
* @param agentId - The ERC-8004 agent ID
|
|
303
|
+
* @param options - Optional overrides (e.g. `{ chain: 'world_chain' }`)
|
|
304
|
+
* @returns Combined human trust profile
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const profile = await valiron.getWorldIdProfile('25459');
|
|
309
|
+
* console.log(profile.humanTrust.hasHumanLink); // true
|
|
310
|
+
* console.log(profile.humanTrust.hasBackground); // true
|
|
311
|
+
* console.log(profile.icebreaker.verifiedHandles); // [{source: 'github', handle: 'alice'}]
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
getWorldIdProfile(agentId: string, options?: CallOptions): Promise<WorldIdAgentProfile>;
|
|
315
|
+
/**
|
|
316
|
+
* Preflight gate check for a Solana payment channel.
|
|
317
|
+
*
|
|
318
|
+
* Checks the agent's trust score and returns the escrow address,
|
|
319
|
+
* credit line, and tier policy. Call this before opening a channel.
|
|
320
|
+
*
|
|
321
|
+
* @param agentId - The agent ID (ERC-8004 or Solana)
|
|
322
|
+
* @param walletAddress - The agent's Solana wallet address
|
|
323
|
+
* @returns Preflight result with escrow address and credit line
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const preflight = await valiron.channelPreflight('25459', 'So1ana...');
|
|
328
|
+
* console.log(preflight.escrowAddress); // deposit USDC here
|
|
329
|
+
* console.log(preflight.creditLineReadable); // '$50.00'
|
|
330
|
+
* console.log(preflight.tier); // 'AA'
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
channelPreflight(agentId: string, walletAddress: string): Promise<ChannelPreflightResponse>;
|
|
334
|
+
/**
|
|
335
|
+
* Open a payment channel after depositing USDC to the escrow.
|
|
336
|
+
*
|
|
337
|
+
* Verifies the deposit transaction on-chain and opens a credit line
|
|
338
|
+
* based on the agent's trust tier.
|
|
339
|
+
*
|
|
340
|
+
* @param agentId - The agent ID
|
|
341
|
+
* @param walletAddress - The agent's Solana wallet address
|
|
342
|
+
* @param depositSignature - The Solana transaction signature of the USDC deposit
|
|
343
|
+
* @returns Channel session with ID, credit line, and expiry
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const channel = await valiron.channelOpen('25459', 'So1ana...', '5eykt...');
|
|
348
|
+
* console.log(channel.sessionId); // 'ch_abc123'
|
|
349
|
+
* console.log(channel.creditLineReadable); // '$50.00'
|
|
350
|
+
* console.log(channel.expiresAt); // ISO timestamp
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
channelOpen(agentId: string, walletAddress: string, depositSignature: string): Promise<ChannelOpenResponse>;
|
|
354
|
+
/**
|
|
355
|
+
* Consume credit from an open payment channel.
|
|
356
|
+
*
|
|
357
|
+
* Records a charge against the channel's credit line. The session ID
|
|
358
|
+
* is used as the authorization token.
|
|
359
|
+
*
|
|
360
|
+
* @param sessionId - The channel session ID from `channelOpen()`
|
|
361
|
+
* @param cost - Amount to charge in USDC (e.g. 0.5 for $0.50)
|
|
362
|
+
* @param description - Optional description of the charge
|
|
363
|
+
* @returns Usage record with remaining balance
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const usage = await valiron.channelConsume('ch_abc123', 0.5, 'GPT-4 call');
|
|
368
|
+
* console.log(usage.session.remainingReadable); // '$49.50'
|
|
369
|
+
* console.log(usage.session.requestCount); // 1
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
channelConsume(sessionId: string, cost: number, description?: string): Promise<ChannelConsumeResponse>;
|
|
373
|
+
/**
|
|
374
|
+
* Get the current status of a payment channel.
|
|
375
|
+
*
|
|
376
|
+
* @param sessionId - The channel session ID
|
|
377
|
+
* @returns Channel status with balance, request count, and expiry
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const status = await valiron.channelStatus('ch_abc123');
|
|
382
|
+
* console.log(status.remainingReadable); // '$49.50'
|
|
383
|
+
* console.log(status.active); // true
|
|
384
|
+
* console.log(status.settled); // false
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
channelStatus(sessionId: string): Promise<ChannelStatusResponse>;
|
|
388
|
+
/**
|
|
389
|
+
* Settle and close a payment channel.
|
|
390
|
+
*
|
|
391
|
+
* Closes the channel, calculates unused credit, and refunds
|
|
392
|
+
* unspent USDC back to the agent's wallet on Solana.
|
|
393
|
+
*
|
|
394
|
+
* @param sessionId - The channel session ID
|
|
395
|
+
* @returns Settlement result with refund details
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const settlement = await valiron.channelSettle('ch_abc123');
|
|
400
|
+
* console.log(settlement.totalConsumedReadable); // '$0.50'
|
|
401
|
+
* console.log(settlement.refundReadable); // '$49.50'
|
|
402
|
+
* console.log(settlement.refundSignature); // Solana TX sig
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
channelSettle(sessionId: string): Promise<ChannelSettlementResponse>;
|
|
406
|
+
/**
|
|
407
|
+
* Check payment channel service health.
|
|
408
|
+
*
|
|
409
|
+
* @returns Health status and escrow address
|
|
410
|
+
*/
|
|
411
|
+
channelHealth(): Promise<ChannelHealthResponse>;
|
|
199
412
|
/**
|
|
200
413
|
* Flush any pending telemetry events and release resources.
|
|
201
414
|
*
|
|
@@ -220,3 +433,7 @@ export * from "./types";
|
|
|
220
433
|
export { ValironClient } from "./clients";
|
|
221
434
|
export { createValironGate, valironFastifyPlugin, createValironNextMiddleware, valironGateCheck, } from "./middleware";
|
|
222
435
|
export type { ValironGateConfig, ValironFastifyConfig, ValironNextConfig, ValironGateCheckResult, } from "./middleware";
|
|
436
|
+
export { generateAgentKeypair, deriveKeyHash, generateChallenge, signChallenge, verifyChallenge, } from "./identity";
|
|
437
|
+
export type { AgentKeypair, ChallengeResponse, } from "./identity";
|
|
438
|
+
export { ValironOperator } from "./operatorSdk";
|
|
439
|
+
export type { ValironOperatorConfig, PaywallConfig } from "./operatorSdk";
|
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.valironGateCheck = exports.createValironNextMiddleware = exports.valironFastifyPlugin = exports.createValironGate = exports.ValironClient = exports.ValironSDK = void 0;
|
|
17
|
+
exports.ValironOperator = exports.verifyChallenge = exports.signChallenge = exports.generateChallenge = exports.deriveKeyHash = exports.generateAgentKeypair = 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
|
|
@@ -229,6 +229,226 @@ class ValironSDK {
|
|
|
229
229
|
async gate(agentId, options) {
|
|
230
230
|
return this.client.gate(agentId, options);
|
|
231
231
|
}
|
|
232
|
+
// ─── Key-Based Agent Identity (Web2 Agents) ─────────────────────────────
|
|
233
|
+
/**
|
|
234
|
+
* Get a challenge nonce for a key-based agent to prove identity.
|
|
235
|
+
*
|
|
236
|
+
* The agent must sign this challenge with its private key and
|
|
237
|
+
* return the signature via `verifyKeyAgent()`.
|
|
238
|
+
*
|
|
239
|
+
* @param agentKeyHash - SHA-256 hash of the agent's public key
|
|
240
|
+
* @returns Challenge nonce and expiry
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const { challenge } = await valiron.getKeyAgentChallenge('a3f8c1d2...');
|
|
245
|
+
* const response = signChallenge(challenge, keypair.privateKey, keypair.publicKey);
|
|
246
|
+
* const profile = await valiron.verifyKeyAgent(response);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async getKeyAgentChallenge(agentKeyHash) {
|
|
250
|
+
return this.client.getKeyAgentChallenge(agentKeyHash);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Verify a key-based agent's identity via challenge-response.
|
|
254
|
+
*
|
|
255
|
+
* Proves the agent controls the private key corresponding to the
|
|
256
|
+
* public key. On success, returns the agent's trust profile.
|
|
257
|
+
*
|
|
258
|
+
* @param params - Challenge response with signature and public key
|
|
259
|
+
* @returns Agent trust profile (behavioral score + Icebreaker context if available)
|
|
260
|
+
*/
|
|
261
|
+
async verifyKeyAgent(params) {
|
|
262
|
+
return this.client.verifyKeyAgent(params);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get trust profile for a key-based agent by its key hash.
|
|
266
|
+
*
|
|
267
|
+
* Returns behavioral score and any Icebreaker ownership context.
|
|
268
|
+
* The agent must have been verified via challenge-response at least once.
|
|
269
|
+
*
|
|
270
|
+
* @param agentKeyHash - SHA-256 hash of the agent's public key
|
|
271
|
+
* @returns Agent trust profile
|
|
272
|
+
*/
|
|
273
|
+
async getKeyAgentProfile(agentKeyHash) {
|
|
274
|
+
return this.client.getKeyAgentProfile(agentKeyHash);
|
|
275
|
+
}
|
|
276
|
+
// ─── World ID (Proof-of-Personhood) ─────────────────────────────────
|
|
277
|
+
/**
|
|
278
|
+
* Verify a World ID proof linking a human to an agent.
|
|
279
|
+
*
|
|
280
|
+
* The human uses World ID (IDKit) to generate a zero-knowledge proof
|
|
281
|
+
* of personhood, which is then verified against the World ID API.
|
|
282
|
+
* On success, the agent is marked as human-linked. Links are immutable.
|
|
283
|
+
*
|
|
284
|
+
* @param agentId - The ERC-8004 agent ID
|
|
285
|
+
* @param proof - World ID proof payload from IDKit
|
|
286
|
+
* @param options - Optional overrides (e.g. `{ chain: 'world_chain' }`)
|
|
287
|
+
* @returns Verification result with updated World ID status
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const result = await valiron.verifyWorldId('25459', {
|
|
292
|
+
* proof: '0x...',
|
|
293
|
+
* merkle_root: '0x...',
|
|
294
|
+
* nullifier_hash: '0x...',
|
|
295
|
+
* verification_level: 'orb',
|
|
296
|
+
* });
|
|
297
|
+
* console.log(result.worldId.verified); // true
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
async verifyWorldId(agentId, proof, options) {
|
|
301
|
+
return this.client.verifyWorldId(agentId, proof, options);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get World ID verification status for an agent.
|
|
305
|
+
*
|
|
306
|
+
* @param agentId - The ERC-8004 agent ID
|
|
307
|
+
* @param options - Optional overrides (e.g. `{ chain: 'base' }`)
|
|
308
|
+
* @returns World ID status including verification level and timestamp
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const { worldId } = await valiron.getWorldIdStatus('25459');
|
|
313
|
+
* if (worldId.verified) {
|
|
314
|
+
* console.log(`Verified via ${worldId.verificationLevel}`);
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
async getWorldIdStatus(agentId, options) {
|
|
319
|
+
return this.client.getWorldIdStatus(agentId, options);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get enriched human-agent trust profile combining World ID + Icebreaker.
|
|
323
|
+
*
|
|
324
|
+
* World ID provides the human-agent link (proof-of-personhood),
|
|
325
|
+
* while Icebreaker provides background enrichment (LinkedIn, GitHub, etc.).
|
|
326
|
+
*
|
|
327
|
+
* @param agentId - The ERC-8004 agent ID
|
|
328
|
+
* @param options - Optional overrides (e.g. `{ chain: 'world_chain' }`)
|
|
329
|
+
* @returns Combined human trust profile
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const profile = await valiron.getWorldIdProfile('25459');
|
|
334
|
+
* console.log(profile.humanTrust.hasHumanLink); // true
|
|
335
|
+
* console.log(profile.humanTrust.hasBackground); // true
|
|
336
|
+
* console.log(profile.icebreaker.verifiedHandles); // [{source: 'github', handle: 'alice'}]
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
async getWorldIdProfile(agentId, options) {
|
|
340
|
+
return this.client.getWorldIdProfile(agentId, options);
|
|
341
|
+
}
|
|
342
|
+
// ─── Payment Channels (Solana) ─────────────────────────────────────────
|
|
343
|
+
/**
|
|
344
|
+
* Preflight gate check for a Solana payment channel.
|
|
345
|
+
*
|
|
346
|
+
* Checks the agent's trust score and returns the escrow address,
|
|
347
|
+
* credit line, and tier policy. Call this before opening a channel.
|
|
348
|
+
*
|
|
349
|
+
* @param agentId - The agent ID (ERC-8004 or Solana)
|
|
350
|
+
* @param walletAddress - The agent's Solana wallet address
|
|
351
|
+
* @returns Preflight result with escrow address and credit line
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const preflight = await valiron.channelPreflight('25459', 'So1ana...');
|
|
356
|
+
* console.log(preflight.escrowAddress); // deposit USDC here
|
|
357
|
+
* console.log(preflight.creditLineReadable); // '$50.00'
|
|
358
|
+
* console.log(preflight.tier); // 'AA'
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
async channelPreflight(agentId, walletAddress) {
|
|
362
|
+
return this.client.channelPreflight(agentId, walletAddress);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Open a payment channel after depositing USDC to the escrow.
|
|
366
|
+
*
|
|
367
|
+
* Verifies the deposit transaction on-chain and opens a credit line
|
|
368
|
+
* based on the agent's trust tier.
|
|
369
|
+
*
|
|
370
|
+
* @param agentId - The agent ID
|
|
371
|
+
* @param walletAddress - The agent's Solana wallet address
|
|
372
|
+
* @param depositSignature - The Solana transaction signature of the USDC deposit
|
|
373
|
+
* @returns Channel session with ID, credit line, and expiry
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const channel = await valiron.channelOpen('25459', 'So1ana...', '5eykt...');
|
|
378
|
+
* console.log(channel.sessionId); // 'ch_abc123'
|
|
379
|
+
* console.log(channel.creditLineReadable); // '$50.00'
|
|
380
|
+
* console.log(channel.expiresAt); // ISO timestamp
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
async channelOpen(agentId, walletAddress, depositSignature) {
|
|
384
|
+
return this.client.channelOpen(agentId, walletAddress, depositSignature);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Consume credit from an open payment channel.
|
|
388
|
+
*
|
|
389
|
+
* Records a charge against the channel's credit line. The session ID
|
|
390
|
+
* is used as the authorization token.
|
|
391
|
+
*
|
|
392
|
+
* @param sessionId - The channel session ID from `channelOpen()`
|
|
393
|
+
* @param cost - Amount to charge in USDC (e.g. 0.5 for $0.50)
|
|
394
|
+
* @param description - Optional description of the charge
|
|
395
|
+
* @returns Usage record with remaining balance
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const usage = await valiron.channelConsume('ch_abc123', 0.5, 'GPT-4 call');
|
|
400
|
+
* console.log(usage.session.remainingReadable); // '$49.50'
|
|
401
|
+
* console.log(usage.session.requestCount); // 1
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
async channelConsume(sessionId, cost, description) {
|
|
405
|
+
return this.client.channelConsume(sessionId, cost, description);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Get the current status of a payment channel.
|
|
409
|
+
*
|
|
410
|
+
* @param sessionId - The channel session ID
|
|
411
|
+
* @returns Channel status with balance, request count, and expiry
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* const status = await valiron.channelStatus('ch_abc123');
|
|
416
|
+
* console.log(status.remainingReadable); // '$49.50'
|
|
417
|
+
* console.log(status.active); // true
|
|
418
|
+
* console.log(status.settled); // false
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
async channelStatus(sessionId) {
|
|
422
|
+
return this.client.channelStatus(sessionId);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Settle and close a payment channel.
|
|
426
|
+
*
|
|
427
|
+
* Closes the channel, calculates unused credit, and refunds
|
|
428
|
+
* unspent USDC back to the agent's wallet on Solana.
|
|
429
|
+
*
|
|
430
|
+
* @param sessionId - The channel session ID
|
|
431
|
+
* @returns Settlement result with refund details
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* const settlement = await valiron.channelSettle('ch_abc123');
|
|
436
|
+
* console.log(settlement.totalConsumedReadable); // '$0.50'
|
|
437
|
+
* console.log(settlement.refundReadable); // '$49.50'
|
|
438
|
+
* console.log(settlement.refundSignature); // Solana TX sig
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
async channelSettle(sessionId) {
|
|
442
|
+
return this.client.channelSettle(sessionId);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Check payment channel service health.
|
|
446
|
+
*
|
|
447
|
+
* @returns Health status and escrow address
|
|
448
|
+
*/
|
|
449
|
+
async channelHealth() {
|
|
450
|
+
return this.client.channelHealth();
|
|
451
|
+
}
|
|
232
452
|
/**
|
|
233
453
|
* Flush any pending telemetry events and release resources.
|
|
234
454
|
*
|
|
@@ -261,3 +481,11 @@ Object.defineProperty(exports, "createValironGate", { enumerable: true, get: fun
|
|
|
261
481
|
Object.defineProperty(exports, "valironFastifyPlugin", { enumerable: true, get: function () { return middleware_1.valironFastifyPlugin; } });
|
|
262
482
|
Object.defineProperty(exports, "createValironNextMiddleware", { enumerable: true, get: function () { return middleware_1.createValironNextMiddleware; } });
|
|
263
483
|
Object.defineProperty(exports, "valironGateCheck", { enumerable: true, get: function () { return middleware_1.valironGateCheck; } });
|
|
484
|
+
var identity_1 = require("./identity");
|
|
485
|
+
Object.defineProperty(exports, "generateAgentKeypair", { enumerable: true, get: function () { return identity_1.generateAgentKeypair; } });
|
|
486
|
+
Object.defineProperty(exports, "deriveKeyHash", { enumerable: true, get: function () { return identity_1.deriveKeyHash; } });
|
|
487
|
+
Object.defineProperty(exports, "generateChallenge", { enumerable: true, get: function () { return identity_1.generateChallenge; } });
|
|
488
|
+
Object.defineProperty(exports, "signChallenge", { enumerable: true, get: function () { return identity_1.signChallenge; } });
|
|
489
|
+
Object.defineProperty(exports, "verifyChallenge", { enumerable: true, get: function () { return identity_1.verifyChallenge; } });
|
|
490
|
+
var operatorSdk_1 = require("./operatorSdk");
|
|
491
|
+
Object.defineProperty(exports, "ValironOperator", { enumerable: true, get: function () { return operatorSdk_1.ValironOperator; } });
|
package/dist/middleware.d.ts
CHANGED
|
@@ -2,15 +2,25 @@ import type { ValironSDK } from "./index";
|
|
|
2
2
|
import type { GateResult } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for the Valiron trust gate middleware.
|
|
5
|
+
*
|
|
6
|
+
* Supports both on-chain (ERC-8004/Solana) and key-based (web2) agents.
|
|
7
|
+
* Auto-detects agent type from request headers:
|
|
8
|
+
* - `x-agent-id` → on-chain gate
|
|
9
|
+
* - `x-agent-key-hash` → key-based profile lookup
|
|
5
10
|
*/
|
|
6
11
|
export interface ValironGateConfig {
|
|
7
12
|
/** Configured ValironSDK instance. */
|
|
8
13
|
sdk: ValironSDK;
|
|
9
14
|
/**
|
|
10
|
-
* Extract the agent ID from an incoming request.
|
|
15
|
+
* Extract the on-chain agent ID from an incoming request.
|
|
11
16
|
* Defaults to reading `x-agent-id` header.
|
|
12
17
|
*/
|
|
13
18
|
extractAgentId?: (req: any) => string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Extract the key-based agent hash from an incoming request.
|
|
21
|
+
* Defaults to reading `x-agent-key-hash` header.
|
|
22
|
+
*/
|
|
23
|
+
extractAgentKeyHash?: (req: any) => string | null;
|
|
14
24
|
/** Minimum Valiron score to allow (default: 65). */
|
|
15
25
|
minScore?: number;
|
|
16
26
|
/** TTL for cached sandbox results in ms (default: 86400000 = 24 h). */
|
|
@@ -35,6 +45,7 @@ export interface ValironGateConfig {
|
|
|
35
45
|
* const valiron = new ValironSDK({ chain: 'monad' });
|
|
36
46
|
*
|
|
37
47
|
* // Apply before your x402 / payment handler
|
|
48
|
+
* // Works with both on-chain (x-agent-id) and key-based (x-agent-key-hash) agents
|
|
38
49
|
* app.use('/api/paid', createValironGate({ sdk: valiron }));
|
|
39
50
|
*
|
|
40
51
|
* // Custom threshold
|
|
@@ -53,10 +64,15 @@ export interface ValironFastifyConfig {
|
|
|
53
64
|
/** Configured ValironSDK instance. */
|
|
54
65
|
sdk: ValironSDK;
|
|
55
66
|
/**
|
|
56
|
-
* Extract the agent ID from a Fastify request.
|
|
67
|
+
* Extract the on-chain agent ID from a Fastify request.
|
|
57
68
|
* Defaults to reading `x-agent-id` header.
|
|
58
69
|
*/
|
|
59
70
|
extractAgentId?: (req: any) => string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Extract the key-based agent hash from a Fastify request.
|
|
73
|
+
* Defaults to reading `x-agent-key-hash` header.
|
|
74
|
+
*/
|
|
75
|
+
extractAgentKeyHash?: (req: any) => string | null;
|
|
60
76
|
/** Minimum Valiron score to allow (default: 65). */
|
|
61
77
|
minScore?: number;
|
|
62
78
|
/** TTL for cached sandbox results in ms (default: 86400000 = 24 h). */
|
|
@@ -106,10 +122,15 @@ export interface ValironNextConfig {
|
|
|
106
122
|
/** Configured ValironSDK instance. */
|
|
107
123
|
sdk: ValironSDK;
|
|
108
124
|
/**
|
|
109
|
-
* Extract the agent ID from a Next.js request.
|
|
125
|
+
* Extract the on-chain agent ID from a Next.js request.
|
|
110
126
|
* Defaults to reading `x-agent-id` header.
|
|
111
127
|
*/
|
|
112
128
|
extractAgentId?: (req: Request) => string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Extract the key-based agent hash from a Next.js request.
|
|
131
|
+
* Defaults to reading `x-agent-key-hash` header.
|
|
132
|
+
*/
|
|
133
|
+
extractAgentKeyHash?: (req: Request) => string | null;
|
|
113
134
|
/** Minimum Valiron score to allow (default: 65). */
|
|
114
135
|
minScore?: number;
|
|
115
136
|
/** TTL for cached sandbox results in ms (default: 86400000 = 24 h). */
|
|
@@ -185,6 +206,7 @@ export interface ValironGateCheckResult {
|
|
|
185
206
|
* app.use('/api/*', async (c, next) => {
|
|
186
207
|
* const gate = await valironGateCheck(valiron, {
|
|
187
208
|
* agentId: c.req.header('x-agent-id') ?? null,
|
|
209
|
+
* agentKeyHash: c.req.header('x-agent-key-hash') ?? null,
|
|
188
210
|
* });
|
|
189
211
|
* if (!gate.allow) return c.json(gate.body, gate.status);
|
|
190
212
|
* c.set('valiron', gate.result);
|
|
@@ -198,6 +220,7 @@ export interface ValironGateCheckResult {
|
|
|
198
220
|
* app.use(async (ctx, next) => {
|
|
199
221
|
* const gate = await valironGateCheck(valiron, {
|
|
200
222
|
* agentId: ctx.get('x-agent-id') || null,
|
|
223
|
+
* agentKeyHash: ctx.get('x-agent-key-hash') || null,
|
|
201
224
|
* });
|
|
202
225
|
* if (!gate.allow) {
|
|
203
226
|
* ctx.status = gate.status;
|
|
@@ -210,7 +233,10 @@ export interface ValironGateCheckResult {
|
|
|
210
233
|
* ```
|
|
211
234
|
*/
|
|
212
235
|
export declare function valironGateCheck(sdk: ValironSDK, opts: {
|
|
213
|
-
|
|
236
|
+
/** On-chain agent ID (ERC-8004 / Solana). */
|
|
237
|
+
agentId?: string | null;
|
|
238
|
+
/** Key-based agent hash (web2). Checked if agentId is not provided. */
|
|
239
|
+
agentKeyHash?: string | null;
|
|
214
240
|
minScore?: number;
|
|
215
241
|
ttlMs?: number;
|
|
216
242
|
}): Promise<ValironGateCheckResult>;
|