@zendfi/sdk 0.7.4 → 0.8.1
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 +64 -64
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.d.mts +231 -485
- package/dist/index.d.ts +231 -485
- package/dist/index.js +1041 -1374
- package/dist/index.mjs +1029 -772
- package/dist/nextjs.d.mts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/{webhook-handler-D5INiR-l.d.mts → webhook-handler-CgaLeGO4.d.mts} +24 -47
- package/dist/{webhook-handler-D5INiR-l.d.ts → webhook-handler-CgaLeGO4.d.ts} +24 -47
- package/package.json +1 -1
- package/dist/chunk-XERHBDUK.mjs +0 -587
- package/dist/device-bound-crypto-VX7SFVHT.mjs +0 -13
package/README.md
CHANGED
|
@@ -262,23 +262,28 @@ const agentKey = await zendfi.agent.createKey({
|
|
|
262
262
|
rate_limit_per_hour: 100,
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
-
// 2.
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
duration_hours: 24,
|
|
265
|
+
// 2. Create device-bound session key (one-time setup with PIN)
|
|
266
|
+
const sessionKey = await zendfi.sessionKeys.create({
|
|
267
|
+
userWallet: 'Hx7B...abc',
|
|
268
|
+
agentId: 'shopping-assistant-v1',
|
|
269
|
+
agentName: 'Shopping Assistant',
|
|
270
|
+
limitUSDC: 200,
|
|
271
|
+
durationDays: 1,
|
|
272
|
+
pin: '123456',
|
|
274
273
|
});
|
|
275
274
|
|
|
276
|
-
// 3.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
// 3. Unlock for payments (client-side)
|
|
276
|
+
await zendfi.sessionKeys.unlock(sessionKey.sessionKeyId, '123456');
|
|
277
|
+
|
|
278
|
+
// 4. AI agent makes payments autonomously (within limits)
|
|
279
|
+
const payment = await zendfi.sessionKeys.makePayment(
|
|
280
|
+
sessionKey.sessionKeyId,
|
|
281
|
+
{
|
|
282
|
+
recipientWallet: 'merchant-wallet',
|
|
283
|
+
amountUSD: 25.00,
|
|
284
|
+
description: 'Coffee order',
|
|
285
|
+
}
|
|
286
|
+
);
|
|
282
287
|
|
|
283
288
|
// Done! User approved once, AI pays within limits
|
|
284
289
|
```
|
|
@@ -587,69 +592,64 @@ const status = await zendfi.autonomy.getStatus(walletAddress);
|
|
|
587
592
|
await zendfi.autonomy.revoke(delegateId);
|
|
588
593
|
```
|
|
589
594
|
|
|
590
|
-
### Session Keys (
|
|
595
|
+
### Session Keys (Device-Bound Non-Custodial)
|
|
591
596
|
|
|
592
|
-
Session keys are
|
|
597
|
+
Session keys are TRUE non-custodial wallets where:
|
|
598
|
+
- **Client generates keypair** (backend NEVER sees private key)
|
|
599
|
+
- **PIN encryption** using Argon2id + AES-256-GCM
|
|
600
|
+
- **Device fingerprint binding** for security
|
|
601
|
+
- **Autonomous payments** within spending limits
|
|
593
602
|
|
|
594
603
|
**The Flow:**
|
|
595
|
-
1. **Create** -
|
|
596
|
-
2. **
|
|
597
|
-
3. **
|
|
598
|
-
4. **Top-up** - Optionally add more funds when needed
|
|
604
|
+
1. **Create** - Client generates keypair, encrypts with PIN (SDK handles this)
|
|
605
|
+
2. **Unlock** - Decrypt with PIN once, enable auto-signing
|
|
606
|
+
3. **Pay** - Make payments instantly without re-entering PIN
|
|
599
607
|
|
|
600
608
|
```typescript
|
|
601
|
-
//
|
|
609
|
+
// Create a device-bound session key
|
|
602
610
|
const key = await zendfi.sessionKeys.create({
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
611
|
+
userWallet: 'Hx7B...abc',
|
|
612
|
+
agentId: 'shopping-assistant-v1',
|
|
613
|
+
agentName: 'AI Shopping Assistant',
|
|
614
|
+
limitUSDC: 100,
|
|
615
|
+
durationDays: 7,
|
|
616
|
+
pin: '123456', // SDK encrypts keypair with this
|
|
617
|
+
generateRecoveryQR: true,
|
|
607
618
|
});
|
|
608
619
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
//
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
620
|
+
console.log(`Session key: ${key.sessionKeyId}`);
|
|
621
|
+
console.log(`Session wallet: ${key.sessionWallet}`);
|
|
622
|
+
console.log(`Recovery QR: ${key.recoveryQR}`);
|
|
623
|
+
|
|
624
|
+
// Session key is auto-unlocked after create()
|
|
625
|
+
// Make payments without PIN!
|
|
626
|
+
const payment = await zendfi.sessionKeys.makePayment(
|
|
627
|
+
key.sessionKeyId,
|
|
628
|
+
{
|
|
629
|
+
recipientWallet: '8xYZA...',
|
|
630
|
+
amountUSD: 5.0,
|
|
631
|
+
description: 'Coffee purchase',
|
|
632
|
+
}
|
|
633
|
+
);
|
|
619
634
|
|
|
620
|
-
//
|
|
621
|
-
|
|
622
|
-
console.log(`Status: ${status.status}`); // "active"
|
|
623
|
-
console.log(`Remaining: $${status.remaining_usdc}`);
|
|
624
|
-
console.log(`Spent: $${status.used_amount_usdc}`);
|
|
625
|
-
console.log(`Transactions: ${status.transaction_count}`);
|
|
635
|
+
// Or unlock an existing session key
|
|
636
|
+
await zendfi.sessionKeys.unlock(key.sessionKeyId, '123456');
|
|
626
637
|
|
|
627
|
-
//
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
const signedTopUp = await wallet.signTransaction(topUp.approval_transaction);
|
|
633
|
-
await zendfi.sessionKeys.submitTopUp(key.session_key_id, {
|
|
634
|
-
signed_transaction: signedTopUp,
|
|
635
|
-
});
|
|
638
|
+
// Check status
|
|
639
|
+
const status = await zendfi.sessionKeys.getStatus(key.sessionKeyId);
|
|
640
|
+
console.log(`Active: ${status.isActive}`);
|
|
641
|
+
console.log(`Remaining: $${status.remainingUSDC}`);
|
|
642
|
+
console.log(`Spent: $${status.usedAmountUSDC}`);
|
|
636
643
|
|
|
637
644
|
// Revoke when done
|
|
638
|
-
await zendfi.sessionKeys.revoke(key.
|
|
639
|
-
|
|
640
|
-
// List all session keys
|
|
641
|
-
const keys = await zendfi.sessionKeys.list();
|
|
642
|
-
keys.session_keys.forEach(k => {
|
|
643
|
-
console.log(`${k.session_key_id}: $${k.remaining_amount} remaining`);
|
|
644
|
-
});
|
|
645
|
+
await zendfi.sessionKeys.revoke(key.sessionKeyId);
|
|
645
646
|
```
|
|
646
647
|
|
|
647
|
-
**
|
|
648
|
-
-
|
|
649
|
-
-
|
|
650
|
-
-
|
|
651
|
-
-
|
|
652
|
-
- `revoked` - Manually revoked
|
|
648
|
+
**Security Features:**
|
|
649
|
+
- **Backend cannot decrypt** - Keys encrypted client-side
|
|
650
|
+
- **Device fingerprint** - Binds key to specific device
|
|
651
|
+
- **Recovery QR** - Migrate to new device
|
|
652
|
+
- **Auto-signing cache** - Instant payments after unlock
|
|
653
653
|
|
|
654
654
|
### Smart Payments
|
|
655
655
|
|
package/dist/express.d.mts
CHANGED
package/dist/express.d.ts
CHANGED