@zendfi/sdk 0.5.3 → 0.5.4
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 +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ Accept **SOL, USDC, and USDT** payments in your app with just a few lines of cod
|
|
|
20
20
|
- **Test Mode** — Free devnet testing with no real money
|
|
21
21
|
- **Multi-Network** — Automatic routing to devnet or mainnet
|
|
22
22
|
- **Agentic Intent Protocol** — AI agent payment capabilities with scoped API keys
|
|
23
|
+
- **Session Keys** — On-chain funded wallets for autonomous agent payments
|
|
23
24
|
- **PPP Pricing** — Purchasing Power Parity for global reach (27+ countries)
|
|
24
25
|
- **Payment Intents** — Two-phase commit pattern for reliable checkout
|
|
25
26
|
|
|
@@ -338,6 +339,71 @@ const status = await zendfi.autonomy.getStatus(walletAddress);
|
|
|
338
339
|
await zendfi.autonomy.revoke(delegateId);
|
|
339
340
|
```
|
|
340
341
|
|
|
342
|
+
### Session Keys (On-Chain Funded Wallets)
|
|
343
|
+
|
|
344
|
+
Session keys are pre-funded wallets with spending limits that enable AI agents to make autonomous payments. They use Lit Protocol's PKP (Programmable Key Pairs) for secure on-chain identity.
|
|
345
|
+
|
|
346
|
+
**The Flow:**
|
|
347
|
+
1. **Create** - Agent requests a session key with spending limit
|
|
348
|
+
2. **Approve** - User signs a one-time approval transaction
|
|
349
|
+
3. **Spend** - Agent makes payments autonomously up to the limit
|
|
350
|
+
4. **Top-up** - Optionally add more funds when needed
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
// Step 1: Create a session key
|
|
354
|
+
const key = await zendfi.sessionKeys.create({
|
|
355
|
+
agent_id: 'shopping-assistant',
|
|
356
|
+
user_wallet: 'Hx7B...abc',
|
|
357
|
+
max_amount: 100, // $100 spending limit
|
|
358
|
+
expiry_hours: 24, // Valid for 24 hours
|
|
359
|
+
token: 'USDC',
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// key.session_key_id - Unique identifier
|
|
363
|
+
// key.approval_transaction - Transaction for user to sign
|
|
364
|
+
// key.session_key_address - The funded wallet address
|
|
365
|
+
// key.pkp_public_key - Lit Protocol PKP public key
|
|
366
|
+
|
|
367
|
+
// Step 2: User signs the approval transaction (one-time)
|
|
368
|
+
const signedTx = await wallet.signTransaction(key.approval_transaction);
|
|
369
|
+
await zendfi.sessionKeys.submitApproval(key.session_key_id, {
|
|
370
|
+
signed_transaction: signedTx,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// Step 3: Check status and make payments
|
|
374
|
+
const status = await zendfi.sessionKeys.getStatus(key.session_key_id);
|
|
375
|
+
console.log(`Status: ${status.status}`); // "active"
|
|
376
|
+
console.log(`Remaining: $${status.remaining_amount}`);
|
|
377
|
+
console.log(`Spent: $${status.spent_amount}`);
|
|
378
|
+
console.log(`Transactions: ${status.transaction_count}`);
|
|
379
|
+
|
|
380
|
+
// Step 4: Top-up if needed
|
|
381
|
+
const topUp = await zendfi.sessionKeys.topUp(key.session_key_id, {
|
|
382
|
+
amount: 50, // Add $50 more
|
|
383
|
+
});
|
|
384
|
+
// User signs the top-up transaction
|
|
385
|
+
const signedTopUp = await wallet.signTransaction(topUp.approval_transaction);
|
|
386
|
+
await zendfi.sessionKeys.submitTopUp(key.session_key_id, {
|
|
387
|
+
signed_transaction: signedTopUp,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// Revoke when done
|
|
391
|
+
await zendfi.sessionKeys.revoke(key.session_key_id);
|
|
392
|
+
|
|
393
|
+
// List all session keys
|
|
394
|
+
const keys = await zendfi.sessionKeys.list();
|
|
395
|
+
keys.session_keys.forEach(k => {
|
|
396
|
+
console.log(`${k.session_key_id}: $${k.remaining_amount} remaining`);
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**Session Key Statuses:**
|
|
401
|
+
- `pending_approval` - Waiting for user to sign approval
|
|
402
|
+
- `active` - Ready for payments
|
|
403
|
+
- `exhausted` - Spending limit reached
|
|
404
|
+
- `expired` - Past expiry time
|
|
405
|
+
- `revoked` - Manually revoked
|
|
406
|
+
|
|
341
407
|
### Smart Payments
|
|
342
408
|
|
|
343
409
|
AI-powered payments that automatically apply optimizations:
|