@wtflabs/x402 0.0.1-beta.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 (96) hide show
  1. package/README.md +60 -0
  2. package/dist/cjs/client/index.d.ts +64 -0
  3. package/dist/cjs/client/index.js +832 -0
  4. package/dist/cjs/client/index.js.map +1 -0
  5. package/dist/cjs/config-CFBSAuxW.d.ts +10 -0
  6. package/dist/cjs/config-Dfuvno71.d.ts +19 -0
  7. package/dist/cjs/facilitator/index.d.ts +42 -0
  8. package/dist/cjs/facilitator/index.js +2574 -0
  9. package/dist/cjs/facilitator/index.js.map +1 -0
  10. package/dist/cjs/index.d.ts +16 -0
  11. package/dist/cjs/index.js +2974 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/middleware-6_1ApcJn.d.ts +93 -0
  14. package/dist/cjs/middleware-B_ewwsQp.d.ts +93 -0
  15. package/dist/cjs/middleware-Brgsx32F.d.ts +93 -0
  16. package/dist/cjs/middleware-BwfW7mAs.d.ts +93 -0
  17. package/dist/cjs/middleware-CQb61c1k.d.ts +93 -0
  18. package/dist/cjs/middleware-DB9lqy9f.d.ts +93 -0
  19. package/dist/cjs/middleware-DcHctwQV.d.ts +93 -0
  20. package/dist/cjs/middleware-De0jD3Bp.d.ts +93 -0
  21. package/dist/cjs/middleware-HoFOmpgv.d.ts +93 -0
  22. package/dist/cjs/middleware-Y8AiAfYw.d.ts +93 -0
  23. package/dist/cjs/middleware-pnres9YM.d.ts +93 -0
  24. package/dist/cjs/network-FrFmmiyj.d.ts +11 -0
  25. package/dist/cjs/network-RtNddYQk.d.ts +11 -0
  26. package/dist/cjs/paywall/index.d.ts +30 -0
  27. package/dist/cjs/paywall/index.js +131 -0
  28. package/dist/cjs/paywall/index.js.map +1 -0
  29. package/dist/cjs/rpc-BMvnNNHd.d.ts +35 -0
  30. package/dist/cjs/rpc-Ca8eHCWz.d.ts +35 -0
  31. package/dist/cjs/schemes/index.d.ts +533 -0
  32. package/dist/cjs/schemes/index.js +3144 -0
  33. package/dist/cjs/schemes/index.js.map +1 -0
  34. package/dist/cjs/shared/evm/index.d.ts +71 -0
  35. package/dist/cjs/shared/evm/index.js +947 -0
  36. package/dist/cjs/shared/evm/index.js.map +1 -0
  37. package/dist/cjs/shared/index.d.ts +182 -0
  38. package/dist/cjs/shared/index.js +674 -0
  39. package/dist/cjs/shared/index.js.map +1 -0
  40. package/dist/cjs/types/index.d.ts +1515 -0
  41. package/dist/cjs/types/index.js +1645 -0
  42. package/dist/cjs/types/index.js.map +1 -0
  43. package/dist/cjs/verify/index.d.ts +7 -0
  44. package/dist/cjs/verify/index.js +438 -0
  45. package/dist/cjs/verify/index.js.map +1 -0
  46. package/dist/cjs/wallet-BRWfOM5D.d.ts +153 -0
  47. package/dist/cjs/wallet-BTqCm9Zp.d.ts +27 -0
  48. package/dist/cjs/wallet-BYRAGtOB.d.ts +153 -0
  49. package/dist/cjs/wallet-BmEtlgEf.d.ts +48 -0
  50. package/dist/cjs/wallet-CNOAmyZ6.d.ts +48 -0
  51. package/dist/cjs/wallet-CQ0Fe_M5.d.ts +88 -0
  52. package/dist/cjs/wallet-D1SoxFTw.d.ts +48 -0
  53. package/dist/cjs/wallet-SJ-hbjm9.d.ts +153 -0
  54. package/dist/cjs/wallet-SJKJpUgQ.d.ts +167 -0
  55. package/dist/cjs/wallet-ecnda4Aj.d.ts +48 -0
  56. package/dist/cjs/wallet-gP8Qoi-c.d.ts +74 -0
  57. package/dist/cjs/x402Specs-B7InXo2L.d.ts +1065 -0
  58. package/dist/cjs/x402Specs-BLH3j34O.d.ts +1696 -0
  59. package/dist/cjs/x402Specs-C7LipAZg.d.ts +1715 -0
  60. package/dist/cjs/x402Specs-CYq5tSY1.d.ts +1745 -0
  61. package/dist/cjs/x402Specs-CeajqonG.d.ts +1696 -0
  62. package/dist/cjs/x402Specs-qMujgEV5.d.ts +1715 -0
  63. package/dist/cjs/x402Specs-qUBCpcuz.d.ts +1715 -0
  64. package/dist/esm/chunk-34YNR4LY.mjs +106 -0
  65. package/dist/esm/chunk-34YNR4LY.mjs.map +1 -0
  66. package/dist/esm/chunk-57UEJN5U.mjs +1416 -0
  67. package/dist/esm/chunk-57UEJN5U.mjs.map +1 -0
  68. package/dist/esm/chunk-5LTKIVOA.mjs +858 -0
  69. package/dist/esm/chunk-5LTKIVOA.mjs.map +1 -0
  70. package/dist/esm/chunk-AQQR4PXH.mjs +80 -0
  71. package/dist/esm/chunk-AQQR4PXH.mjs.map +1 -0
  72. package/dist/esm/chunk-LGXWNXCO.mjs +76 -0
  73. package/dist/esm/chunk-LGXWNXCO.mjs.map +1 -0
  74. package/dist/esm/chunk-RX2JKK4O.mjs +349 -0
  75. package/dist/esm/chunk-RX2JKK4O.mjs.map +1 -0
  76. package/dist/esm/chunk-UCBE7FDY.mjs +1041 -0
  77. package/dist/esm/chunk-UCBE7FDY.mjs.map +1 -0
  78. package/dist/esm/client/index.mjs +17 -0
  79. package/dist/esm/client/index.mjs.map +1 -0
  80. package/dist/esm/facilitator/index.mjs +14 -0
  81. package/dist/esm/facilitator/index.mjs.map +1 -0
  82. package/dist/esm/index.mjs +28 -0
  83. package/dist/esm/index.mjs.map +1 -0
  84. package/dist/esm/paywall/index.mjs +46 -0
  85. package/dist/esm/paywall/index.mjs.map +1 -0
  86. package/dist/esm/schemes/index.mjs +16 -0
  87. package/dist/esm/schemes/index.mjs.map +1 -0
  88. package/dist/esm/shared/evm/index.mjs +20 -0
  89. package/dist/esm/shared/evm/index.mjs.map +1 -0
  90. package/dist/esm/shared/index.mjs +31 -0
  91. package/dist/esm/shared/index.mjs.map +1 -0
  92. package/dist/esm/types/index.mjs +87 -0
  93. package/dist/esm/types/index.mjs.map +1 -0
  94. package/dist/esm/verify/index.mjs +105 -0
  95. package/dist/esm/verify/index.mjs.map +1 -0
  96. package/package.json +148 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # x402
2
+
3
+ Core TypeScript implementation of the x402 Payment Protocol. This package provides the foundational types, schemas, and utilities that power all x402 integrations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install x402
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ The x402 package provides the core building blocks for implementing the x402 Payment Protocol in TypeScript. It's designed to be used by:
14
+
15
+ - Middleware implementations (Express, Hono, Next.js)
16
+ - Client-side payment handlers (fetch wrapper)
17
+ - Facilitator services
18
+ - Custom integrations
19
+
20
+ ## Integration Packages
21
+
22
+ This core package is used by the following integration packages:
23
+
24
+ - `x402-express`: Express.js middleware
25
+ - `x402-hono`: Hono middleware
26
+ - `x402-next`: Next.js middleware
27
+ - `x402-fetch`: Fetch API wrapper
28
+ - `x402-axios`: Axios interceptor
29
+
30
+ ## Manual Server Integration
31
+
32
+ If you're not using one of our server middleware packages, you can implement the x402 protocol manually. Here's what you'll need to handle:
33
+
34
+ 1. Return 402 error responses with the appropriate response body
35
+ 2. Use the facilitator to validate payments
36
+ 3. Use the facilitator to settle payments
37
+ 4. Return the appropriate response header to the caller
38
+
39
+ For a complete example implementation, see our [advanced server example](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/advanced) which demonstrates both synchronous and asynchronous payment processing patterns.
40
+
41
+ ## Manual Client Integration
42
+
43
+ If you're not using our `x402-fetch` or `x402-axios` packages, you can manually integrate the x402 protocol in your client application. Here's how:
44
+
45
+ 1. Make a request to a x402-protected endpoint. The server will respond with a 402 status code and a JSON object containing:
46
+ - `x402Version`: The version of the x402 protocol being used
47
+ - `accepts`: An array of payment requirements you can fulfill
48
+
49
+ 2. Select the payment requirement you wish to fulfill from the `accepts` array
50
+
51
+ 3. Create the payment header using the selected payment requirement
52
+
53
+ 4. Retry your network call with:
54
+ - The payment header assigned to the `X-PAYMENT` field
55
+ - The `Access-Control-Expose-Headers` field set to `"X-PAYMENT-RESPONSE"` to receive the server's transaction response
56
+
57
+ For implementation examples, we recommend reviewing our official client packages:
58
+ - [x402-fetch implementation](https://github.com/coinbase/x402/blob/main/typescript/packages/x402-fetch/src/index.ts)
59
+ - [x402-axios implementation](https://github.com/coinbase/x402/blob/main/typescript/packages/x402-axios/src/index.ts)
60
+
@@ -0,0 +1,64 @@
1
+ import { X as X402Config } from '../config-Dfuvno71.js';
2
+ import { P as PaymentRequirements, p as UnsignedEip3009PaymentPayload } from '../x402Specs-CYq5tSY1.js';
3
+ import { S as Signer, M as MultiNetworkSigner } from '../wallet-CQ0Fe_M5.js';
4
+ import { Address } from 'viem';
5
+ import { N as Network } from '../network-FrFmmiyj.js';
6
+ import 'zod';
7
+ import '../wallet-SJKJpUgQ.js';
8
+ import 'viem/chains';
9
+ import '../wallet-BTqCm9Zp.js';
10
+ import '@solana/kit';
11
+
12
+ /**
13
+ * Creates a payment header based on the provided client and payment requirements.
14
+ *
15
+ * @param client - The signer wallet instance used to create the payment header
16
+ * @param x402Version - The version of the X402 protocol to use
17
+ * @param paymentRequirements - The payment requirements containing scheme and network information
18
+ * @param config - Optional configuration for X402 operations (e.g., custom RPC URLs)
19
+ * @returns A promise that resolves to the created payment header string
20
+ */
21
+ declare function createPaymentHeader(client: Signer | MultiNetworkSigner, x402Version: number, paymentRequirements: PaymentRequirements, config?: X402Config): Promise<string>;
22
+
23
+ /**
24
+ * Prepares a payment header with the given sender address and payment requirements.
25
+ *
26
+ * @param from - The sender's address from which the payment will be made
27
+ * @param x402Version - The version of the X402 protocol to use
28
+ * @param paymentRequirements - The payment requirements containing scheme and network information
29
+ * @returns An unsigned payment payload that can be used to create a payment header
30
+ */
31
+ declare function preparePaymentHeader(from: Address, x402Version: number, paymentRequirements: PaymentRequirements): UnsignedEip3009PaymentPayload;
32
+
33
+ /**
34
+ * Default selector for payment requirements.
35
+ * Default behavior is to select the first payment requirement that has a USDC asset.
36
+ * If no USDC payment requirement is found, the first payment requirement is selected.
37
+ *
38
+ * @param paymentRequirements - The payment requirements to select from.
39
+ * @param network - The network to check against. If not provided, the network will not be checked.
40
+ * @param scheme - The scheme to check against. If not provided, the scheme will not be checked.
41
+ * @returns The payment requirement that is the most appropriate for the user.
42
+ */
43
+ declare function selectPaymentRequirements(paymentRequirements: PaymentRequirements[], network?: Network | Network[], scheme?: "exact"): PaymentRequirements;
44
+ /**
45
+ * Selector for payment requirements.
46
+ *
47
+ * @param paymentRequirements - The payment requirements to select from.
48
+ * @param network - The network to check against. If not provided, the network will not be checked.
49
+ * @param scheme - The scheme to check against. If not provided, the scheme will not be checked.
50
+ * @returns The payment requirement that is the most appropriate for the user.
51
+ */
52
+ type PaymentRequirementsSelector = (paymentRequirements: PaymentRequirements[], network?: Network | Network[], scheme?: "exact") => PaymentRequirements;
53
+
54
+ /**
55
+ * Signs a payment header using the provided client and payment requirements.
56
+ *
57
+ * @param client - The signer wallet instance used to sign the payment header
58
+ * @param paymentRequirements - The payment requirements containing scheme and network information
59
+ * @param unsignedPaymentHeader - The unsigned payment payload to be signed
60
+ * @returns A promise that resolves to the encoded signed payment header string
61
+ */
62
+ declare function signPaymentHeader(client: Signer | MultiNetworkSigner, paymentRequirements: PaymentRequirements, unsignedPaymentHeader: UnsignedEip3009PaymentPayload): Promise<string>;
63
+
64
+ export { type PaymentRequirementsSelector, createPaymentHeader, preparePaymentHeader, selectPaymentRequirements, signPaymentHeader };