moltspay 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -5,7 +5,8 @@ export { PermitPayment } from './permit/index.mjs';
5
5
  export { CreateOrderParams, MemoryOrderStore, Order, OrderManager, OrderStatus, OrderStore } from './orders/index.mjs';
6
6
  export { VerifyPaymentParams, VerifyPaymentResult, getTransactionStatus, verifyPayment, waitForTransaction } from './verify/index.mjs';
7
7
  export { PaymentGuideParams, extractTransactionHash, generatePaymentGuide, generatePaymentReminder, generateWalletGuide, hasTransactionHash } from './guide/index.mjs';
8
- export { CHAINS, ERC20_ABI, getChain, getChainById, listChains } from './chains/index.mjs';
8
+ import { getChain } from './chains/index.mjs';
9
+ export { CHAINS, ERC20_ABI, getChainById, listChains } from './chains/index.mjs';
9
10
  import { ethers } from 'ethers';
10
11
 
11
12
  /**
@@ -616,6 +617,87 @@ declare function parseStatusMarker(message: string): {
616
617
  data: Record<string, string>;
617
618
  } | null;
618
619
 
620
+ /**
621
+ * x402 Client - Easy HTTP client with automatic payment handling
622
+ *
623
+ * Wraps @x402/fetch to provide simple API for AI Agents.
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * import { createX402Client } from 'moltspay/x402';
628
+ *
629
+ * // Using local wallet (AgentWallet)
630
+ * const client = await createX402Client({ chain: 'base' });
631
+ *
632
+ * // Using CDP wallet
633
+ * const client = await createX402Client({ chain: 'base', useCDP: true });
634
+ *
635
+ * // Make request - payment handled automatically
636
+ * const response = await client.fetch('https://juai8.com/x402pay');
637
+ * ```
638
+ */
639
+
640
+ interface X402ClientConfig {
641
+ /** Chain to use */
642
+ chain?: ChainName;
643
+ /** Use CDP wallet instead of local wallet */
644
+ useCDP?: boolean;
645
+ /** Custom private key (overrides stored wallet) */
646
+ privateKey?: string;
647
+ /** Storage directory for wallet */
648
+ storageDir?: string;
649
+ }
650
+ interface X402Client {
651
+ /** Fetch with automatic x402 payment handling */
652
+ fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
653
+ /** Wallet address */
654
+ address: string;
655
+ /** Chain being used */
656
+ chain: ChainName;
657
+ }
658
+ /**
659
+ * Check if @x402/fetch is available
660
+ */
661
+ declare function isX402Available(): boolean;
662
+ /**
663
+ * Create x402 client
664
+ *
665
+ * Automatically handles 402 Payment Required responses.
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * import { createX402Client } from 'moltspay/x402';
670
+ *
671
+ * const client = await createX402Client({ chain: 'base' });
672
+ *
673
+ * // Request paid API - payment handled automatically
674
+ * const response = await client.fetch('https://juai8.com/x402pay', {
675
+ * method: 'POST',
676
+ * headers: { 'Content-Type': 'application/json' },
677
+ * body: JSON.stringify({ prompt: 'a cat dancing' })
678
+ * });
679
+ *
680
+ * const result = await response.json();
681
+ * ```
682
+ */
683
+ declare function createX402Client(config?: X402ClientConfig): Promise<X402Client>;
684
+ /**
685
+ * Simple one-shot x402 request
686
+ *
687
+ * For when you just need to make one paid request.
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * import { x402Fetch } from 'moltspay/x402';
692
+ *
693
+ * const response = await x402Fetch('https://juai8.com/x402pay', {
694
+ * method: 'POST',
695
+ * body: JSON.stringify({ prompt: 'a cat dancing' })
696
+ * }, { chain: 'base' });
697
+ * ```
698
+ */
699
+ declare function x402Fetch(input: string | URL | Request, init?: RequestInit, config?: X402ClientConfig): Promise<Response>;
700
+
619
701
  /**
620
702
  * x402 Protocol Support for MoltsPay
621
703
  *
@@ -746,4 +828,111 @@ declare function verifyPaymentHeader(header: string, expectedRecipient: string,
746
828
  payload?: X402PaymentPayload;
747
829
  };
748
830
 
749
- export { AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, ChainConfig, ChainName, CreateInvoiceParams, type EIP3009Authorization, Invoice, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAgent, PaymentAgentConfig, type Receipt, type ReceiptParams, SellerTemplates, StatusMarkers, VerifyOptions, VerifyResult, WalletBalance, type X402PaymentPayload, type X402PaymentRequirements, X402_VERSION, chainToNetwork, createExactEvmPayload, createPaymentRequiredResponse, encodePaymentPayload, formatReceiptJson, formatReceiptMessage, formatReceiptText, generateReceipt, generateReceiptFromInvoice, getAgentAddress, networkToChain, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402 };
831
+ /**
832
+ * CDP (Coinbase Developer Platform) Wallet Integration
833
+ *
834
+ * Creates and manages wallets via Coinbase's CDP SDK.
835
+ * These wallets are hosted by Coinbase, making them easy to use for AI Agents.
836
+ *
837
+ * @see https://docs.cdp.coinbase.com/
838
+ */
839
+
840
+ interface CDPWalletConfig {
841
+ /** Storage directory (default: ~/.moltspay) */
842
+ storageDir?: string;
843
+ /** Chain name */
844
+ chain?: ChainName;
845
+ /** CDP API credentials (or use env vars) */
846
+ apiKeyId?: string;
847
+ apiKeySecret?: string;
848
+ walletSecret?: string;
849
+ }
850
+ interface CDPWalletData {
851
+ /** Wallet address */
852
+ address: string;
853
+ /** CDP wallet ID */
854
+ walletId: string;
855
+ /** Chain */
856
+ chain: ChainName;
857
+ /** Created timestamp */
858
+ createdAt: string;
859
+ /** CDP account data (for restoration) */
860
+ accountData?: string;
861
+ }
862
+ interface CDPInitResult {
863
+ success: boolean;
864
+ address?: string;
865
+ walletId?: string;
866
+ isNew?: boolean;
867
+ error?: string;
868
+ storagePath?: string;
869
+ }
870
+ /**
871
+ * Check if CDP SDK is available
872
+ */
873
+ declare function isCDPAvailable(): boolean;
874
+ /**
875
+ * Initialize CDP wallet
876
+ *
877
+ * Creates a new CDP wallet or loads existing one.
878
+ *
879
+ * @example
880
+ * ```bash
881
+ * # Set credentials
882
+ * export CDP_API_KEY_ID=your-key-id
883
+ * export CDP_API_KEY_SECRET=your-key-secret
884
+ *
885
+ * # Initialize
886
+ * npx moltspay init --cdp --chain base
887
+ * ```
888
+ */
889
+ declare function initCDPWallet(config?: CDPWalletConfig): Promise<CDPInitResult>;
890
+ /**
891
+ * Load existing CDP wallet
892
+ */
893
+ declare function loadCDPWallet(config?: CDPWalletConfig): CDPWalletData | null;
894
+ /**
895
+ * Get CDP wallet address (quick check without full init)
896
+ */
897
+ declare function getCDPWalletAddress(storageDir?: string): string | null;
898
+ /**
899
+ * CDP Wallet class for making payments
900
+ *
901
+ * Uses CDP SDK for wallet operations with x402 support.
902
+ */
903
+ declare class CDPWallet {
904
+ readonly address: string;
905
+ readonly chain: ChainName;
906
+ readonly chainConfig: ReturnType<typeof getChain>;
907
+ private storageDir;
908
+ constructor(config?: CDPWalletConfig);
909
+ /**
910
+ * Get USDC balance
911
+ */
912
+ getBalance(): Promise<{
913
+ usdc: string;
914
+ eth: string;
915
+ }>;
916
+ /**
917
+ * Transfer USDC to a recipient
918
+ *
919
+ * Requires CDP SDK and credentials to sign transactions.
920
+ */
921
+ transfer(params: {
922
+ to: string;
923
+ amount: number;
924
+ }): Promise<{
925
+ success: boolean;
926
+ txHash?: string;
927
+ error?: string;
928
+ explorerUrl?: string;
929
+ }>;
930
+ /**
931
+ * Create viem-compatible signer for x402
932
+ *
933
+ * This allows using CDP wallet with x402 protocol.
934
+ */
935
+ getViemAccount(): Promise<unknown>;
936
+ }
937
+
938
+ export { AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, ChainConfig, ChainName, CreateInvoiceParams, type EIP3009Authorization, Invoice, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAgent, PaymentAgentConfig, type Receipt, type ReceiptParams, SellerTemplates, StatusMarkers, VerifyOptions, VerifyResult, WalletBalance, type X402Client, type X402ClientConfig, type X402PaymentPayload, type X402PaymentRequirements, X402_VERSION, chainToNetwork, createExactEvmPayload, createPaymentRequiredResponse, createX402Client, encodePaymentPayload, formatReceiptJson, formatReceiptMessage, formatReceiptText, generateReceipt, generateReceiptFromInvoice, getAgentAddress, getCDPWalletAddress, getChain, initCDPWallet, isCDPAvailable, isX402Available, loadCDPWallet, networkToChain, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402, x402Fetch };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ export { PermitPayment } from './permit/index.js';
5
5
  export { CreateOrderParams, MemoryOrderStore, Order, OrderManager, OrderStatus, OrderStore } from './orders/index.js';
6
6
  export { VerifyPaymentParams, VerifyPaymentResult, getTransactionStatus, verifyPayment, waitForTransaction } from './verify/index.js';
7
7
  export { PaymentGuideParams, extractTransactionHash, generatePaymentGuide, generatePaymentReminder, generateWalletGuide, hasTransactionHash } from './guide/index.js';
8
- export { CHAINS, ERC20_ABI, getChain, getChainById, listChains } from './chains/index.js';
8
+ import { getChain } from './chains/index.js';
9
+ export { CHAINS, ERC20_ABI, getChainById, listChains } from './chains/index.js';
9
10
  import { ethers } from 'ethers';
10
11
 
11
12
  /**
@@ -616,6 +617,87 @@ declare function parseStatusMarker(message: string): {
616
617
  data: Record<string, string>;
617
618
  } | null;
618
619
 
620
+ /**
621
+ * x402 Client - Easy HTTP client with automatic payment handling
622
+ *
623
+ * Wraps @x402/fetch to provide simple API for AI Agents.
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * import { createX402Client } from 'moltspay/x402';
628
+ *
629
+ * // Using local wallet (AgentWallet)
630
+ * const client = await createX402Client({ chain: 'base' });
631
+ *
632
+ * // Using CDP wallet
633
+ * const client = await createX402Client({ chain: 'base', useCDP: true });
634
+ *
635
+ * // Make request - payment handled automatically
636
+ * const response = await client.fetch('https://juai8.com/x402pay');
637
+ * ```
638
+ */
639
+
640
+ interface X402ClientConfig {
641
+ /** Chain to use */
642
+ chain?: ChainName;
643
+ /** Use CDP wallet instead of local wallet */
644
+ useCDP?: boolean;
645
+ /** Custom private key (overrides stored wallet) */
646
+ privateKey?: string;
647
+ /** Storage directory for wallet */
648
+ storageDir?: string;
649
+ }
650
+ interface X402Client {
651
+ /** Fetch with automatic x402 payment handling */
652
+ fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
653
+ /** Wallet address */
654
+ address: string;
655
+ /** Chain being used */
656
+ chain: ChainName;
657
+ }
658
+ /**
659
+ * Check if @x402/fetch is available
660
+ */
661
+ declare function isX402Available(): boolean;
662
+ /**
663
+ * Create x402 client
664
+ *
665
+ * Automatically handles 402 Payment Required responses.
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * import { createX402Client } from 'moltspay/x402';
670
+ *
671
+ * const client = await createX402Client({ chain: 'base' });
672
+ *
673
+ * // Request paid API - payment handled automatically
674
+ * const response = await client.fetch('https://juai8.com/x402pay', {
675
+ * method: 'POST',
676
+ * headers: { 'Content-Type': 'application/json' },
677
+ * body: JSON.stringify({ prompt: 'a cat dancing' })
678
+ * });
679
+ *
680
+ * const result = await response.json();
681
+ * ```
682
+ */
683
+ declare function createX402Client(config?: X402ClientConfig): Promise<X402Client>;
684
+ /**
685
+ * Simple one-shot x402 request
686
+ *
687
+ * For when you just need to make one paid request.
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * import { x402Fetch } from 'moltspay/x402';
692
+ *
693
+ * const response = await x402Fetch('https://juai8.com/x402pay', {
694
+ * method: 'POST',
695
+ * body: JSON.stringify({ prompt: 'a cat dancing' })
696
+ * }, { chain: 'base' });
697
+ * ```
698
+ */
699
+ declare function x402Fetch(input: string | URL | Request, init?: RequestInit, config?: X402ClientConfig): Promise<Response>;
700
+
619
701
  /**
620
702
  * x402 Protocol Support for MoltsPay
621
703
  *
@@ -746,4 +828,111 @@ declare function verifyPaymentHeader(header: string, expectedRecipient: string,
746
828
  payload?: X402PaymentPayload;
747
829
  };
748
830
 
749
- export { AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, ChainConfig, ChainName, CreateInvoiceParams, type EIP3009Authorization, Invoice, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAgent, PaymentAgentConfig, type Receipt, type ReceiptParams, SellerTemplates, StatusMarkers, VerifyOptions, VerifyResult, WalletBalance, type X402PaymentPayload, type X402PaymentRequirements, X402_VERSION, chainToNetwork, createExactEvmPayload, createPaymentRequiredResponse, encodePaymentPayload, formatReceiptJson, formatReceiptMessage, formatReceiptText, generateReceipt, generateReceiptFromInvoice, getAgentAddress, networkToChain, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402 };
831
+ /**
832
+ * CDP (Coinbase Developer Platform) Wallet Integration
833
+ *
834
+ * Creates and manages wallets via Coinbase's CDP SDK.
835
+ * These wallets are hosted by Coinbase, making them easy to use for AI Agents.
836
+ *
837
+ * @see https://docs.cdp.coinbase.com/
838
+ */
839
+
840
+ interface CDPWalletConfig {
841
+ /** Storage directory (default: ~/.moltspay) */
842
+ storageDir?: string;
843
+ /** Chain name */
844
+ chain?: ChainName;
845
+ /** CDP API credentials (or use env vars) */
846
+ apiKeyId?: string;
847
+ apiKeySecret?: string;
848
+ walletSecret?: string;
849
+ }
850
+ interface CDPWalletData {
851
+ /** Wallet address */
852
+ address: string;
853
+ /** CDP wallet ID */
854
+ walletId: string;
855
+ /** Chain */
856
+ chain: ChainName;
857
+ /** Created timestamp */
858
+ createdAt: string;
859
+ /** CDP account data (for restoration) */
860
+ accountData?: string;
861
+ }
862
+ interface CDPInitResult {
863
+ success: boolean;
864
+ address?: string;
865
+ walletId?: string;
866
+ isNew?: boolean;
867
+ error?: string;
868
+ storagePath?: string;
869
+ }
870
+ /**
871
+ * Check if CDP SDK is available
872
+ */
873
+ declare function isCDPAvailable(): boolean;
874
+ /**
875
+ * Initialize CDP wallet
876
+ *
877
+ * Creates a new CDP wallet or loads existing one.
878
+ *
879
+ * @example
880
+ * ```bash
881
+ * # Set credentials
882
+ * export CDP_API_KEY_ID=your-key-id
883
+ * export CDP_API_KEY_SECRET=your-key-secret
884
+ *
885
+ * # Initialize
886
+ * npx moltspay init --cdp --chain base
887
+ * ```
888
+ */
889
+ declare function initCDPWallet(config?: CDPWalletConfig): Promise<CDPInitResult>;
890
+ /**
891
+ * Load existing CDP wallet
892
+ */
893
+ declare function loadCDPWallet(config?: CDPWalletConfig): CDPWalletData | null;
894
+ /**
895
+ * Get CDP wallet address (quick check without full init)
896
+ */
897
+ declare function getCDPWalletAddress(storageDir?: string): string | null;
898
+ /**
899
+ * CDP Wallet class for making payments
900
+ *
901
+ * Uses CDP SDK for wallet operations with x402 support.
902
+ */
903
+ declare class CDPWallet {
904
+ readonly address: string;
905
+ readonly chain: ChainName;
906
+ readonly chainConfig: ReturnType<typeof getChain>;
907
+ private storageDir;
908
+ constructor(config?: CDPWalletConfig);
909
+ /**
910
+ * Get USDC balance
911
+ */
912
+ getBalance(): Promise<{
913
+ usdc: string;
914
+ eth: string;
915
+ }>;
916
+ /**
917
+ * Transfer USDC to a recipient
918
+ *
919
+ * Requires CDP SDK and credentials to sign transactions.
920
+ */
921
+ transfer(params: {
922
+ to: string;
923
+ amount: number;
924
+ }): Promise<{
925
+ success: boolean;
926
+ txHash?: string;
927
+ error?: string;
928
+ explorerUrl?: string;
929
+ }>;
930
+ /**
931
+ * Create viem-compatible signer for x402
932
+ *
933
+ * This allows using CDP wallet with x402 protocol.
934
+ */
935
+ getViemAccount(): Promise<unknown>;
936
+ }
937
+
938
+ export { AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, ChainConfig, ChainName, CreateInvoiceParams, type EIP3009Authorization, Invoice, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAgent, PaymentAgentConfig, type Receipt, type ReceiptParams, SellerTemplates, StatusMarkers, VerifyOptions, VerifyResult, WalletBalance, type X402Client, type X402ClientConfig, type X402PaymentPayload, type X402PaymentRequirements, X402_VERSION, chainToNetwork, createExactEvmPayload, createPaymentRequiredResponse, createX402Client, encodePaymentPayload, formatReceiptJson, formatReceiptMessage, formatReceiptText, generateReceipt, generateReceiptFromInvoice, getAgentAddress, getCDPWalletAddress, getChain, initCDPWallet, isCDPAvailable, isX402Available, loadCDPWallet, networkToChain, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402, x402Fetch };