uvd-x402-sdk 2.5.0 → 2.10.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.
Files changed (75) hide show
  1. package/README.md +380 -3
  2. package/dist/adapters/index.d.mts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/adapters/index.js +82 -1
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +82 -1
  7. package/dist/adapters/index.mjs.map +1 -1
  8. package/dist/backend/index.d.mts +1036 -0
  9. package/dist/backend/index.d.ts +1036 -0
  10. package/dist/backend/index.js +1722 -0
  11. package/dist/backend/index.js.map +1 -0
  12. package/dist/backend/index.mjs +1704 -0
  13. package/dist/backend/index.mjs.map +1 -0
  14. package/dist/{index-BrFeSWKm.d.mts → index-C60c_e5z.d.mts} +13 -4
  15. package/dist/{index-DR2vXt-c.d.mts → index-D-dO_FoP.d.mts} +70 -4
  16. package/dist/{index-DR2vXt-c.d.ts → index-D-dO_FoP.d.ts} +70 -4
  17. package/dist/{index-BYX9BU79.d.ts → index-VIOUicmO.d.ts} +13 -4
  18. package/dist/index.d.mts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +115 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +110 -2
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/providers/algorand/index.d.mts +86 -0
  25. package/dist/providers/algorand/index.d.ts +86 -0
  26. package/dist/providers/algorand/index.js +903 -0
  27. package/dist/providers/algorand/index.js.map +1 -0
  28. package/dist/providers/algorand/index.mjs +898 -0
  29. package/dist/providers/algorand/index.mjs.map +1 -0
  30. package/dist/providers/evm/index.d.mts +1 -1
  31. package/dist/providers/evm/index.d.ts +1 -1
  32. package/dist/providers/evm/index.js +78 -1
  33. package/dist/providers/evm/index.js.map +1 -1
  34. package/dist/providers/evm/index.mjs +78 -1
  35. package/dist/providers/evm/index.mjs.map +1 -1
  36. package/dist/providers/near/index.d.mts +1 -1
  37. package/dist/providers/near/index.d.ts +1 -1
  38. package/dist/providers/near/index.js +78 -1
  39. package/dist/providers/near/index.js.map +1 -1
  40. package/dist/providers/near/index.mjs +78 -1
  41. package/dist/providers/near/index.mjs.map +1 -1
  42. package/dist/providers/solana/index.d.mts +1 -1
  43. package/dist/providers/solana/index.d.ts +1 -1
  44. package/dist/providers/solana/index.js +78 -1
  45. package/dist/providers/solana/index.js.map +1 -1
  46. package/dist/providers/solana/index.mjs +78 -1
  47. package/dist/providers/solana/index.mjs.map +1 -1
  48. package/dist/providers/stellar/index.d.mts +1 -1
  49. package/dist/providers/stellar/index.d.ts +1 -1
  50. package/dist/providers/stellar/index.js +78 -1
  51. package/dist/providers/stellar/index.js.map +1 -1
  52. package/dist/providers/stellar/index.mjs +78 -1
  53. package/dist/providers/stellar/index.mjs.map +1 -1
  54. package/dist/react/index.d.mts +3 -3
  55. package/dist/react/index.d.ts +3 -3
  56. package/dist/react/index.js +82 -1
  57. package/dist/react/index.js.map +1 -1
  58. package/dist/react/index.mjs +82 -1
  59. package/dist/react/index.mjs.map +1 -1
  60. package/dist/utils/index.d.mts +57 -5
  61. package/dist/utils/index.d.ts +57 -5
  62. package/dist/utils/index.js +96 -1
  63. package/dist/utils/index.js.map +1 -1
  64. package/dist/utils/index.mjs +93 -2
  65. package/dist/utils/index.mjs.map +1 -1
  66. package/package.json +24 -3
  67. package/src/adapters/wagmi.ts +4 -0
  68. package/src/backend/index.ts +2131 -0
  69. package/src/chains/index.ts +94 -2
  70. package/src/client/X402Client.ts +4 -0
  71. package/src/index.ts +26 -1
  72. package/src/providers/algorand/index.ts +356 -0
  73. package/src/types/index.ts +78 -3
  74. package/src/utils/index.ts +4 -0
  75. package/src/utils/validation.ts +76 -3
@@ -15,10 +15,11 @@
15
15
  * - 'svm': Solana Virtual Machine chains (Solana, Fogo) (use SPL tokens)
16
16
  * - 'stellar': Stellar network (use Soroban)
17
17
  * - 'near': NEAR Protocol (use NEP-366)
18
+ * - 'algorand': Algorand network (use ASA transfers with atomic transactions)
18
19
  *
19
20
  * @deprecated 'solana' type is deprecated, use 'svm' instead
20
21
  */
21
- export type NetworkType = 'evm' | 'svm' | 'solana' | 'stellar' | 'near';
22
+ export type NetworkType = 'evm' | 'svm' | 'solana' | 'stellar' | 'near' | 'algorand';
22
23
 
23
24
  /**
24
25
  * Supported stablecoin token types
@@ -200,6 +201,7 @@ export interface PaymentInfo {
200
201
  solana?: string;
201
202
  near?: string;
202
203
  stellar?: string;
204
+ algorand?: string;
203
205
  };
204
206
  /** Facilitator address (for Solana fee payer) */
205
207
  facilitator?: string;
@@ -230,6 +232,27 @@ export interface PaymentRequest {
230
232
  metadata?: Record<string, unknown>;
231
233
  }
232
234
 
235
+ /**
236
+ * x402 payment header names
237
+ *
238
+ * - 'X-PAYMENT': v1 header name (default, most compatible)
239
+ * - 'PAYMENT-SIGNATURE': v2 header name (newer standard)
240
+ *
241
+ * Both headers use the same base64-encoded JSON payload format.
242
+ * The facilitator accepts both headers.
243
+ */
244
+ export type X402HeaderName = 'X-PAYMENT' | 'PAYMENT-SIGNATURE';
245
+
246
+ /**
247
+ * Payment headers object containing both v1 and v2 header formats
248
+ */
249
+ export interface PaymentHeaders {
250
+ /** v1 header: X-PAYMENT */
251
+ 'X-PAYMENT': string;
252
+ /** v2 header: PAYMENT-SIGNATURE (same value, different header name) */
253
+ 'PAYMENT-SIGNATURE': string;
254
+ }
255
+
233
256
  /**
234
257
  * Result of a payment operation
235
258
  */
@@ -238,6 +261,19 @@ export interface PaymentResult {
238
261
  success: boolean;
239
262
  /** Base64-encoded X-PAYMENT header value */
240
263
  paymentHeader: string;
264
+ /**
265
+ * Payment headers object for easy use with fetch/axios
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * // Use v1 header
270
+ * fetch(url, { headers: { 'X-PAYMENT': result.headers['X-PAYMENT'] } });
271
+ *
272
+ * // Use v2 header
273
+ * fetch(url, { headers: { 'PAYMENT-SIGNATURE': result.headers['PAYMENT-SIGNATURE'] } });
274
+ * ```
275
+ */
276
+ headers: PaymentHeaders;
241
277
  /** Transaction hash (if available) */
242
278
  transactionHash?: string;
243
279
  /** Network where payment was made */
@@ -306,6 +342,28 @@ export interface NEARPaymentPayload {
306
342
  network: 'near';
307
343
  }
308
344
 
345
+ /**
346
+ * Algorand payment payload (atomic transaction group)
347
+ *
348
+ * Algorand uses a unique payment model where the facilitator creates and signs
349
+ * an atomic transaction group. The user signs their portion (the ASA transfer)
350
+ * and the facilitator submits the complete group.
351
+ */
352
+ export interface AlgorandPaymentPayload {
353
+ /** Sender's Algorand address (58-character base32) */
354
+ from: string;
355
+ /** Recipient's Algorand address */
356
+ to: string;
357
+ /** Amount in base units (microAlgos for ALGO, or base units for ASA) */
358
+ amount: string;
359
+ /** USDC ASA ID (31566704 for mainnet, 10458941 for testnet) */
360
+ assetId: number;
361
+ /** Base64-encoded signed transaction bytes */
362
+ signedTxn: string;
363
+ /** Optional note field */
364
+ note?: string;
365
+ }
366
+
309
367
  /**
310
368
  * Union type for all payment payloads
311
369
  */
@@ -313,7 +371,8 @@ export type PaymentPayload =
313
371
  | EVMPaymentPayload
314
372
  | SolanaPaymentPayload
315
373
  | StellarPaymentPayload
316
- | NEARPaymentPayload;
374
+ | NEARPaymentPayload
375
+ | AlgorandPaymentPayload;
317
376
 
318
377
  // ============================================================================
319
378
  // X402 HEADER TYPES (v1 and v2)
@@ -347,6 +406,9 @@ export const CAIP2_IDENTIFIERS: Record<string, string> = {
347
406
  stellar: 'stellar:pubnet',
348
407
  // NEAR
349
408
  near: 'near:mainnet',
409
+ // Algorand
410
+ algorand: 'algorand:mainnet',
411
+ 'algorand-testnet': 'algorand:testnet',
350
412
  };
351
413
 
352
414
  /**
@@ -434,6 +496,18 @@ export interface X402NEARPayload {
434
496
  signedDelegateAction: string;
435
497
  }
436
498
 
499
+ /**
500
+ * Algorand-specific payload in x402 header
501
+ */
502
+ export interface X402AlgorandPayload {
503
+ from: string;
504
+ to: string;
505
+ amount: string;
506
+ assetId: number;
507
+ signedTxn: string;
508
+ note?: string;
509
+ }
510
+
437
511
  /**
438
512
  * Union of all x402 payload types
439
513
  */
@@ -441,7 +515,8 @@ export type X402PayloadData =
441
515
  | X402EVMPayload
442
516
  | X402SolanaPayload
443
517
  | X402StellarPayload
444
- | X402NEARPayload;
518
+ | X402NEARPayload
519
+ | X402AlgorandPayload;
445
520
 
446
521
  // ============================================================================
447
522
  // CLIENT CONFIGURATION
@@ -22,4 +22,8 @@ export {
22
22
  export {
23
23
  validateRecipient,
24
24
  validateAmount,
25
+ createPaymentHeaders,
26
+ getPaymentHeader,
27
+ DEFAULT_PAYMENT_HEADER,
28
+ PAYMENT_HEADER_NAMES,
25
29
  } from './validation';
@@ -1,10 +1,11 @@
1
1
  /**
2
- * uvd-x402-sdk - Validation Utilities
2
+ * uvd-x402-sdk - Validation and Payment Header Utilities
3
3
  *
4
- * Functions for validating payment parameters to prevent
5
- * invalid or empty values from being processed.
4
+ * Functions for validating payment parameters and creating
5
+ * payment headers for HTTP requests.
6
6
  */
7
7
 
8
+ import type { X402HeaderName, PaymentHeaders } from '../types';
8
9
  import { X402Error } from '../types';
9
10
 
10
11
  /**
@@ -149,3 +150,75 @@ export function validateAmount(amount: string | undefined | null): asserts amoun
149
150
  );
150
151
  }
151
152
  }
153
+
154
+ // ============================================================================
155
+ // PAYMENT HEADER UTILITIES
156
+ // ============================================================================
157
+
158
+ /**
159
+ * Create payment headers object from a base64-encoded payload
160
+ *
161
+ * Returns an object with both X-PAYMENT and PAYMENT-SIGNATURE headers,
162
+ * making it easy to use either header format.
163
+ *
164
+ * @param paymentHeader - Base64-encoded payment payload
165
+ * @returns PaymentHeaders object with both header formats
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const headers = createPaymentHeaders(paymentHeader);
170
+ *
171
+ * // Use v1 header (most compatible)
172
+ * fetch(url, { headers: { 'X-PAYMENT': headers['X-PAYMENT'] } });
173
+ *
174
+ * // Use v2 header
175
+ * fetch(url, { headers: { 'PAYMENT-SIGNATURE': headers['PAYMENT-SIGNATURE'] } });
176
+ * ```
177
+ */
178
+ export function createPaymentHeaders(paymentHeader: string): PaymentHeaders {
179
+ return {
180
+ 'X-PAYMENT': paymentHeader,
181
+ 'PAYMENT-SIGNATURE': paymentHeader,
182
+ };
183
+ }
184
+
185
+ /**
186
+ * Get a single payment header by name
187
+ *
188
+ * @param paymentHeader - Base64-encoded payment payload
189
+ * @param headerName - Header name to use ('X-PAYMENT' or 'PAYMENT-SIGNATURE')
190
+ * @returns Object with a single header entry
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * // Use with fetch spread operator
195
+ * fetch(url, {
196
+ * headers: {
197
+ * 'Content-Type': 'application/json',
198
+ * ...getPaymentHeader(result.paymentHeader, 'X-PAYMENT'),
199
+ * },
200
+ * });
201
+ * ```
202
+ */
203
+ export function getPaymentHeader(
204
+ paymentHeader: string,
205
+ headerName: X402HeaderName = 'X-PAYMENT'
206
+ ): Record<X402HeaderName, string> {
207
+ return { [headerName]: paymentHeader } as Record<X402HeaderName, string>;
208
+ }
209
+
210
+ /**
211
+ * Default x402 payment header name
212
+ *
213
+ * Use 'X-PAYMENT' for maximum compatibility with all facilitators.
214
+ * Use 'PAYMENT-SIGNATURE' for x402 v2 compliance.
215
+ */
216
+ export const DEFAULT_PAYMENT_HEADER: X402HeaderName = 'X-PAYMENT';
217
+
218
+ /**
219
+ * All supported x402 payment header names
220
+ */
221
+ export const PAYMENT_HEADER_NAMES: readonly X402HeaderName[] = [
222
+ 'X-PAYMENT',
223
+ 'PAYMENT-SIGNATURE',
224
+ ] as const;