uvd-x402-sdk 2.0.3 → 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.
@@ -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 };