@valiron/sdk 0.11.0 → 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 +26 -61
- 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 +375 -3
- package/docs/CHAINS.md +37 -3
- package/docs/ERRORS.md +40 -2
- package/docs/IDENTITY.md +94 -8
- package/docs/QUICKSTART.md +185 -28
- package/docs/README.md +21 -11
- package/docs/SANDBOX.md +58 -23
- package/docs/SDK-REFERENCE.md +275 -1
- package/docs/TRUST-MODEL.md +57 -60
- package/docs/llms.txt +52 -4
- package/package.json +5 -4
package/dist/identity.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAgentKeypair = generateAgentKeypair;
|
|
4
|
+
exports.deriveKeyHash = deriveKeyHash;
|
|
5
|
+
exports.generateChallenge = generateChallenge;
|
|
6
|
+
exports.signChallenge = signChallenge;
|
|
7
|
+
exports.verifyChallenge = verifyChallenge;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
// ─── Keypair Generation ─────────────────────────────────────────────────────
|
|
10
|
+
/**
|
|
11
|
+
* Generate an Ed25519 keypair for an agent.
|
|
12
|
+
*
|
|
13
|
+
* The SHA-256 hash of the public key becomes the agent's
|
|
14
|
+
* stable, portable identifier — no registration needed.
|
|
15
|
+
*
|
|
16
|
+
* @returns The keypair and derived agent key hash
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { generateAgentKeypair } from '@valiron/sdk';
|
|
21
|
+
*
|
|
22
|
+
* const keypair = generateAgentKeypair();
|
|
23
|
+
* console.log(keypair.agentKeyHash); // "a3f8c1d2e5..."
|
|
24
|
+
*
|
|
25
|
+
* // Store privateKey securely (env var, file, KMS)
|
|
26
|
+
* // Use agentKeyHash as the agent's identity
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function generateAgentKeypair() {
|
|
30
|
+
const { publicKey, privateKey } = (0, crypto_1.generateKeyPairSync)("ed25519", {
|
|
31
|
+
publicKeyEncoding: { type: "spki", format: "der" },
|
|
32
|
+
privateKeyEncoding: { type: "pkcs8", format: "der" },
|
|
33
|
+
});
|
|
34
|
+
const publicKeyB64 = Buffer.from(publicKey).toString("base64");
|
|
35
|
+
const privateKeyB64 = Buffer.from(privateKey).toString("base64");
|
|
36
|
+
const agentKeyHash = deriveKeyHash(publicKeyB64);
|
|
37
|
+
return {
|
|
38
|
+
privateKey: privateKeyB64,
|
|
39
|
+
publicKey: publicKeyB64,
|
|
40
|
+
agentKeyHash,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// ─── Key Hash Derivation ────────────────────────────────────────────────────
|
|
44
|
+
/**
|
|
45
|
+
* Derive the agent key hash from a base64-encoded public key.
|
|
46
|
+
*
|
|
47
|
+
* @param publicKeyB64 - Base64-encoded Ed25519 public key (SPKI DER format)
|
|
48
|
+
* @returns SHA-256 hex hash of the public key
|
|
49
|
+
*/
|
|
50
|
+
function deriveKeyHash(publicKeyB64) {
|
|
51
|
+
return (0, crypto_1.createHash)("sha256")
|
|
52
|
+
.update(Buffer.from(publicKeyB64, "base64"))
|
|
53
|
+
.digest("hex");
|
|
54
|
+
}
|
|
55
|
+
// ─── Challenge-Response ─────────────────────────────────────────────────────
|
|
56
|
+
/**
|
|
57
|
+
* Generate a random challenge nonce for identity verification.
|
|
58
|
+
*
|
|
59
|
+
* @returns A 32-byte hex-encoded nonce
|
|
60
|
+
*/
|
|
61
|
+
function generateChallenge() {
|
|
62
|
+
return (0, crypto_1.randomBytes)(32).toString("hex");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sign a challenge with the agent's private key.
|
|
66
|
+
* Used to prove the agent controls the keypair.
|
|
67
|
+
*
|
|
68
|
+
* @param challenge - The challenge nonce to sign
|
|
69
|
+
* @param privateKeyB64 - Base64-encoded Ed25519 private key (PKCS8 DER format)
|
|
70
|
+
* @param publicKeyB64 - Base64-encoded Ed25519 public key (SPKI DER format)
|
|
71
|
+
* @returns The challenge response containing signature + identity info
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { signChallenge } from '@valiron/sdk';
|
|
76
|
+
*
|
|
77
|
+
* // Agent receives a challenge from Valiron middleware
|
|
78
|
+
* const response = signChallenge(challenge, keypair.privateKey, keypair.publicKey);
|
|
79
|
+
* // Send response back to prove identity
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
function signChallenge(challenge, privateKeyB64, publicKeyB64) {
|
|
83
|
+
const privateKeyObj = createPrivateKeyFromB64(privateKeyB64);
|
|
84
|
+
const signature = (0, crypto_1.sign)(null, Buffer.from(challenge), privateKeyObj);
|
|
85
|
+
return {
|
|
86
|
+
challenge,
|
|
87
|
+
signature: signature.toString("base64"),
|
|
88
|
+
publicKey: publicKeyB64,
|
|
89
|
+
agentKeyHash: deriveKeyHash(publicKeyB64),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Verify a challenge-response signature.
|
|
94
|
+
* Confirms the agent controls the private key corresponding to the public key.
|
|
95
|
+
*
|
|
96
|
+
* @param challenge - The original challenge nonce
|
|
97
|
+
* @param signatureB64 - Base64-encoded signature
|
|
98
|
+
* @param publicKeyB64 - Base64-encoded Ed25519 public key
|
|
99
|
+
* @returns true if the signature is valid
|
|
100
|
+
*/
|
|
101
|
+
function verifyChallenge(challenge, signatureB64, publicKeyB64) {
|
|
102
|
+
try {
|
|
103
|
+
const publicKeyObj = (0, crypto_1.createPublicKey)({
|
|
104
|
+
key: Buffer.from(publicKeyB64, "base64"),
|
|
105
|
+
format: "der",
|
|
106
|
+
type: "spki",
|
|
107
|
+
});
|
|
108
|
+
return (0, crypto_1.verify)(null, Buffer.from(challenge), publicKeyObj, Buffer.from(signatureB64, "base64"));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
115
|
+
function createPrivateKeyFromB64(privateKeyB64) {
|
|
116
|
+
return {
|
|
117
|
+
key: Buffer.from(privateKeyB64, "base64"),
|
|
118
|
+
format: "der",
|
|
119
|
+
type: "pkcs8",
|
|
120
|
+
};
|
|
121
|
+
}
|
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; } });
|