@zendfi/sdk 0.5.4 → 0.5.7
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 +139 -61
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.d.mts +104 -2
- package/dist/index.d.ts +104 -2
- package/dist/index.js +103 -1
- package/dist/index.mjs +103 -1
- package/dist/nextjs.d.mts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/{webhook-handler-B-RdABQr.d.mts → webhook-handler-D5CigE9G.d.mts} +34 -1
- package/dist/{webhook-handler-B-RdABQr.d.ts → webhook-handler-D5CigE9G.d.ts} +34 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,28 +1,64 @@
|
|
|
1
1
|
# @zendfi/sdk
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> The only crypto payment API built for the AI era
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@zendfi/sdk)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
Accept **SOL, USDC, and USDT** payments in
|
|
8
|
+
Accept **SOL, USDC, and USDT** payments in 7 lines of code. Built for e-commerce. Ready for AI agents.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { zendfi } from '@zendfi/sdk';
|
|
12
|
+
|
|
13
|
+
const payment = await zendfi.createPayment({
|
|
14
|
+
amount: 50,
|
|
15
|
+
description: 'Premium subscription',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
console.log(payment.payment_url); // Send customer here
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**That's it.** Works for traditional payments AND AI agents. Same API.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why ZendFi?
|
|
26
|
+
|
|
27
|
+
| Feature | Stripe | PayPal | **ZendFi** |
|
|
28
|
+
|---------|--------|--------|------------|
|
|
29
|
+
| **Fees** | 2.9% + $0.30 | 3.5% + $0.49 | **0.6% flat** ✨ |
|
|
30
|
+
| **Settlement** | 7 days | 3-5 days | **Instant** ✨ |
|
|
31
|
+
| **Crypto Native** | Via 3rd party | Via 3rd party | **Built-in** ✨ |
|
|
32
|
+
| **AI Agent Ready** | ❌ | ❌ | **✅ Native** ✨ |
|
|
33
|
+
| **Setup Time** | 30 min | 30 min | **5 min** ✨ |
|
|
34
|
+
|
|
35
|
+
**Save 81% on fees.** Get paid instantly. Scale to AI when ready.
|
|
9
36
|
|
|
10
37
|
---
|
|
11
38
|
|
|
12
39
|
## Features
|
|
13
40
|
|
|
14
|
-
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **Idempotency** — Automatic duplicate prevention for safe retries
|
|
19
|
-
- **Webhook Helpers** — Auto-verified handlers for Next.js, Express, and more
|
|
41
|
+
### 🚀 **Core Payments** (Start Here)
|
|
42
|
+
- **Simple Payments** — QR codes, payment links, instant settlements
|
|
43
|
+
- **Payment Links** — Reusable checkout pages for social/email
|
|
44
|
+
- **Webhooks** — Real-time notifications with auto-verification
|
|
20
45
|
- **Test Mode** — Free devnet testing with no real money
|
|
21
|
-
- **
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
46
|
+
- **Type-Safe** — Full TypeScript support with auto-completion
|
|
47
|
+
|
|
48
|
+
### 💼 **Scale Up** (When You Grow)
|
|
49
|
+
- **Subscriptions** — Recurring billing with trials
|
|
50
|
+
- **Installments** — Buy now, pay later flows
|
|
51
|
+
- **Invoices** — Professional invoicing with email
|
|
52
|
+
- **Payment Splits** — Revenue sharing for marketplaces
|
|
53
|
+
|
|
54
|
+
### 🤖 **AI-Ready** (Optional Advanced)
|
|
55
|
+
- **Agent Keys** — Scoped API keys for AI with spending limits
|
|
56
|
+
- **Session Keys** — Pre-funded wallets for autonomous payments
|
|
57
|
+
- **Payment Intents** — Two-phase commit for reliable checkout
|
|
58
|
+
- **PPP Pricing** — Auto-adjust prices for 27+ countries
|
|
59
|
+
- **Smart Payments** — AI-optimized payment routing
|
|
60
|
+
|
|
61
|
+
Don't need AI features? **Ignore them.** The SDK works perfectly for traditional payments.
|
|
26
62
|
|
|
27
63
|
---
|
|
28
64
|
|
|
@@ -42,7 +78,7 @@ yarn add @zendfi/sdk
|
|
|
42
78
|
|
|
43
79
|
### 1. Get your API key
|
|
44
80
|
|
|
45
|
-
Sign up at [zendfi.tech](https://zendfi.tech)
|
|
81
|
+
Sign up at [zendfi.tech](https://zendfi.tech) to get your API keys.
|
|
46
82
|
|
|
47
83
|
### 2. Set environment variables
|
|
48
84
|
|
|
@@ -106,6 +142,9 @@ For devnet testing:
|
|
|
106
142
|
1. Use your `zfi_test_` API key
|
|
107
143
|
2. Get free SOL from [sol-faucet.com](https://www.sol-faucet.com/)
|
|
108
144
|
3. All transactions use test tokens (zero value)
|
|
145
|
+
4. Devnet SOL is NOT real SOL (zero value)
|
|
146
|
+
6. Use devnet-compatible wallets (Phantom, Solflare support devnet)
|
|
147
|
+
7. Switch network in wallet: Settings → Developer Settings → Change Network → Devnet
|
|
109
148
|
|
|
110
149
|
### Going Live
|
|
111
150
|
|
|
@@ -133,47 +172,90 @@ This covers:
|
|
|
133
172
|
|
|
134
173
|
---
|
|
135
174
|
|
|
136
|
-
##
|
|
175
|
+
## 🤖 AI-Ready Features (Optional Advanced)
|
|
137
176
|
|
|
138
|
-
|
|
177
|
+
Building AI agents? ZendFi has native support for autonomous payments with cryptographic security and spending limits.
|
|
139
178
|
|
|
140
|
-
###
|
|
179
|
+
### When Do I Need This?
|
|
180
|
+
|
|
181
|
+
**Use traditional payments if:**
|
|
182
|
+
- Building e-commerce, SaaS, or creator tools
|
|
183
|
+
- User clicks "Pay" button for each transaction
|
|
184
|
+
- Standard checkout flow
|
|
185
|
+
|
|
186
|
+
**Use AI features if:**
|
|
187
|
+
- Building AI agents that make purchases
|
|
188
|
+
- Need autonomous payments without per-transaction approval
|
|
189
|
+
- Want spending limits and scoped permissions
|
|
190
|
+
|
|
191
|
+
### Quick Example: AI Agent Payment
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { zendfi } from '@zendfi/sdk';
|
|
141
195
|
|
|
142
|
-
|
|
196
|
+
// 1. Create agent key with limited permissions
|
|
197
|
+
const agentKey = await zendfi.agent.createKey({
|
|
198
|
+
name: 'Shopping Assistant',
|
|
199
|
+
agent_id: 'shopping-assistant-v1',
|
|
200
|
+
scopes: ['create_payments'],
|
|
201
|
+
rate_limit_per_hour: 100,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// 2. User approves spending session (one-time)
|
|
205
|
+
const session = await zendfi.agent.createSession({
|
|
206
|
+
agent_id: 'shopping-assistant-v1',
|
|
207
|
+
user_wallet: 'Hx7B...abc',
|
|
208
|
+
limits: {
|
|
209
|
+
max_per_transaction: 50, // $50 max per payment
|
|
210
|
+
max_per_day: 200, // $200 daily cap
|
|
211
|
+
},
|
|
212
|
+
duration_hours: 24,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// 3. AI agent makes payments autonomously (within limits)
|
|
216
|
+
const payment = await zendfi.agent.pay({
|
|
217
|
+
session_token: session.session_token,
|
|
218
|
+
amount: 25.00,
|
|
219
|
+
description: 'Coffee order',
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Done! User approved once, AI pays within limits
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Learn more:** [AI Payments Documentation](https://docs.zendfi.tech/agentic)
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 📚 Core API Reference
|
|
230
|
+
|
|
231
|
+
### Namespaced APIs
|
|
143
232
|
|
|
144
233
|
```typescript
|
|
145
234
|
import { zendfi } from '@zendfi/sdk';
|
|
146
235
|
|
|
147
|
-
//
|
|
148
|
-
zendfi.
|
|
149
|
-
zendfi.
|
|
150
|
-
zendfi.
|
|
151
|
-
|
|
152
|
-
// Payment
|
|
153
|
-
zendfi.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
zendfi.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
zendfi.
|
|
162
|
-
zendfi.
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
zendfi.
|
|
166
|
-
zendfi.
|
|
167
|
-
|
|
168
|
-
// Session Keys - On-chain funded wallets with PKP identity
|
|
169
|
-
zendfi.sessionKeys.create(...)
|
|
170
|
-
zendfi.sessionKeys.submitApproval(...)
|
|
171
|
-
zendfi.sessionKeys.getStatus(...)
|
|
172
|
-
zendfi.sessionKeys.topUp(...)
|
|
173
|
-
zendfi.sessionKeys.revoke(...)
|
|
236
|
+
// Traditional Payments (Most Common)
|
|
237
|
+
zendfi.createPayment(...)
|
|
238
|
+
zendfi.getPayment(...)
|
|
239
|
+
zendfi.listPayments(...)
|
|
240
|
+
|
|
241
|
+
// Payment Links
|
|
242
|
+
zendfi.createPaymentLink(...)
|
|
243
|
+
|
|
244
|
+
// Subscriptions
|
|
245
|
+
zendfi.createSubscription(...)
|
|
246
|
+
zendfi.cancelSubscription(...)
|
|
247
|
+
|
|
248
|
+
// AI Features (Optional)
|
|
249
|
+
zendfi.agent.createKey(...) // Scoped API keys
|
|
250
|
+
zendfi.agent.createSession(...) // Spending limits
|
|
251
|
+
zendfi.agent.pay(...) // Autonomous payments
|
|
252
|
+
zendfi.intents.create(...) // Two-phase checkout
|
|
253
|
+
zendfi.sessionKeys.create(...) // Pre-funded wallets
|
|
254
|
+
zendfi.autonomy.enable(...) // User-granted delegation
|
|
255
|
+
zendfi.pricing.getPPPFactor(...) // Global pricing
|
|
174
256
|
```
|
|
175
257
|
|
|
176
|
-
###
|
|
258
|
+
### Core Payments
|
|
177
259
|
|
|
178
260
|
Create scoped API keys for AI agents with limited permissions:
|
|
179
261
|
|
|
@@ -323,13 +405,10 @@ Enable agents to make payments without per-transaction approval:
|
|
|
323
405
|
|
|
324
406
|
```typescript
|
|
325
407
|
// Enable autonomous mode for a wallet
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
max_per_transaction_usd: 25,
|
|
331
|
-
duration_hours: 24,
|
|
332
|
-
allowed_categories: ['subscriptions', 'digital_goods'],
|
|
408
|
+
await zendfi.autonomy.enable(sessionKeyId, {
|
|
409
|
+
max_amount_usd: 100, // Total amount, not per-day
|
|
410
|
+
duration_hours: 24, // Duration
|
|
411
|
+
delegation_signature: sig, // Required signature
|
|
333
412
|
});
|
|
334
413
|
|
|
335
414
|
// Check autonomy status
|
|
@@ -352,17 +431,16 @@ Session keys are pre-funded wallets with spending limits that enable AI agents t
|
|
|
352
431
|
```typescript
|
|
353
432
|
// Step 1: Create a session key
|
|
354
433
|
const key = await zendfi.sessionKeys.create({
|
|
355
|
-
agent_id: 'shopping-assistant',
|
|
356
434
|
user_wallet: 'Hx7B...abc',
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
435
|
+
limit_usdc: 100,
|
|
436
|
+
duration_days: 7,
|
|
437
|
+
device_fingerprint: await generateFingerprint(),
|
|
360
438
|
});
|
|
361
439
|
|
|
362
440
|
// key.session_key_id - Unique identifier
|
|
363
441
|
// key.approval_transaction - Transaction for user to sign
|
|
364
|
-
// key.
|
|
365
|
-
// key.pkp_public_key - Lit Protocol PKP public key
|
|
442
|
+
// key.session_wallet - The funded wallet address
|
|
443
|
+
// key.pkp_public_key - Lit Protocol PKP public key NB: This only exists if mint_pkp is set to true in sessions
|
|
366
444
|
|
|
367
445
|
// Step 2: User signs the approval transaction (one-time)
|
|
368
446
|
const signedTx = await wallet.signTransaction(key.approval_transaction);
|
|
@@ -373,8 +451,8 @@ await zendfi.sessionKeys.submitApproval(key.session_key_id, {
|
|
|
373
451
|
// Step 3: Check status and make payments
|
|
374
452
|
const status = await zendfi.sessionKeys.getStatus(key.session_key_id);
|
|
375
453
|
console.log(`Status: ${status.status}`); // "active"
|
|
376
|
-
console.log(`Remaining: $${status.
|
|
377
|
-
console.log(`Spent: $${status.
|
|
454
|
+
console.log(`Remaining: $${status.remaining_usdc}`);
|
|
455
|
+
console.log(`Spent: $${status.used_amount_usdc}`);
|
|
378
456
|
console.log(`Transactions: ${status.transaction_count}`);
|
|
379
457
|
|
|
380
458
|
// Step 4: Top-up if needed
|
package/dist/express.d.mts
CHANGED
package/dist/express.d.ts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CreateAgentApiKeyRequest, A as AgentApiKey, b as CreateAgentSessionRequest, c as AgentSession, d as AgentPaymentRequest, e as AgentPaymentResponse, f as AgentAnalytics, g as CreatePaymentIntentRequest, P as PaymentIntent, h as ConfirmPaymentIntentRequest, i as PaymentIntentEvent, j as PPPFactor, k as PricingSuggestionRequest, l as PricingSuggestion, E as EnableAutonomyRequest, m as EnableAutonomyResponse, n as AutonomyStatus, S as SmartPaymentRequest, o as SmartPaymentResponse, p as CreateSessionKeyRequest, q as CreateSessionKeyResponse, r as CreateDeviceBoundSessionKeyRequest$1, s as CreateDeviceBoundSessionKeyResponse$1, t as SubmitSignedTransactionRequest, u as SubmitTransactionResponse, v as SessionKeyStatus, w as SessionKeyListResponse, T as TopUpSessionKeyRequest, x as TopUpSessionKeyResponse, Z as ZendFiConfig, y as CreatePaymentRequest, z as Payment, L as ListPaymentsRequest, B as PaginatedResponse, D as CreateSubscriptionPlanRequest, F as SubscriptionPlan, G as CreateSubscriptionRequest, H as Subscription, I as CreatePaymentLinkRequest, J as PaymentLink, K as CreateInstallmentPlanRequest, M as InstallmentPlan, N as CreateEscrowRequest, O as Escrow, Q as ApproveEscrowRequest, R as RefundEscrowRequest, U as DisputeEscrowRequest, V as CreateInvoiceRequest, X as Invoice, Y as VerifyWebhookRequest, _ as WebhookPayload } from './webhook-handler-
|
|
2
|
-
export { a5 as AgentKeyId, ao as ApiKeyMode, aD as ApiKeyScope, aJ as AutonomousDelegate, a2 as Brand, aG as CaptureMethod, aA as CreateInstallmentPlanResponse, ap as Currency, an as Environment, a9 as EscrowId, au as EscrowStatus, aa as InstallmentPlanId, at as InstallmentPlanStatus, az as InstallmentScheduleItem, ac as IntentId, a7 as InvoiceId, aC as InvoiceLineItem, av as InvoiceStatus, a6 as MerchantId, aI as PPPConfig, a3 as PaymentId, aF as PaymentIntentStatus, ab as PaymentLinkCode, ar as PaymentStatus, aq as PaymentToken, aB as ReleaseCondition, aK as RevokeAutonomyRequest,
|
|
1
|
+
import { C as CreateAgentApiKeyRequest, A as AgentApiKey, b as CreateAgentSessionRequest, c as AgentSession, d as AgentPaymentRequest, e as AgentPaymentResponse, f as AgentAnalytics, g as CreatePaymentIntentRequest, P as PaymentIntent, h as ConfirmPaymentIntentRequest, i as PaymentIntentEvent, j as PPPFactor, k as PricingSuggestionRequest, l as PricingSuggestion, E as EnableAutonomyRequest, m as EnableAutonomyResponse, n as AutonomyStatus, S as SmartPaymentRequest, o as SmartPaymentResponse, p as CreateSessionKeyRequest, q as CreateSessionKeyResponse, r as CreateDeviceBoundSessionKeyRequest$1, s as CreateDeviceBoundSessionKeyResponse$1, t as SubmitSignedTransactionRequest, u as SubmitTransactionResponse, v as SessionKeyStatus, w as SessionKeyListResponse, T as TopUpSessionKeyRequest, x as TopUpSessionKeyResponse, Z as ZendFiConfig, y as CreatePaymentRequest, z as Payment, L as ListPaymentsRequest, B as PaginatedResponse, D as CreateSubscriptionPlanRequest, F as SubscriptionPlan, G as CreateSubscriptionRequest, H as Subscription, I as CreatePaymentLinkRequest, J as PaymentLink, K as CreateInstallmentPlanRequest, M as InstallmentPlan, N as CreateEscrowRequest, O as Escrow, Q as ApproveEscrowRequest, R as RefundEscrowRequest, U as DisputeEscrowRequest, V as CreateInvoiceRequest, X as Invoice, Y as VerifyWebhookRequest, _ as WebhookPayload } from './webhook-handler-D5CigE9G.mjs';
|
|
2
|
+
export { a5 as AgentKeyId, ao as ApiKeyMode, aD as ApiKeyScope, aJ as AutonomousDelegate, a2 as Brand, aG as CaptureMethod, aA as CreateInstallmentPlanResponse, ap as Currency, an as Environment, a9 as EscrowId, au as EscrowStatus, aa as InstallmentPlanId, at as InstallmentPlanStatus, az as InstallmentScheduleItem, ac as IntentId, a7 as InvoiceId, aC as InvoiceLineItem, av as InvoiceStatus, aO as LinkedSessionInfo, a6 as MerchantId, aI as PPPConfig, a3 as PaymentId, aF as PaymentIntentStatus, ab as PaymentLinkCode, ar as PaymentStatus, aq as PaymentToken, aB as ReleaseCondition, aK as RevokeAutonomyRequest, aP as SecurityStatus, a4 as SessionId, aM as SessionKeyInstructions, aN as SessionKeySecurityInfo, aQ as SessionKeyStats, aE as SessionLimits, aL as SmartPaymentStatus, ay as SplitRecipient, aw as SplitStatus, a8 as SubscriptionId, as as SubscriptionStatus, aH as UserProfile, ax as WebhookEvent, a1 as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, a0 as WebhookResult, af as asAgentKeyId, aj as asEscrowId, ak as asInstallmentPlanId, am as asIntentId, ah as asInvoiceId, ag as asMerchantId, ad as asPaymentId, al as asPaymentLinkCode, ae as asSessionId, ai as asSubscriptionId, $ as processWebhook } from './webhook-handler-D5CigE9G.mjs';
|
|
3
3
|
import { Transaction, Keypair } from '@solana/web3.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -872,6 +872,7 @@ declare class SessionKeysAPI {
|
|
|
872
872
|
*
|
|
873
873
|
* @example
|
|
874
874
|
* ```typescript
|
|
875
|
+
* // Basic creation
|
|
875
876
|
* const result = await zendfi.sessionKeys.create({
|
|
876
877
|
* user_wallet: 'Hx7B...abc',
|
|
877
878
|
* limit_usdc: 100,
|
|
@@ -879,6 +880,15 @@ declare class SessionKeysAPI {
|
|
|
879
880
|
* device_fingerprint: deviceFingerprint,
|
|
880
881
|
* });
|
|
881
882
|
*
|
|
883
|
+
* // Create with linked session for policy enforcement
|
|
884
|
+
* const result = await zendfi.sessionKeys.create({
|
|
885
|
+
* user_wallet: 'Hx7B...abc',
|
|
886
|
+
* limit_usdc: 500,
|
|
887
|
+
* duration_days: 7,
|
|
888
|
+
* device_fingerprint: deviceFingerprint,
|
|
889
|
+
* link_session_id: session.id, // Links to existing session
|
|
890
|
+
* });
|
|
891
|
+
*
|
|
882
892
|
* console.log(`Session key: ${result.session_key_id}`);
|
|
883
893
|
* console.log('Please sign the approval transaction');
|
|
884
894
|
* ```
|
|
@@ -1056,6 +1066,98 @@ declare class SessionKeysAPI {
|
|
|
1056
1066
|
message: string;
|
|
1057
1067
|
};
|
|
1058
1068
|
}>;
|
|
1069
|
+
/**
|
|
1070
|
+
* Link a session key to an AI session for policy enforcement
|
|
1071
|
+
*
|
|
1072
|
+
* When linked, payments through this session key will check both:
|
|
1073
|
+
* 1. Session key balance (hard cap)
|
|
1074
|
+
* 2. AI session limits (per-tx, daily, weekly, monthly)
|
|
1075
|
+
*
|
|
1076
|
+
* This provides defense-in-depth: the session key provides signing
|
|
1077
|
+
* capability while the session enforces granular spending policies.
|
|
1078
|
+
*
|
|
1079
|
+
* @param sessionKeyId - UUID of the session key
|
|
1080
|
+
* @param sessionId - UUID of the AI session to link
|
|
1081
|
+
* @returns Updated session key status
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```typescript
|
|
1085
|
+
* // Create a session with limits
|
|
1086
|
+
* const session = await zendfi.agent.createSession({
|
|
1087
|
+
* agent_id: 'shopping-bot',
|
|
1088
|
+
* user_wallet: userWallet,
|
|
1089
|
+
* limits: {
|
|
1090
|
+
* max_per_transaction: 25,
|
|
1091
|
+
* max_per_day: 100,
|
|
1092
|
+
* },
|
|
1093
|
+
* duration_hours: 24,
|
|
1094
|
+
* });
|
|
1095
|
+
*
|
|
1096
|
+
* // Create and fund a session key
|
|
1097
|
+
* const key = await zendfi.sessionKeys.create({
|
|
1098
|
+
* user_wallet: userWallet,
|
|
1099
|
+
* limit_usdc: 500, // Fund with $500
|
|
1100
|
+
* duration_days: 7,
|
|
1101
|
+
* device_fingerprint: fp,
|
|
1102
|
+
* });
|
|
1103
|
+
*
|
|
1104
|
+
* // Link them together
|
|
1105
|
+
* await zendfi.sessionKeys.linkSession(key.session_key_id, session.id);
|
|
1106
|
+
*
|
|
1107
|
+
* // Now payments will:
|
|
1108
|
+
* // - Be limited to $25 per transaction (session policy)
|
|
1109
|
+
* // - Be limited to $100 per day (session policy)
|
|
1110
|
+
* // - Never exceed $500 total (session key balance)
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
linkSession(sessionKeyId: string, sessionId: string): Promise<{
|
|
1114
|
+
success: boolean;
|
|
1115
|
+
session_key_id: string;
|
|
1116
|
+
linked_session_id: string;
|
|
1117
|
+
message: string;
|
|
1118
|
+
}>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Unlink a session key from its AI session
|
|
1121
|
+
*
|
|
1122
|
+
* After unlinking, the session key will only be limited by its funded balance.
|
|
1123
|
+
*
|
|
1124
|
+
* @param sessionKeyId - UUID of the session key
|
|
1125
|
+
* @returns Result of the unlink operation
|
|
1126
|
+
*/
|
|
1127
|
+
unlinkSession(sessionKeyId: string): Promise<{
|
|
1128
|
+
success: boolean;
|
|
1129
|
+
session_key_id: string;
|
|
1130
|
+
message: string;
|
|
1131
|
+
}>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Check if a payment amount is allowed
|
|
1134
|
+
*
|
|
1135
|
+
* Checks both session key balance and linked session limits (if any).
|
|
1136
|
+
* Useful for pre-validating payments before attempting them.
|
|
1137
|
+
*
|
|
1138
|
+
* @param sessionKeyId - UUID of the session key
|
|
1139
|
+
* @param amount - Amount in USD to check
|
|
1140
|
+
* @returns Whether the payment is allowed and the effective limit
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* const check = await zendfi.sessionKeys.canAfford(keyId, 50);
|
|
1145
|
+
*
|
|
1146
|
+
* if (check.allowed) {
|
|
1147
|
+
* await zendfi.smart.execute({ ... });
|
|
1148
|
+
* } else {
|
|
1149
|
+
* console.log(`Cannot afford: ${check.reason}`);
|
|
1150
|
+
* console.log(`Effective limit: $${check.effective_limit}`);
|
|
1151
|
+
* }
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
canAfford(sessionKeyId: string, amount: number): Promise<{
|
|
1155
|
+
allowed: boolean;
|
|
1156
|
+
reason?: string;
|
|
1157
|
+
effective_limit: number;
|
|
1158
|
+
session_key_remaining: number;
|
|
1159
|
+
session_remaining_today?: number;
|
|
1160
|
+
}>;
|
|
1059
1161
|
}
|
|
1060
1162
|
|
|
1061
1163
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CreateAgentApiKeyRequest, A as AgentApiKey, b as CreateAgentSessionRequest, c as AgentSession, d as AgentPaymentRequest, e as AgentPaymentResponse, f as AgentAnalytics, g as CreatePaymentIntentRequest, P as PaymentIntent, h as ConfirmPaymentIntentRequest, i as PaymentIntentEvent, j as PPPFactor, k as PricingSuggestionRequest, l as PricingSuggestion, E as EnableAutonomyRequest, m as EnableAutonomyResponse, n as AutonomyStatus, S as SmartPaymentRequest, o as SmartPaymentResponse, p as CreateSessionKeyRequest, q as CreateSessionKeyResponse, r as CreateDeviceBoundSessionKeyRequest$1, s as CreateDeviceBoundSessionKeyResponse$1, t as SubmitSignedTransactionRequest, u as SubmitTransactionResponse, v as SessionKeyStatus, w as SessionKeyListResponse, T as TopUpSessionKeyRequest, x as TopUpSessionKeyResponse, Z as ZendFiConfig, y as CreatePaymentRequest, z as Payment, L as ListPaymentsRequest, B as PaginatedResponse, D as CreateSubscriptionPlanRequest, F as SubscriptionPlan, G as CreateSubscriptionRequest, H as Subscription, I as CreatePaymentLinkRequest, J as PaymentLink, K as CreateInstallmentPlanRequest, M as InstallmentPlan, N as CreateEscrowRequest, O as Escrow, Q as ApproveEscrowRequest, R as RefundEscrowRequest, U as DisputeEscrowRequest, V as CreateInvoiceRequest, X as Invoice, Y as VerifyWebhookRequest, _ as WebhookPayload } from './webhook-handler-
|
|
2
|
-
export { a5 as AgentKeyId, ao as ApiKeyMode, aD as ApiKeyScope, aJ as AutonomousDelegate, a2 as Brand, aG as CaptureMethod, aA as CreateInstallmentPlanResponse, ap as Currency, an as Environment, a9 as EscrowId, au as EscrowStatus, aa as InstallmentPlanId, at as InstallmentPlanStatus, az as InstallmentScheduleItem, ac as IntentId, a7 as InvoiceId, aC as InvoiceLineItem, av as InvoiceStatus, a6 as MerchantId, aI as PPPConfig, a3 as PaymentId, aF as PaymentIntentStatus, ab as PaymentLinkCode, ar as PaymentStatus, aq as PaymentToken, aB as ReleaseCondition, aK as RevokeAutonomyRequest,
|
|
1
|
+
import { C as CreateAgentApiKeyRequest, A as AgentApiKey, b as CreateAgentSessionRequest, c as AgentSession, d as AgentPaymentRequest, e as AgentPaymentResponse, f as AgentAnalytics, g as CreatePaymentIntentRequest, P as PaymentIntent, h as ConfirmPaymentIntentRequest, i as PaymentIntentEvent, j as PPPFactor, k as PricingSuggestionRequest, l as PricingSuggestion, E as EnableAutonomyRequest, m as EnableAutonomyResponse, n as AutonomyStatus, S as SmartPaymentRequest, o as SmartPaymentResponse, p as CreateSessionKeyRequest, q as CreateSessionKeyResponse, r as CreateDeviceBoundSessionKeyRequest$1, s as CreateDeviceBoundSessionKeyResponse$1, t as SubmitSignedTransactionRequest, u as SubmitTransactionResponse, v as SessionKeyStatus, w as SessionKeyListResponse, T as TopUpSessionKeyRequest, x as TopUpSessionKeyResponse, Z as ZendFiConfig, y as CreatePaymentRequest, z as Payment, L as ListPaymentsRequest, B as PaginatedResponse, D as CreateSubscriptionPlanRequest, F as SubscriptionPlan, G as CreateSubscriptionRequest, H as Subscription, I as CreatePaymentLinkRequest, J as PaymentLink, K as CreateInstallmentPlanRequest, M as InstallmentPlan, N as CreateEscrowRequest, O as Escrow, Q as ApproveEscrowRequest, R as RefundEscrowRequest, U as DisputeEscrowRequest, V as CreateInvoiceRequest, X as Invoice, Y as VerifyWebhookRequest, _ as WebhookPayload } from './webhook-handler-D5CigE9G.js';
|
|
2
|
+
export { a5 as AgentKeyId, ao as ApiKeyMode, aD as ApiKeyScope, aJ as AutonomousDelegate, a2 as Brand, aG as CaptureMethod, aA as CreateInstallmentPlanResponse, ap as Currency, an as Environment, a9 as EscrowId, au as EscrowStatus, aa as InstallmentPlanId, at as InstallmentPlanStatus, az as InstallmentScheduleItem, ac as IntentId, a7 as InvoiceId, aC as InvoiceLineItem, av as InvoiceStatus, aO as LinkedSessionInfo, a6 as MerchantId, aI as PPPConfig, a3 as PaymentId, aF as PaymentIntentStatus, ab as PaymentLinkCode, ar as PaymentStatus, aq as PaymentToken, aB as ReleaseCondition, aK as RevokeAutonomyRequest, aP as SecurityStatus, a4 as SessionId, aM as SessionKeyInstructions, aN as SessionKeySecurityInfo, aQ as SessionKeyStats, aE as SessionLimits, aL as SmartPaymentStatus, ay as SplitRecipient, aw as SplitStatus, a8 as SubscriptionId, as as SubscriptionStatus, aH as UserProfile, ax as WebhookEvent, a1 as WebhookEventHandler, W as WebhookHandlerConfig, a as WebhookHandlers, a0 as WebhookResult, af as asAgentKeyId, aj as asEscrowId, ak as asInstallmentPlanId, am as asIntentId, ah as asInvoiceId, ag as asMerchantId, ad as asPaymentId, al as asPaymentLinkCode, ae as asSessionId, ai as asSubscriptionId, $ as processWebhook } from './webhook-handler-D5CigE9G.js';
|
|
3
3
|
import { Transaction, Keypair } from '@solana/web3.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -872,6 +872,7 @@ declare class SessionKeysAPI {
|
|
|
872
872
|
*
|
|
873
873
|
* @example
|
|
874
874
|
* ```typescript
|
|
875
|
+
* // Basic creation
|
|
875
876
|
* const result = await zendfi.sessionKeys.create({
|
|
876
877
|
* user_wallet: 'Hx7B...abc',
|
|
877
878
|
* limit_usdc: 100,
|
|
@@ -879,6 +880,15 @@ declare class SessionKeysAPI {
|
|
|
879
880
|
* device_fingerprint: deviceFingerprint,
|
|
880
881
|
* });
|
|
881
882
|
*
|
|
883
|
+
* // Create with linked session for policy enforcement
|
|
884
|
+
* const result = await zendfi.sessionKeys.create({
|
|
885
|
+
* user_wallet: 'Hx7B...abc',
|
|
886
|
+
* limit_usdc: 500,
|
|
887
|
+
* duration_days: 7,
|
|
888
|
+
* device_fingerprint: deviceFingerprint,
|
|
889
|
+
* link_session_id: session.id, // Links to existing session
|
|
890
|
+
* });
|
|
891
|
+
*
|
|
882
892
|
* console.log(`Session key: ${result.session_key_id}`);
|
|
883
893
|
* console.log('Please sign the approval transaction');
|
|
884
894
|
* ```
|
|
@@ -1056,6 +1066,98 @@ declare class SessionKeysAPI {
|
|
|
1056
1066
|
message: string;
|
|
1057
1067
|
};
|
|
1058
1068
|
}>;
|
|
1069
|
+
/**
|
|
1070
|
+
* Link a session key to an AI session for policy enforcement
|
|
1071
|
+
*
|
|
1072
|
+
* When linked, payments through this session key will check both:
|
|
1073
|
+
* 1. Session key balance (hard cap)
|
|
1074
|
+
* 2. AI session limits (per-tx, daily, weekly, monthly)
|
|
1075
|
+
*
|
|
1076
|
+
* This provides defense-in-depth: the session key provides signing
|
|
1077
|
+
* capability while the session enforces granular spending policies.
|
|
1078
|
+
*
|
|
1079
|
+
* @param sessionKeyId - UUID of the session key
|
|
1080
|
+
* @param sessionId - UUID of the AI session to link
|
|
1081
|
+
* @returns Updated session key status
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```typescript
|
|
1085
|
+
* // Create a session with limits
|
|
1086
|
+
* const session = await zendfi.agent.createSession({
|
|
1087
|
+
* agent_id: 'shopping-bot',
|
|
1088
|
+
* user_wallet: userWallet,
|
|
1089
|
+
* limits: {
|
|
1090
|
+
* max_per_transaction: 25,
|
|
1091
|
+
* max_per_day: 100,
|
|
1092
|
+
* },
|
|
1093
|
+
* duration_hours: 24,
|
|
1094
|
+
* });
|
|
1095
|
+
*
|
|
1096
|
+
* // Create and fund a session key
|
|
1097
|
+
* const key = await zendfi.sessionKeys.create({
|
|
1098
|
+
* user_wallet: userWallet,
|
|
1099
|
+
* limit_usdc: 500, // Fund with $500
|
|
1100
|
+
* duration_days: 7,
|
|
1101
|
+
* device_fingerprint: fp,
|
|
1102
|
+
* });
|
|
1103
|
+
*
|
|
1104
|
+
* // Link them together
|
|
1105
|
+
* await zendfi.sessionKeys.linkSession(key.session_key_id, session.id);
|
|
1106
|
+
*
|
|
1107
|
+
* // Now payments will:
|
|
1108
|
+
* // - Be limited to $25 per transaction (session policy)
|
|
1109
|
+
* // - Be limited to $100 per day (session policy)
|
|
1110
|
+
* // - Never exceed $500 total (session key balance)
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
linkSession(sessionKeyId: string, sessionId: string): Promise<{
|
|
1114
|
+
success: boolean;
|
|
1115
|
+
session_key_id: string;
|
|
1116
|
+
linked_session_id: string;
|
|
1117
|
+
message: string;
|
|
1118
|
+
}>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Unlink a session key from its AI session
|
|
1121
|
+
*
|
|
1122
|
+
* After unlinking, the session key will only be limited by its funded balance.
|
|
1123
|
+
*
|
|
1124
|
+
* @param sessionKeyId - UUID of the session key
|
|
1125
|
+
* @returns Result of the unlink operation
|
|
1126
|
+
*/
|
|
1127
|
+
unlinkSession(sessionKeyId: string): Promise<{
|
|
1128
|
+
success: boolean;
|
|
1129
|
+
session_key_id: string;
|
|
1130
|
+
message: string;
|
|
1131
|
+
}>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Check if a payment amount is allowed
|
|
1134
|
+
*
|
|
1135
|
+
* Checks both session key balance and linked session limits (if any).
|
|
1136
|
+
* Useful for pre-validating payments before attempting them.
|
|
1137
|
+
*
|
|
1138
|
+
* @param sessionKeyId - UUID of the session key
|
|
1139
|
+
* @param amount - Amount in USD to check
|
|
1140
|
+
* @returns Whether the payment is allowed and the effective limit
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* const check = await zendfi.sessionKeys.canAfford(keyId, 50);
|
|
1145
|
+
*
|
|
1146
|
+
* if (check.allowed) {
|
|
1147
|
+
* await zendfi.smart.execute({ ... });
|
|
1148
|
+
* } else {
|
|
1149
|
+
* console.log(`Cannot afford: ${check.reason}`);
|
|
1150
|
+
* console.log(`Effective limit: $${check.effective_limit}`);
|
|
1151
|
+
* }
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
canAfford(sessionKeyId: string, amount: number): Promise<{
|
|
1155
|
+
allowed: boolean;
|
|
1156
|
+
reason?: string;
|
|
1157
|
+
effective_limit: number;
|
|
1158
|
+
session_key_remaining: number;
|
|
1159
|
+
session_remaining_today?: number;
|
|
1160
|
+
}>;
|
|
1059
1161
|
}
|
|
1060
1162
|
|
|
1061
1163
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1403,6 +1403,7 @@ var SessionKeysAPI = class {
|
|
|
1403
1403
|
*
|
|
1404
1404
|
* @example
|
|
1405
1405
|
* ```typescript
|
|
1406
|
+
* // Basic creation
|
|
1406
1407
|
* const result = await zendfi.sessionKeys.create({
|
|
1407
1408
|
* user_wallet: 'Hx7B...abc',
|
|
1408
1409
|
* limit_usdc: 100,
|
|
@@ -1410,6 +1411,15 @@ var SessionKeysAPI = class {
|
|
|
1410
1411
|
* device_fingerprint: deviceFingerprint,
|
|
1411
1412
|
* });
|
|
1412
1413
|
*
|
|
1414
|
+
* // Create with linked session for policy enforcement
|
|
1415
|
+
* const result = await zendfi.sessionKeys.create({
|
|
1416
|
+
* user_wallet: 'Hx7B...abc',
|
|
1417
|
+
* limit_usdc: 500,
|
|
1418
|
+
* duration_days: 7,
|
|
1419
|
+
* device_fingerprint: deviceFingerprint,
|
|
1420
|
+
* link_session_id: session.id, // Links to existing session
|
|
1421
|
+
* });
|
|
1422
|
+
*
|
|
1413
1423
|
* console.log(`Session key: ${result.session_key_id}`);
|
|
1414
1424
|
* console.log('Please sign the approval transaction');
|
|
1415
1425
|
* ```
|
|
@@ -1419,7 +1429,9 @@ var SessionKeysAPI = class {
|
|
|
1419
1429
|
user_wallet: request.user_wallet,
|
|
1420
1430
|
limit_usdc: request.limit_usdc,
|
|
1421
1431
|
duration_days: request.duration_days ?? 7,
|
|
1422
|
-
device_fingerprint: request.device_fingerprint
|
|
1432
|
+
device_fingerprint: request.device_fingerprint,
|
|
1433
|
+
link_session_id: request.link_session_id,
|
|
1434
|
+
link_session_token: request.link_session_token
|
|
1423
1435
|
});
|
|
1424
1436
|
}
|
|
1425
1437
|
// ============================================
|
|
@@ -1645,6 +1657,96 @@ var SessionKeysAPI = class {
|
|
|
1645
1657
|
session_key_id: sessionKeyId
|
|
1646
1658
|
});
|
|
1647
1659
|
}
|
|
1660
|
+
// ============================================
|
|
1661
|
+
// Session Linking
|
|
1662
|
+
// ============================================
|
|
1663
|
+
/**
|
|
1664
|
+
* Link a session key to an AI session for policy enforcement
|
|
1665
|
+
*
|
|
1666
|
+
* When linked, payments through this session key will check both:
|
|
1667
|
+
* 1. Session key balance (hard cap)
|
|
1668
|
+
* 2. AI session limits (per-tx, daily, weekly, monthly)
|
|
1669
|
+
*
|
|
1670
|
+
* This provides defense-in-depth: the session key provides signing
|
|
1671
|
+
* capability while the session enforces granular spending policies.
|
|
1672
|
+
*
|
|
1673
|
+
* @param sessionKeyId - UUID of the session key
|
|
1674
|
+
* @param sessionId - UUID of the AI session to link
|
|
1675
|
+
* @returns Updated session key status
|
|
1676
|
+
*
|
|
1677
|
+
* @example
|
|
1678
|
+
* ```typescript
|
|
1679
|
+
* // Create a session with limits
|
|
1680
|
+
* const session = await zendfi.agent.createSession({
|
|
1681
|
+
* agent_id: 'shopping-bot',
|
|
1682
|
+
* user_wallet: userWallet,
|
|
1683
|
+
* limits: {
|
|
1684
|
+
* max_per_transaction: 25,
|
|
1685
|
+
* max_per_day: 100,
|
|
1686
|
+
* },
|
|
1687
|
+
* duration_hours: 24,
|
|
1688
|
+
* });
|
|
1689
|
+
*
|
|
1690
|
+
* // Create and fund a session key
|
|
1691
|
+
* const key = await zendfi.sessionKeys.create({
|
|
1692
|
+
* user_wallet: userWallet,
|
|
1693
|
+
* limit_usdc: 500, // Fund with $500
|
|
1694
|
+
* duration_days: 7,
|
|
1695
|
+
* device_fingerprint: fp,
|
|
1696
|
+
* });
|
|
1697
|
+
*
|
|
1698
|
+
* // Link them together
|
|
1699
|
+
* await zendfi.sessionKeys.linkSession(key.session_key_id, session.id);
|
|
1700
|
+
*
|
|
1701
|
+
* // Now payments will:
|
|
1702
|
+
* // - Be limited to $25 per transaction (session policy)
|
|
1703
|
+
* // - Be limited to $100 per day (session policy)
|
|
1704
|
+
* // - Never exceed $500 total (session key balance)
|
|
1705
|
+
* ```
|
|
1706
|
+
*/
|
|
1707
|
+
async linkSession(sessionKeyId, sessionId) {
|
|
1708
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/link-session`, {
|
|
1709
|
+
session_id: sessionId
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Unlink a session key from its AI session
|
|
1714
|
+
*
|
|
1715
|
+
* After unlinking, the session key will only be limited by its funded balance.
|
|
1716
|
+
*
|
|
1717
|
+
* @param sessionKeyId - UUID of the session key
|
|
1718
|
+
* @returns Result of the unlink operation
|
|
1719
|
+
*/
|
|
1720
|
+
async unlinkSession(sessionKeyId) {
|
|
1721
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/unlink-session`, {});
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Check if a payment amount is allowed
|
|
1725
|
+
*
|
|
1726
|
+
* Checks both session key balance and linked session limits (if any).
|
|
1727
|
+
* Useful for pre-validating payments before attempting them.
|
|
1728
|
+
*
|
|
1729
|
+
* @param sessionKeyId - UUID of the session key
|
|
1730
|
+
* @param amount - Amount in USD to check
|
|
1731
|
+
* @returns Whether the payment is allowed and the effective limit
|
|
1732
|
+
*
|
|
1733
|
+
* @example
|
|
1734
|
+
* ```typescript
|
|
1735
|
+
* const check = await zendfi.sessionKeys.canAfford(keyId, 50);
|
|
1736
|
+
*
|
|
1737
|
+
* if (check.allowed) {
|
|
1738
|
+
* await zendfi.smart.execute({ ... });
|
|
1739
|
+
* } else {
|
|
1740
|
+
* console.log(`Cannot afford: ${check.reason}`);
|
|
1741
|
+
* console.log(`Effective limit: $${check.effective_limit}`);
|
|
1742
|
+
* }
|
|
1743
|
+
* ```
|
|
1744
|
+
*/
|
|
1745
|
+
async canAfford(sessionKeyId, amount) {
|
|
1746
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/check-payment`, {
|
|
1747
|
+
amount
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1648
1750
|
};
|
|
1649
1751
|
|
|
1650
1752
|
// src/client.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1325,6 +1325,7 @@ var SessionKeysAPI = class {
|
|
|
1325
1325
|
*
|
|
1326
1326
|
* @example
|
|
1327
1327
|
* ```typescript
|
|
1328
|
+
* // Basic creation
|
|
1328
1329
|
* const result = await zendfi.sessionKeys.create({
|
|
1329
1330
|
* user_wallet: 'Hx7B...abc',
|
|
1330
1331
|
* limit_usdc: 100,
|
|
@@ -1332,6 +1333,15 @@ var SessionKeysAPI = class {
|
|
|
1332
1333
|
* device_fingerprint: deviceFingerprint,
|
|
1333
1334
|
* });
|
|
1334
1335
|
*
|
|
1336
|
+
* // Create with linked session for policy enforcement
|
|
1337
|
+
* const result = await zendfi.sessionKeys.create({
|
|
1338
|
+
* user_wallet: 'Hx7B...abc',
|
|
1339
|
+
* limit_usdc: 500,
|
|
1340
|
+
* duration_days: 7,
|
|
1341
|
+
* device_fingerprint: deviceFingerprint,
|
|
1342
|
+
* link_session_id: session.id, // Links to existing session
|
|
1343
|
+
* });
|
|
1344
|
+
*
|
|
1335
1345
|
* console.log(`Session key: ${result.session_key_id}`);
|
|
1336
1346
|
* console.log('Please sign the approval transaction');
|
|
1337
1347
|
* ```
|
|
@@ -1341,7 +1351,9 @@ var SessionKeysAPI = class {
|
|
|
1341
1351
|
user_wallet: request.user_wallet,
|
|
1342
1352
|
limit_usdc: request.limit_usdc,
|
|
1343
1353
|
duration_days: request.duration_days ?? 7,
|
|
1344
|
-
device_fingerprint: request.device_fingerprint
|
|
1354
|
+
device_fingerprint: request.device_fingerprint,
|
|
1355
|
+
link_session_id: request.link_session_id,
|
|
1356
|
+
link_session_token: request.link_session_token
|
|
1345
1357
|
});
|
|
1346
1358
|
}
|
|
1347
1359
|
// ============================================
|
|
@@ -1567,6 +1579,96 @@ var SessionKeysAPI = class {
|
|
|
1567
1579
|
session_key_id: sessionKeyId
|
|
1568
1580
|
});
|
|
1569
1581
|
}
|
|
1582
|
+
// ============================================
|
|
1583
|
+
// Session Linking
|
|
1584
|
+
// ============================================
|
|
1585
|
+
/**
|
|
1586
|
+
* Link a session key to an AI session for policy enforcement
|
|
1587
|
+
*
|
|
1588
|
+
* When linked, payments through this session key will check both:
|
|
1589
|
+
* 1. Session key balance (hard cap)
|
|
1590
|
+
* 2. AI session limits (per-tx, daily, weekly, monthly)
|
|
1591
|
+
*
|
|
1592
|
+
* This provides defense-in-depth: the session key provides signing
|
|
1593
|
+
* capability while the session enforces granular spending policies.
|
|
1594
|
+
*
|
|
1595
|
+
* @param sessionKeyId - UUID of the session key
|
|
1596
|
+
* @param sessionId - UUID of the AI session to link
|
|
1597
|
+
* @returns Updated session key status
|
|
1598
|
+
*
|
|
1599
|
+
* @example
|
|
1600
|
+
* ```typescript
|
|
1601
|
+
* // Create a session with limits
|
|
1602
|
+
* const session = await zendfi.agent.createSession({
|
|
1603
|
+
* agent_id: 'shopping-bot',
|
|
1604
|
+
* user_wallet: userWallet,
|
|
1605
|
+
* limits: {
|
|
1606
|
+
* max_per_transaction: 25,
|
|
1607
|
+
* max_per_day: 100,
|
|
1608
|
+
* },
|
|
1609
|
+
* duration_hours: 24,
|
|
1610
|
+
* });
|
|
1611
|
+
*
|
|
1612
|
+
* // Create and fund a session key
|
|
1613
|
+
* const key = await zendfi.sessionKeys.create({
|
|
1614
|
+
* user_wallet: userWallet,
|
|
1615
|
+
* limit_usdc: 500, // Fund with $500
|
|
1616
|
+
* duration_days: 7,
|
|
1617
|
+
* device_fingerprint: fp,
|
|
1618
|
+
* });
|
|
1619
|
+
*
|
|
1620
|
+
* // Link them together
|
|
1621
|
+
* await zendfi.sessionKeys.linkSession(key.session_key_id, session.id);
|
|
1622
|
+
*
|
|
1623
|
+
* // Now payments will:
|
|
1624
|
+
* // - Be limited to $25 per transaction (session policy)
|
|
1625
|
+
* // - Be limited to $100 per day (session policy)
|
|
1626
|
+
* // - Never exceed $500 total (session key balance)
|
|
1627
|
+
* ```
|
|
1628
|
+
*/
|
|
1629
|
+
async linkSession(sessionKeyId, sessionId) {
|
|
1630
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/link-session`, {
|
|
1631
|
+
session_id: sessionId
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Unlink a session key from its AI session
|
|
1636
|
+
*
|
|
1637
|
+
* After unlinking, the session key will only be limited by its funded balance.
|
|
1638
|
+
*
|
|
1639
|
+
* @param sessionKeyId - UUID of the session key
|
|
1640
|
+
* @returns Result of the unlink operation
|
|
1641
|
+
*/
|
|
1642
|
+
async unlinkSession(sessionKeyId) {
|
|
1643
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/unlink-session`, {});
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Check if a payment amount is allowed
|
|
1647
|
+
*
|
|
1648
|
+
* Checks both session key balance and linked session limits (if any).
|
|
1649
|
+
* Useful for pre-validating payments before attempting them.
|
|
1650
|
+
*
|
|
1651
|
+
* @param sessionKeyId - UUID of the session key
|
|
1652
|
+
* @param amount - Amount in USD to check
|
|
1653
|
+
* @returns Whether the payment is allowed and the effective limit
|
|
1654
|
+
*
|
|
1655
|
+
* @example
|
|
1656
|
+
* ```typescript
|
|
1657
|
+
* const check = await zendfi.sessionKeys.canAfford(keyId, 50);
|
|
1658
|
+
*
|
|
1659
|
+
* if (check.allowed) {
|
|
1660
|
+
* await zendfi.smart.execute({ ... });
|
|
1661
|
+
* } else {
|
|
1662
|
+
* console.log(`Cannot afford: ${check.reason}`);
|
|
1663
|
+
* console.log(`Effective limit: $${check.effective_limit}`);
|
|
1664
|
+
* }
|
|
1665
|
+
* ```
|
|
1666
|
+
*/
|
|
1667
|
+
async canAfford(sessionKeyId, amount) {
|
|
1668
|
+
return this.request("POST", `/api/v1/ai/session-keys/${sessionKeyId}/check-payment`, {
|
|
1669
|
+
amount
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1570
1672
|
};
|
|
1571
1673
|
|
|
1572
1674
|
// src/client.ts
|
package/dist/nextjs.d.mts
CHANGED
package/dist/nextjs.d.ts
CHANGED
|
@@ -822,6 +822,16 @@ interface CreateSessionKeyRequest {
|
|
|
822
822
|
duration_days?: number;
|
|
823
823
|
/** Device fingerprint for security */
|
|
824
824
|
device_fingerprint: string;
|
|
825
|
+
/**
|
|
826
|
+
* Optional: Link to an existing AI session for policy enforcement.
|
|
827
|
+
* When linked, payments will check both session key balance AND session limits.
|
|
828
|
+
*/
|
|
829
|
+
link_session_id?: string;
|
|
830
|
+
/**
|
|
831
|
+
* Optional: Link to a session by token instead of ID.
|
|
832
|
+
* Mutually exclusive with link_session_id.
|
|
833
|
+
*/
|
|
834
|
+
link_session_token?: string;
|
|
825
835
|
}
|
|
826
836
|
/**
|
|
827
837
|
* Session key creation response (custodial mode)
|
|
@@ -921,6 +931,29 @@ interface SessionKeyStatus {
|
|
|
921
931
|
days_until_expiry: number;
|
|
922
932
|
/** Security status */
|
|
923
933
|
security_status: SecurityStatus;
|
|
934
|
+
/** Linked AI session info (if linked) */
|
|
935
|
+
linked_session?: LinkedSessionInfo;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Information about a linked AI session (for policy enforcement)
|
|
939
|
+
*/
|
|
940
|
+
interface LinkedSessionInfo {
|
|
941
|
+
/** Session ID */
|
|
942
|
+
session_id: string;
|
|
943
|
+
/** Agent ID */
|
|
944
|
+
agent_id: string;
|
|
945
|
+
/** Whether the linked session is active */
|
|
946
|
+
is_active: boolean;
|
|
947
|
+
/** Per-transaction limit */
|
|
948
|
+
max_per_transaction?: number;
|
|
949
|
+
/** Daily remaining */
|
|
950
|
+
remaining_today: number;
|
|
951
|
+
/** Weekly remaining */
|
|
952
|
+
remaining_this_week: number;
|
|
953
|
+
/** Monthly remaining */
|
|
954
|
+
remaining_this_month: number;
|
|
955
|
+
/** Effective limit (minimum of session key balance and session limits) */
|
|
956
|
+
effective_limit: number;
|
|
924
957
|
}
|
|
925
958
|
interface SecurityStatus {
|
|
926
959
|
device_fingerprint_matched: boolean;
|
|
@@ -1095,4 +1128,4 @@ interface WebhookResult {
|
|
|
1095
1128
|
}
|
|
1096
1129
|
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
1097
1130
|
|
|
1098
|
-
export { processWebhook as $, type AgentApiKey as A, type PaginatedResponse as B, type CreateAgentApiKeyRequest as C, type CreateSubscriptionPlanRequest as D, type EnableAutonomyRequest as E, type SubscriptionPlan as F, type CreateSubscriptionRequest as G, type Subscription as H, type CreatePaymentLinkRequest as I, type PaymentLink as J, type CreateInstallmentPlanRequest as K, type ListPaymentsRequest as L, type InstallmentPlan as M, type CreateEscrowRequest as N, type Escrow as O, type PaymentIntent as P, type ApproveEscrowRequest as Q, type RefundEscrowRequest as R, type SmartPaymentRequest as S, type TopUpSessionKeyRequest as T, type DisputeEscrowRequest as U, type CreateInvoiceRequest as V, type WebhookHandlerConfig as W, type Invoice as X, type VerifyWebhookRequest as Y, type ZendFiConfig as Z, type WebhookPayload as _, type WebhookHandlers as a, type WebhookResult as a0, type WebhookEventHandler as a1, type Brand as a2, type PaymentId as a3, type SessionId as a4, type AgentKeyId as a5, type MerchantId as a6, type InvoiceId as a7, type SubscriptionId as a8, type EscrowId as a9, type CreateInstallmentPlanResponse as aA, type ReleaseCondition as aB, type InvoiceLineItem as aC, type ApiKeyScope as aD, type SessionLimits as aE, type PaymentIntentStatus as aF, type CaptureMethod as aG, type UserProfile as aH, type PPPConfig as aI, type AutonomousDelegate as aJ, type RevokeAutonomyRequest as aK, type SmartPaymentStatus as aL, type SessionKeyInstructions as aM, type SessionKeySecurityInfo as aN, type
|
|
1131
|
+
export { processWebhook as $, type AgentApiKey as A, type PaginatedResponse as B, type CreateAgentApiKeyRequest as C, type CreateSubscriptionPlanRequest as D, type EnableAutonomyRequest as E, type SubscriptionPlan as F, type CreateSubscriptionRequest as G, type Subscription as H, type CreatePaymentLinkRequest as I, type PaymentLink as J, type CreateInstallmentPlanRequest as K, type ListPaymentsRequest as L, type InstallmentPlan as M, type CreateEscrowRequest as N, type Escrow as O, type PaymentIntent as P, type ApproveEscrowRequest as Q, type RefundEscrowRequest as R, type SmartPaymentRequest as S, type TopUpSessionKeyRequest as T, type DisputeEscrowRequest as U, type CreateInvoiceRequest as V, type WebhookHandlerConfig as W, type Invoice as X, type VerifyWebhookRequest as Y, type ZendFiConfig as Z, type WebhookPayload as _, type WebhookHandlers as a, type WebhookResult as a0, type WebhookEventHandler as a1, type Brand as a2, type PaymentId as a3, type SessionId as a4, type AgentKeyId as a5, type MerchantId as a6, type InvoiceId as a7, type SubscriptionId as a8, type EscrowId as a9, type CreateInstallmentPlanResponse as aA, type ReleaseCondition as aB, type InvoiceLineItem as aC, type ApiKeyScope as aD, type SessionLimits as aE, type PaymentIntentStatus as aF, type CaptureMethod as aG, type UserProfile as aH, type PPPConfig as aI, type AutonomousDelegate as aJ, type RevokeAutonomyRequest as aK, type SmartPaymentStatus as aL, type SessionKeyInstructions as aM, type SessionKeySecurityInfo as aN, type LinkedSessionInfo as aO, type SecurityStatus as aP, type SessionKeyStats as aQ, type InstallmentPlanId as aa, type PaymentLinkCode as ab, type IntentId as ac, asPaymentId as ad, asSessionId as ae, asAgentKeyId as af, asMerchantId as ag, asInvoiceId as ah, asSubscriptionId as ai, asEscrowId as aj, asInstallmentPlanId as ak, asPaymentLinkCode as al, asIntentId as am, type Environment as an, type ApiKeyMode as ao, type Currency as ap, type PaymentToken as aq, type PaymentStatus as ar, type SubscriptionStatus as as, type InstallmentPlanStatus as at, type EscrowStatus as au, type InvoiceStatus as av, type SplitStatus as aw, type WebhookEvent as ax, type SplitRecipient as ay, type InstallmentScheduleItem as az, type CreateAgentSessionRequest as b, type AgentSession as c, type AgentPaymentRequest as d, type AgentPaymentResponse as e, type AgentAnalytics as f, type CreatePaymentIntentRequest as g, type ConfirmPaymentIntentRequest as h, type PaymentIntentEvent as i, type PPPFactor as j, type PricingSuggestionRequest as k, type PricingSuggestion as l, type EnableAutonomyResponse as m, type AutonomyStatus as n, type SmartPaymentResponse as o, type CreateSessionKeyRequest as p, type CreateSessionKeyResponse as q, type CreateDeviceBoundSessionKeyRequest as r, type CreateDeviceBoundSessionKeyResponse as s, type SubmitSignedTransactionRequest as t, type SubmitTransactionResponse as u, type SessionKeyStatus as v, type SessionKeyListResponse as w, type TopUpSessionKeyResponse as x, type CreatePaymentRequest as y, type Payment as z };
|
|
@@ -822,6 +822,16 @@ interface CreateSessionKeyRequest {
|
|
|
822
822
|
duration_days?: number;
|
|
823
823
|
/** Device fingerprint for security */
|
|
824
824
|
device_fingerprint: string;
|
|
825
|
+
/**
|
|
826
|
+
* Optional: Link to an existing AI session for policy enforcement.
|
|
827
|
+
* When linked, payments will check both session key balance AND session limits.
|
|
828
|
+
*/
|
|
829
|
+
link_session_id?: string;
|
|
830
|
+
/**
|
|
831
|
+
* Optional: Link to a session by token instead of ID.
|
|
832
|
+
* Mutually exclusive with link_session_id.
|
|
833
|
+
*/
|
|
834
|
+
link_session_token?: string;
|
|
825
835
|
}
|
|
826
836
|
/**
|
|
827
837
|
* Session key creation response (custodial mode)
|
|
@@ -921,6 +931,29 @@ interface SessionKeyStatus {
|
|
|
921
931
|
days_until_expiry: number;
|
|
922
932
|
/** Security status */
|
|
923
933
|
security_status: SecurityStatus;
|
|
934
|
+
/** Linked AI session info (if linked) */
|
|
935
|
+
linked_session?: LinkedSessionInfo;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Information about a linked AI session (for policy enforcement)
|
|
939
|
+
*/
|
|
940
|
+
interface LinkedSessionInfo {
|
|
941
|
+
/** Session ID */
|
|
942
|
+
session_id: string;
|
|
943
|
+
/** Agent ID */
|
|
944
|
+
agent_id: string;
|
|
945
|
+
/** Whether the linked session is active */
|
|
946
|
+
is_active: boolean;
|
|
947
|
+
/** Per-transaction limit */
|
|
948
|
+
max_per_transaction?: number;
|
|
949
|
+
/** Daily remaining */
|
|
950
|
+
remaining_today: number;
|
|
951
|
+
/** Weekly remaining */
|
|
952
|
+
remaining_this_week: number;
|
|
953
|
+
/** Monthly remaining */
|
|
954
|
+
remaining_this_month: number;
|
|
955
|
+
/** Effective limit (minimum of session key balance and session limits) */
|
|
956
|
+
effective_limit: number;
|
|
924
957
|
}
|
|
925
958
|
interface SecurityStatus {
|
|
926
959
|
device_fingerprint_matched: boolean;
|
|
@@ -1095,4 +1128,4 @@ interface WebhookResult {
|
|
|
1095
1128
|
}
|
|
1096
1129
|
declare function processWebhook(a: any, b?: any, c?: any): Promise<WebhookResult>;
|
|
1097
1130
|
|
|
1098
|
-
export { processWebhook as $, type AgentApiKey as A, type PaginatedResponse as B, type CreateAgentApiKeyRequest as C, type CreateSubscriptionPlanRequest as D, type EnableAutonomyRequest as E, type SubscriptionPlan as F, type CreateSubscriptionRequest as G, type Subscription as H, type CreatePaymentLinkRequest as I, type PaymentLink as J, type CreateInstallmentPlanRequest as K, type ListPaymentsRequest as L, type InstallmentPlan as M, type CreateEscrowRequest as N, type Escrow as O, type PaymentIntent as P, type ApproveEscrowRequest as Q, type RefundEscrowRequest as R, type SmartPaymentRequest as S, type TopUpSessionKeyRequest as T, type DisputeEscrowRequest as U, type CreateInvoiceRequest as V, type WebhookHandlerConfig as W, type Invoice as X, type VerifyWebhookRequest as Y, type ZendFiConfig as Z, type WebhookPayload as _, type WebhookHandlers as a, type WebhookResult as a0, type WebhookEventHandler as a1, type Brand as a2, type PaymentId as a3, type SessionId as a4, type AgentKeyId as a5, type MerchantId as a6, type InvoiceId as a7, type SubscriptionId as a8, type EscrowId as a9, type CreateInstallmentPlanResponse as aA, type ReleaseCondition as aB, type InvoiceLineItem as aC, type ApiKeyScope as aD, type SessionLimits as aE, type PaymentIntentStatus as aF, type CaptureMethod as aG, type UserProfile as aH, type PPPConfig as aI, type AutonomousDelegate as aJ, type RevokeAutonomyRequest as aK, type SmartPaymentStatus as aL, type SessionKeyInstructions as aM, type SessionKeySecurityInfo as aN, type
|
|
1131
|
+
export { processWebhook as $, type AgentApiKey as A, type PaginatedResponse as B, type CreateAgentApiKeyRequest as C, type CreateSubscriptionPlanRequest as D, type EnableAutonomyRequest as E, type SubscriptionPlan as F, type CreateSubscriptionRequest as G, type Subscription as H, type CreatePaymentLinkRequest as I, type PaymentLink as J, type CreateInstallmentPlanRequest as K, type ListPaymentsRequest as L, type InstallmentPlan as M, type CreateEscrowRequest as N, type Escrow as O, type PaymentIntent as P, type ApproveEscrowRequest as Q, type RefundEscrowRequest as R, type SmartPaymentRequest as S, type TopUpSessionKeyRequest as T, type DisputeEscrowRequest as U, type CreateInvoiceRequest as V, type WebhookHandlerConfig as W, type Invoice as X, type VerifyWebhookRequest as Y, type ZendFiConfig as Z, type WebhookPayload as _, type WebhookHandlers as a, type WebhookResult as a0, type WebhookEventHandler as a1, type Brand as a2, type PaymentId as a3, type SessionId as a4, type AgentKeyId as a5, type MerchantId as a6, type InvoiceId as a7, type SubscriptionId as a8, type EscrowId as a9, type CreateInstallmentPlanResponse as aA, type ReleaseCondition as aB, type InvoiceLineItem as aC, type ApiKeyScope as aD, type SessionLimits as aE, type PaymentIntentStatus as aF, type CaptureMethod as aG, type UserProfile as aH, type PPPConfig as aI, type AutonomousDelegate as aJ, type RevokeAutonomyRequest as aK, type SmartPaymentStatus as aL, type SessionKeyInstructions as aM, type SessionKeySecurityInfo as aN, type LinkedSessionInfo as aO, type SecurityStatus as aP, type SessionKeyStats as aQ, type InstallmentPlanId as aa, type PaymentLinkCode as ab, type IntentId as ac, asPaymentId as ad, asSessionId as ae, asAgentKeyId as af, asMerchantId as ag, asInvoiceId as ah, asSubscriptionId as ai, asEscrowId as aj, asInstallmentPlanId as ak, asPaymentLinkCode as al, asIntentId as am, type Environment as an, type ApiKeyMode as ao, type Currency as ap, type PaymentToken as aq, type PaymentStatus as ar, type SubscriptionStatus as as, type InstallmentPlanStatus as at, type EscrowStatus as au, type InvoiceStatus as av, type SplitStatus as aw, type WebhookEvent as ax, type SplitRecipient as ay, type InstallmentScheduleItem as az, type CreateAgentSessionRequest as b, type AgentSession as c, type AgentPaymentRequest as d, type AgentPaymentResponse as e, type AgentAnalytics as f, type CreatePaymentIntentRequest as g, type ConfirmPaymentIntentRequest as h, type PaymentIntentEvent as i, type PPPFactor as j, type PricingSuggestionRequest as k, type PricingSuggestion as l, type EnableAutonomyResponse as m, type AutonomyStatus as n, type SmartPaymentResponse as o, type CreateSessionKeyRequest as p, type CreateSessionKeyResponse as q, type CreateDeviceBoundSessionKeyRequest as r, type CreateDeviceBoundSessionKeyResponse as s, type SubmitSignedTransactionRequest as t, type SubmitTransactionResponse as u, type SessionKeyStatus as v, type SessionKeyListResponse as w, type TopUpSessionKeyResponse as x, type CreatePaymentRequest as y, type Payment as z };
|