@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/docs/API-REFERENCE.md
CHANGED
|
@@ -294,6 +294,260 @@ Health check endpoint.
|
|
|
294
294
|
|
|
295
295
|
---
|
|
296
296
|
|
|
297
|
+
## Payment Channels (Solana)
|
|
298
|
+
|
|
299
|
+
Trust-adaptive USDC payment channels on Solana. Base URL: `https://valiron-edge-proxy.onrender.com`
|
|
300
|
+
|
|
301
|
+
All channel endpoints are under the `/channel/` prefix (not `/operator/`).
|
|
302
|
+
|
|
303
|
+
### POST /channel/preflight/:agentId
|
|
304
|
+
|
|
305
|
+
Pre-flight gate check. Returns escrow address, credit line, and tier policy.
|
|
306
|
+
|
|
307
|
+
#### Parameters
|
|
308
|
+
|
|
309
|
+
| Parameter | Location | Type | Required | Description |
|
|
310
|
+
|-----------|----------|------|----------|-------------|
|
|
311
|
+
| `agentId` | path | string | yes | Agent ID (ERC-8004 or Solana sequential) |
|
|
312
|
+
| `walletAddress` | body | string | yes | Agent's Solana wallet pubkey |
|
|
313
|
+
|
|
314
|
+
#### Request
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/preflight/1226 \
|
|
318
|
+
-H "Content-Type: application/json" \
|
|
319
|
+
-d '{"walletAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"}'
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Response — 200 OK
|
|
323
|
+
|
|
324
|
+
```json
|
|
325
|
+
{
|
|
326
|
+
"agentId": "1226",
|
|
327
|
+
"tier": "AA",
|
|
328
|
+
"score": 85,
|
|
329
|
+
"riskLevel": "GREEN",
|
|
330
|
+
"creditLine": "50000000",
|
|
331
|
+
"creditLineReadable": "$50.00",
|
|
332
|
+
"maxRequests": null,
|
|
333
|
+
"durationSeconds": 2700,
|
|
334
|
+
"escrowAddress": "EscrowPubkey..."
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Error Responses
|
|
339
|
+
|
|
340
|
+
| Status | Error | Meaning |
|
|
341
|
+
|--------|-------|---------|
|
|
342
|
+
| 400 | `wallet_required` | Missing `walletAddress` in body |
|
|
343
|
+
| 403 | `agent_denied` | Agent trust score below threshold |
|
|
344
|
+
| 503 | `escrow_not_configured` | Server has no escrow wallet configured |
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
### POST /channel/open/:agentId
|
|
349
|
+
|
|
350
|
+
Open a payment channel by verifying a USDC deposit transaction.
|
|
351
|
+
|
|
352
|
+
#### Parameters
|
|
353
|
+
|
|
354
|
+
| Parameter | Location | Type | Required | Description |
|
|
355
|
+
|-----------|----------|------|----------|-------------|
|
|
356
|
+
| `agentId` | path | string | yes | Agent ID |
|
|
357
|
+
| `walletAddress` | body | string | yes | Agent's Solana wallet |
|
|
358
|
+
| `depositSignature` | body | string | yes | Solana TX signature of USDC deposit |
|
|
359
|
+
|
|
360
|
+
#### Request
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/open/1226 \
|
|
364
|
+
-H "Content-Type: application/json" \
|
|
365
|
+
-d '{"walletAddress": "7xKXtg...", "depositSignature": "5eykt..."}'
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
#### Response — 200 OK
|
|
369
|
+
|
|
370
|
+
```json
|
|
371
|
+
{
|
|
372
|
+
"sessionId": "ch_a1b2c3d4",
|
|
373
|
+
"agentId": "1226",
|
|
374
|
+
"tier": "AA",
|
|
375
|
+
"score": 85,
|
|
376
|
+
"riskLevel": "GREEN",
|
|
377
|
+
"creditLine": "50000000",
|
|
378
|
+
"creditLineReadable": "$50.00",
|
|
379
|
+
"maxRequests": null,
|
|
380
|
+
"expiresAt": "2026-04-23T13:45:00.000Z",
|
|
381
|
+
"durationSeconds": 2700,
|
|
382
|
+
"depositConfirmed": true,
|
|
383
|
+
"depositSignature": "5eykt...",
|
|
384
|
+
"escrowAddress": "EscrowPubkey..."
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### Error Responses
|
|
389
|
+
|
|
390
|
+
| Status | Error | Meaning |
|
|
391
|
+
|--------|-------|---------|
|
|
392
|
+
| 400 | `wallet_required` | Missing wallet address |
|
|
393
|
+
| 400 | `deposit_required` | Missing deposit signature |
|
|
394
|
+
| 409 | `deposit_already_claimed` | TX signature already used for another channel |
|
|
395
|
+
| 503 | `escrow_not_configured` | No escrow wallet on server |
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
### POST /channel/consume/:sessionId
|
|
400
|
+
|
|
401
|
+
Charge against an open channel. Requires the session ID as a Bearer token.
|
|
402
|
+
|
|
403
|
+
#### Parameters
|
|
404
|
+
|
|
405
|
+
| Parameter | Location | Type | Required | Description |
|
|
406
|
+
|-----------|----------|------|----------|-------------|
|
|
407
|
+
| `sessionId` | path | string | yes | Channel session ID |
|
|
408
|
+
| `Authorization` | header | string | yes | `Bearer <sessionId>` |
|
|
409
|
+
| `cost` | body | number | yes | Amount to charge (USDC, e.g. 0.50) |
|
|
410
|
+
| `description` | body | string | no | Description of the charge |
|
|
411
|
+
|
|
412
|
+
#### Request
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/consume/ch_a1b2c3d4 \
|
|
416
|
+
-H "Content-Type: application/json" \
|
|
417
|
+
-H "Authorization: Bearer ch_a1b2c3d4" \
|
|
418
|
+
-d '{"cost": 0.50, "description": "GPT-4o inference"}'
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### Response — 200 OK
|
|
422
|
+
|
|
423
|
+
```json
|
|
424
|
+
{
|
|
425
|
+
"requestId": "req_xyz789",
|
|
426
|
+
"cost": "500000",
|
|
427
|
+
"costReadable": "$0.50",
|
|
428
|
+
"description": "GPT-4o inference",
|
|
429
|
+
"session": {
|
|
430
|
+
"consumed": "500000",
|
|
431
|
+
"consumedReadable": "$0.50",
|
|
432
|
+
"remaining": "49500000",
|
|
433
|
+
"remainingReadable": "$49.50",
|
|
434
|
+
"requestCount": 1,
|
|
435
|
+
"maxRequests": null,
|
|
436
|
+
"secondsRemaining": 2685
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
#### Error Responses
|
|
442
|
+
|
|
443
|
+
| Status | Error | Meaning |
|
|
444
|
+
|--------|-------|---------|
|
|
445
|
+
| 400 | `bad_request` | Missing `cost` field |
|
|
446
|
+
| 401 | `unauthorized` | Missing or invalid Authorization header |
|
|
447
|
+
| 403 | `credit_exceeded` | Insufficient credit remaining |
|
|
448
|
+
| 404 | `not_found` | Channel not found |
|
|
449
|
+
| 410 | `channel_expired` | Channel has expired |
|
|
450
|
+
| 429 | `max_requests` | Request limit reached |
|
|
451
|
+
| 429 | `consume_in_progress` | Another consume is being processed (retry) |
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
### GET /channel/status/:sessionId
|
|
456
|
+
|
|
457
|
+
Get current status of a payment channel.
|
|
458
|
+
|
|
459
|
+
#### Request
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
curl https://valiron-edge-proxy.onrender.com/channel/status/ch_a1b2c3d4
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
#### Response — 200 OK
|
|
466
|
+
|
|
467
|
+
```json
|
|
468
|
+
{
|
|
469
|
+
"sessionId": "ch_a1b2c3d4",
|
|
470
|
+
"agentId": "1226",
|
|
471
|
+
"tier": "AA",
|
|
472
|
+
"creditLine": "50000000",
|
|
473
|
+
"creditLineReadable": "$50.00",
|
|
474
|
+
"consumed": "500000",
|
|
475
|
+
"consumedReadable": "$0.50",
|
|
476
|
+
"remaining": "49500000",
|
|
477
|
+
"remainingReadable": "$49.50",
|
|
478
|
+
"requestCount": 1,
|
|
479
|
+
"maxRequests": null,
|
|
480
|
+
"expiresAt": "2026-04-23T13:45:00.000Z",
|
|
481
|
+
"secondsRemaining": 2685,
|
|
482
|
+
"active": true,
|
|
483
|
+
"settled": false
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### Error Responses
|
|
488
|
+
|
|
489
|
+
| Status | Error | Meaning |
|
|
490
|
+
|--------|-------|---------|
|
|
491
|
+
| 404 | `not_found` | Channel not found |
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
### POST /channel/settle/:sessionId
|
|
496
|
+
|
|
497
|
+
Close a payment channel and refund unused USDC.
|
|
498
|
+
|
|
499
|
+
#### Request
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/settle/ch_a1b2c3d4 \
|
|
503
|
+
-H "Content-Type: application/json" \
|
|
504
|
+
-d '{}'
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
#### Response — 200 OK
|
|
508
|
+
|
|
509
|
+
```json
|
|
510
|
+
{
|
|
511
|
+
"sessionId": "ch_a1b2c3d4",
|
|
512
|
+
"settled": true,
|
|
513
|
+
"totalConsumed": "500000",
|
|
514
|
+
"totalConsumedReadable": "$0.50",
|
|
515
|
+
"requestsServed": 1,
|
|
516
|
+
"unusedCredit": "49500000",
|
|
517
|
+
"unusedCreditReadable": "$49.50",
|
|
518
|
+
"refundAmount": "49500000",
|
|
519
|
+
"refundReadable": "$49.50",
|
|
520
|
+
"refundSignature": "4sGjMW..."
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
#### Error Responses
|
|
525
|
+
|
|
526
|
+
| Status | Error | Meaning |
|
|
527
|
+
|--------|-------|---------|
|
|
528
|
+
| 404 | `not_found` | Channel not found |
|
|
529
|
+
| 409 | `already_settled` | Channel already settled |
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
### GET /channel/health
|
|
534
|
+
|
|
535
|
+
Health check for the payment channel service.
|
|
536
|
+
|
|
537
|
+
#### Response — 200 OK
|
|
538
|
+
|
|
539
|
+
```json
|
|
540
|
+
{
|
|
541
|
+
"status": "ok",
|
|
542
|
+
"service": "dynamic-payment-channels",
|
|
543
|
+
"escrowAddress": "EscrowPubkey..."
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
`escrowAddress` is `null` if no escrow wallet is configured.
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
297
551
|
## Solana Support
|
|
298
552
|
|
|
299
553
|
All `/operator/*` endpoints support Solana agents when `chain=solana` is passed as a query parameter or `x-chain: solana` header.
|
package/docs/QUICKSTART.md
CHANGED
|
@@ -123,6 +123,71 @@ curl -X POST https://valiron-edge-proxy.onrender.com/operator/webhooks/register
|
|
|
123
123
|
|
|
124
124
|
---
|
|
125
125
|
|
|
126
|
+
## Quickstart: Payment Channels (Solana)
|
|
127
|
+
|
|
128
|
+
Monetize your API with trust-adaptive USDC credit lines. Agents deposit USDC, consume on a tab, and get refunded unused balance.
|
|
129
|
+
|
|
130
|
+
### Step 1 — Preflight check
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const valiron = new ValironSDK({ chain: "solana" });
|
|
134
|
+
|
|
135
|
+
const preflight = await valiron.channelPreflight("1226", "7xKXtg2CW87d...");
|
|
136
|
+
console.log(preflight.escrowAddress); // deposit USDC here
|
|
137
|
+
console.log(preflight.creditLineReadable); // "$50.00"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Step 2 — Agent deposits USDC, then open the channel
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// After the agent sends USDC to preflight.escrowAddress...
|
|
144
|
+
const channel = await valiron.channelOpen("1226", "7xKXtg2CW87d...", "5eykt...");
|
|
145
|
+
const sessionId = channel.sessionId; // "ch_a1b2c3..."
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Step 3 — Charge per API call
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
const usage = await valiron.channelConsume(sessionId, 0.50, "GPT-4o call");
|
|
152
|
+
console.log(usage.session.remainingReadable); // "$49.50"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Step 4 — Settle and refund
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const settlement = await valiron.channelSettle(sessionId);
|
|
159
|
+
console.log(settlement.refundReadable); // "$49.50" refunded to agent
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Using the HTTP API directly
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Preflight
|
|
166
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/preflight/1226 \
|
|
167
|
+
-H "Content-Type: application/json" \
|
|
168
|
+
-d '{"walletAddress": "7xKXtg2CW87d..."}'
|
|
169
|
+
|
|
170
|
+
# Open channel
|
|
171
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/open/1226 \
|
|
172
|
+
-H "Content-Type: application/json" \
|
|
173
|
+
-d '{"walletAddress": "7xKXtg2CW87d...", "depositSignature": "5eykt..."}'
|
|
174
|
+
|
|
175
|
+
# Consume (use sessionId as Bearer token)
|
|
176
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/consume/ch_a1b2c3 \
|
|
177
|
+
-H "Content-Type: application/json" \
|
|
178
|
+
-H "Authorization: Bearer ch_a1b2c3" \
|
|
179
|
+
-d '{"cost": 0.50, "description": "GPT-4o call"}'
|
|
180
|
+
|
|
181
|
+
# Status
|
|
182
|
+
curl https://valiron-edge-proxy.onrender.com/channel/status/ch_a1b2c3
|
|
183
|
+
|
|
184
|
+
# Settle
|
|
185
|
+
curl -X POST https://valiron-edge-proxy.onrender.com/channel/settle/ch_a1b2c3 \
|
|
186
|
+
-H "Content-Type: application/json" -d '{}'
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
126
191
|
## Quickstart: Solana Agents
|
|
127
192
|
|
|
128
193
|
Solana agents use a different registry ([QuantuLabs 8004-solana](https://8004.qnt.sh/)) but the same Valiron API. Here's how to evaluate Solana-based agents calling your API.
|
package/docs/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Valiron is trust infrastructure for API sellers. It evaluates AI agents using on
|
|
|
29
29
|
- **Risk Level**: GREEN, YELLOW, or RED.
|
|
30
30
|
- **Route Decision**: `prod`, `prod_throttled`, `sandbox`, or `sandbox_only` — determines what access level your API should give.
|
|
31
31
|
- **Sandbox**: An isolated test environment where Valiron evaluates agent behavior before granting production access.
|
|
32
|
+
- **Payment Channel** (Solana): Trust-adaptive USDC credit line. Agents deposit to escrow, consume per API call, and get refunded on settlement.
|
|
32
33
|
- **Liveness** (Solana only): Endpoint health probe via `isItAlive()`. See [API-REFERENCE.md](./API-REFERENCE.md#solana-support).
|
|
33
34
|
|
|
34
35
|
## Supported Registries
|
package/docs/SDK-REFERENCE.md
CHANGED
|
@@ -376,3 +376,238 @@ await valiron.dispose(): Promise<void>;
|
|
|
376
376
|
```
|
|
377
377
|
|
|
378
378
|
Call this when shutting down long-running processes.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## Payment Channels (Solana)
|
|
383
|
+
|
|
384
|
+
Trust-adaptive USDC payment channels on Solana. Agents deposit USDC to an escrow, receive a credit line based on their trust tier, consume credit per API call, and get refunded unused balance on settlement.
|
|
385
|
+
|
|
386
|
+
> **Solana only.** These methods call `/channel/*` endpoints, not `/operator/*`.
|
|
387
|
+
|
|
388
|
+
### channelPreflight(agentId, walletAddress)
|
|
389
|
+
|
|
390
|
+
Pre-flight gate check. Returns the agent's trust tier, credit line, and the escrow address to deposit USDC to.
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
const preflight = await valiron.channelPreflight(
|
|
394
|
+
agentId: string,
|
|
395
|
+
walletAddress: string,
|
|
396
|
+
): Promise<ChannelPreflightResponse>;
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
**Returns**: `ChannelPreflightResponse`
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
interface ChannelPreflightResponse {
|
|
403
|
+
agentId: string;
|
|
404
|
+
tier: string; // "AAA" | "AA" | "A" | "BAA" | "BA" | "B"
|
|
405
|
+
score: number;
|
|
406
|
+
riskLevel: string; // "GREEN" | "YELLOW" | "RED"
|
|
407
|
+
creditLine: string; // USDC in base units (6 decimals)
|
|
408
|
+
creditLineReadable: string; // e.g. "$50.00"
|
|
409
|
+
maxRequests: number | null;
|
|
410
|
+
durationSeconds: number;
|
|
411
|
+
escrowAddress: string; // deposit USDC here
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**Example**:
|
|
416
|
+
```typescript
|
|
417
|
+
const preflight = await valiron.channelPreflight("1226", "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU");
|
|
418
|
+
console.log(preflight.escrowAddress); // "EscrowPubkey..."
|
|
419
|
+
console.log(preflight.creditLineReadable); // "$50.00"
|
|
420
|
+
console.log(preflight.tier); // "AA"
|
|
421
|
+
console.log(preflight.durationSeconds); // 2700 (45 min)
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
**Tier Credit Line Table**:
|
|
425
|
+
|
|
426
|
+
| Tier | Credit Line | Duration | Max Requests |
|
|
427
|
+
|------|-------------|----------|--------------|
|
|
428
|
+
| AAA | $100 | 60 min | unlimited |
|
|
429
|
+
| AA | $50 | 45 min | unlimited |
|
|
430
|
+
| A | $25 | 30 min | unlimited |
|
|
431
|
+
| BAA | $10 | 20 min | 100 |
|
|
432
|
+
| BA | $5 | 15 min | 50 |
|
|
433
|
+
| B | $1 | 10 min | 10 |
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
### channelOpen(agentId, walletAddress, depositSignature)
|
|
438
|
+
|
|
439
|
+
Open a payment channel after depositing USDC to the escrow address.
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
const channel = await valiron.channelOpen(
|
|
443
|
+
agentId: string,
|
|
444
|
+
walletAddress: string,
|
|
445
|
+
depositSignature: string,
|
|
446
|
+
): Promise<ChannelOpenResponse>;
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**Returns**: `ChannelOpenResponse`
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
interface ChannelOpenResponse {
|
|
453
|
+
sessionId: string; // use this for consume/status/settle
|
|
454
|
+
agentId: string;
|
|
455
|
+
tier: string;
|
|
456
|
+
score: number;
|
|
457
|
+
riskLevel: string;
|
|
458
|
+
creditLine: string;
|
|
459
|
+
creditLineReadable: string;
|
|
460
|
+
maxRequests: number | null;
|
|
461
|
+
expiresAt: string; // ISO 8601
|
|
462
|
+
durationSeconds: number;
|
|
463
|
+
depositConfirmed: boolean;
|
|
464
|
+
depositSignature: string;
|
|
465
|
+
escrowAddress: string;
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
**Example**:
|
|
470
|
+
```typescript
|
|
471
|
+
const channel = await valiron.channelOpen(
|
|
472
|
+
"1226",
|
|
473
|
+
"7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
|
|
474
|
+
"5eykt4UsFv8P8njDFTxgkW8oVTc4BM3dTCrssAtMJDVmqYS5",
|
|
475
|
+
);
|
|
476
|
+
console.log(channel.sessionId); // "ch_a1b2c3..."
|
|
477
|
+
console.log(channel.creditLineReadable); // "$50.00"
|
|
478
|
+
console.log(channel.expiresAt); // "2026-04-23T13:45:00.000Z"
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
### channelConsume(sessionId, cost, description?)
|
|
484
|
+
|
|
485
|
+
Charge against an open channel's credit line. Each call records a usage entry.
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
const usage = await valiron.channelConsume(
|
|
489
|
+
sessionId: string,
|
|
490
|
+
cost: number,
|
|
491
|
+
description?: string,
|
|
492
|
+
): Promise<ChannelConsumeResponse>;
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Returns**: `ChannelConsumeResponse`
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
interface ChannelConsumeResponse {
|
|
499
|
+
requestId: string;
|
|
500
|
+
cost: string;
|
|
501
|
+
costReadable: string;
|
|
502
|
+
description?: string;
|
|
503
|
+
session: {
|
|
504
|
+
consumed: string;
|
|
505
|
+
consumedReadable: string;
|
|
506
|
+
remaining: string;
|
|
507
|
+
remainingReadable: string;
|
|
508
|
+
requestCount: number;
|
|
509
|
+
maxRequests: number | null;
|
|
510
|
+
secondsRemaining: number;
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Example**:
|
|
516
|
+
```typescript
|
|
517
|
+
const usage = await valiron.channelConsume("ch_a1b2c3", 0.50, "GPT-4o inference");
|
|
518
|
+
console.log(usage.session.remainingReadable); // "$49.50"
|
|
519
|
+
console.log(usage.session.requestCount); // 1
|
|
520
|
+
console.log(usage.session.secondsRemaining); // 2685
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
### channelStatus(sessionId)
|
|
526
|
+
|
|
527
|
+
Query current state of a payment channel.
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
const status = await valiron.channelStatus(
|
|
531
|
+
sessionId: string,
|
|
532
|
+
): Promise<ChannelStatusResponse>;
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**Returns**: `ChannelStatusResponse`
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
interface ChannelStatusResponse {
|
|
539
|
+
sessionId: string;
|
|
540
|
+
agentId: string;
|
|
541
|
+
tier: string;
|
|
542
|
+
creditLine: string;
|
|
543
|
+
creditLineReadable: string;
|
|
544
|
+
consumed: string;
|
|
545
|
+
consumedReadable: string;
|
|
546
|
+
remaining: string;
|
|
547
|
+
remainingReadable: string;
|
|
548
|
+
requestCount: number;
|
|
549
|
+
maxRequests: number | null;
|
|
550
|
+
expiresAt: string;
|
|
551
|
+
secondsRemaining: number;
|
|
552
|
+
active: boolean;
|
|
553
|
+
settled: boolean;
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Example**:
|
|
558
|
+
```typescript
|
|
559
|
+
const status = await valiron.channelStatus("ch_a1b2c3");
|
|
560
|
+
if (status.active && !status.settled) {
|
|
561
|
+
console.log(`${status.remainingReadable} remaining, ${status.requestCount} requests served`);
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
### channelSettle(sessionId)
|
|
568
|
+
|
|
569
|
+
Close a payment channel and refund unused USDC to the agent's wallet.
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
const settlement = await valiron.channelSettle(
|
|
573
|
+
sessionId: string,
|
|
574
|
+
): Promise<ChannelSettlementResponse>;
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Returns**: `ChannelSettlementResponse`
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
interface ChannelSettlementResponse {
|
|
581
|
+
sessionId: string;
|
|
582
|
+
settled: boolean;
|
|
583
|
+
totalConsumed: string;
|
|
584
|
+
totalConsumedReadable: string;
|
|
585
|
+
requestsServed: number;
|
|
586
|
+
unusedCredit: string;
|
|
587
|
+
unusedCreditReadable: string;
|
|
588
|
+
refundAmount?: string;
|
|
589
|
+
refundReadable?: string;
|
|
590
|
+
refundSignature?: string; // Solana TX signature
|
|
591
|
+
refundWarning?: string; // set if refund failed
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**Example**:
|
|
596
|
+
```typescript
|
|
597
|
+
const settlement = await valiron.channelSettle("ch_a1b2c3");
|
|
598
|
+
console.log(settlement.totalConsumedReadable); // "$0.50"
|
|
599
|
+
console.log(settlement.refundReadable); // "$49.50"
|
|
600
|
+
console.log(settlement.refundSignature); // "4sGjMW..." (Solana TX)
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
### channelHealth()
|
|
606
|
+
|
|
607
|
+
Check if the payment channel service is running and whether an escrow wallet is configured.
|
|
608
|
+
|
|
609
|
+
```typescript
|
|
610
|
+
const health = await valiron.channelHealth(): Promise<ChannelHealthResponse>;
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
**Returns**: `{ status: string; service: string; escrowAddress: string | null }`
|
package/docs/llms.txt
CHANGED
|
@@ -37,6 +37,24 @@ Body: { "event": "evaluation_complete", "url": "https://your-endpoint.com/hooks"
|
|
|
37
37
|
### Health check
|
|
38
38
|
GET /operator/health
|
|
39
39
|
|
|
40
|
+
### Payment Channels (Solana — USDC credit lines)
|
|
41
|
+
POST /channel/preflight/{agentId}
|
|
42
|
+
Body: { "walletAddress": "SolanaWalletPubkey" }
|
|
43
|
+
|
|
44
|
+
POST /channel/open/{agentId}
|
|
45
|
+
Body: { "walletAddress": "...", "depositSignature": "SolanaTxSig" }
|
|
46
|
+
|
|
47
|
+
POST /channel/consume/{sessionId}
|
|
48
|
+
Headers: Authorization: Bearer {sessionId}
|
|
49
|
+
Body: { "cost": 0.50, "description": "API call" }
|
|
50
|
+
|
|
51
|
+
GET /channel/status/{sessionId}
|
|
52
|
+
|
|
53
|
+
POST /channel/settle/{sessionId}
|
|
54
|
+
Body: {}
|
|
55
|
+
|
|
56
|
+
GET /channel/health
|
|
57
|
+
|
|
40
58
|
## SDK
|
|
41
59
|
|
|
42
60
|
Install: npm install @valiron/sdk
|
|
@@ -60,6 +78,13 @@ if (gate.allow) { /* proceed */ }
|
|
|
60
78
|
const snapshot = await valiron.getAgentSnapshot("AGENT_ID");
|
|
61
79
|
console.log(snapshot.snapshotHash); // "0xabc..."
|
|
62
80
|
console.log(snapshot.previousHash); // "0x0" (genesis)
|
|
81
|
+
|
|
82
|
+
// Payment channels (Solana) — trust-adaptive USDC credit lines
|
|
83
|
+
const preflight = await valiron.channelPreflight("1226", "SolanaWallet...");
|
|
84
|
+
const channel = await valiron.channelOpen("1226", "SolanaWallet...", "depositTxSig");
|
|
85
|
+
const usage = await valiron.channelConsume(channel.sessionId, 0.50, "GPT-4o call");
|
|
86
|
+
const status = await valiron.channelStatus(channel.sessionId);
|
|
87
|
+
const settlement = await valiron.channelSettle(channel.sessionId);
|
|
63
88
|
```
|
|
64
89
|
|
|
65
90
|
## Trust Tiers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valiron/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Valiron — Trust & Reputation Middleware for API Protection",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true});\"",
|
|
21
21
|
"build": "pnpm clean && tsc",
|
|
22
22
|
"dev": "tsc --watch",
|
|
23
|
-
"test": "node test/validate.mjs && node test/validate-examples.mjs",
|
|
23
|
+
"test": "node test/validate.mjs && node test/validate-examples.mjs && npx tsx test/test-identity.ts",
|
|
24
24
|
"prepublishOnly": "pnpm build"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^24.10.1",
|
|
39
|
+
"tsx": "^4.19.0",
|
|
39
40
|
"typescript": "^5.9.3"
|
|
40
41
|
},
|
|
41
42
|
"exports": {
|