uvd-x402-sdk 2.0.2 → 2.1.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/README.md CHANGED
@@ -69,9 +69,66 @@ npm install react
69
69
 
70
70
  ---
71
71
 
72
+ ## WalletConnect Integration
73
+
74
+ The SDK works with any EVM wallet that injects into `window.ethereum`, including:
75
+
76
+ - **Browser extensions**: MetaMask, Rainbow, Rabby, Coinbase Wallet
77
+ - **Mobile wallets**: Rainbow, MetaMask Mobile, Trust Wallet (via WalletConnect)
78
+
79
+ ### Using WalletConnect (Mobile Wallets)
80
+
81
+ For mobile wallet support (Rainbow, MetaMask Mobile, etc.), initialize WalletConnect before using the SDK:
82
+
83
+ ```typescript
84
+ import { EthereumProvider } from '@walletconnect/ethereum-provider';
85
+ import { X402Client } from 'uvd-x402-sdk';
86
+
87
+ // 1. Initialize WalletConnect
88
+ const walletConnectProvider = await EthereumProvider.init({
89
+ projectId: 'YOUR_WALLETCONNECT_PROJECT_ID', // Get from cloud.walletconnect.com
90
+ chains: [8453], // Base mainnet
91
+ optionalChains: [1, 137, 42161, 10], // ETH, Polygon, Arbitrum, Optimism
92
+ showQrModal: true,
93
+ });
94
+
95
+ // 2. Connect wallet (shows QR code for mobile wallet to scan)
96
+ await walletConnectProvider.connect();
97
+
98
+ // 3. Use the SDK normally
99
+ const client = new X402Client({ defaultChain: 'base' });
100
+ const address = await client.connect('base');
101
+
102
+ // 4. Create payment
103
+ const result = await client.createPayment({
104
+ recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
105
+ amount: '10.00',
106
+ });
107
+ ```
108
+
109
+ ### Using Browser Extensions (Rainbow, MetaMask, etc.)
110
+
111
+ Browser extension wallets work automatically - no extra setup needed:
112
+
113
+ ```typescript
114
+ import { X402Client } from 'uvd-x402-sdk';
115
+
116
+ const client = new X402Client({ defaultChain: 'base' });
117
+
118
+ // Connects to whatever wallet is installed (Rainbow, MetaMask, Rabby, etc.)
119
+ const address = await client.connect('base');
120
+
121
+ const result = await client.createPayment({
122
+ recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
123
+ amount: '10.00',
124
+ });
125
+ ```
126
+
127
+ ---
128
+
72
129
  ## Network Examples
73
130
 
74
- ### EVM Chains (11 Networks)
131
+ ### EVM Chains (10 Networks)
75
132
 
76
133
  All EVM chains use EIP-712 typed data signing with ERC-3009 TransferWithAuthorization.
77
134
 
@@ -0,0 +1,139 @@
1
+ import { e as PaymentResult } from '../index-MTBgC_SL.mjs';
2
+
3
+ /**
4
+ * uvd-x402-sdk - Wagmi/Viem Adapter
5
+ *
6
+ * Provides integration with wagmi/viem for projects using RainbowKit,
7
+ * ConnectKit, or other wagmi-based wallet connection libraries.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { useWalletClient } from 'wagmi';
12
+ * import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
13
+ *
14
+ * function PayButton() {
15
+ * const { data: walletClient } = useWalletClient();
16
+ *
17
+ * const handlePay = async () => {
18
+ * const paymentHeader = await createPaymentFromWalletClient(walletClient, {
19
+ * recipient: '0x...',
20
+ * amount: '1.00',
21
+ * chainName: 'base',
22
+ * });
23
+ *
24
+ * // Use in your API request
25
+ * await fetch('/api/paid-endpoint', {
26
+ * headers: { 'X-PAYMENT': paymentHeader }
27
+ * });
28
+ * };
29
+ *
30
+ * return <button onClick={handlePay}>Pay $1.00</button>;
31
+ * }
32
+ * ```
33
+ */
34
+
35
+ /**
36
+ * Viem WalletClient interface (minimal type to avoid viem dependency)
37
+ */
38
+ interface WalletClient {
39
+ account: {
40
+ address: `0x${string}`;
41
+ };
42
+ signTypedData: (args: {
43
+ domain: {
44
+ name: string;
45
+ version: string;
46
+ chainId: number;
47
+ verifyingContract: `0x${string}`;
48
+ };
49
+ types: Record<string, Array<{
50
+ name: string;
51
+ type: string;
52
+ }>>;
53
+ primaryType: string;
54
+ message: Record<string, unknown>;
55
+ }) => Promise<`0x${string}`>;
56
+ }
57
+ /**
58
+ * Payment options for wagmi adapter
59
+ */
60
+ interface WagmiPaymentOptions {
61
+ /** Recipient address */
62
+ recipient: string;
63
+ /** Amount in USDC (e.g., "1.00", "10.50") */
64
+ amount: string;
65
+ /** Chain name (default: 'base') */
66
+ chainName?: string;
67
+ /** Validity window in seconds (default: 300 = 5 minutes) */
68
+ validitySeconds?: number;
69
+ }
70
+ /**
71
+ * Create an x402 payment header using a wagmi/viem WalletClient
72
+ *
73
+ * This function allows you to use the x402 SDK with wagmi-based wallet
74
+ * connections (RainbowKit, ConnectKit, etc.) instead of the built-in
75
+ * wallet connection.
76
+ *
77
+ * @param walletClient - The WalletClient from wagmi's useWalletClient hook
78
+ * @param options - Payment options (recipient, amount, chainName)
79
+ * @returns Base64-encoded payment header ready for X-PAYMENT HTTP header
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * import { useWalletClient } from 'wagmi';
84
+ * import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
85
+ *
86
+ * const { data: walletClient } = useWalletClient();
87
+ *
88
+ * const paymentHeader = await createPaymentFromWalletClient(walletClient, {
89
+ * recipient: '0xRecipientAddress',
90
+ * amount: '5.00',
91
+ * chainName: 'base',
92
+ * });
93
+ * ```
94
+ */
95
+ declare function createPaymentFromWalletClient(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<string>;
96
+ /**
97
+ * Create payment with full result object (includes metadata)
98
+ *
99
+ * Same as createPaymentFromWalletClient but returns a PaymentResult
100
+ * object with additional metadata.
101
+ *
102
+ * @param walletClient - The WalletClient from wagmi
103
+ * @param options - Payment options
104
+ * @returns PaymentResult with paymentHeader and metadata
105
+ */
106
+ declare function createPaymentWithResult(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<PaymentResult>;
107
+ /**
108
+ * React hook helper for wagmi integration
109
+ *
110
+ * Returns a function that creates payments using the connected wallet.
111
+ * This is a simple wrapper - for more control, use createPaymentFromWalletClient directly.
112
+ *
113
+ * @example
114
+ * ```tsx
115
+ * import { useWalletClient } from 'wagmi';
116
+ * import { useX402Wagmi } from 'uvd-x402-sdk/wagmi';
117
+ *
118
+ * function PayButton() {
119
+ * const { data: walletClient } = useWalletClient();
120
+ * const { createPayment, isReady } = useX402Wagmi(walletClient);
121
+ *
122
+ * return (
123
+ * <button
124
+ * disabled={!isReady}
125
+ * onClick={() => createPayment({ recipient: '0x...', amount: '1.00' })}
126
+ * >
127
+ * Pay
128
+ * </button>
129
+ * );
130
+ * }
131
+ * ```
132
+ */
133
+ declare function useX402Wagmi(walletClient: WalletClient | undefined | null): {
134
+ isReady: boolean;
135
+ createPayment: (options: WagmiPaymentOptions) => Promise<string>;
136
+ createPaymentFull: (options: WagmiPaymentOptions) => Promise<PaymentResult>;
137
+ };
138
+
139
+ export { type WagmiPaymentOptions, type WalletClient, createPaymentFromWalletClient, createPaymentWithResult, useX402Wagmi };
@@ -0,0 +1,139 @@
1
+ import { e as PaymentResult } from '../index-MTBgC_SL.js';
2
+
3
+ /**
4
+ * uvd-x402-sdk - Wagmi/Viem Adapter
5
+ *
6
+ * Provides integration with wagmi/viem for projects using RainbowKit,
7
+ * ConnectKit, or other wagmi-based wallet connection libraries.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { useWalletClient } from 'wagmi';
12
+ * import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
13
+ *
14
+ * function PayButton() {
15
+ * const { data: walletClient } = useWalletClient();
16
+ *
17
+ * const handlePay = async () => {
18
+ * const paymentHeader = await createPaymentFromWalletClient(walletClient, {
19
+ * recipient: '0x...',
20
+ * amount: '1.00',
21
+ * chainName: 'base',
22
+ * });
23
+ *
24
+ * // Use in your API request
25
+ * await fetch('/api/paid-endpoint', {
26
+ * headers: { 'X-PAYMENT': paymentHeader }
27
+ * });
28
+ * };
29
+ *
30
+ * return <button onClick={handlePay}>Pay $1.00</button>;
31
+ * }
32
+ * ```
33
+ */
34
+
35
+ /**
36
+ * Viem WalletClient interface (minimal type to avoid viem dependency)
37
+ */
38
+ interface WalletClient {
39
+ account: {
40
+ address: `0x${string}`;
41
+ };
42
+ signTypedData: (args: {
43
+ domain: {
44
+ name: string;
45
+ version: string;
46
+ chainId: number;
47
+ verifyingContract: `0x${string}`;
48
+ };
49
+ types: Record<string, Array<{
50
+ name: string;
51
+ type: string;
52
+ }>>;
53
+ primaryType: string;
54
+ message: Record<string, unknown>;
55
+ }) => Promise<`0x${string}`>;
56
+ }
57
+ /**
58
+ * Payment options for wagmi adapter
59
+ */
60
+ interface WagmiPaymentOptions {
61
+ /** Recipient address */
62
+ recipient: string;
63
+ /** Amount in USDC (e.g., "1.00", "10.50") */
64
+ amount: string;
65
+ /** Chain name (default: 'base') */
66
+ chainName?: string;
67
+ /** Validity window in seconds (default: 300 = 5 minutes) */
68
+ validitySeconds?: number;
69
+ }
70
+ /**
71
+ * Create an x402 payment header using a wagmi/viem WalletClient
72
+ *
73
+ * This function allows you to use the x402 SDK with wagmi-based wallet
74
+ * connections (RainbowKit, ConnectKit, etc.) instead of the built-in
75
+ * wallet connection.
76
+ *
77
+ * @param walletClient - The WalletClient from wagmi's useWalletClient hook
78
+ * @param options - Payment options (recipient, amount, chainName)
79
+ * @returns Base64-encoded payment header ready for X-PAYMENT HTTP header
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * import { useWalletClient } from 'wagmi';
84
+ * import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
85
+ *
86
+ * const { data: walletClient } = useWalletClient();
87
+ *
88
+ * const paymentHeader = await createPaymentFromWalletClient(walletClient, {
89
+ * recipient: '0xRecipientAddress',
90
+ * amount: '5.00',
91
+ * chainName: 'base',
92
+ * });
93
+ * ```
94
+ */
95
+ declare function createPaymentFromWalletClient(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<string>;
96
+ /**
97
+ * Create payment with full result object (includes metadata)
98
+ *
99
+ * Same as createPaymentFromWalletClient but returns a PaymentResult
100
+ * object with additional metadata.
101
+ *
102
+ * @param walletClient - The WalletClient from wagmi
103
+ * @param options - Payment options
104
+ * @returns PaymentResult with paymentHeader and metadata
105
+ */
106
+ declare function createPaymentWithResult(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<PaymentResult>;
107
+ /**
108
+ * React hook helper for wagmi integration
109
+ *
110
+ * Returns a function that creates payments using the connected wallet.
111
+ * This is a simple wrapper - for more control, use createPaymentFromWalletClient directly.
112
+ *
113
+ * @example
114
+ * ```tsx
115
+ * import { useWalletClient } from 'wagmi';
116
+ * import { useX402Wagmi } from 'uvd-x402-sdk/wagmi';
117
+ *
118
+ * function PayButton() {
119
+ * const { data: walletClient } = useWalletClient();
120
+ * const { createPayment, isReady } = useX402Wagmi(walletClient);
121
+ *
122
+ * return (
123
+ * <button
124
+ * disabled={!isReady}
125
+ * onClick={() => createPayment({ recipient: '0x...', amount: '1.00' })}
126
+ * >
127
+ * Pay
128
+ * </button>
129
+ * );
130
+ * }
131
+ * ```
132
+ */
133
+ declare function useX402Wagmi(walletClient: WalletClient | undefined | null): {
134
+ isReady: boolean;
135
+ createPayment: (options: WagmiPaymentOptions) => Promise<string>;
136
+ createPaymentFull: (options: WagmiPaymentOptions) => Promise<PaymentResult>;
137
+ };
138
+
139
+ export { type WagmiPaymentOptions, type WalletClient, createPaymentFromWalletClient, createPaymentWithResult, useX402Wagmi };