moltspay 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -289,4 +289,203 @@ declare function formatPermitRequest(params: {
289
289
  reason?: string;
290
290
  }): string;
291
291
 
292
- export { type CreateWalletOptions, type CreateWalletResult, type PermitData, PermitWallet, type PermitWalletConfig, SecureWallet, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, getWalletAddress, loadWallet, walletExists };
292
+ /**
293
+ * signPermit - Agent signs EIP-2612 Permit to authorize another address to spend USDC
294
+ *
295
+ * Used for Agent-to-Agent payments where the client agent authorizes
296
+ * the service provider to pull payment.
297
+ */
298
+
299
+ interface SignPermitParams {
300
+ /** Spender address (service provider's wallet) */
301
+ spender: string;
302
+ /** Amount in USDC (e.g., 0.99) */
303
+ amount: number;
304
+ /** Deadline timestamp (Unix seconds) or minutes from now if < 1000000 */
305
+ deadline?: number;
306
+ }
307
+ interface SignPermitResult {
308
+ /** Permit owner (signer's address) */
309
+ owner: string;
310
+ /** Authorized spender */
311
+ spender: string;
312
+ /** Authorized amount (raw, 6 decimals) */
313
+ value: string;
314
+ /** Expiration timestamp */
315
+ deadline: number;
316
+ /** Nonce used */
317
+ nonce: number;
318
+ /** Signature v */
319
+ v: number;
320
+ /** Signature r */
321
+ r: string;
322
+ /** Signature s */
323
+ s: string;
324
+ }
325
+ interface SignPermitConfig {
326
+ chain?: ChainName;
327
+ privateKey?: string;
328
+ rpcUrl?: string;
329
+ }
330
+ /**
331
+ * Sign an EIP-2612 Permit
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * import { signPermit } from 'moltspay';
336
+ *
337
+ * const permit = await signPermit(
338
+ * { chain: 'base', privateKey: process.env.WALLET_KEY },
339
+ * {
340
+ * spender: '0xZen7Wallet...',
341
+ * amount: 0.99,
342
+ * deadline: 30 // 30 minutes from now
343
+ * }
344
+ * );
345
+ *
346
+ * // Send permit to service provider
347
+ * await fetch('https://service/api/pay', {
348
+ * body: JSON.stringify({ permit })
349
+ * });
350
+ * ```
351
+ */
352
+ declare function signPermit(config: SignPermitConfig, params: SignPermitParams): Promise<SignPermitResult>;
353
+ /**
354
+ * Convenient class method version
355
+ */
356
+ declare class PermitSigner {
357
+ private config;
358
+ constructor(config: SignPermitConfig);
359
+ sign(params: SignPermitParams): Promise<SignPermitResult>;
360
+ }
361
+
362
+ /**
363
+ * AllowanceWallet - Agent spends from Owner's wallet using Permit allowance
364
+ *
365
+ * This is the recommended pattern for AI Agents:
366
+ * 1. Owner signs EIP-2612 Permit in MetaMask (off-chain, no gas)
367
+ * 2. Owner sends Permit data to Agent
368
+ * 3. Agent stores Permit and spends within the allowance
369
+ * 4. Agent only needs minimal ETH for gas, USDC stays in Owner's wallet
370
+ *
371
+ * Benefits:
372
+ * - Agent never holds significant funds
373
+ * - Owner maintains custody of USDC
374
+ * - Owner can revoke by spending/transferring USDC
375
+ * - Clear audit trail of Agent spending
376
+ */
377
+
378
+ interface OwnerPermit {
379
+ /** Owner's wallet address (USDC holder, e.g., MetaMask) */
380
+ owner: string;
381
+ /** Authorized amount (raw, 6 decimals for USDC) */
382
+ value: string;
383
+ /** Expiration timestamp (Unix seconds) */
384
+ deadline: number;
385
+ /** Nonce used when signing */
386
+ nonce: number;
387
+ /** Signature components */
388
+ v: number;
389
+ r: string;
390
+ s: string;
391
+ }
392
+ interface AllowanceWalletConfig {
393
+ chain?: ChainName;
394
+ /** Agent's private key (only for gas, not for USDC) */
395
+ privateKey: string;
396
+ rpcUrl?: string;
397
+ }
398
+ interface SpendParams {
399
+ /** Recipient address (e.g., service provider) */
400
+ to: string;
401
+ /** Amount in USDC */
402
+ amount: number;
403
+ /** Owner's Permit (if not yet submitted on-chain) */
404
+ permit?: OwnerPermit;
405
+ }
406
+ interface SpendResult {
407
+ success: boolean;
408
+ txHash?: string;
409
+ error?: string;
410
+ from: string;
411
+ to: string;
412
+ amount: number;
413
+ remainingAllowance?: string;
414
+ explorerUrl?: string;
415
+ }
416
+ interface AllowanceStatus {
417
+ owner: string;
418
+ agent: string;
419
+ allowance: string;
420
+ ownerBalance: string;
421
+ agentGasBalance: string;
422
+ canSpend: boolean;
423
+ chain: string;
424
+ }
425
+ declare class AllowanceWallet {
426
+ readonly chain: ChainName;
427
+ readonly chainConfig: ChainConfig;
428
+ readonly address: string;
429
+ private wallet;
430
+ private provider;
431
+ private usdcContract;
432
+ /** Stored permits from owners */
433
+ private permits;
434
+ constructor(config: AllowanceWalletConfig);
435
+ /**
436
+ * Store a Permit received from Owner
437
+ * Call this when Owner sends you a signed Permit
438
+ */
439
+ storePermit(permit: OwnerPermit): void;
440
+ /**
441
+ * Get stored Permit for an owner
442
+ */
443
+ getPermit(owner: string): OwnerPermit | undefined;
444
+ /**
445
+ * Check allowance status with an owner
446
+ */
447
+ checkAllowance(owner: string): Promise<AllowanceStatus>;
448
+ /**
449
+ * Spend from Owner's wallet using Permit allowance
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * const agent = new AllowanceWallet({
454
+ * chain: 'base',
455
+ * privateKey: process.env.AGENT_KEY // Only needs gas
456
+ * });
457
+ *
458
+ * // Owner gave us a Permit
459
+ * agent.storePermit(ownerPermit);
460
+ *
461
+ * // Spend to pay for a service
462
+ * const result = await agent.spend({
463
+ * to: '0xServiceProvider...',
464
+ * amount: 2.99,
465
+ * });
466
+ * ```
467
+ */
468
+ spend(params: SpendParams): Promise<SpendResult>;
469
+ /**
470
+ * Get Agent's gas balance (ETH)
471
+ */
472
+ getGasBalance(): Promise<string>;
473
+ }
474
+ /**
475
+ * Generate instructions for Owner to sign a Permit in MetaMask
476
+ *
477
+ * Owner can use this with eth_signTypedData_v4 in any web3 wallet
478
+ */
479
+ declare function generatePermitInstructions(params: {
480
+ ownerAddress: string;
481
+ agentAddress: string;
482
+ amount: number;
483
+ deadlineHours?: number;
484
+ chain?: ChainName;
485
+ }): {
486
+ instructions: string;
487
+ typedData: object;
488
+ eip712Domain: object;
489
+ };
490
+
491
+ export { type AllowanceStatus, AllowanceWallet, type AllowanceWalletConfig, type CreateWalletOptions, type CreateWalletResult, type OwnerPermit, type PermitData, PermitSigner, PermitWallet, type PermitWalletConfig, SecureWallet, type SignPermitConfig, type SignPermitParams, type SignPermitResult, type SpendParams, type SpendResult, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, generatePermitInstructions, getWalletAddress, loadWallet, signPermit, walletExists };
@@ -289,4 +289,203 @@ declare function formatPermitRequest(params: {
289
289
  reason?: string;
290
290
  }): string;
291
291
 
292
- export { type CreateWalletOptions, type CreateWalletResult, type PermitData, PermitWallet, type PermitWalletConfig, SecureWallet, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, getWalletAddress, loadWallet, walletExists };
292
+ /**
293
+ * signPermit - Agent signs EIP-2612 Permit to authorize another address to spend USDC
294
+ *
295
+ * Used for Agent-to-Agent payments where the client agent authorizes
296
+ * the service provider to pull payment.
297
+ */
298
+
299
+ interface SignPermitParams {
300
+ /** Spender address (service provider's wallet) */
301
+ spender: string;
302
+ /** Amount in USDC (e.g., 0.99) */
303
+ amount: number;
304
+ /** Deadline timestamp (Unix seconds) or minutes from now if < 1000000 */
305
+ deadline?: number;
306
+ }
307
+ interface SignPermitResult {
308
+ /** Permit owner (signer's address) */
309
+ owner: string;
310
+ /** Authorized spender */
311
+ spender: string;
312
+ /** Authorized amount (raw, 6 decimals) */
313
+ value: string;
314
+ /** Expiration timestamp */
315
+ deadline: number;
316
+ /** Nonce used */
317
+ nonce: number;
318
+ /** Signature v */
319
+ v: number;
320
+ /** Signature r */
321
+ r: string;
322
+ /** Signature s */
323
+ s: string;
324
+ }
325
+ interface SignPermitConfig {
326
+ chain?: ChainName;
327
+ privateKey?: string;
328
+ rpcUrl?: string;
329
+ }
330
+ /**
331
+ * Sign an EIP-2612 Permit
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * import { signPermit } from 'moltspay';
336
+ *
337
+ * const permit = await signPermit(
338
+ * { chain: 'base', privateKey: process.env.WALLET_KEY },
339
+ * {
340
+ * spender: '0xZen7Wallet...',
341
+ * amount: 0.99,
342
+ * deadline: 30 // 30 minutes from now
343
+ * }
344
+ * );
345
+ *
346
+ * // Send permit to service provider
347
+ * await fetch('https://service/api/pay', {
348
+ * body: JSON.stringify({ permit })
349
+ * });
350
+ * ```
351
+ */
352
+ declare function signPermit(config: SignPermitConfig, params: SignPermitParams): Promise<SignPermitResult>;
353
+ /**
354
+ * Convenient class method version
355
+ */
356
+ declare class PermitSigner {
357
+ private config;
358
+ constructor(config: SignPermitConfig);
359
+ sign(params: SignPermitParams): Promise<SignPermitResult>;
360
+ }
361
+
362
+ /**
363
+ * AllowanceWallet - Agent spends from Owner's wallet using Permit allowance
364
+ *
365
+ * This is the recommended pattern for AI Agents:
366
+ * 1. Owner signs EIP-2612 Permit in MetaMask (off-chain, no gas)
367
+ * 2. Owner sends Permit data to Agent
368
+ * 3. Agent stores Permit and spends within the allowance
369
+ * 4. Agent only needs minimal ETH for gas, USDC stays in Owner's wallet
370
+ *
371
+ * Benefits:
372
+ * - Agent never holds significant funds
373
+ * - Owner maintains custody of USDC
374
+ * - Owner can revoke by spending/transferring USDC
375
+ * - Clear audit trail of Agent spending
376
+ */
377
+
378
+ interface OwnerPermit {
379
+ /** Owner's wallet address (USDC holder, e.g., MetaMask) */
380
+ owner: string;
381
+ /** Authorized amount (raw, 6 decimals for USDC) */
382
+ value: string;
383
+ /** Expiration timestamp (Unix seconds) */
384
+ deadline: number;
385
+ /** Nonce used when signing */
386
+ nonce: number;
387
+ /** Signature components */
388
+ v: number;
389
+ r: string;
390
+ s: string;
391
+ }
392
+ interface AllowanceWalletConfig {
393
+ chain?: ChainName;
394
+ /** Agent's private key (only for gas, not for USDC) */
395
+ privateKey: string;
396
+ rpcUrl?: string;
397
+ }
398
+ interface SpendParams {
399
+ /** Recipient address (e.g., service provider) */
400
+ to: string;
401
+ /** Amount in USDC */
402
+ amount: number;
403
+ /** Owner's Permit (if not yet submitted on-chain) */
404
+ permit?: OwnerPermit;
405
+ }
406
+ interface SpendResult {
407
+ success: boolean;
408
+ txHash?: string;
409
+ error?: string;
410
+ from: string;
411
+ to: string;
412
+ amount: number;
413
+ remainingAllowance?: string;
414
+ explorerUrl?: string;
415
+ }
416
+ interface AllowanceStatus {
417
+ owner: string;
418
+ agent: string;
419
+ allowance: string;
420
+ ownerBalance: string;
421
+ agentGasBalance: string;
422
+ canSpend: boolean;
423
+ chain: string;
424
+ }
425
+ declare class AllowanceWallet {
426
+ readonly chain: ChainName;
427
+ readonly chainConfig: ChainConfig;
428
+ readonly address: string;
429
+ private wallet;
430
+ private provider;
431
+ private usdcContract;
432
+ /** Stored permits from owners */
433
+ private permits;
434
+ constructor(config: AllowanceWalletConfig);
435
+ /**
436
+ * Store a Permit received from Owner
437
+ * Call this when Owner sends you a signed Permit
438
+ */
439
+ storePermit(permit: OwnerPermit): void;
440
+ /**
441
+ * Get stored Permit for an owner
442
+ */
443
+ getPermit(owner: string): OwnerPermit | undefined;
444
+ /**
445
+ * Check allowance status with an owner
446
+ */
447
+ checkAllowance(owner: string): Promise<AllowanceStatus>;
448
+ /**
449
+ * Spend from Owner's wallet using Permit allowance
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * const agent = new AllowanceWallet({
454
+ * chain: 'base',
455
+ * privateKey: process.env.AGENT_KEY // Only needs gas
456
+ * });
457
+ *
458
+ * // Owner gave us a Permit
459
+ * agent.storePermit(ownerPermit);
460
+ *
461
+ * // Spend to pay for a service
462
+ * const result = await agent.spend({
463
+ * to: '0xServiceProvider...',
464
+ * amount: 2.99,
465
+ * });
466
+ * ```
467
+ */
468
+ spend(params: SpendParams): Promise<SpendResult>;
469
+ /**
470
+ * Get Agent's gas balance (ETH)
471
+ */
472
+ getGasBalance(): Promise<string>;
473
+ }
474
+ /**
475
+ * Generate instructions for Owner to sign a Permit in MetaMask
476
+ *
477
+ * Owner can use this with eth_signTypedData_v4 in any web3 wallet
478
+ */
479
+ declare function generatePermitInstructions(params: {
480
+ ownerAddress: string;
481
+ agentAddress: string;
482
+ amount: number;
483
+ deadlineHours?: number;
484
+ chain?: ChainName;
485
+ }): {
486
+ instructions: string;
487
+ typedData: object;
488
+ eip712Domain: object;
489
+ };
490
+
491
+ export { type AllowanceStatus, AllowanceWallet, type AllowanceWalletConfig, type CreateWalletOptions, type CreateWalletResult, type OwnerPermit, type PermitData, PermitSigner, PermitWallet, type PermitWalletConfig, SecureWallet, type SignPermitConfig, type SignPermitParams, type SignPermitResult, type SpendParams, type SpendResult, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, generatePermitInstructions, getWalletAddress, loadWallet, signPermit, walletExists };