@mixrpay/merchant-sdk 0.2.0 → 0.3.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,289 @@
1
+ import { V as VerifyReceiptOptions, P as PaymentReceipt } from './types-jelXkTp9.mjs';
2
+ export { M as MixrPayOptions, a as MixrPayPaymentResult, b as PaymentMethod, c as PriceContext } from './types-jelXkTp9.mjs';
3
+
4
+ /**
5
+ * MixrPay Merchant SDK - Payment Receipt Verification
6
+ *
7
+ * Verify JWT payment receipts issued by MixrPay after successful x402 payments.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { verifyPaymentReceipt } from '@mixrpay/merchant-sdk';
12
+ *
13
+ * const receipt = req.headers['x-payment-receipt'];
14
+ * const payment = await verifyPaymentReceipt(receipt);
15
+ *
16
+ * console.log(`Payment received: $${payment.amountUsd} from ${payment.payer}`);
17
+ * console.log(`Transaction: ${payment.txHash}`);
18
+ * ```
19
+ */
20
+
21
+ /**
22
+ * Verify a JWT payment receipt from MixrPay.
23
+ *
24
+ * This function:
25
+ * 1. Fetches the JWKS from MixrPay (cached for 1 hour)
26
+ * 2. Verifies the JWT signature using RS256
27
+ * 3. Validates standard JWT claims (exp, iat)
28
+ * 4. Returns the typed payment receipt
29
+ *
30
+ * @param receipt - The JWT receipt string from X-Payment-Receipt header
31
+ * @param options - Optional configuration (custom JWKS URL, issuer validation)
32
+ * @returns Verified payment receipt
33
+ * @throws Error if verification fails
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Basic usage
38
+ * const payment = await verifyPaymentReceipt(receipt);
39
+ *
40
+ * // With custom JWKS URL (for testing or self-hosted)
41
+ * const payment = await verifyPaymentReceipt(receipt, {
42
+ * jwksUrl: 'https://your-mixrpay.com/.well-known/jwks'
43
+ * });
44
+ * ```
45
+ */
46
+ declare function verifyPaymentReceipt(receipt: string, options?: VerifyReceiptOptions): Promise<PaymentReceipt>;
47
+
48
+ interface SessionGrant {
49
+ /** Session key ID */
50
+ sessionId: string;
51
+ /** User's wallet address */
52
+ userWallet: string;
53
+ /** Your merchant wallet address */
54
+ merchantWallet: string;
55
+ /** Spending limits */
56
+ limits: {
57
+ maxTotalUsd?: number;
58
+ maxPerTxUsd?: number;
59
+ expiresAt: string;
60
+ };
61
+ /** When the session was granted */
62
+ grantedAt: string;
63
+ }
64
+ /**
65
+ * Verify a session.granted webhook signature.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const payload = req.body;
70
+ * const signature = req.headers['x-mixrpay-signature'];
71
+ *
72
+ * if (verifySessionWebhook(JSON.stringify(payload), signature, webhookSecret)) {
73
+ * const grant = parseSessionGrant(payload);
74
+ * console.log(`User ${grant.userWallet} granted access`);
75
+ * }
76
+ * ```
77
+ */
78
+ declare function verifySessionWebhook(payload: string, signature: string, secret: string): boolean;
79
+
80
+ /**
81
+ * MixrPay Widget Custom Element Type Declarations
82
+ *
83
+ * These types enable TypeScript support for MixrPay widget custom elements
84
+ * in JSX/TSX files.
85
+ *
86
+ * Usage in your app:
87
+ * ```typescript
88
+ * // Option 1: Import for side effects (recommended)
89
+ * import '@mixrpay/merchant-sdk/widget-elements';
90
+ *
91
+ * // Option 2: Reference directly
92
+ * /// <reference types="@mixrpay/merchant-sdk/widget-elements" />
93
+ * ```
94
+ *
95
+ * Now these work without TypeScript errors:
96
+ * ```tsx
97
+ * <mixr-balance data-theme="dark" />
98
+ * <mixr-wallet />
99
+ * ```
100
+ */
101
+
102
+ // =============================================================================
103
+ // Widget Attribute Types
104
+ // =============================================================================
105
+
106
+ interface MixrWidgetAttributes {
107
+ /** Theme for the widget - 'dark' or 'light' */
108
+ 'data-theme'?: 'dark' | 'light';
109
+ /** Additional class names */
110
+ class?: string;
111
+ className?: string;
112
+ }
113
+
114
+ interface MixrBalanceAttributes extends MixrWidgetAttributes {
115
+ // Balance-specific attributes (currently none beyond base)
116
+ }
117
+
118
+ interface MixrWalletAttributes extends MixrWidgetAttributes {
119
+ // Wallet-specific attributes (currently none beyond base)
120
+ }
121
+
122
+ // =============================================================================
123
+ // Global State Types
124
+ // =============================================================================
125
+
126
+ /**
127
+ * State object returned by window.Mixr.getState()
128
+ */
129
+ interface MixrState {
130
+ /** User's balance in minor units (bigint) */
131
+ balance: bigint;
132
+ /** User's balance in USD */
133
+ balanceUsd: number;
134
+ /** Currency code (e.g., 'USD') */
135
+ currency: string;
136
+ /** Whether the user is authenticated */
137
+ isAuthenticated: boolean;
138
+ /** Whether the user has completed onboarding */
139
+ isOnboarded: boolean;
140
+ /** User's wallet address (null if not authenticated) */
141
+ walletAddress: string | null;
142
+ /** Whether the widget is loading */
143
+ loading: boolean;
144
+ /** Error message if any */
145
+ error: string | null;
146
+ }
147
+
148
+ // =============================================================================
149
+ // Global API Types
150
+ // =============================================================================
151
+
152
+ /**
153
+ * MixrPay global API available on window.Mixr
154
+ */
155
+ interface MixrAPI {
156
+ /** Initialize the widget (called automatically on load) */
157
+ init(): void;
158
+
159
+ /**
160
+ * Open the wallet popup
161
+ * @param tab - Optional tab to open: 'add_funds', 'send', 'receive', 'sessions'
162
+ */
163
+ openWallet(tab?: 'add_funds' | 'send' | 'receive' | 'sessions'): void;
164
+
165
+ /** Get current widget state */
166
+ getState(): MixrState;
167
+
168
+ /** Refresh user balance and state */
169
+ refresh(): Promise<void>;
170
+
171
+ /**
172
+ * Programmatically charge a user
173
+ * @param feature - Feature slug to charge for
174
+ * @param priceUsd - Price in USD as string (e.g., "0.25")
175
+ * @param element - The element that triggered the charge (for UI feedback)
176
+ */
177
+ charge(feature: string, priceUsd: string, element: HTMLElement): Promise<void>;
178
+ }
179
+
180
+ // =============================================================================
181
+ // Event Detail Types
182
+ // =============================================================================
183
+
184
+ interface MixrChargeSuccessDetail {
185
+ /** The feature that was charged */
186
+ feature: string;
187
+ /** The price that was charged */
188
+ price: string;
189
+ /** Unique charge ID */
190
+ chargeId?: string;
191
+ }
192
+
193
+ interface MixrChargeErrorDetail {
194
+ /** Error message */
195
+ error: string;
196
+ /** The feature that failed to charge */
197
+ feature?: string;
198
+ }
199
+
200
+ interface MixrLowBalanceDetail {
201
+ /** Current balance */
202
+ balance: number;
203
+ /** Required amount */
204
+ required: number;
205
+ }
206
+
207
+ interface MixrStateUpdatedDetail extends MixrState {}
208
+
209
+ interface MixrFundingDetail {
210
+ /** Amount funded */
211
+ amount: number;
212
+ /** Transaction hash if available */
213
+ txHash?: string;
214
+ }
215
+
216
+ interface MixrTransactionDetail {
217
+ /** Transaction hash */
218
+ txHash: string;
219
+ /** Amount transferred */
220
+ amount: number;
221
+ }
222
+
223
+ // =============================================================================
224
+ // Custom Events Map
225
+ // =============================================================================
226
+
227
+ /**
228
+ * MixrPay custom events that can be listened to via addEventListener
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * window.addEventListener('mixr:charge-success', (e) => {
233
+ * console.log('Charged:', e.detail.feature, e.detail.price);
234
+ * });
235
+ * ```
236
+ */
237
+ interface MixrEventMap {
238
+ 'mixr:charge-success': CustomEvent<MixrChargeSuccessDetail>;
239
+ 'mixr:charge-error': CustomEvent<MixrChargeErrorDetail>;
240
+ 'mixr:low-balance': CustomEvent<MixrLowBalanceDetail>;
241
+ 'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
242
+ 'mixr:funding': CustomEvent<MixrFundingDetail>;
243
+ 'mixr:transaction': CustomEvent<MixrTransactionDetail>;
244
+ }
245
+
246
+ // =============================================================================
247
+ // Global Augmentations
248
+ // =============================================================================
249
+
250
+ declare global {
251
+ interface Window {
252
+ /** MixrPay global API */
253
+ Mixr: MixrAPI;
254
+ }
255
+
256
+ interface WindowEventMap extends MixrEventMap {}
257
+
258
+ namespace JSX {
259
+ interface IntrinsicElements {
260
+ /**
261
+ * MixrPay balance display component
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * <mixr-balance data-theme="dark" />
266
+ * ```
267
+ */
268
+ 'mixr-balance': React.DetailedHTMLProps<
269
+ React.HTMLAttributes<HTMLElement> & MixrBalanceAttributes,
270
+ HTMLElement
271
+ >;
272
+
273
+ /**
274
+ * MixrPay wallet widget component
275
+ *
276
+ * @example
277
+ * ```tsx
278
+ * <mixr-wallet data-theme="dark" />
279
+ * ```
280
+ */
281
+ 'mixr-wallet': React.DetailedHTMLProps<
282
+ React.HTMLAttributes<HTMLElement> & MixrWalletAttributes,
283
+ HTMLElement
284
+ >;
285
+ }
286
+ }
287
+ }
288
+
289
+ export { PaymentReceipt, type SessionGrant, verifyPaymentReceipt, verifySessionWebhook };
@@ -0,0 +1,289 @@
1
+ import { V as VerifyReceiptOptions, P as PaymentReceipt } from './types-jelXkTp9.js';
2
+ export { M as MixrPayOptions, a as MixrPayPaymentResult, b as PaymentMethod, c as PriceContext } from './types-jelXkTp9.js';
3
+
4
+ /**
5
+ * MixrPay Merchant SDK - Payment Receipt Verification
6
+ *
7
+ * Verify JWT payment receipts issued by MixrPay after successful x402 payments.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { verifyPaymentReceipt } from '@mixrpay/merchant-sdk';
12
+ *
13
+ * const receipt = req.headers['x-payment-receipt'];
14
+ * const payment = await verifyPaymentReceipt(receipt);
15
+ *
16
+ * console.log(`Payment received: $${payment.amountUsd} from ${payment.payer}`);
17
+ * console.log(`Transaction: ${payment.txHash}`);
18
+ * ```
19
+ */
20
+
21
+ /**
22
+ * Verify a JWT payment receipt from MixrPay.
23
+ *
24
+ * This function:
25
+ * 1. Fetches the JWKS from MixrPay (cached for 1 hour)
26
+ * 2. Verifies the JWT signature using RS256
27
+ * 3. Validates standard JWT claims (exp, iat)
28
+ * 4. Returns the typed payment receipt
29
+ *
30
+ * @param receipt - The JWT receipt string from X-Payment-Receipt header
31
+ * @param options - Optional configuration (custom JWKS URL, issuer validation)
32
+ * @returns Verified payment receipt
33
+ * @throws Error if verification fails
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Basic usage
38
+ * const payment = await verifyPaymentReceipt(receipt);
39
+ *
40
+ * // With custom JWKS URL (for testing or self-hosted)
41
+ * const payment = await verifyPaymentReceipt(receipt, {
42
+ * jwksUrl: 'https://your-mixrpay.com/.well-known/jwks'
43
+ * });
44
+ * ```
45
+ */
46
+ declare function verifyPaymentReceipt(receipt: string, options?: VerifyReceiptOptions): Promise<PaymentReceipt>;
47
+
48
+ interface SessionGrant {
49
+ /** Session key ID */
50
+ sessionId: string;
51
+ /** User's wallet address */
52
+ userWallet: string;
53
+ /** Your merchant wallet address */
54
+ merchantWallet: string;
55
+ /** Spending limits */
56
+ limits: {
57
+ maxTotalUsd?: number;
58
+ maxPerTxUsd?: number;
59
+ expiresAt: string;
60
+ };
61
+ /** When the session was granted */
62
+ grantedAt: string;
63
+ }
64
+ /**
65
+ * Verify a session.granted webhook signature.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const payload = req.body;
70
+ * const signature = req.headers['x-mixrpay-signature'];
71
+ *
72
+ * if (verifySessionWebhook(JSON.stringify(payload), signature, webhookSecret)) {
73
+ * const grant = parseSessionGrant(payload);
74
+ * console.log(`User ${grant.userWallet} granted access`);
75
+ * }
76
+ * ```
77
+ */
78
+ declare function verifySessionWebhook(payload: string, signature: string, secret: string): boolean;
79
+
80
+ /**
81
+ * MixrPay Widget Custom Element Type Declarations
82
+ *
83
+ * These types enable TypeScript support for MixrPay widget custom elements
84
+ * in JSX/TSX files.
85
+ *
86
+ * Usage in your app:
87
+ * ```typescript
88
+ * // Option 1: Import for side effects (recommended)
89
+ * import '@mixrpay/merchant-sdk/widget-elements';
90
+ *
91
+ * // Option 2: Reference directly
92
+ * /// <reference types="@mixrpay/merchant-sdk/widget-elements" />
93
+ * ```
94
+ *
95
+ * Now these work without TypeScript errors:
96
+ * ```tsx
97
+ * <mixr-balance data-theme="dark" />
98
+ * <mixr-wallet />
99
+ * ```
100
+ */
101
+
102
+ // =============================================================================
103
+ // Widget Attribute Types
104
+ // =============================================================================
105
+
106
+ interface MixrWidgetAttributes {
107
+ /** Theme for the widget - 'dark' or 'light' */
108
+ 'data-theme'?: 'dark' | 'light';
109
+ /** Additional class names */
110
+ class?: string;
111
+ className?: string;
112
+ }
113
+
114
+ interface MixrBalanceAttributes extends MixrWidgetAttributes {
115
+ // Balance-specific attributes (currently none beyond base)
116
+ }
117
+
118
+ interface MixrWalletAttributes extends MixrWidgetAttributes {
119
+ // Wallet-specific attributes (currently none beyond base)
120
+ }
121
+
122
+ // =============================================================================
123
+ // Global State Types
124
+ // =============================================================================
125
+
126
+ /**
127
+ * State object returned by window.Mixr.getState()
128
+ */
129
+ interface MixrState {
130
+ /** User's balance in minor units (bigint) */
131
+ balance: bigint;
132
+ /** User's balance in USD */
133
+ balanceUsd: number;
134
+ /** Currency code (e.g., 'USD') */
135
+ currency: string;
136
+ /** Whether the user is authenticated */
137
+ isAuthenticated: boolean;
138
+ /** Whether the user has completed onboarding */
139
+ isOnboarded: boolean;
140
+ /** User's wallet address (null if not authenticated) */
141
+ walletAddress: string | null;
142
+ /** Whether the widget is loading */
143
+ loading: boolean;
144
+ /** Error message if any */
145
+ error: string | null;
146
+ }
147
+
148
+ // =============================================================================
149
+ // Global API Types
150
+ // =============================================================================
151
+
152
+ /**
153
+ * MixrPay global API available on window.Mixr
154
+ */
155
+ interface MixrAPI {
156
+ /** Initialize the widget (called automatically on load) */
157
+ init(): void;
158
+
159
+ /**
160
+ * Open the wallet popup
161
+ * @param tab - Optional tab to open: 'add_funds', 'send', 'receive', 'sessions'
162
+ */
163
+ openWallet(tab?: 'add_funds' | 'send' | 'receive' | 'sessions'): void;
164
+
165
+ /** Get current widget state */
166
+ getState(): MixrState;
167
+
168
+ /** Refresh user balance and state */
169
+ refresh(): Promise<void>;
170
+
171
+ /**
172
+ * Programmatically charge a user
173
+ * @param feature - Feature slug to charge for
174
+ * @param priceUsd - Price in USD as string (e.g., "0.25")
175
+ * @param element - The element that triggered the charge (for UI feedback)
176
+ */
177
+ charge(feature: string, priceUsd: string, element: HTMLElement): Promise<void>;
178
+ }
179
+
180
+ // =============================================================================
181
+ // Event Detail Types
182
+ // =============================================================================
183
+
184
+ interface MixrChargeSuccessDetail {
185
+ /** The feature that was charged */
186
+ feature: string;
187
+ /** The price that was charged */
188
+ price: string;
189
+ /** Unique charge ID */
190
+ chargeId?: string;
191
+ }
192
+
193
+ interface MixrChargeErrorDetail {
194
+ /** Error message */
195
+ error: string;
196
+ /** The feature that failed to charge */
197
+ feature?: string;
198
+ }
199
+
200
+ interface MixrLowBalanceDetail {
201
+ /** Current balance */
202
+ balance: number;
203
+ /** Required amount */
204
+ required: number;
205
+ }
206
+
207
+ interface MixrStateUpdatedDetail extends MixrState {}
208
+
209
+ interface MixrFundingDetail {
210
+ /** Amount funded */
211
+ amount: number;
212
+ /** Transaction hash if available */
213
+ txHash?: string;
214
+ }
215
+
216
+ interface MixrTransactionDetail {
217
+ /** Transaction hash */
218
+ txHash: string;
219
+ /** Amount transferred */
220
+ amount: number;
221
+ }
222
+
223
+ // =============================================================================
224
+ // Custom Events Map
225
+ // =============================================================================
226
+
227
+ /**
228
+ * MixrPay custom events that can be listened to via addEventListener
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * window.addEventListener('mixr:charge-success', (e) => {
233
+ * console.log('Charged:', e.detail.feature, e.detail.price);
234
+ * });
235
+ * ```
236
+ */
237
+ interface MixrEventMap {
238
+ 'mixr:charge-success': CustomEvent<MixrChargeSuccessDetail>;
239
+ 'mixr:charge-error': CustomEvent<MixrChargeErrorDetail>;
240
+ 'mixr:low-balance': CustomEvent<MixrLowBalanceDetail>;
241
+ 'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
242
+ 'mixr:funding': CustomEvent<MixrFundingDetail>;
243
+ 'mixr:transaction': CustomEvent<MixrTransactionDetail>;
244
+ }
245
+
246
+ // =============================================================================
247
+ // Global Augmentations
248
+ // =============================================================================
249
+
250
+ declare global {
251
+ interface Window {
252
+ /** MixrPay global API */
253
+ Mixr: MixrAPI;
254
+ }
255
+
256
+ interface WindowEventMap extends MixrEventMap {}
257
+
258
+ namespace JSX {
259
+ interface IntrinsicElements {
260
+ /**
261
+ * MixrPay balance display component
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * <mixr-balance data-theme="dark" />
266
+ * ```
267
+ */
268
+ 'mixr-balance': React.DetailedHTMLProps<
269
+ React.HTMLAttributes<HTMLElement> & MixrBalanceAttributes,
270
+ HTMLElement
271
+ >;
272
+
273
+ /**
274
+ * MixrPay wallet widget component
275
+ *
276
+ * @example
277
+ * ```tsx
278
+ * <mixr-wallet data-theme="dark" />
279
+ * ```
280
+ */
281
+ 'mixr-wallet': React.DetailedHTMLProps<
282
+ React.HTMLAttributes<HTMLElement> & MixrWalletAttributes,
283
+ HTMLElement
284
+ >;
285
+ }
286
+ }
287
+ }
288
+
289
+ export { PaymentReceipt, type SessionGrant, verifyPaymentReceipt, verifySessionWebhook };