@mixrpay/agent-sdk 0.8.9 → 0.10.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/LICENSE +21 -0
- package/README.md +49 -113
- package/dist/agent-wallet-FDRSEXLB.js +2 -0
- package/dist/chunk-IBXQMJ7G.js +1 -0
- package/dist/chunk-RAJSYN5T.js +32 -0
- package/dist/chunk-SWK4Q2A3.js +2 -0
- package/dist/cli.js +147 -0
- package/dist/credentials-QUSJGKLZ.js +2 -0
- package/dist/credentials-XJV2ESBQ.js +2 -0
- package/dist/credentials-Z4HQDXFU.js +1 -0
- package/dist/index.cjs +28 -4642
- package/dist/index.d.cts +1327 -303
- package/dist/index.d.ts +1327 -303
- package/dist/index.js +28 -4604
- package/dist/mcp-server.js +35 -0
- package/package.json +25 -10
package/dist/index.d.cts
CHANGED
|
@@ -1,356 +1,131 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This file contains all TypeScript types and interfaces used throughout the SDK.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for AgentWallet.
|
|
8
|
-
*
|
|
9
|
-
* @example Minimal configuration
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const config: AgentWalletConfig = {
|
|
12
|
-
* sessionKey: 'sk_live_abc123...'
|
|
13
|
-
* };
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example Full configuration
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const config: AgentWalletConfig = {
|
|
19
|
-
* sessionKey: 'sk_live_abc123...',
|
|
20
|
-
* maxPaymentUsd: 5.0,
|
|
21
|
-
* onPayment: (p) => console.log(`Paid $${p.amountUsd}`),
|
|
22
|
-
* logLevel: 'info',
|
|
23
|
-
* timeout: 60000,
|
|
24
|
-
* };
|
|
25
|
-
* ```
|
|
2
|
+
* @packageDocumentation
|
|
26
3
|
*/
|
|
27
4
|
interface AgentWalletConfig {
|
|
28
|
-
/**
|
|
29
|
-
* Session key granted by the wallet owner.
|
|
30
|
-
*
|
|
31
|
-
* Format: `sk_live_` (mainnet) or `sk_test_` (testnet) followed by 64 hex characters.
|
|
32
|
-
*
|
|
33
|
-
* Get session keys from:
|
|
34
|
-
* - The wallet owner at https://mixrpay.com/manage/invites
|
|
35
|
-
* - Programmatically via the MixrPay API
|
|
36
|
-
*
|
|
37
|
-
* @example 'sk_live_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
38
|
-
*/
|
|
5
|
+
/** Session key (sk_live_ or sk_test_ prefix). */
|
|
39
6
|
sessionKey: string;
|
|
40
|
-
/**
|
|
41
|
-
* Optional smart wallet address.
|
|
42
|
-
*
|
|
43
|
-
* If not provided, will be derived from the session key.
|
|
44
|
-
* Only needed in advanced scenarios where the session key address
|
|
45
|
-
* differs from the wallet address.
|
|
46
|
-
*/
|
|
7
|
+
/** Override wallet address. */
|
|
47
8
|
walletAddress?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Optional client-side maximum payment per request in USD.
|
|
50
|
-
*
|
|
51
|
-
* This is an additional safety limit on the client side, independent
|
|
52
|
-
* of the session key's limits. Useful for preventing accidental
|
|
53
|
-
* large payments due to bugs or misconfiguration.
|
|
54
|
-
*
|
|
55
|
-
* @example 5.0 - Maximum $5 per request
|
|
56
|
-
*/
|
|
9
|
+
/** Client-side max payment per request in USD. */
|
|
57
10
|
maxPaymentUsd?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Optional callback when a payment is successfully made.
|
|
60
|
-
*
|
|
61
|
-
* Use this to track payments in your application, update UI,
|
|
62
|
-
* or log payment events.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* onPayment: (payment) => {
|
|
67
|
-
* console.log(`Paid $${payment.amountUsd} for ${payment.description}`);
|
|
68
|
-
* analytics.track('payment', payment);
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
11
|
+
/** Payment event callback. */
|
|
72
12
|
onPayment?: (payment: PaymentEvent) => void;
|
|
73
|
-
/**
|
|
74
|
-
* x402 facilitator endpoint.
|
|
75
|
-
*
|
|
76
|
-
* The facilitator processes the payment and forwards the request.
|
|
77
|
-
* Default: 'https://x402.org/facilitator'
|
|
78
|
-
*/
|
|
13
|
+
/** Override facilitator URL. */
|
|
79
14
|
facilitatorUrl?: string;
|
|
80
|
-
/**
|
|
81
|
-
* MixrPay API base URL.
|
|
82
|
-
*
|
|
83
|
-
* Default: 'http://localhost:3000' (or MIXRPAY_BASE_URL env var)
|
|
84
|
-
*/
|
|
15
|
+
/** Override API base URL. */
|
|
85
16
|
baseUrl?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Request timeout in milliseconds.
|
|
88
|
-
*
|
|
89
|
-
* Default: 30000 (30 seconds)
|
|
90
|
-
*/
|
|
17
|
+
/** Request timeout in ms (default: 30000). */
|
|
91
18
|
timeout?: number;
|
|
92
|
-
/**
|
|
93
|
-
* Log level for SDK operations.
|
|
94
|
-
*
|
|
95
|
-
* - 'debug': Verbose logging for development
|
|
96
|
-
* - 'info': Important events (payments, etc.)
|
|
97
|
-
* - 'warn': Warnings only
|
|
98
|
-
* - 'error': Errors only
|
|
99
|
-
* - 'none': No logging (default)
|
|
100
|
-
*
|
|
101
|
-
* @example 'info' - Log payments and important events
|
|
102
|
-
*/
|
|
19
|
+
/** Log level (default: 'none'). */
|
|
103
20
|
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
21
|
+
/** Agent API key (agt_live_ prefix). Set automatically by connect(). */
|
|
22
|
+
apiKey?: string;
|
|
104
23
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Record of a payment made by the SDK.
|
|
107
|
-
*
|
|
108
|
-
* This is emitted via the `onPayment` callback and stored in the payment history.
|
|
109
|
-
*/
|
|
110
24
|
interface PaymentEvent {
|
|
111
|
-
/** Payment amount in USD */
|
|
112
25
|
amountUsd: number;
|
|
113
|
-
/** Recipient wallet address */
|
|
114
26
|
recipient: string;
|
|
115
|
-
/** Transaction hash on the blockchain (if available) */
|
|
116
27
|
txHash: string | null;
|
|
117
|
-
/** Timestamp when the payment was made */
|
|
118
28
|
timestamp: Date;
|
|
119
|
-
/** Description of what was paid for (from the server) */
|
|
120
29
|
description?: string;
|
|
121
|
-
/** URL that triggered the payment */
|
|
122
30
|
url?: string;
|
|
123
|
-
/** Auto-generated unique ID for this request */
|
|
124
31
|
requestId: string;
|
|
125
|
-
/** User-provided correlation ID (from X-Correlation-Id header if provided) */
|
|
126
32
|
correlationId?: string;
|
|
127
33
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Information about a session key.
|
|
130
|
-
*/
|
|
131
34
|
interface SessionKeyInfo {
|
|
132
|
-
/** The session key's derived address (used for signing requests) */
|
|
133
35
|
address: string;
|
|
134
|
-
/**
|
|
135
|
-
* The wallet address this session key is authorized to spend from.
|
|
136
|
-
* This is the human's funded wallet, NOT your agent's external wallet.
|
|
137
|
-
* All charges are deducted from this wallet.
|
|
138
|
-
*/
|
|
139
36
|
walletAddress: string | null;
|
|
140
|
-
/** Whether the session key is currently valid */
|
|
141
37
|
isValid: boolean;
|
|
142
|
-
/** Spending limits configured for this session key */
|
|
143
38
|
limits: {
|
|
144
|
-
/** Maximum amount per transaction in USD (null = no limit) */
|
|
145
39
|
perTxUsd: number | null;
|
|
146
|
-
/** Maximum amount per day in USD (null = no limit) */
|
|
147
40
|
dailyUsd: number | null;
|
|
148
|
-
/** Maximum total amount in USD (null = no limit) */
|
|
149
41
|
totalUsd: number | null;
|
|
150
42
|
};
|
|
151
|
-
/** Current usage statistics */
|
|
152
43
|
usage: {
|
|
153
|
-
/** Amount spent today in USD */
|
|
154
44
|
todayUsd: number;
|
|
155
|
-
/** Total amount spent in USD */
|
|
156
45
|
totalUsd: number;
|
|
157
|
-
/** Number of transactions made */
|
|
158
46
|
txCount: number;
|
|
159
47
|
};
|
|
160
|
-
/** When the session key expires (null = never) */
|
|
161
48
|
expiresAt: Date | null;
|
|
162
|
-
/** When the session key was created */
|
|
163
49
|
createdAt: Date | null;
|
|
164
|
-
/** Optional name given to this session key */
|
|
165
50
|
name?: string;
|
|
166
|
-
/** Allowed merchants/tools (empty = allow all) */
|
|
167
51
|
allowedMerchants?: string[];
|
|
168
52
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Spending statistics for the current session.
|
|
171
|
-
*/
|
|
172
53
|
interface SpendingStats {
|
|
173
|
-
/** Total amount spent in USD during this session */
|
|
174
54
|
totalSpentUsd: number;
|
|
175
|
-
/** Number of payment transactions made */
|
|
176
55
|
txCount: number;
|
|
177
|
-
/** Remaining daily limit in USD (null if no limit or unknown) */
|
|
178
56
|
remainingDailyUsd: number | null;
|
|
179
|
-
/** Remaining total limit in USD (null if no limit or unknown) */
|
|
180
57
|
remainingTotalUsd: number | null;
|
|
181
|
-
/** When the session key expires (null if never or unknown) */
|
|
182
58
|
expiresAt: Date | null;
|
|
183
59
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Result of running diagnostics on the wallet.
|
|
186
|
-
*/
|
|
187
60
|
interface DiagnosticsResult {
|
|
188
|
-
/** Whether all checks passed */
|
|
189
61
|
healthy: boolean;
|
|
190
|
-
/** List of issues found (empty if healthy) */
|
|
191
62
|
issues: string[];
|
|
192
|
-
/** Individual check results */
|
|
193
63
|
checks: {
|
|
194
|
-
/** Session key format is valid */
|
|
195
64
|
sessionKeyFormat?: boolean;
|
|
196
|
-
/** Can connect to MixrPay API */
|
|
197
65
|
apiConnectivity?: boolean;
|
|
198
|
-
/** Session key is valid and not expired */
|
|
199
66
|
sessionKeyValid?: boolean;
|
|
200
|
-
/** Wallet has USDC balance */
|
|
201
67
|
hasBalance?: boolean;
|
|
202
68
|
};
|
|
203
|
-
/** SDK version */
|
|
204
69
|
sdkVersion: string;
|
|
205
|
-
/** Network name (Base or Base Sepolia) */
|
|
206
70
|
network: string;
|
|
207
|
-
/** Wallet address */
|
|
208
71
|
walletAddress: string;
|
|
209
|
-
/** Session key limit info (if available) */
|
|
210
72
|
sessionLimits?: {
|
|
211
|
-
/** Remaining daily limit in USD (null if no limit) */
|
|
212
73
|
remainingDailyUsd: number | null;
|
|
213
|
-
/** Remaining total limit in USD (null if no limit) */
|
|
214
74
|
remainingTotalUsd: number | null;
|
|
215
|
-
/** When the session key expires (null if never) */
|
|
216
75
|
expiresAt: Date | null;
|
|
217
|
-
/** Hours until expiration (null if never) */
|
|
218
76
|
expiresInHours: number | null;
|
|
219
77
|
};
|
|
220
|
-
/** Network latency to API in milliseconds */
|
|
221
78
|
latencyMs?: number;
|
|
222
|
-
/** Actionable recommendations based on issues found */
|
|
223
79
|
recommendations: string[];
|
|
224
80
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Options for creating a session authorization with a MixrPay merchant.
|
|
227
|
-
*/
|
|
81
|
+
/** @internal */
|
|
228
82
|
interface CreateSessionOptions {
|
|
229
|
-
/**
|
|
230
|
-
* The merchant's MixrPay public key.
|
|
231
|
-
* Format: `pk_live_...` or `pk_test_...`
|
|
232
|
-
*/
|
|
233
83
|
merchantPublicKey: string;
|
|
234
|
-
/**
|
|
235
|
-
* Maximum spending limit for this session in USD.
|
|
236
|
-
* @default 25.00
|
|
237
|
-
*/
|
|
238
84
|
spendingLimitUsd?: number;
|
|
239
|
-
/**
|
|
240
|
-
* Number of days this session should be valid.
|
|
241
|
-
* @default 7
|
|
242
|
-
*/
|
|
243
85
|
durationDays?: number;
|
|
244
86
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Status of a session authorization.
|
|
247
|
-
*/
|
|
87
|
+
/** @internal */
|
|
248
88
|
type SessionAuthStatus = 'pending' | 'active' | 'expired' | 'revoked';
|
|
249
|
-
/**
|
|
250
|
-
* A session authorization with a MixrPay merchant.
|
|
251
|
-
*
|
|
252
|
-
* This represents a user-approved spending permission for a specific merchant.
|
|
253
|
-
*/
|
|
254
89
|
interface SessionAuthorization {
|
|
255
|
-
/** Unique session ID */
|
|
256
90
|
id: string;
|
|
257
|
-
/** Merchant ID */
|
|
258
91
|
merchantId: string;
|
|
259
|
-
/** Merchant name */
|
|
260
92
|
merchantName: string;
|
|
261
|
-
/** Current session status */
|
|
262
93
|
status: SessionAuthStatus;
|
|
263
|
-
/** Maximum spending limit in USD */
|
|
264
94
|
spendingLimitUsd: number;
|
|
265
|
-
/** Amount already spent in USD */
|
|
266
95
|
amountUsedUsd: number;
|
|
267
|
-
/** Remaining spending limit in USD */
|
|
268
96
|
remainingLimitUsd: number;
|
|
269
|
-
/** When the session expires */
|
|
270
97
|
expiresAt: Date;
|
|
271
|
-
/** When the session was created */
|
|
272
98
|
createdAt: Date;
|
|
273
99
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Options for calling a MixrPay merchant's API.
|
|
276
|
-
*/
|
|
277
100
|
interface CallMerchantApiOptions {
|
|
278
|
-
/**
|
|
279
|
-
* The merchant API URL to call.
|
|
280
|
-
*/
|
|
281
101
|
url: string;
|
|
282
|
-
/**
|
|
283
|
-
* HTTP method (default: 'POST').
|
|
284
|
-
*/
|
|
285
102
|
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
286
|
-
/**
|
|
287
|
-
* Request body (will be JSON-serialized if object).
|
|
288
|
-
*/
|
|
289
103
|
body?: unknown;
|
|
290
|
-
/**
|
|
291
|
-
* Additional headers to include.
|
|
292
|
-
*/
|
|
293
104
|
headers?: Record<string, string>;
|
|
294
|
-
/**
|
|
295
|
-
* The merchant's MixrPay public key.
|
|
296
|
-
* Required to identify which session to use.
|
|
297
|
-
*/
|
|
298
105
|
merchantPublicKey: string;
|
|
299
|
-
/**
|
|
300
|
-
* Expected price in USD for this request.
|
|
301
|
-
* Used for client-side validation.
|
|
302
|
-
*/
|
|
303
106
|
priceUsd?: number;
|
|
304
|
-
/**
|
|
305
|
-
* Feature slug for tracking/analytics.
|
|
306
|
-
*/
|
|
307
107
|
feature?: string;
|
|
308
108
|
}
|
|
309
|
-
/**
|
|
310
|
-
* Options for charging against a session.
|
|
311
|
-
*/
|
|
109
|
+
/** @internal */
|
|
312
110
|
interface ChargeSessionOptions {
|
|
313
|
-
/** Feature slug for tracking */
|
|
314
111
|
feature?: string;
|
|
315
|
-
/** Idempotency key to prevent double-charges */
|
|
316
112
|
idempotencyKey?: string;
|
|
317
|
-
/** Additional metadata */
|
|
318
113
|
metadata?: Record<string, unknown>;
|
|
319
114
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Result of a session charge.
|
|
322
|
-
*/
|
|
323
115
|
interface ChargeResult {
|
|
324
|
-
/** Whether the charge succeeded */
|
|
325
116
|
success: boolean;
|
|
326
|
-
/** Charge ID */
|
|
327
117
|
chargeId: string;
|
|
328
|
-
/** Amount charged in USD */
|
|
329
118
|
amountUsd: number;
|
|
330
|
-
/** Transaction hash (if on-chain) */
|
|
331
119
|
txHash?: string;
|
|
332
|
-
/** Remaining session balance in USD */
|
|
333
120
|
remainingSessionBalanceUsd: number;
|
|
334
121
|
}
|
|
335
|
-
/**
|
|
336
|
-
* Statistics about session authorizations.
|
|
337
|
-
*
|
|
338
|
-
* This provides an overview of all sessions managed by the wallet.
|
|
339
|
-
*/
|
|
340
122
|
interface SessionStats {
|
|
341
|
-
/** Number of active sessions */
|
|
342
123
|
activeCount: number;
|
|
343
|
-
/** Number of expired sessions */
|
|
344
124
|
expiredCount: number;
|
|
345
|
-
/** Number of revoked sessions */
|
|
346
125
|
revokedCount: number;
|
|
347
|
-
/** Total amount authorized across all active sessions in USD */
|
|
348
126
|
totalAuthorizedUsd: number;
|
|
349
|
-
/** Total amount spent across all sessions in USD */
|
|
350
127
|
totalSpentUsd: number;
|
|
351
|
-
/** Total remaining across all active sessions in USD */
|
|
352
128
|
totalRemainingUsd: number;
|
|
353
|
-
/** List of active sessions (summary) */
|
|
354
129
|
activeSessions: Array<{
|
|
355
130
|
id: string;
|
|
356
131
|
merchantName: string;
|
|
@@ -360,32 +135,184 @@ interface SessionStats {
|
|
|
360
135
|
expiresAt: Date;
|
|
361
136
|
}>;
|
|
362
137
|
}
|
|
363
|
-
|
|
138
|
+
interface TokenBalance {
|
|
139
|
+
balance: string;
|
|
140
|
+
raw: string;
|
|
141
|
+
decimals?: number;
|
|
142
|
+
}
|
|
143
|
+
interface DelegationBudget {
|
|
144
|
+
budget_total_usd: string;
|
|
145
|
+
budget_spent_usd: string;
|
|
146
|
+
budget_remaining_usd: string;
|
|
147
|
+
per_tx_limit_usd: string;
|
|
148
|
+
daily_limit_usd: string;
|
|
149
|
+
}
|
|
150
|
+
interface BalancesResponse {
|
|
151
|
+
wallet_address: string;
|
|
152
|
+
chain: string;
|
|
153
|
+
chain_id: number;
|
|
154
|
+
balances: Record<string, TokenBalance>;
|
|
155
|
+
delegation?: DelegationBudget;
|
|
156
|
+
request_id: string;
|
|
157
|
+
}
|
|
158
|
+
interface TransferResponse {
|
|
159
|
+
success: boolean;
|
|
160
|
+
tx_hash: string;
|
|
161
|
+
amount_usd: string;
|
|
162
|
+
remaining_budget_usd: string | null;
|
|
163
|
+
charge_id: string;
|
|
164
|
+
}
|
|
165
|
+
interface SwapResponse {
|
|
166
|
+
success: boolean;
|
|
167
|
+
tx_hash: string;
|
|
168
|
+
sell_amount: string;
|
|
169
|
+
sell_token: string;
|
|
170
|
+
buy_amount: string;
|
|
171
|
+
min_buy_amount: string;
|
|
172
|
+
buy_token: string;
|
|
173
|
+
price: string;
|
|
174
|
+
gas_estimate: string;
|
|
175
|
+
remaining_budget_usd: string | null;
|
|
176
|
+
charge_id: string;
|
|
177
|
+
}
|
|
178
|
+
interface BridgeResponse {
|
|
179
|
+
success: boolean;
|
|
180
|
+
tx_hash: string;
|
|
181
|
+
order_id: string;
|
|
182
|
+
amount: string;
|
|
183
|
+
source_chain: string;
|
|
184
|
+
dest_chain: string;
|
|
185
|
+
estimated_receive: string;
|
|
186
|
+
remaining_budget_usd: string | null;
|
|
187
|
+
charge_id: string;
|
|
188
|
+
}
|
|
189
|
+
interface BridgeStatusResponse {
|
|
190
|
+
order_id: string;
|
|
191
|
+
status: 'pending' | 'fulfilled' | 'failed' | 'cancelled';
|
|
192
|
+
source_chain: string;
|
|
193
|
+
source_tx_hash: string;
|
|
194
|
+
dest_chain: string;
|
|
195
|
+
dest_tx_hash?: string;
|
|
196
|
+
estimated_time_remaining?: string;
|
|
197
|
+
}
|
|
198
|
+
interface FetchPaymentInfo {
|
|
199
|
+
paid: boolean;
|
|
200
|
+
amount_usd: string;
|
|
201
|
+
tx_hash?: string;
|
|
202
|
+
remaining_budget_usd: string | null;
|
|
203
|
+
}
|
|
204
|
+
interface FetchPaidResponse {
|
|
205
|
+
status: number;
|
|
206
|
+
headers: Record<string, string>;
|
|
207
|
+
body: unknown;
|
|
208
|
+
payment?: FetchPaymentInfo;
|
|
209
|
+
}
|
|
210
|
+
interface FetchPaidOptions {
|
|
211
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
212
|
+
headers?: Record<string, string>;
|
|
213
|
+
body?: unknown;
|
|
214
|
+
maxPaymentUsd?: number;
|
|
215
|
+
}
|
|
364
216
|
/**
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
*
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
*
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
217
|
+
* Known charge types in the MixrPay system.
|
|
218
|
+
* The API may return additional types not listed here.
|
|
219
|
+
*/
|
|
220
|
+
type KnownChargeType = 'payment' | 'defi_tx' | 'tool_call' | 'transfer' | 'swap' | 'bridge' | 'x402_payment' | 'jit_deploy';
|
|
221
|
+
/**
|
|
222
|
+
* Charge type - known types with autocomplete, plus string for forward compatibility.
|
|
223
|
+
*/
|
|
224
|
+
type ChargeType = KnownChargeType | (string & {});
|
|
225
|
+
/**
|
|
226
|
+
* A single transaction record from the agent's transaction history.
|
|
227
|
+
*/
|
|
228
|
+
interface TransactionRecord {
|
|
229
|
+
/** Unique charge ID */
|
|
230
|
+
id: string;
|
|
231
|
+
/** Type of charge (e.g., 'swap', 'transfer', 'bridge') */
|
|
232
|
+
chargeType: ChargeType;
|
|
233
|
+
/** Amount in USD (formatted string, e.g., "10.00") */
|
|
234
|
+
amount: string;
|
|
235
|
+
/** Currency (typically "USDC") */
|
|
236
|
+
currency: string;
|
|
237
|
+
/** Transaction status */
|
|
238
|
+
status: 'pending' | 'submitted' | 'confirmed' | 'failed';
|
|
239
|
+
/** Human-readable description */
|
|
240
|
+
description: string | null;
|
|
241
|
+
/** On-chain transaction hash (null if not yet submitted) */
|
|
242
|
+
txHash: string | null;
|
|
243
|
+
/** Source wallet address */
|
|
244
|
+
fromAddress: string;
|
|
245
|
+
/** Destination address */
|
|
246
|
+
toAddress: string;
|
|
247
|
+
/** Plan ID if this charge was part of a plan execution */
|
|
248
|
+
planId: string | null;
|
|
249
|
+
/** Step index within the plan */
|
|
250
|
+
planStepIndex: number | null;
|
|
251
|
+
/** ISO 8601 timestamp when the charge was created */
|
|
252
|
+
createdAt: string;
|
|
253
|
+
/** ISO 8601 timestamp when the charge was confirmed (null if pending/failed) */
|
|
254
|
+
confirmedAt: string | null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Response from getTransactions() containing paginated transaction history.
|
|
258
|
+
*/
|
|
259
|
+
interface TransactionsResponse {
|
|
260
|
+
/** Array of transaction records */
|
|
261
|
+
transactions: TransactionRecord[];
|
|
262
|
+
/** Total number of matching transactions */
|
|
263
|
+
total: number;
|
|
264
|
+
/** Whether there are more transactions beyond the current page */
|
|
265
|
+
hasMore: boolean;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Options for querying transaction history.
|
|
269
|
+
*/
|
|
270
|
+
interface GetTransactionsOptions {
|
|
271
|
+
/** Maximum number of transactions to return (default: 20, max: 100) */
|
|
272
|
+
limit?: number;
|
|
273
|
+
/** Number of transactions to skip (for pagination) */
|
|
274
|
+
offset?: number;
|
|
275
|
+
/** Filter by charge type (e.g., 'swap', 'transfer') */
|
|
276
|
+
chargeType?: string;
|
|
277
|
+
/** Filter by status */
|
|
278
|
+
status?: 'pending' | 'submitted' | 'confirmed' | 'failed';
|
|
279
|
+
/** Only return transactions after this date */
|
|
280
|
+
since?: Date;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* A tool definition formatted for the Anthropic API.
|
|
284
|
+
* Compatible with anthropic.messages.create({ tools: [...] }).
|
|
385
285
|
*/
|
|
286
|
+
interface AnthropicToolDefinition {
|
|
287
|
+
/** Tool name (e.g., 'check_balance', 'transfer_usdc') */
|
|
288
|
+
name: string;
|
|
289
|
+
/** Description of what the tool does (shown to the LLM) */
|
|
290
|
+
description: string;
|
|
291
|
+
/** JSON Schema for the tool's input parameters */
|
|
292
|
+
input_schema: {
|
|
293
|
+
type: 'object';
|
|
294
|
+
properties: Record<string, unknown>;
|
|
295
|
+
required?: string[];
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* A toolkit containing Anthropic-compatible tool definitions and an executor.
|
|
300
|
+
* Returned by wallet.tools() for use with raw Anthropic SDK.
|
|
301
|
+
*/
|
|
302
|
+
interface AnthropicToolkit {
|
|
303
|
+
/** Array of tool definitions for anthropic.messages.create({ tools: [...] }) */
|
|
304
|
+
definitions: AnthropicToolDefinition[];
|
|
305
|
+
/**
|
|
306
|
+
* Execute a tool by name with the given input.
|
|
307
|
+
* @param name - Tool name (e.g., 'check_balance')
|
|
308
|
+
* @param input - Tool input parameters
|
|
309
|
+
* @returns JSON string result (for tool_result content)
|
|
310
|
+
*/
|
|
311
|
+
execute: (name: string, input: Record<string, unknown>) => Promise<string>;
|
|
312
|
+
}
|
|
386
313
|
|
|
387
314
|
/** Current SDK version */
|
|
388
|
-
declare const SDK_VERSION = "0.
|
|
315
|
+
declare const SDK_VERSION = "0.10.0";
|
|
389
316
|
/** Supported networks */
|
|
390
317
|
declare const NETWORKS: {
|
|
391
318
|
readonly BASE_MAINNET: {
|
|
@@ -553,11 +480,122 @@ interface AgentClaimInviteResult {
|
|
|
553
480
|
/** Name of the person who created the invite */
|
|
554
481
|
inviterName: string;
|
|
555
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* Options for activating an agent
|
|
485
|
+
*/
|
|
486
|
+
interface AgentActivateOptions {
|
|
487
|
+
/** MixrPay API base URL (default: https://www.mixrpay.com) */
|
|
488
|
+
baseUrl?: string;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Agent runtime returned from activation
|
|
492
|
+
* Contains the wallet instance and all capabilities/tools available to the agent
|
|
493
|
+
*/
|
|
494
|
+
interface AgentRuntime {
|
|
495
|
+
/** Pre-configured AgentWallet instance */
|
|
496
|
+
wallet: AgentWallet;
|
|
497
|
+
/** Budget limits and current spending */
|
|
498
|
+
budget: {
|
|
499
|
+
maxTotalUsd: number | null;
|
|
500
|
+
maxDailyUsd: number | null;
|
|
501
|
+
maxPerTxUsd: number | null;
|
|
502
|
+
spentUsd: number;
|
|
503
|
+
remainingUsd: number | null;
|
|
504
|
+
};
|
|
505
|
+
/** Feature capabilities */
|
|
506
|
+
capabilities: {
|
|
507
|
+
executeTransactions: boolean;
|
|
508
|
+
gasSponsored: boolean;
|
|
509
|
+
batchedTx: boolean;
|
|
510
|
+
};
|
|
511
|
+
/** Installed business skills */
|
|
512
|
+
skills: Array<{
|
|
513
|
+
id: string;
|
|
514
|
+
name: string;
|
|
515
|
+
version: number;
|
|
516
|
+
}>;
|
|
517
|
+
/** Available tools */
|
|
518
|
+
tools: Array<{
|
|
519
|
+
name: string;
|
|
520
|
+
type: string;
|
|
521
|
+
}>;
|
|
522
|
+
/** Configured gateway providers and their tools */
|
|
523
|
+
gatewayProviders: Array<{
|
|
524
|
+
name: string;
|
|
525
|
+
tools: string[];
|
|
526
|
+
}>;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Options for AgentWallet.connect() auth cascade
|
|
530
|
+
*/
|
|
531
|
+
interface ConnectOptions {
|
|
532
|
+
/** Explicit session key (highest priority) */
|
|
533
|
+
sessionKey?: string;
|
|
534
|
+
/** Access code from MixrPay dashboard (mixr-xxx) - one-time use, auto-cached */
|
|
535
|
+
accessCode?: string;
|
|
536
|
+
/** Master key for multi-agent deployments */
|
|
537
|
+
masterKey?: string;
|
|
538
|
+
/** Agent name when using master key */
|
|
539
|
+
agentName?: string;
|
|
540
|
+
/** Enable interactive device flow login if no credentials found */
|
|
541
|
+
interactive?: boolean;
|
|
542
|
+
/** MixrPay API base URL (default: https://www.mixrpay.com) */
|
|
543
|
+
baseUrl?: string;
|
|
544
|
+
/** Log level for debugging */
|
|
545
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
546
|
+
/** Client-side maximum payment amount in USD */
|
|
547
|
+
maxPaymentUsd?: number;
|
|
548
|
+
/** Callback for payment events */
|
|
549
|
+
onPayment?: (payment: PaymentEvent) => void;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Options for generating a SIWE (Sign-In with Ethereum) message
|
|
553
|
+
* Per EIP-4361: https://eips.ethereum.org/EIPS/eip-4361
|
|
554
|
+
*/
|
|
555
|
+
interface SiweOptions {
|
|
556
|
+
/** The domain making the request (e.g., "example.com") */
|
|
557
|
+
domain: string;
|
|
558
|
+
/** The URI of the resource being accessed */
|
|
559
|
+
uri: string;
|
|
560
|
+
/** Human-readable statement for the user */
|
|
561
|
+
statement?: string;
|
|
562
|
+
/** Server-provided nonce for replay protection (default: random UUID) */
|
|
563
|
+
nonce?: string;
|
|
564
|
+
/** When the message was issued (default: now) */
|
|
565
|
+
issuedAt?: Date;
|
|
566
|
+
/** When the signed message expires */
|
|
567
|
+
expirationTime?: Date;
|
|
568
|
+
/** When the signed message becomes valid */
|
|
569
|
+
notBefore?: Date;
|
|
570
|
+
/** System-specific request identifier */
|
|
571
|
+
requestId?: string;
|
|
572
|
+
/** List of resources the user is authorizing */
|
|
573
|
+
resources?: string[];
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Result from generating a SIWE message
|
|
577
|
+
*/
|
|
578
|
+
interface SiweResult {
|
|
579
|
+
/** The formatted SIWE message */
|
|
580
|
+
message: string;
|
|
581
|
+
/** The signature (hex string with 0x prefix) */
|
|
582
|
+
signature: string;
|
|
583
|
+
/** The signing address */
|
|
584
|
+
address: string;
|
|
585
|
+
/** The chain ID */
|
|
586
|
+
chainId: number;
|
|
587
|
+
/** The nonce used */
|
|
588
|
+
nonce: string;
|
|
589
|
+
/** When the message was issued */
|
|
590
|
+
issuedAt: Date;
|
|
591
|
+
/** When the message expires (if set) */
|
|
592
|
+
expirationTime?: Date;
|
|
593
|
+
}
|
|
556
594
|
/**
|
|
557
595
|
* Options for spawning a child invite
|
|
558
596
|
*/
|
|
559
597
|
interface SpawnChildOptions {
|
|
560
|
-
/** Budget in USD for the child (
|
|
598
|
+
/** Budget in USD for the child (subject to platform limits) */
|
|
561
599
|
budgetUsd: number;
|
|
562
600
|
/** Name for the child invite */
|
|
563
601
|
name: string;
|
|
@@ -574,13 +612,13 @@ interface SpawnChildResult {
|
|
|
574
612
|
inviteCode: string;
|
|
575
613
|
/** Database ID of the invite */
|
|
576
614
|
inviteId: string;
|
|
577
|
-
/** Actual budget (may be less than requested due to
|
|
615
|
+
/** Actual budget (may be less than requested due to platform limits) */
|
|
578
616
|
budgetUsd: number;
|
|
579
617
|
/** When the invite expires */
|
|
580
618
|
expiresAt: Date;
|
|
581
619
|
/** Depth in hierarchy (1 = child, 2 = grandchild, etc.) */
|
|
582
620
|
depth: number;
|
|
583
|
-
/** How much this child can spawn
|
|
621
|
+
/** How much this child can spawn */
|
|
584
622
|
maxSpawnBudget: number;
|
|
585
623
|
/** Allowed merchants for this child */
|
|
586
624
|
allowedMerchants: string[];
|
|
@@ -597,9 +635,9 @@ interface AvailableBudget {
|
|
|
597
635
|
allocatedToChildren: number;
|
|
598
636
|
/** Available for spending or spawning */
|
|
599
637
|
available: number;
|
|
600
|
-
/** Maximum budget for next spawn
|
|
638
|
+
/** Maximum budget for next spawn */
|
|
601
639
|
maxSpawnBudget: number;
|
|
602
|
-
/** Whether spawning is allowed
|
|
640
|
+
/** Whether spawning is allowed */
|
|
603
641
|
canSpawn: boolean;
|
|
604
642
|
}
|
|
605
643
|
/**
|
|
@@ -673,6 +711,16 @@ type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
|
673
711
|
* @see {@link AgentWalletConfig} for configuration options
|
|
674
712
|
* @see {@link PaymentEvent} for payment tracking
|
|
675
713
|
*/
|
|
714
|
+
/**
|
|
715
|
+
* Configuration returned by {@link AgentWallet.mcp} for use with the
|
|
716
|
+
* Claude Agent SDK's `mcpServers` option or any MCP client that accepts
|
|
717
|
+
* stdio server configs.
|
|
718
|
+
*/
|
|
719
|
+
interface McpServerConfig {
|
|
720
|
+
command: string;
|
|
721
|
+
args: string[];
|
|
722
|
+
env: Record<string, string>;
|
|
723
|
+
}
|
|
676
724
|
declare class AgentWallet {
|
|
677
725
|
private readonly sessionKey;
|
|
678
726
|
private readonly walletAddress;
|
|
@@ -687,6 +735,10 @@ declare class AgentWallet {
|
|
|
687
735
|
private sessionKeyInfoFetchedAt?;
|
|
688
736
|
private allowlist?;
|
|
689
737
|
private allowlistFetchedAt?;
|
|
738
|
+
private selfCustodyAddress?;
|
|
739
|
+
private selfCustodyKey?;
|
|
740
|
+
private agentInstanceId?;
|
|
741
|
+
private apiKey?;
|
|
690
742
|
/**
|
|
691
743
|
* Create a new AgentWallet instance.
|
|
692
744
|
*
|
|
@@ -748,7 +800,7 @@ declare class AgentWallet {
|
|
|
748
800
|
/**
|
|
749
801
|
* Register a new agent with MixrPay.
|
|
750
802
|
*
|
|
751
|
-
* This creates a
|
|
803
|
+
* This creates a platform-managed embedded wallet for the agent's payments.
|
|
752
804
|
* The agent proves ownership of their external wallet by signing a challenge.
|
|
753
805
|
*
|
|
754
806
|
* @param options - Registration options including the private key
|
|
@@ -786,7 +838,7 @@ declare class AgentWallet {
|
|
|
786
838
|
healthy: boolean;
|
|
787
839
|
database: string;
|
|
788
840
|
agentRegistrationAvailable: boolean;
|
|
789
|
-
|
|
841
|
+
walletServiceConfigured: boolean;
|
|
790
842
|
error?: string;
|
|
791
843
|
}>;
|
|
792
844
|
/**
|
|
@@ -885,9 +937,11 @@ declare class AgentWallet {
|
|
|
885
937
|
/**
|
|
886
938
|
* Claim an agent invite code to receive a session key for the inviter's wallet.
|
|
887
939
|
*
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
940
|
+
* @deprecated Use `AgentWallet.fromAccessCode()` instead for a simpler flow that requires
|
|
941
|
+
* no wallet or signature. The new method:
|
|
942
|
+
* - Accepts a simple access code (mixr-xxx) instead of requiring a private key
|
|
943
|
+
* - Auto-caches credentials for subsequent calls
|
|
944
|
+
* - Works with `connect({ accessCode: 'mixr-xxx' })` or `MIXRPAY_ACCESS_CODE` env var
|
|
891
945
|
*
|
|
892
946
|
* @param options - Claim invite options including the invite code and agent's private key
|
|
893
947
|
* @returns Claim result with the new session key
|
|
@@ -895,28 +949,211 @@ declare class AgentWallet {
|
|
|
895
949
|
*
|
|
896
950
|
* @example
|
|
897
951
|
* ```typescript
|
|
898
|
-
* //
|
|
899
|
-
*
|
|
952
|
+
* // DEPRECATED: Old way requiring private key
|
|
900
953
|
* const result = await AgentWallet.claimInvite({
|
|
901
954
|
* inviteCode: 'mixr-abc123',
|
|
902
955
|
* privateKey: process.env.AGENT_WALLET_KEY as `0x${string}`,
|
|
903
956
|
* });
|
|
904
957
|
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* // Use the session key to make payments
|
|
910
|
-
* const wallet = new AgentWallet({ sessionKey: result.sessionKey });
|
|
911
|
-
* const response = await wallet.fetch('https://api.example.com/endpoint');
|
|
958
|
+
* // NEW: Use fromAccessCode() instead - no private key needed
|
|
959
|
+
* const wallet = await AgentWallet.fromAccessCode('mixr-abc123');
|
|
960
|
+
* // or: const wallet = await AgentWallet.connect({ accessCode: 'mixr-abc123' });
|
|
912
961
|
* ```
|
|
913
962
|
*/
|
|
914
963
|
static claimInvite(options: AgentClaimInviteOptions): Promise<AgentClaimInviteResult>;
|
|
964
|
+
/**
|
|
965
|
+
* Activate an agent using a session key.
|
|
966
|
+
*
|
|
967
|
+
* This is the recommended way to initialize an agent at startup. It creates
|
|
968
|
+
* an AgentWallet instance and fetches all capabilities, budget info, skills,
|
|
969
|
+
* tools, and gateway providers in a single call.
|
|
970
|
+
*
|
|
971
|
+
* @param sessionKey - The session key in sk_live_ or sk_test_ format
|
|
972
|
+
* @param options - Optional configuration
|
|
973
|
+
* @returns AgentRuntime with wallet and all capabilities
|
|
974
|
+
* @throws {MixrPayError} If activation fails
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* ```typescript
|
|
978
|
+
* // Activate at agent startup
|
|
979
|
+
* const runtime = await AgentWallet.activate(process.env.MIXRPAY_SESSION_KEY!);
|
|
980
|
+
*
|
|
981
|
+
* // Use the wallet for payments
|
|
982
|
+
* const response = await runtime.wallet.fetch('https://api.example.com/endpoint');
|
|
983
|
+
*
|
|
984
|
+
* // Check capabilities
|
|
985
|
+
* if (runtime.capabilities.gasSponsored) {
|
|
986
|
+
* console.log('Gas is sponsored - no ETH needed!');
|
|
987
|
+
* }
|
|
988
|
+
*
|
|
989
|
+
* // List available gateway providers
|
|
990
|
+
* for (const provider of runtime.gatewayProviders) {
|
|
991
|
+
* console.log(`${provider.name}: ${provider.tools.join(', ')}`);
|
|
992
|
+
* }
|
|
993
|
+
*
|
|
994
|
+
* // Check budget
|
|
995
|
+
* console.log(`Budget remaining: $${runtime.budget.remainingUsd}`);
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
static activate(sessionKey: string, options?: AgentActivateOptions): Promise<AgentRuntime>;
|
|
999
|
+
/**
|
|
1000
|
+
* Connect to MixrPay with automatic credential resolution.
|
|
1001
|
+
*
|
|
1002
|
+
* This is the recommended zero-config entry point for agents. It implements
|
|
1003
|
+
* an auth cascade that tries multiple credential sources in order:
|
|
1004
|
+
*
|
|
1005
|
+
* 1. **Explicit key**: If `sessionKey` is provided in options
|
|
1006
|
+
* 2. **Environment variables**: `MIXRPAY_SESSION_KEY` (session key)
|
|
1007
|
+
* 3. **Environment variables**: `MIXRPAY_API_KEY` or `MIXRPAY_AGENT_TOKEN` (agent token)
|
|
1008
|
+
* 4. **Access code**: `options.accessCode` or `MIXRPAY_ACCESS_CODE` env var (one-time use)
|
|
1009
|
+
* 5. **Master key + name**: `MIXRPAY_MASTER_KEY` + `options.agentName` (for multi-agent setups)
|
|
1010
|
+
* 6. **Cached credentials**: Previously saved via `saveCredentials()` or CLI login
|
|
1011
|
+
* 7. **Device flow**: Interactive browser-based login (if `interactive: true`)
|
|
1012
|
+
*
|
|
1013
|
+
* @param options - Optional connection options
|
|
1014
|
+
* @returns Connected AgentWallet instance
|
|
1015
|
+
* @throws {MixrPayError} If no credentials found and interactive mode disabled
|
|
1016
|
+
*
|
|
1017
|
+
* @example Zero-config (uses env vars or cached creds)
|
|
1018
|
+
* ```typescript
|
|
1019
|
+
* const wallet = await AgentWallet.connect();
|
|
1020
|
+
* await wallet.fetch('https://api.example.com/endpoint');
|
|
1021
|
+
* ```
|
|
1022
|
+
*
|
|
1023
|
+
* @example With explicit session key
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* const wallet = await AgentWallet.connect({
|
|
1026
|
+
* sessionKey: 'sk_live_...',
|
|
1027
|
+
* });
|
|
1028
|
+
* ```
|
|
1029
|
+
*
|
|
1030
|
+
* @example With master key for specific agent
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* const wallet = await AgentWallet.connect({
|
|
1033
|
+
* masterKey: process.env.MIXRPAY_MASTER_KEY,
|
|
1034
|
+
* agentName: 'research-agent',
|
|
1035
|
+
* });
|
|
1036
|
+
* ```
|
|
1037
|
+
*
|
|
1038
|
+
* @example Interactive mode (prompts for login if no creds)
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* const wallet = await AgentWallet.connect({
|
|
1041
|
+
* interactive: true,
|
|
1042
|
+
* });
|
|
1043
|
+
* ```
|
|
1044
|
+
*/
|
|
1045
|
+
static connect(options?: ConnectOptions): Promise<AgentWallet>;
|
|
1046
|
+
/**
|
|
1047
|
+
* Create an AgentWallet from an API key (agt_live_xxx format).
|
|
1048
|
+
*
|
|
1049
|
+
* API keys are long-lived tokens that can be exchanged for session keys.
|
|
1050
|
+
* This is useful for server-side deployments where you don't want to
|
|
1051
|
+
* manage session key rotation manually.
|
|
1052
|
+
*
|
|
1053
|
+
* @param apiKey - API key in agt_live_xxx or agt_test_xxx format
|
|
1054
|
+
* @param options - Optional configuration
|
|
1055
|
+
* @returns Connected AgentWallet instance
|
|
1056
|
+
* @throws {MixrPayError} If API key is invalid or exchange fails
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```typescript
|
|
1060
|
+
* const wallet = await AgentWallet.fromApiKey('agt_live_xxx');
|
|
1061
|
+
* await wallet.fetch('https://api.example.com/endpoint');
|
|
1062
|
+
* ```
|
|
1063
|
+
*/
|
|
1064
|
+
static fromApiKey(apiKey: string, options?: {
|
|
1065
|
+
baseUrl?: string;
|
|
1066
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
1067
|
+
}): Promise<AgentWallet>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Create an AgentWallet from an access code (mixr-xxx format).
|
|
1070
|
+
*
|
|
1071
|
+
* Access codes are one-time use codes generated in the MixrPay dashboard.
|
|
1072
|
+
* After activation, the code is consumed and credentials are cached
|
|
1073
|
+
* for subsequent use. This is the recommended method for external agents
|
|
1074
|
+
* (Cursor, Claude, GPT, etc.) to connect to MixrPay.
|
|
1075
|
+
*
|
|
1076
|
+
* The access code is exchanged for:
|
|
1077
|
+
* - `session_key` (sk_live_xxx) - used for signing delegation payments
|
|
1078
|
+
* - `token` (agt_live_xxx) - bearer token for API calls
|
|
1079
|
+
* - `agent_id` - AgentInstance ID for reference
|
|
1080
|
+
* - `budget` - spending limits
|
|
1081
|
+
* - `tools` - available MCP tools
|
|
1082
|
+
*
|
|
1083
|
+
* @param code - Access code in mixr-xxx format
|
|
1084
|
+
* @param options - Optional configuration
|
|
1085
|
+
* @returns Connected AgentWallet instance
|
|
1086
|
+
* @throws {MixrPayError} If access code is invalid, expired, or already used
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* // First-time setup with access code
|
|
1091
|
+
* const wallet = await AgentWallet.fromAccessCode('mixr-abc123def456');
|
|
1092
|
+
*
|
|
1093
|
+
* // Session key is auto-cached, subsequent calls use cached credentials
|
|
1094
|
+
* const wallet2 = await AgentWallet.connect();
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
static fromAccessCode(code: string, options?: {
|
|
1098
|
+
baseUrl?: string;
|
|
1099
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
1100
|
+
}): Promise<AgentWallet>;
|
|
1101
|
+
/**
|
|
1102
|
+
* Create an AgentWallet using a master key for a specific agent.
|
|
1103
|
+
*
|
|
1104
|
+
* Master keys (mk_live_xxx) are organization-level credentials that can
|
|
1105
|
+
* create sessions for any agent in the organization. This is useful for
|
|
1106
|
+
* multi-agent deployments managed by a single entity.
|
|
1107
|
+
*
|
|
1108
|
+
* Note: Master key flow provides delegation access only. Self-custody
|
|
1109
|
+
* wallet operations (createSelfCustodyWallet, transferUSDC, executeFromOwnWallet)
|
|
1110
|
+
* require an agt_live_ token -- use fromApiKey() or fromAccessCode() instead.
|
|
1111
|
+
*
|
|
1112
|
+
* @param masterKey - Master key in mk_live_xxx format
|
|
1113
|
+
* @param agentName - Name of the agent to connect as
|
|
1114
|
+
* @param options - Optional configuration
|
|
1115
|
+
* @returns Connected AgentWallet instance
|
|
1116
|
+
* @throws {MixrPayError} If master key is invalid or agent not found
|
|
1117
|
+
*
|
|
1118
|
+
* @example
|
|
1119
|
+
* ```typescript
|
|
1120
|
+
* const wallet = await AgentWallet.fromMasterKey(
|
|
1121
|
+
* process.env.MIXRPAY_MASTER_KEY!,
|
|
1122
|
+
* 'research-agent'
|
|
1123
|
+
* );
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
static fromMasterKey(masterKey: string, agentName: string, options?: {
|
|
1127
|
+
baseUrl?: string;
|
|
1128
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
1129
|
+
}): Promise<AgentWallet>;
|
|
1130
|
+
/**
|
|
1131
|
+
* Interactive device flow login.
|
|
1132
|
+
*
|
|
1133
|
+
* Opens a browser for the user to authenticate, then polls for completion.
|
|
1134
|
+
* This is the OAuth 2.0 Device Authorization Grant flow.
|
|
1135
|
+
*
|
|
1136
|
+
* @param options - Optional configuration
|
|
1137
|
+
* @returns Connected AgentWallet instance
|
|
1138
|
+
* @throws {MixrPayError} If device flow fails or times out
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* ```typescript
|
|
1142
|
+
* // In a CLI or terminal application
|
|
1143
|
+
* const wallet = await AgentWallet.deviceFlowLogin();
|
|
1144
|
+
* // User sees: "Visit https://mixrpay.com/device and enter code: ABCD-1234"
|
|
1145
|
+
* // After user authenticates, wallet is ready to use
|
|
1146
|
+
* ```
|
|
1147
|
+
*/
|
|
1148
|
+
static deviceFlowLogin(options?: {
|
|
1149
|
+
baseUrl?: string;
|
|
1150
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
1151
|
+
}): Promise<AgentWallet>;
|
|
915
1152
|
/**
|
|
916
1153
|
* Spawn a child invite for sub-agents.
|
|
917
1154
|
*
|
|
918
1155
|
* Allows an agent to create an invite code for a sub-agent with a portion
|
|
919
|
-
* of their remaining budget
|
|
1156
|
+
* of their remaining budget. The child inherits merchant restrictions
|
|
920
1157
|
* and cannot outlive the parent session.
|
|
921
1158
|
*
|
|
922
1159
|
* @param options - Spawn options
|
|
@@ -930,7 +1167,7 @@ declare class AgentWallet {
|
|
|
930
1167
|
*
|
|
931
1168
|
* // Spawn a child invite for a sub-agent
|
|
932
1169
|
* const childInvite = await wallet.spawnChildInvite({
|
|
933
|
-
* budgetUsd: 10.00,
|
|
1170
|
+
* budgetUsd: 10.00,
|
|
934
1171
|
* name: 'Research Sub-Agent',
|
|
935
1172
|
* allowedMerchants: ['firecrawl.dev'], // Must be subset of parent
|
|
936
1173
|
* expiresInDays: 7, // Will be capped to parent's expiry
|
|
@@ -944,8 +1181,7 @@ declare class AgentWallet {
|
|
|
944
1181
|
/**
|
|
945
1182
|
* Get available budget information for spawning.
|
|
946
1183
|
*
|
|
947
|
-
* Returns the current budget status including
|
|
948
|
-
* to child agents (20% of available).
|
|
1184
|
+
* Returns the current budget status including spawn availability.
|
|
949
1185
|
*
|
|
950
1186
|
* @returns Budget information
|
|
951
1187
|
*
|
|
@@ -1130,9 +1366,13 @@ declare class AgentWallet {
|
|
|
1130
1366
|
*/
|
|
1131
1367
|
getSpendingStats(): Promise<SpendingStats>;
|
|
1132
1368
|
/**
|
|
1133
|
-
* Get list of payments made in this session.
|
|
1369
|
+
* Get list of payments made in this session (in-memory only).
|
|
1134
1370
|
*
|
|
1135
|
-
* @
|
|
1371
|
+
* @deprecated Use {@link getTransactions} instead for persistent transaction history.
|
|
1372
|
+
* This method only returns payments from the current process and is lost on restart.
|
|
1373
|
+
* `getTransactions()` returns server-persisted transaction history across all sessions.
|
|
1374
|
+
*
|
|
1375
|
+
* @returns Array of payment events from the current session
|
|
1136
1376
|
*/
|
|
1137
1377
|
getPaymentHistory(): PaymentEvent[];
|
|
1138
1378
|
/**
|
|
@@ -1140,7 +1380,212 @@ declare class AgentWallet {
|
|
|
1140
1380
|
*
|
|
1141
1381
|
* @returns Total spent in USD
|
|
1142
1382
|
*/
|
|
1143
|
-
getTotalSpent(): number;
|
|
1383
|
+
getTotalSpent(): number;
|
|
1384
|
+
/**
|
|
1385
|
+
* Create a self-custody wallet for this agent.
|
|
1386
|
+
*
|
|
1387
|
+
* Generates a new private key, signs a proof of ownership, registers the
|
|
1388
|
+
* address with MixrPay, and persists the key locally.
|
|
1389
|
+
*
|
|
1390
|
+
* The private key is stored locally and NEVER transmitted to MixrPay.
|
|
1391
|
+
* MixrPay only stores the public address for transaction verification.
|
|
1392
|
+
*
|
|
1393
|
+
* @returns The wallet address and private key
|
|
1394
|
+
* @throws {MixrPayError} If agent instance ID is not set or registration fails
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```typescript
|
|
1398
|
+
* const wallet = await AgentWallet.connect();
|
|
1399
|
+
*
|
|
1400
|
+
* // Create self-custody wallet (only needed once)
|
|
1401
|
+
* const { address, privateKey } = await wallet.createSelfCustodyWallet();
|
|
1402
|
+
* console.log(`Deposit address: ${address}`);
|
|
1403
|
+
*
|
|
1404
|
+
* // The private key is stored locally and loaded automatically
|
|
1405
|
+
* ```
|
|
1406
|
+
*/
|
|
1407
|
+
createSelfCustodyWallet(): Promise<{
|
|
1408
|
+
address: `0x${string}`;
|
|
1409
|
+
privateKey: `0x${string}`;
|
|
1410
|
+
}>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Register a wallet address with MixrPay.
|
|
1413
|
+
*
|
|
1414
|
+
* This is called automatically by createSelfCustodyWallet().
|
|
1415
|
+
* Only use directly if you have an existing private key.
|
|
1416
|
+
*
|
|
1417
|
+
* @param address - The wallet address to register
|
|
1418
|
+
* @param signature - Signature proving ownership
|
|
1419
|
+
* @param timestamp - Timestamp used in signature message
|
|
1420
|
+
* @throws {MixrPayError} If registration fails
|
|
1421
|
+
*/
|
|
1422
|
+
private registerWalletAddress;
|
|
1423
|
+
/**
|
|
1424
|
+
* Load an existing self-custody wallet from local storage.
|
|
1425
|
+
*
|
|
1426
|
+
* @returns True if wallet was loaded, false if no wallet exists
|
|
1427
|
+
*/
|
|
1428
|
+
loadSelfCustodyWallet(): Promise<boolean>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Check if this agent has a self-custody wallet.
|
|
1431
|
+
*
|
|
1432
|
+
* @returns True if a self-custody wallet exists
|
|
1433
|
+
*/
|
|
1434
|
+
hasSelfCustodyWallet(): Promise<boolean>;
|
|
1435
|
+
/**
|
|
1436
|
+
* Get the self-custody wallet address if one exists.
|
|
1437
|
+
*
|
|
1438
|
+
* @returns The wallet address or null if no self-custody wallet
|
|
1439
|
+
*/
|
|
1440
|
+
getSelfCustodyAddress(): `0x${string}` | null;
|
|
1441
|
+
/**
|
|
1442
|
+
* Execute a transaction from the agent's self-custody wallet.
|
|
1443
|
+
*
|
|
1444
|
+
* Signs the transaction locally using viem and submits directly to Base RPC.
|
|
1445
|
+
* Reports the transaction to MixrPay for audit logging.
|
|
1446
|
+
*
|
|
1447
|
+
* @param params - Transaction parameters
|
|
1448
|
+
* @returns Transaction result with hash
|
|
1449
|
+
* @throws {MixrPayError} If wallet not loaded or transaction fails
|
|
1450
|
+
*
|
|
1451
|
+
* @example
|
|
1452
|
+
* ```typescript
|
|
1453
|
+
* const result = await wallet.executeFromOwnWallet({
|
|
1454
|
+
* to: '0x...',
|
|
1455
|
+
* value: parseEther('0.01'),
|
|
1456
|
+
* data: '0x...',
|
|
1457
|
+
* });
|
|
1458
|
+
* console.log(`TX: ${result.txHash}`);
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
executeFromOwnWallet(params: {
|
|
1462
|
+
to: `0x${string}`;
|
|
1463
|
+
value?: bigint;
|
|
1464
|
+
data?: `0x${string}`;
|
|
1465
|
+
gasLimit?: bigint;
|
|
1466
|
+
}): Promise<{
|
|
1467
|
+
txHash: `0x${string}`;
|
|
1468
|
+
reportedToMixrPay: boolean;
|
|
1469
|
+
}>;
|
|
1470
|
+
/**
|
|
1471
|
+
* Transfer USDC from the agent's self-custody wallet.
|
|
1472
|
+
*
|
|
1473
|
+
* This is a convenience method for ERC-20 USDC transfers on Base.
|
|
1474
|
+
* Returns the transaction hash. The transaction is automatically
|
|
1475
|
+
* reported to MixrPay for audit logging.
|
|
1476
|
+
*
|
|
1477
|
+
* @param params - Transfer parameters
|
|
1478
|
+
* @returns Transaction hash
|
|
1479
|
+
* @throws {MixrPayError} If wallet not loaded or transfer fails
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```typescript
|
|
1483
|
+
* // Pay $5 USDC to a recipient
|
|
1484
|
+
* const txHash = await wallet.transferUSDC({
|
|
1485
|
+
* to: '0xRecipientAddress...',
|
|
1486
|
+
* amountUsdc: 5.00,
|
|
1487
|
+
* });
|
|
1488
|
+
*
|
|
1489
|
+
* console.log(`Transfer complete: ${txHash}`);
|
|
1490
|
+
* ```
|
|
1491
|
+
*/
|
|
1492
|
+
transferUSDC(params: {
|
|
1493
|
+
to: `0x${string}`;
|
|
1494
|
+
amountUsdc: number;
|
|
1495
|
+
}): Promise<`0x${string}`>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Report a transaction to MixrPay for audit logging.
|
|
1498
|
+
*
|
|
1499
|
+
* This is called automatically by executeFromOwnWallet().
|
|
1500
|
+
*
|
|
1501
|
+
* @param txHash - The transaction hash
|
|
1502
|
+
* @param to - The recipient address
|
|
1503
|
+
* @param value - The value transferred (in wei)
|
|
1504
|
+
*/
|
|
1505
|
+
private reportTransaction;
|
|
1506
|
+
/**
|
|
1507
|
+
* Get the agent instance ID.
|
|
1508
|
+
*
|
|
1509
|
+
* @returns The agent instance ID or undefined if not set
|
|
1510
|
+
*/
|
|
1511
|
+
getAgentInstanceId(): string | undefined;
|
|
1512
|
+
/**
|
|
1513
|
+
* Set the agent instance ID.
|
|
1514
|
+
*
|
|
1515
|
+
* This is typically set automatically when using fromApiKey() or connect().
|
|
1516
|
+
*
|
|
1517
|
+
* @param id - The agent instance ID
|
|
1518
|
+
*/
|
|
1519
|
+
setAgentInstanceId(id: string): void;
|
|
1520
|
+
/**
|
|
1521
|
+
* Set the API key for self-custody operations.
|
|
1522
|
+
*
|
|
1523
|
+
* This is set automatically when using fromApiKey(). The API key is used
|
|
1524
|
+
* for bearer token authentication on self-custody API calls (wallet registration,
|
|
1525
|
+
* transaction reporting, etc.).
|
|
1526
|
+
*
|
|
1527
|
+
* @param key - The API key (agt_live_xxx or agt_test_xxx)
|
|
1528
|
+
*/
|
|
1529
|
+
setApiKey(key: string): void;
|
|
1530
|
+
/**
|
|
1531
|
+
* Return an MCP server config for use with the Claude Agent SDK.
|
|
1532
|
+
*
|
|
1533
|
+
* Spawns a child stdio MCP server process that exposes wallet tools
|
|
1534
|
+
* (balance, marketplace, skills, transfers, budget delegation, tasks).
|
|
1535
|
+
*
|
|
1536
|
+
* @example With the Claude Agent SDK
|
|
1537
|
+
* ```typescript
|
|
1538
|
+
* import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
1539
|
+
* import { AgentWallet } from "@mixrpay/agent-sdk";
|
|
1540
|
+
*
|
|
1541
|
+
* const wallet = new AgentWallet({ sessionKey: process.env.MIXRPAY_SESSION_KEY! });
|
|
1542
|
+
*
|
|
1543
|
+
* for await (const msg of query({
|
|
1544
|
+
* prompt: "Use firecrawl to scrape example.com",
|
|
1545
|
+
* options: {
|
|
1546
|
+
* mcpServers: { mixrpay: wallet.mcp() },
|
|
1547
|
+
* allowedTools: ["mcp__mixrpay__*"],
|
|
1548
|
+
* },
|
|
1549
|
+
* })) {
|
|
1550
|
+
* if (msg.type === "result" && msg.subtype === "success") console.log(msg.result);
|
|
1551
|
+
* }
|
|
1552
|
+
* ```
|
|
1553
|
+
*/
|
|
1554
|
+
mcp(): McpServerConfig;
|
|
1555
|
+
/**
|
|
1556
|
+
* Get tool definitions for use with the Anthropic SDK or other LLM frameworks.
|
|
1557
|
+
*
|
|
1558
|
+
* This provides an in-process alternative to the MCP server. While `mcp()` spawns
|
|
1559
|
+
* a subprocess for Claude Agent SDK integration, `tools()` returns function-callable
|
|
1560
|
+
* tools for direct use with `anthropic.messages.create({ tools: [...] })`.
|
|
1561
|
+
*
|
|
1562
|
+
* @returns Toolkit with Anthropic-compatible definitions and execute dispatcher
|
|
1563
|
+
*
|
|
1564
|
+
* @example
|
|
1565
|
+
* ```typescript
|
|
1566
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
1567
|
+
* import { AgentWallet } from '@mixrpay/agent-sdk';
|
|
1568
|
+
*
|
|
1569
|
+
* const wallet = AgentWallet.fromApiKey('agt_live_xxx');
|
|
1570
|
+
* const { definitions, execute } = wallet.tools();
|
|
1571
|
+
*
|
|
1572
|
+
* const response = await anthropic.messages.create({
|
|
1573
|
+
* model: 'claude-sonnet-4-5-20250514',
|
|
1574
|
+
* max_tokens: 1024,
|
|
1575
|
+
* tools: definitions,
|
|
1576
|
+
* messages: [{ role: 'user', content: 'Check my USDC balance' }],
|
|
1577
|
+
* });
|
|
1578
|
+
*
|
|
1579
|
+
* for (const block of response.content) {
|
|
1580
|
+
* if (block.type === 'tool_use') {
|
|
1581
|
+
* const result = await execute(block.name, block.input as Record<string, unknown>);
|
|
1582
|
+
* // Feed result back to Claude as tool_result
|
|
1583
|
+
* console.log(`Tool ${block.name} returned:`, result);
|
|
1584
|
+
* }
|
|
1585
|
+
* }
|
|
1586
|
+
* ```
|
|
1587
|
+
*/
|
|
1588
|
+
tools(): AnthropicToolkit;
|
|
1144
1589
|
/**
|
|
1145
1590
|
* Run diagnostics to verify the wallet is properly configured.
|
|
1146
1591
|
*
|
|
@@ -1160,6 +1605,41 @@ declare class AgentWallet {
|
|
|
1160
1605
|
* ```
|
|
1161
1606
|
*/
|
|
1162
1607
|
runDiagnostics(): Promise<DiagnosticsResult>;
|
|
1608
|
+
/**
|
|
1609
|
+
* Generate a SIWE (Sign-In with Ethereum) message and signature.
|
|
1610
|
+
*
|
|
1611
|
+
* This implements EIP-4361 and can be used to authenticate with services
|
|
1612
|
+
* that support Sign-In with Ethereum, proving ownership of the session key.
|
|
1613
|
+
*
|
|
1614
|
+
* @param options - SIWE message options
|
|
1615
|
+
* @returns SIWE message and signature
|
|
1616
|
+
*
|
|
1617
|
+
* @example Basic usage
|
|
1618
|
+
* ```typescript
|
|
1619
|
+
* const { message, signature } = await wallet.generateSiwe({
|
|
1620
|
+
* domain: 'example.com',
|
|
1621
|
+
* uri: 'https://example.com/login',
|
|
1622
|
+
* statement: 'Sign in to Example App',
|
|
1623
|
+
* });
|
|
1624
|
+
*
|
|
1625
|
+
* // Send to server for verification
|
|
1626
|
+
* await fetch('/api/verify', {
|
|
1627
|
+
* method: 'POST',
|
|
1628
|
+
* body: JSON.stringify({ message, signature }),
|
|
1629
|
+
* });
|
|
1630
|
+
* ```
|
|
1631
|
+
*
|
|
1632
|
+
* @example With nonce and expiration
|
|
1633
|
+
* ```typescript
|
|
1634
|
+
* const { message, signature } = await wallet.generateSiwe({
|
|
1635
|
+
* domain: 'myapp.com',
|
|
1636
|
+
* uri: 'https://myapp.com',
|
|
1637
|
+
* nonce: 'abc123', // Server-provided nonce
|
|
1638
|
+
* expirationTime: new Date(Date.now() + 5 * 60 * 1000), // 5 min
|
|
1639
|
+
* });
|
|
1640
|
+
* ```
|
|
1641
|
+
*/
|
|
1642
|
+
generateSiwe(options: SiweOptions): Promise<SiweResult>;
|
|
1163
1643
|
/**
|
|
1164
1644
|
* Enable or disable debug logging.
|
|
1165
1645
|
*
|
|
@@ -1202,8 +1682,8 @@ declare class AgentWallet {
|
|
|
1202
1682
|
* ```typescript
|
|
1203
1683
|
* const session = await wallet.getOrCreateSession({
|
|
1204
1684
|
* merchantPublicKey: 'pk_live_abc123...',
|
|
1205
|
-
* spendingLimitUsd:
|
|
1206
|
-
* durationDays:
|
|
1685
|
+
* spendingLimitUsd: 100,
|
|
1686
|
+
* durationDays: 30,
|
|
1207
1687
|
* });
|
|
1208
1688
|
*
|
|
1209
1689
|
* console.log(`Session active: $${session.remainingLimitUsd} remaining`);
|
|
@@ -1353,19 +1833,23 @@ declare class AgentWallet {
|
|
|
1353
1833
|
* Returns all tools exposed by MCP providers on the MixrPay marketplace.
|
|
1354
1834
|
* Each tool includes pricing information.
|
|
1355
1835
|
*
|
|
1356
|
-
* @returns Array of
|
|
1836
|
+
* @returns Array of tools with pricing and metadata
|
|
1357
1837
|
*
|
|
1358
1838
|
* @example
|
|
1359
1839
|
* ```typescript
|
|
1360
|
-
* const tools = await wallet.
|
|
1840
|
+
* const tools = await wallet.listTools();
|
|
1361
1841
|
* for (const tool of tools) {
|
|
1362
1842
|
* console.log(`${tool.name}: $${tool.priceUsd} - ${tool.description}`);
|
|
1363
1843
|
* }
|
|
1364
1844
|
* ```
|
|
1365
1845
|
*/
|
|
1366
|
-
|
|
1846
|
+
listTools(): Promise<Tool[]>;
|
|
1847
|
+
/**
|
|
1848
|
+
* @deprecated Use listTools() instead.
|
|
1849
|
+
*/
|
|
1850
|
+
listMCPTools(): Promise<Tool[]>;
|
|
1367
1851
|
/**
|
|
1368
|
-
* Call
|
|
1852
|
+
* Call a tool with wallet authentication (direct pay per call).
|
|
1369
1853
|
*
|
|
1370
1854
|
* This method signs a fresh auth message for each call, charging
|
|
1371
1855
|
* directly from your wallet balance without needing a session.
|
|
@@ -1376,14 +1860,18 @@ declare class AgentWallet {
|
|
|
1376
1860
|
*
|
|
1377
1861
|
* @example
|
|
1378
1862
|
* ```typescript
|
|
1379
|
-
* const result = await wallet.
|
|
1863
|
+
* const result = await wallet.callTool('firecrawl/scrape', {
|
|
1380
1864
|
* url: 'https://example.com',
|
|
1381
1865
|
* });
|
|
1382
1866
|
* console.log(result.data);
|
|
1383
1867
|
* console.log(`Charged: $${result.chargedUsd}`);
|
|
1384
1868
|
* ```
|
|
1385
1869
|
*/
|
|
1386
|
-
|
|
1870
|
+
callTool(toolName: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
1871
|
+
/**
|
|
1872
|
+
* @deprecated Use callTool() instead.
|
|
1873
|
+
*/
|
|
1874
|
+
callMCPTool(toolName: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
1387
1875
|
/**
|
|
1388
1876
|
* Deploy a JIT MCP server from the Glama directory.
|
|
1389
1877
|
*
|
|
@@ -1459,6 +1947,46 @@ declare class AgentWallet {
|
|
|
1459
1947
|
* ```
|
|
1460
1948
|
*/
|
|
1461
1949
|
getJitInstance(instanceId: string): Promise<JitInstance>;
|
|
1950
|
+
/**
|
|
1951
|
+
* Execute an on-chain transaction from the human's wallet.
|
|
1952
|
+
*
|
|
1953
|
+
* Submits arbitrary calldata to any contract, bounded by the session key's
|
|
1954
|
+
* budget limits (max_total, max_per_tx, max_daily). The platform validates
|
|
1955
|
+
* the budget, executes the transaction, and records a charge.
|
|
1956
|
+
*
|
|
1957
|
+
* @param params - Transaction parameters
|
|
1958
|
+
* @returns Transaction result with hash and remaining budget
|
|
1959
|
+
* @throws {MixrPayError} If budget exceeded, tx reverted, or auth fails
|
|
1960
|
+
*
|
|
1961
|
+
* @example
|
|
1962
|
+
* ```typescript
|
|
1963
|
+
* // Bridge USDC via deBridge
|
|
1964
|
+
* const quote = await deBridgeMcp.create_tx({ ... });
|
|
1965
|
+
* const result = await wallet.executeTransaction({
|
|
1966
|
+
* to: quote.contractAddress,
|
|
1967
|
+
* data: quote.calldata,
|
|
1968
|
+
* estimatedCostUsd: 25.0,
|
|
1969
|
+
* description: 'Bridge 25 USDC Base -> Avalanche via deBridge',
|
|
1970
|
+
* });
|
|
1971
|
+
* console.log('TX:', result.txHash);
|
|
1972
|
+
* console.log('Budget remaining:', result.remainingBudgetUsd);
|
|
1973
|
+
* ```
|
|
1974
|
+
*/
|
|
1975
|
+
executeTransaction(params: {
|
|
1976
|
+
to: `0x${string}`;
|
|
1977
|
+
data: `0x${string}`;
|
|
1978
|
+
value?: bigint;
|
|
1979
|
+
chainId?: number;
|
|
1980
|
+
estimatedCostUsd: number;
|
|
1981
|
+
description?: string;
|
|
1982
|
+
idempotencyKey?: string;
|
|
1983
|
+
}): Promise<{
|
|
1984
|
+
success: boolean;
|
|
1985
|
+
txHash: string;
|
|
1986
|
+
chargeId: string;
|
|
1987
|
+
estimatedCostUsd: number;
|
|
1988
|
+
remainingBudgetUsd: number | null;
|
|
1989
|
+
}>;
|
|
1462
1990
|
/**
|
|
1463
1991
|
* Use a configured skill by deploying a JIT MCP server with your saved API keys.
|
|
1464
1992
|
*
|
|
@@ -1916,7 +2444,7 @@ declare class AgentWallet {
|
|
|
1916
2444
|
*/
|
|
1917
2445
|
getAgentRunStatus(runId: string, _sessionId?: string): Promise<AgentRunStatusResult>;
|
|
1918
2446
|
/**
|
|
1919
|
-
* Call
|
|
2447
|
+
* Call a gateway tool using session authorization (pre-authorized spending limit).
|
|
1920
2448
|
*
|
|
1921
2449
|
* Use this when you've already created a session with the tool provider
|
|
1922
2450
|
* and want to use that spending limit instead of direct wallet charges.
|
|
@@ -1935,14 +2463,18 @@ declare class AgentWallet {
|
|
|
1935
2463
|
* });
|
|
1936
2464
|
*
|
|
1937
2465
|
* // Use session for multiple calls
|
|
1938
|
-
* const result = await wallet.
|
|
2466
|
+
* const result = await wallet.callToolWithSession(
|
|
1939
2467
|
* session.id,
|
|
1940
2468
|
* 'firecrawl/scrape',
|
|
1941
2469
|
* { url: 'https://example.com' }
|
|
1942
2470
|
* );
|
|
1943
2471
|
* ```
|
|
1944
2472
|
*/
|
|
1945
|
-
|
|
2473
|
+
callToolWithSession(sessionId: string, toolName: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
2474
|
+
/**
|
|
2475
|
+
* @deprecated Use callToolWithSession() instead.
|
|
2476
|
+
*/
|
|
2477
|
+
callMCPToolWithSession(sessionId: string, toolName: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
1946
2478
|
/**
|
|
1947
2479
|
* Create a new task on the Task Board.
|
|
1948
2480
|
*
|
|
@@ -2275,6 +2807,190 @@ declare class AgentWallet {
|
|
|
2275
2807
|
private parseApprovalRequest;
|
|
2276
2808
|
/** Helper to parse task from API response */
|
|
2277
2809
|
private parseTask;
|
|
2810
|
+
/**
|
|
2811
|
+
* Get token balances for the wallet.
|
|
2812
|
+
*
|
|
2813
|
+
* Returns balances for USDC, ETH, and other tokens on the current chain.
|
|
2814
|
+
* For delegation wallets, also includes budget information.
|
|
2815
|
+
*
|
|
2816
|
+
* @returns Multi-token balance information
|
|
2817
|
+
* @throws {MixrPayError} If the request fails
|
|
2818
|
+
*
|
|
2819
|
+
* @example
|
|
2820
|
+
* ```typescript
|
|
2821
|
+
* const balances = await wallet.getBalances();
|
|
2822
|
+
* console.log(`USDC: ${balances.balances.USDC.balance}`);
|
|
2823
|
+
* console.log(`ETH: ${balances.balances.ETH.balance}`);
|
|
2824
|
+
* if (balances.delegation) {
|
|
2825
|
+
* console.log(`Budget remaining: $${balances.delegation.remaining_usd}`);
|
|
2826
|
+
* }
|
|
2827
|
+
* ```
|
|
2828
|
+
*/
|
|
2829
|
+
getBalances(): Promise<BalancesResponse>;
|
|
2830
|
+
/**
|
|
2831
|
+
* Get the agent's transaction history with filtering and pagination.
|
|
2832
|
+
*
|
|
2833
|
+
* Returns server-persisted transaction records including swaps, transfers,
|
|
2834
|
+
* bridges, and tool payments. Unlike `getPaymentHistory()`, this data
|
|
2835
|
+
* persists across process restarts and includes all historical transactions.
|
|
2836
|
+
*
|
|
2837
|
+
* @param options - Query options for filtering and pagination
|
|
2838
|
+
* @returns Paginated transaction records
|
|
2839
|
+
* @throws {MixrPayError} If the query fails
|
|
2840
|
+
*
|
|
2841
|
+
* @example
|
|
2842
|
+
* ```typescript
|
|
2843
|
+
* // Get recent transactions
|
|
2844
|
+
* const { transactions, total, hasMore } = await wallet.getTransactions();
|
|
2845
|
+
*
|
|
2846
|
+
* // Filter by type
|
|
2847
|
+
* const swaps = await wallet.getTransactions({ chargeType: 'swap' });
|
|
2848
|
+
*
|
|
2849
|
+
* // Paginate
|
|
2850
|
+
* const page2 = await wallet.getTransactions({ limit: 20, offset: 20 });
|
|
2851
|
+
*
|
|
2852
|
+
* // Get transactions since yesterday
|
|
2853
|
+
* const recent = await wallet.getTransactions({
|
|
2854
|
+
* since: new Date(Date.now() - 24 * 60 * 60 * 1000)
|
|
2855
|
+
* });
|
|
2856
|
+
* ```
|
|
2857
|
+
*/
|
|
2858
|
+
getTransactions(options?: GetTransactionsOptions): Promise<TransactionsResponse>;
|
|
2859
|
+
/**
|
|
2860
|
+
* Transfer USDC to another address.
|
|
2861
|
+
*
|
|
2862
|
+
* For delegation wallets: Uses delegation signing (no local key needed).
|
|
2863
|
+
* For self-custody wallets: Use transferUSDC() instead.
|
|
2864
|
+
*
|
|
2865
|
+
* @param to - Recipient address
|
|
2866
|
+
* @param amount - Amount in USD (e.g., "10.50")
|
|
2867
|
+
* @param currency - Currency to transfer (default: "USDC")
|
|
2868
|
+
* @returns Transfer result with transaction hash
|
|
2869
|
+
* @throws {MixrPayError} If the transfer fails
|
|
2870
|
+
*
|
|
2871
|
+
* @example
|
|
2872
|
+
* ```typescript
|
|
2873
|
+
* const result = await wallet.transfer('0x1234...', '10.00');
|
|
2874
|
+
* console.log(`Transferred $${result.amount_usd}`);
|
|
2875
|
+
* console.log(`TX: ${result.tx_hash}`);
|
|
2876
|
+
* console.log(`Remaining budget: $${result.remaining_budget_usd}`);
|
|
2877
|
+
* ```
|
|
2878
|
+
*/
|
|
2879
|
+
transfer(to: string, amount: string, currency?: string): Promise<TransferResponse>;
|
|
2880
|
+
/**
|
|
2881
|
+
* Swap tokens using 0x Protocol on Base.
|
|
2882
|
+
*
|
|
2883
|
+
* Supports any ERC-20 token pair. First swap of a token may require
|
|
2884
|
+
* an approval transaction (extra gas).
|
|
2885
|
+
*
|
|
2886
|
+
* @param sellToken - Token to sell (symbol or address, e.g., "USDC", "ETH")
|
|
2887
|
+
* @param buyToken - Token to buy (symbol or address, e.g., "WETH", "USDC")
|
|
2888
|
+
* @param sellAmount - Amount to sell in human-readable format (e.g., "100" for 100 USDC)
|
|
2889
|
+
* @param slippageBps - Slippage tolerance in basis points (default: 100 = 1%)
|
|
2890
|
+
* @returns Swap result with transaction hash and amounts
|
|
2891
|
+
* @throws {MixrPayError} If the swap fails
|
|
2892
|
+
*
|
|
2893
|
+
* @example
|
|
2894
|
+
* ```typescript
|
|
2895
|
+
* // Swap 100 USDC for ETH
|
|
2896
|
+
* const result = await wallet.swap('USDC', 'ETH', '100');
|
|
2897
|
+
* console.log(`Swapped ${result.sell_amount} ${result.sell_token}`);
|
|
2898
|
+
* console.log(`Received ${result.buy_amount} ${result.buy_token}`);
|
|
2899
|
+
* console.log(`Price: ${result.price}`);
|
|
2900
|
+
* ```
|
|
2901
|
+
*/
|
|
2902
|
+
swap(sellToken: string, buyToken: string, sellAmount: string, slippageBps?: number): Promise<SwapResponse>;
|
|
2903
|
+
/**
|
|
2904
|
+
* Bridge tokens to another chain using deBridge.
|
|
2905
|
+
*
|
|
2906
|
+
* Currently supports bridging from Base to other EVM chains.
|
|
2907
|
+
* The bridge transaction is submitted on the source chain; use
|
|
2908
|
+
* getBridgeStatus() to check completion on the destination chain.
|
|
2909
|
+
*
|
|
2910
|
+
* @param token - Token to bridge (symbol, e.g., "USDC")
|
|
2911
|
+
* @param amount - Amount in human-readable format (e.g., "100")
|
|
2912
|
+
* @param destChain - Destination chain ID or name (e.g., "1" for Ethereum, "arbitrum")
|
|
2913
|
+
* @param destAddress - Destination address (defaults to same address)
|
|
2914
|
+
* @returns Bridge result with order ID for tracking
|
|
2915
|
+
* @throws {MixrPayError} If the bridge fails
|
|
2916
|
+
*
|
|
2917
|
+
* @example
|
|
2918
|
+
* ```typescript
|
|
2919
|
+
* // Bridge 100 USDC to Arbitrum
|
|
2920
|
+
* const result = await wallet.bridge('USDC', '100', 'arbitrum');
|
|
2921
|
+
* console.log(`Bridge order: ${result.order_id}`);
|
|
2922
|
+
* console.log(`Expected to receive: ${result.estimated_receive}`);
|
|
2923
|
+
*
|
|
2924
|
+
* // Check status later
|
|
2925
|
+
* const status = await wallet.getBridgeStatus(result.order_id);
|
|
2926
|
+
* if (status.status === 'fulfilled') {
|
|
2927
|
+
* console.log(`Completed! Dest TX: ${status.dest_tx_hash}`);
|
|
2928
|
+
* }
|
|
2929
|
+
* ```
|
|
2930
|
+
*/
|
|
2931
|
+
bridge(token: string, amount: string, destChain: string, destAddress?: string): Promise<BridgeResponse>;
|
|
2932
|
+
/**
|
|
2933
|
+
* Check the status of a bridge order.
|
|
2934
|
+
*
|
|
2935
|
+
* @param orderId - The order ID from bridge()
|
|
2936
|
+
* @returns Bridge status information
|
|
2937
|
+
* @throws {MixrPayError} If the status check fails
|
|
2938
|
+
*
|
|
2939
|
+
* @example
|
|
2940
|
+
* ```typescript
|
|
2941
|
+
* const status = await wallet.getBridgeStatus('abc123');
|
|
2942
|
+
* switch (status.status) {
|
|
2943
|
+
* case 'pending':
|
|
2944
|
+
* console.log(`Still bridging... ETA: ${status.estimated_time_remaining}`);
|
|
2945
|
+
* break;
|
|
2946
|
+
* case 'fulfilled':
|
|
2947
|
+
* console.log(`Complete! TX: ${status.dest_tx_hash}`);
|
|
2948
|
+
* break;
|
|
2949
|
+
* case 'failed':
|
|
2950
|
+
* console.log('Bridge failed');
|
|
2951
|
+
* break;
|
|
2952
|
+
* }
|
|
2953
|
+
* ```
|
|
2954
|
+
*/
|
|
2955
|
+
getBridgeStatus(orderId: string): Promise<BridgeStatusResponse>;
|
|
2956
|
+
/**
|
|
2957
|
+
* Fetch a URL with automatic x402 payment handling.
|
|
2958
|
+
*
|
|
2959
|
+
* If the server returns 402 Payment Required, this method automatically
|
|
2960
|
+
* handles the payment from the wallet's delegation budget and retries
|
|
2961
|
+
* the request. Zero x402 knowledge needed.
|
|
2962
|
+
*
|
|
2963
|
+
* This is the agent-facing version of x402 fetch. For the underlying
|
|
2964
|
+
* fetch() that uses session key auth for x402, see the standard fetch() method.
|
|
2965
|
+
*
|
|
2966
|
+
* @param url - URL to fetch
|
|
2967
|
+
* @param options - Fetch options (method, headers, body, maxPaymentUsd)
|
|
2968
|
+
* @returns Response with status, headers, body, and optional payment info
|
|
2969
|
+
* @throws {MixrPayError} If the fetch fails
|
|
2970
|
+
*
|
|
2971
|
+
* @example
|
|
2972
|
+
* ```typescript
|
|
2973
|
+
* // Fetch from an x402-enabled API
|
|
2974
|
+
* const result = await wallet.fetchPaid('https://api.example.com/data', {
|
|
2975
|
+
* method: 'POST',
|
|
2976
|
+
* body: { query: 'AI analysis' },
|
|
2977
|
+
* maxPaymentUsd: 1.0,
|
|
2978
|
+
* });
|
|
2979
|
+
*
|
|
2980
|
+
* console.log(`Status: ${result.status}`);
|
|
2981
|
+
* console.log(`Data: ${JSON.stringify(result.body)}`);
|
|
2982
|
+
*
|
|
2983
|
+
* if (result.payment?.paid) {
|
|
2984
|
+
* console.log(`Paid $${result.payment.amount_usd}`);
|
|
2985
|
+
* }
|
|
2986
|
+
* ```
|
|
2987
|
+
*/
|
|
2988
|
+
fetchPaid(url: string, options?: FetchPaidOptions): Promise<FetchPaidResponse>;
|
|
2989
|
+
/**
|
|
2990
|
+
* Call the API with agent token auth (agt_live_xxx bearer token).
|
|
2991
|
+
* Used by DeFi methods that require delegation auth.
|
|
2992
|
+
*/
|
|
2993
|
+
private callApiWithAuth;
|
|
2278
2994
|
/** Helper to call our API with auth */
|
|
2279
2995
|
private callApi;
|
|
2280
2996
|
}
|
|
@@ -2506,9 +3222,9 @@ interface MyTasksResult {
|
|
|
2506
3222
|
};
|
|
2507
3223
|
}
|
|
2508
3224
|
/**
|
|
2509
|
-
*
|
|
3225
|
+
* Tool definition returned by listTools()
|
|
2510
3226
|
*/
|
|
2511
|
-
interface
|
|
3227
|
+
interface Tool {
|
|
2512
3228
|
/** Tool name in format "merchant/tool" */
|
|
2513
3229
|
name: string;
|
|
2514
3230
|
/** Human-readable description with price */
|
|
@@ -2524,10 +3240,12 @@ interface MCPTool {
|
|
|
2524
3240
|
/** Whether the provider is domain-verified */
|
|
2525
3241
|
verified: boolean;
|
|
2526
3242
|
}
|
|
3243
|
+
/** @deprecated Use Tool instead */
|
|
3244
|
+
type MCPTool = Tool;
|
|
2527
3245
|
/**
|
|
2528
|
-
* Result from calling
|
|
3246
|
+
* Result from calling a tool
|
|
2529
3247
|
*/
|
|
2530
|
-
interface
|
|
3248
|
+
interface ToolResult {
|
|
2531
3249
|
/** The tool's response data */
|
|
2532
3250
|
data: unknown;
|
|
2533
3251
|
/** Amount charged in USD */
|
|
@@ -2537,6 +3255,8 @@ interface MCPToolResult {
|
|
|
2537
3255
|
/** Execution latency in milliseconds */
|
|
2538
3256
|
latencyMs?: number;
|
|
2539
3257
|
}
|
|
3258
|
+
/** @deprecated Use ToolResult instead */
|
|
3259
|
+
type MCPToolResult = ToolResult;
|
|
2540
3260
|
/**
|
|
2541
3261
|
* Message in an agent conversation
|
|
2542
3262
|
*/
|
|
@@ -3613,6 +4333,115 @@ declare class MerchantNotAllowedError extends MixrPayError {
|
|
|
3613
4333
|
readonly allowedPatterns: string[];
|
|
3614
4334
|
constructor(attempted: string, allowedPatterns: string[]);
|
|
3615
4335
|
}
|
|
4336
|
+
/**
|
|
4337
|
+
* Thrown when the API returns a 429 rate limit response.
|
|
4338
|
+
*
|
|
4339
|
+
* This error includes a suggested retry delay. The operation can be retried
|
|
4340
|
+
* after waiting the specified time.
|
|
4341
|
+
*
|
|
4342
|
+
* ## Resolution
|
|
4343
|
+
* 1. Wait for `retryAfterMs` milliseconds
|
|
4344
|
+
* 2. Reduce request frequency
|
|
4345
|
+
* 3. Contact support if limits are too restrictive
|
|
4346
|
+
*
|
|
4347
|
+
* @example
|
|
4348
|
+
* ```typescript
|
|
4349
|
+
* try {
|
|
4350
|
+
* await wallet.fetch(...);
|
|
4351
|
+
* } catch (error) {
|
|
4352
|
+
* if (error instanceof RateLimitError) {
|
|
4353
|
+
* console.log(`Rate limited. Retry after ${error.retryAfterMs}ms`);
|
|
4354
|
+
* await sleep(error.retryAfterMs);
|
|
4355
|
+
* // Retry the operation
|
|
4356
|
+
* }
|
|
4357
|
+
* }
|
|
4358
|
+
* ```
|
|
4359
|
+
*/
|
|
4360
|
+
declare class RateLimitError extends MixrPayError {
|
|
4361
|
+
constructor(retryAfterMs?: number, message?: string);
|
|
4362
|
+
/**
|
|
4363
|
+
* Rate limits are transient and operations can be retried after waiting.
|
|
4364
|
+
* @returns true - always retryable after the delay
|
|
4365
|
+
*/
|
|
4366
|
+
isRetryable(): boolean;
|
|
4367
|
+
}
|
|
4368
|
+
/**
|
|
4369
|
+
* Thrown when a network error occurs during an API call.
|
|
4370
|
+
*
|
|
4371
|
+
* This includes:
|
|
4372
|
+
* - DNS resolution failures
|
|
4373
|
+
* - Connection timeouts
|
|
4374
|
+
* - Network disconnection
|
|
4375
|
+
* - SSL/TLS errors
|
|
4376
|
+
*
|
|
4377
|
+
* ## Resolution
|
|
4378
|
+
* 1. Check network connectivity
|
|
4379
|
+
* 2. Retry the operation with exponential backoff
|
|
4380
|
+
* 3. Check if the API endpoint is reachable
|
|
4381
|
+
*
|
|
4382
|
+
* @example
|
|
4383
|
+
* ```typescript
|
|
4384
|
+
* try {
|
|
4385
|
+
* await wallet.fetch(...);
|
|
4386
|
+
* } catch (error) {
|
|
4387
|
+
* if (error instanceof NetworkError) {
|
|
4388
|
+
* console.log(`Network error: ${error.reason}`);
|
|
4389
|
+
* if (error.isRetryable()) {
|
|
4390
|
+
* await retry();
|
|
4391
|
+
* }
|
|
4392
|
+
* }
|
|
4393
|
+
* }
|
|
4394
|
+
* ```
|
|
4395
|
+
*/
|
|
4396
|
+
declare class NetworkError extends MixrPayError {
|
|
4397
|
+
/** The underlying error reason */
|
|
4398
|
+
readonly reason: string;
|
|
4399
|
+
constructor(reason: string, originalError?: Error);
|
|
4400
|
+
/**
|
|
4401
|
+
* Network errors are typically transient.
|
|
4402
|
+
* @returns true - network issues usually resolve
|
|
4403
|
+
*/
|
|
4404
|
+
isRetryable(): boolean;
|
|
4405
|
+
}
|
|
4406
|
+
/**
|
|
4407
|
+
* Thrown when authentication fails (401/403 responses).
|
|
4408
|
+
*
|
|
4409
|
+
* This error indicates:
|
|
4410
|
+
* - Invalid API key or session key
|
|
4411
|
+
* - Expired credentials
|
|
4412
|
+
* - Missing authentication headers
|
|
4413
|
+
* - Insufficient permissions
|
|
4414
|
+
*
|
|
4415
|
+
* ## Resolution
|
|
4416
|
+
* 1. Verify your session key is correct
|
|
4417
|
+
* 2. Check if the key has expired
|
|
4418
|
+
* 3. Ensure the key has permissions for the operation
|
|
4419
|
+
* 4. Request a new session key if needed
|
|
4420
|
+
*
|
|
4421
|
+
* @example
|
|
4422
|
+
* ```typescript
|
|
4423
|
+
* try {
|
|
4424
|
+
* await wallet.fetch(...);
|
|
4425
|
+
* } catch (error) {
|
|
4426
|
+
* if (error instanceof AuthenticationError) {
|
|
4427
|
+
* console.log(`Auth failed: ${error.reason}`);
|
|
4428
|
+
* // Request new credentials
|
|
4429
|
+
* }
|
|
4430
|
+
* }
|
|
4431
|
+
* ```
|
|
4432
|
+
*/
|
|
4433
|
+
declare class AuthenticationError extends MixrPayError {
|
|
4434
|
+
/** The specific authentication failure reason */
|
|
4435
|
+
readonly reason: string;
|
|
4436
|
+
/** HTTP status code (401 or 403) */
|
|
4437
|
+
readonly statusCode: number;
|
|
4438
|
+
constructor(reason: string, statusCode?: 401 | 403);
|
|
4439
|
+
/**
|
|
4440
|
+
* Authentication errors are not retryable without user action.
|
|
4441
|
+
* @returns false - requires new credentials
|
|
4442
|
+
*/
|
|
4443
|
+
isRetryable(): boolean;
|
|
4444
|
+
}
|
|
3616
4445
|
/**
|
|
3617
4446
|
* Check if an error is a MixrPay SDK error.
|
|
3618
4447
|
*
|
|
@@ -3649,4 +4478,199 @@ declare function isMixrPayError(error: unknown): error is MixrPayError;
|
|
|
3649
4478
|
*/
|
|
3650
4479
|
declare function getErrorMessage(error: unknown): string;
|
|
3651
4480
|
|
|
3652
|
-
|
|
4481
|
+
/**
|
|
4482
|
+
* MixrPay Agent SDK - Credential Management
|
|
4483
|
+
*
|
|
4484
|
+
* Platform-aware credential storage for session keys and API tokens.
|
|
4485
|
+
* Stores credentials securely with appropriate file permissions.
|
|
4486
|
+
*
|
|
4487
|
+
* Storage locations:
|
|
4488
|
+
* - Linux/macOS: ~/.config/mixrpay/credentials.json
|
|
4489
|
+
* - Windows: %APPDATA%/mixrpay/credentials.json
|
|
4490
|
+
*
|
|
4491
|
+
* File permissions: 0600 (read/write for owner only)
|
|
4492
|
+
*/
|
|
4493
|
+
interface StoredCredentials {
|
|
4494
|
+
/** Session key (sk_live_xxx or sk_test_xxx) */
|
|
4495
|
+
sessionKey?: string;
|
|
4496
|
+
/** API token (agt_live_xxx) for API calls */
|
|
4497
|
+
apiToken?: string;
|
|
4498
|
+
/** @deprecated Use apiToken instead. Legacy connect token (ac_live_xxx) */
|
|
4499
|
+
connectToken?: string;
|
|
4500
|
+
/** Master key (mk_live_xxx) for multi-agent management */
|
|
4501
|
+
masterKey?: string;
|
|
4502
|
+
/** Default agent name (used with master key) */
|
|
4503
|
+
defaultAgentName?: string;
|
|
4504
|
+
/** Base URL override */
|
|
4505
|
+
baseUrl?: string;
|
|
4506
|
+
/** When credentials were last updated */
|
|
4507
|
+
updatedAt?: string;
|
|
4508
|
+
}
|
|
4509
|
+
type CredentialLoadResult = {
|
|
4510
|
+
success: true;
|
|
4511
|
+
credentials: StoredCredentials;
|
|
4512
|
+
} | {
|
|
4513
|
+
success: false;
|
|
4514
|
+
error: string;
|
|
4515
|
+
};
|
|
4516
|
+
/**
|
|
4517
|
+
* Save credentials to the platform-specific config location.
|
|
4518
|
+
*
|
|
4519
|
+
* @param credentials - Credentials to save (merged with existing)
|
|
4520
|
+
* @returns true if successful, false otherwise
|
|
4521
|
+
*
|
|
4522
|
+
* @example
|
|
4523
|
+
* ```typescript
|
|
4524
|
+
* // Save a session key
|
|
4525
|
+
* await saveCredentials({ sessionKey: 'sk_live_xxx' });
|
|
4526
|
+
*
|
|
4527
|
+
* // Save multiple credentials
|
|
4528
|
+
* await saveCredentials({
|
|
4529
|
+
* masterKey: 'mk_live_xxx',
|
|
4530
|
+
* defaultAgentName: 'my-agent',
|
|
4531
|
+
* });
|
|
4532
|
+
* ```
|
|
4533
|
+
*/
|
|
4534
|
+
declare function saveCredentials(credentials: Partial<StoredCredentials>): boolean;
|
|
4535
|
+
/**
|
|
4536
|
+
* Load credentials from the platform-specific config location.
|
|
4537
|
+
*
|
|
4538
|
+
* @returns Loaded credentials or error
|
|
4539
|
+
*
|
|
4540
|
+
* @example
|
|
4541
|
+
* ```typescript
|
|
4542
|
+
* const result = loadCredentials();
|
|
4543
|
+
* if (result.success) {
|
|
4544
|
+
* console.log('Session key:', result.credentials.sessionKey);
|
|
4545
|
+
* }
|
|
4546
|
+
* ```
|
|
4547
|
+
*/
|
|
4548
|
+
declare function loadCredentials(): CredentialLoadResult;
|
|
4549
|
+
/**
|
|
4550
|
+
* Delete stored credentials.
|
|
4551
|
+
*
|
|
4552
|
+
* @param keys - Specific keys to delete, or undefined to delete all
|
|
4553
|
+
* @returns true if successful
|
|
4554
|
+
*
|
|
4555
|
+
* @example
|
|
4556
|
+
* ```typescript
|
|
4557
|
+
* // Delete specific credentials
|
|
4558
|
+
* deleteCredentials(['sessionKey', 'apiToken']);
|
|
4559
|
+
*
|
|
4560
|
+
* // Delete all credentials
|
|
4561
|
+
* deleteCredentials();
|
|
4562
|
+
* ```
|
|
4563
|
+
*/
|
|
4564
|
+
declare function deleteCredentials(keys?: (keyof StoredCredentials)[]): boolean;
|
|
4565
|
+
/**
|
|
4566
|
+
* Check if credentials are stored.
|
|
4567
|
+
*
|
|
4568
|
+
* @returns true if any credentials are stored
|
|
4569
|
+
*/
|
|
4570
|
+
declare function hasCredentials(): boolean;
|
|
4571
|
+
/**
|
|
4572
|
+
* Get the path to the credentials file (for debugging/info).
|
|
4573
|
+
*
|
|
4574
|
+
* @returns The credentials file path
|
|
4575
|
+
*/
|
|
4576
|
+
declare function getCredentialsFilePath(): string;
|
|
4577
|
+
|
|
4578
|
+
/**
|
|
4579
|
+
* MixrPay Agent SDK - Wallet Storage
|
|
4580
|
+
* @packageDocumentation
|
|
4581
|
+
*/
|
|
4582
|
+
/**
|
|
4583
|
+
* Structure of the stored wallet file
|
|
4584
|
+
*/
|
|
4585
|
+
interface StoredWallet {
|
|
4586
|
+
/** Wallet address (0x-prefixed) */
|
|
4587
|
+
address: string;
|
|
4588
|
+
/** Private key (0x-prefixed hex) */
|
|
4589
|
+
privateKey: string;
|
|
4590
|
+
/** ISO timestamp when wallet was created */
|
|
4591
|
+
createdAt: string;
|
|
4592
|
+
/** SDK version that created the wallet */
|
|
4593
|
+
sdkVersion: string;
|
|
4594
|
+
}
|
|
4595
|
+
/**
|
|
4596
|
+
* Save a wallet private key to local storage.
|
|
4597
|
+
*
|
|
4598
|
+
* Creates the config directory if it doesn't exist.
|
|
4599
|
+
* Sets file permissions to 0o600 (owner read/write only).
|
|
4600
|
+
*
|
|
4601
|
+
* @param privateKey - The wallet private key (0x-prefixed hex)
|
|
4602
|
+
* @param address - The wallet address (0x-prefixed)
|
|
4603
|
+
* @throws Error if unable to write to filesystem
|
|
4604
|
+
*
|
|
4605
|
+
* @example
|
|
4606
|
+
* ```typescript
|
|
4607
|
+
* import { saveWalletKey } from '@mixrpay/agent-sdk';
|
|
4608
|
+
* import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
4609
|
+
*
|
|
4610
|
+
* const privateKey = generatePrivateKey();
|
|
4611
|
+
* const account = privateKeyToAccount(privateKey);
|
|
4612
|
+
* await saveWalletKey(privateKey, account.address);
|
|
4613
|
+
* ```
|
|
4614
|
+
*/
|
|
4615
|
+
declare function saveWalletKey(privateKey: `0x${string}`, address: string): Promise<void>;
|
|
4616
|
+
/**
|
|
4617
|
+
* Load the wallet private key from storage.
|
|
4618
|
+
*
|
|
4619
|
+
* Checks in order:
|
|
4620
|
+
* 1. MIXRPAY_WALLET_KEY environment variable
|
|
4621
|
+
* 2. Local wallet file
|
|
4622
|
+
*
|
|
4623
|
+
* @returns The private key (0x-prefixed hex) or null if not found
|
|
4624
|
+
*
|
|
4625
|
+
* @example
|
|
4626
|
+
* ```typescript
|
|
4627
|
+
* import { loadWalletKey } from '@mixrpay/agent-sdk';
|
|
4628
|
+
*
|
|
4629
|
+
* const privateKey = await loadWalletKey();
|
|
4630
|
+
* if (privateKey) {
|
|
4631
|
+
* console.log('Wallet loaded successfully');
|
|
4632
|
+
* }
|
|
4633
|
+
* ```
|
|
4634
|
+
*/
|
|
4635
|
+
declare function loadWalletKey(): Promise<`0x${string}` | null>;
|
|
4636
|
+
/**
|
|
4637
|
+
* Load the full wallet data including address and metadata.
|
|
4638
|
+
*
|
|
4639
|
+
* @returns The stored wallet data or null if not found
|
|
4640
|
+
*/
|
|
4641
|
+
declare function loadWalletData(): Promise<StoredWallet | null>;
|
|
4642
|
+
/**
|
|
4643
|
+
* Check if a wallet key exists in storage.
|
|
4644
|
+
*
|
|
4645
|
+
* @returns True if a wallet key is available
|
|
4646
|
+
*
|
|
4647
|
+
* @example
|
|
4648
|
+
* ```typescript
|
|
4649
|
+
* import { hasWalletKey, loadWalletKey } from '@mixrpay/agent-sdk';
|
|
4650
|
+
*
|
|
4651
|
+
* if (await hasWalletKey()) {
|
|
4652
|
+
* const key = await loadWalletKey();
|
|
4653
|
+
* // Use existing wallet
|
|
4654
|
+
* } else {
|
|
4655
|
+
* // Create new wallet
|
|
4656
|
+
* }
|
|
4657
|
+
* ```
|
|
4658
|
+
*/
|
|
4659
|
+
declare function hasWalletKey(): Promise<boolean>;
|
|
4660
|
+
/**
|
|
4661
|
+
* Get the wallet storage path for debugging.
|
|
4662
|
+
*
|
|
4663
|
+
* @returns The path where the wallet would be stored
|
|
4664
|
+
*/
|
|
4665
|
+
declare function getWalletStoragePath(): string;
|
|
4666
|
+
/**
|
|
4667
|
+
* Delete the stored wallet key.
|
|
4668
|
+
*
|
|
4669
|
+
* WARNING: This permanently deletes the wallet key. Make sure you have
|
|
4670
|
+
* backed up the key before calling this.
|
|
4671
|
+
*
|
|
4672
|
+
* @returns True if a wallet was deleted, false if no wallet existed
|
|
4673
|
+
*/
|
|
4674
|
+
declare function deleteWalletKey(): Promise<boolean>;
|
|
4675
|
+
|
|
4676
|
+
export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AnthropicToolDefinition, type AnthropicToolkit, AuthenticationError, type AvailableBudget, type BalancesResponse, type BridgeResponse, type BridgeStatusResponse, type CallMerchantApiOptions, type ChargeResult, type ChargeType, type ChildSession, type CompleteOptions, type CompleteResult, type ConnectOptions, type CredentialLoadResult, type DelegationBudget, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, type FetchPaidOptions, type FetchPaidResponse, type FetchPaymentInfo, type GetTransactionsOptions, type GlamaImportData, type GlamaSearchResult, type GlamaServer, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, type KnownChargeType, type MCPTool, type MCPToolResult, type McpServerConfig, MerchantNotAllowedError, MixrPayError, NetworkError, type PaymentEvent, PaymentFailedError, RateLimitError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SiweOptions, type SiweResult, type SkillInfo, type SkillStatus, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, type StoredCredentials, type StoredWallet, type SwapResponse, type TokenBalance, type Tool, type ToolResult, type TransactionRecord, type TransactionsResponse, type TransferResponse, type UseSkillOptions, type UseSkillResult, X402ProtocolError, deleteCredentials, deleteWalletKey, getCredentialsFilePath, getErrorMessage, getWalletStoragePath, hasCredentials, hasWalletKey, isMixrPayError, loadCredentials, loadWalletData, loadWalletKey, saveCredentials, saveWalletKey };
|