@xpaysh/x402 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present XPay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @xpaysh/x402
2
+
3
+ XPay facilitator for the [x402 payment protocol](https://www.x402.org/) — **open, no API keys required**.
4
+
5
+ Drop-in replacement for [`@coinbase/x402`](https://www.npmjs.com/package/@coinbase/x402). Works with [`@x402/express`](https://www.npmjs.com/package/@x402/express) and [`@x402/next`](https://www.npmjs.com/package/@x402/next) middleware.
6
+
7
+ ## Why XPay?
8
+
9
+ | | XPay | Coinbase | PayAI |
10
+ |---|---|---|---|
11
+ | **Auth required** | None | CDP API keys | JWT token |
12
+ | **Setup time** | 0 min | ~5 min | ~5 min |
13
+ | **Networks** | Base, Base Sepolia | Base, Base Sepolia | Base, Base Sepolia |
14
+ | **Asset** | USDC | USDC | USDC |
15
+ | **Custodial** | No | No | No |
16
+ | **Open source** | Yes | Yes | No |
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @xpaysh/x402
22
+ # or
23
+ bun add @xpaysh/x402
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Express
29
+
30
+ ```ts
31
+ import express from "express";
32
+ import { paymentMiddleware } from "@x402/express";
33
+ import { facilitator } from "@xpaysh/x402";
34
+
35
+ const app = express();
36
+
37
+ app.use(
38
+ paymentMiddleware(facilitator, "0xYourWalletAddress", {
39
+ "/api/premium": {
40
+ price: "$0.01",
41
+ network: "base-sepolia",
42
+ description: "Access premium endpoint",
43
+ },
44
+ }),
45
+ );
46
+
47
+ app.get("/api/premium", (req, res) => {
48
+ res.json({ data: "premium content" });
49
+ });
50
+
51
+ app.listen(3000);
52
+ ```
53
+
54
+ ### Next.js
55
+
56
+ ```ts
57
+ // middleware.ts
58
+ import { paymentMiddleware } from "@x402/next";
59
+ import { facilitator } from "@xpaysh/x402";
60
+
61
+ export const middleware = paymentMiddleware(facilitator, "0xYourWalletAddress", {
62
+ "/api/premium": {
63
+ price: "$0.01",
64
+ network: "base-sepolia",
65
+ description: "Access premium endpoint",
66
+ },
67
+ });
68
+
69
+ export const config = {
70
+ matcher: ["/api/premium"],
71
+ };
72
+ ```
73
+
74
+ ### Custom facilitator URL
75
+
76
+ ```ts
77
+ import { createFacilitatorConfig } from "@xpaysh/x402";
78
+
79
+ const facilitator = createFacilitatorConfig({
80
+ url: "https://my-facilitator.example.com",
81
+ });
82
+ ```
83
+
84
+ ## API
85
+
86
+ ### `facilitator`
87
+
88
+ Pre-configured `FacilitatorConfig` pointing to `https://facilitator.xpay.sh`. No authentication needed.
89
+
90
+ ### `createFacilitatorConfig(options?)`
91
+
92
+ Factory function to create a facilitator config with optional overrides.
93
+
94
+ | Option | Type | Default | Description |
95
+ |--------|------|---------|-------------|
96
+ | `url` | `string` | `https://facilitator.xpay.sh` | Facilitator service URL |
97
+
98
+ ### `FacilitatorConfig`
99
+
100
+ ```ts
101
+ interface FacilitatorConfig {
102
+ url: string;
103
+ createAuthHeaders?: () => Promise<{
104
+ verify: Record<string, string>;
105
+ settle: Record<string, string>;
106
+ supported: Record<string, string>;
107
+ }>;
108
+ }
109
+ ```
110
+
111
+ ## Supported networks
112
+
113
+ - **Base Mainnet** (`eip155:8453` / `base`)
114
+ - **Base Sepolia** (`eip155:84532` / `base-sepolia`)
115
+
116
+ Both x402 v1 and v2 are supported.
117
+
118
+ ## Links
119
+
120
+ - [x402 Protocol](https://www.x402.org/)
121
+ - [XPay](https://xpay.sh)
122
+ - [Facilitator health check](https://facilitator.xpay.sh/health)
123
+ - [GitHub](https://github.com/xpaysh/x402)
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @xpaysh/x402 — XPay facilitator config for the x402 payment protocol.
3
+ *
4
+ * Drop-in replacement for @coinbase/x402.
5
+ * No API keys required — facilitator.xpay.sh is open and free to use.
6
+ */
7
+ /**
8
+ * Configuration for the XPay x402 facilitator service.
9
+ * Compatible with `FacilitatorConfig` from `@x402/core/http`.
10
+ */
11
+ interface FacilitatorConfig {
12
+ url: string;
13
+ createAuthHeaders?: () => Promise<{
14
+ verify: Record<string, string>;
15
+ settle: Record<string, string>;
16
+ supported: Record<string, string>;
17
+ }>;
18
+ }
19
+ interface CreateFacilitatorOptions {
20
+ /** Override the facilitator URL. Defaults to https://facilitator.xpay.sh */
21
+ url?: string;
22
+ }
23
+ /**
24
+ * Create a facilitator config with optional overrides.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { createFacilitatorConfig } from "@xpaysh/x402";
29
+ *
30
+ * const facilitator = createFacilitatorConfig();
31
+ * // or with a custom URL:
32
+ * const facilitator = createFacilitatorConfig({ url: "https://my-facilitator.example.com" });
33
+ * ```
34
+ */
35
+ declare function createFacilitatorConfig(options?: CreateFacilitatorOptions): FacilitatorConfig;
36
+ /**
37
+ * Pre-configured facilitator pointing to https://facilitator.xpay.sh
38
+ *
39
+ * Works as a drop-in replacement for the `facilitator` export from `@coinbase/x402`.
40
+ * No API keys or authentication required.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { facilitator } from "@xpaysh/x402";
45
+ * import { paymentMiddleware } from "@x402/express";
46
+ *
47
+ * app.use(paymentMiddleware(facilitator, payTo, routes));
48
+ * ```
49
+ */
50
+ declare const facilitator: FacilitatorConfig;
51
+
52
+ export { type CreateFacilitatorOptions, type FacilitatorConfig, createFacilitatorConfig, facilitator };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @xpaysh/x402 — XPay facilitator config for the x402 payment protocol.
3
+ *
4
+ * Drop-in replacement for @coinbase/x402.
5
+ * No API keys required — facilitator.xpay.sh is open and free to use.
6
+ */
7
+ /**
8
+ * Configuration for the XPay x402 facilitator service.
9
+ * Compatible with `FacilitatorConfig` from `@x402/core/http`.
10
+ */
11
+ interface FacilitatorConfig {
12
+ url: string;
13
+ createAuthHeaders?: () => Promise<{
14
+ verify: Record<string, string>;
15
+ settle: Record<string, string>;
16
+ supported: Record<string, string>;
17
+ }>;
18
+ }
19
+ interface CreateFacilitatorOptions {
20
+ /** Override the facilitator URL. Defaults to https://facilitator.xpay.sh */
21
+ url?: string;
22
+ }
23
+ /**
24
+ * Create a facilitator config with optional overrides.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { createFacilitatorConfig } from "@xpaysh/x402";
29
+ *
30
+ * const facilitator = createFacilitatorConfig();
31
+ * // or with a custom URL:
32
+ * const facilitator = createFacilitatorConfig({ url: "https://my-facilitator.example.com" });
33
+ * ```
34
+ */
35
+ declare function createFacilitatorConfig(options?: CreateFacilitatorOptions): FacilitatorConfig;
36
+ /**
37
+ * Pre-configured facilitator pointing to https://facilitator.xpay.sh
38
+ *
39
+ * Works as a drop-in replacement for the `facilitator` export from `@coinbase/x402`.
40
+ * No API keys or authentication required.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { facilitator } from "@xpaysh/x402";
45
+ * import { paymentMiddleware } from "@x402/express";
46
+ *
47
+ * app.use(paymentMiddleware(facilitator, payTo, routes));
48
+ * ```
49
+ */
50
+ declare const facilitator: FacilitatorConfig;
51
+
52
+ export { type CreateFacilitatorOptions, type FacilitatorConfig, createFacilitatorConfig, facilitator };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createFacilitatorConfig: () => createFacilitatorConfig,
24
+ facilitator: () => facilitator
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var DEFAULT_URL = "https://facilitator.xpay.sh";
28
+ function createFacilitatorConfig(options) {
29
+ return {
30
+ url: options?.url ?? DEFAULT_URL
31
+ };
32
+ }
33
+ var facilitator = createFacilitatorConfig();
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ createFacilitatorConfig,
37
+ facilitator
38
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,12 @@
1
+ // src/index.ts
2
+ var DEFAULT_URL = "https://facilitator.xpay.sh";
3
+ function createFacilitatorConfig(options) {
4
+ return {
5
+ url: options?.url ?? DEFAULT_URL
6
+ };
7
+ }
8
+ var facilitator = createFacilitatorConfig();
9
+ export {
10
+ createFacilitatorConfig,
11
+ facilitator
12
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@xpaysh/x402",
3
+ "version": "0.1.0",
4
+ "description": "XPay facilitator for the x402 payment protocol — open, no auth required",
5
+ "author": "XPay <hello@xpay.sh> (https://xpay.sh)",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/xpaysh/x402"
10
+ },
11
+ "homepage": "https://xpay.sh",
12
+ "keywords": [
13
+ "x402",
14
+ "payments",
15
+ "web3",
16
+ "USDC",
17
+ "facilitator",
18
+ "base",
19
+ "coinbase",
20
+ "ai-agents",
21
+ "http-402",
22
+ "payment-protocol"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "import": {
27
+ "types": "./dist/index.d.mts",
28
+ "default": "./dist/index.mjs"
29
+ },
30
+ "require": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
34
+ }
35
+ },
36
+ "main": "./dist/index.js",
37
+ "module": "./dist/index.mjs",
38
+ "types": "./dist/index.d.ts",
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "prepublishOnly": "tsup"
46
+ },
47
+ "devDependencies": {
48
+ "tsup": "^8.4.0",
49
+ "typescript": "^5.7.3"
50
+ }
51
+ }