@parallel-protocol/x402 0.5.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,128 @@
1
+ import { raceTimeout, HANDLER_TIMEOUT } from './chunk-2UEAVMCH.js';
2
+ import { createPaymentMiddleware } from './chunk-FDQULXKG.js';
3
+
4
+ // src/express/adapter.ts
5
+ var TIMEOUT_BODY = JSON.stringify({
6
+ error: "HANDLER_TIMEOUT",
7
+ message: "The resource handler did not respond in time."
8
+ });
9
+ var ExpressAdapter = class {
10
+ constructor(req, res, next) {
11
+ this.req = req;
12
+ this.res = res;
13
+ this.next = next;
14
+ }
15
+ req;
16
+ res;
17
+ next;
18
+ getHeader(name) {
19
+ const value = this.req.header(name);
20
+ return Array.isArray(value) ? value[0] : value;
21
+ }
22
+ getMethod() {
23
+ return this.req.method;
24
+ }
25
+ getPath() {
26
+ return this.req.path;
27
+ }
28
+ getUrl() {
29
+ return `${this.req.protocol}://${this.req.headers.host}${this.req.originalUrl}`;
30
+ }
31
+ async runHandler() {
32
+ const res = this.res;
33
+ const next = this.next;
34
+ const originalWriteHead = res.writeHead.bind(res);
35
+ const originalWrite = res.write.bind(res);
36
+ const originalEnd = res.end.bind(res);
37
+ const buffered = [];
38
+ let settled = false;
39
+ let discarded = false;
40
+ let endCalled;
41
+ const endPromise = new Promise((resolve) => {
42
+ endCalled = resolve;
43
+ });
44
+ const restore = () => {
45
+ res.writeHead = originalWriteHead;
46
+ res.write = originalWrite;
47
+ res.end = originalEnd;
48
+ };
49
+ res.writeHead = ((...args) => {
50
+ if (discarded) return res;
51
+ if (!settled) {
52
+ buffered.push(["writeHead", args]);
53
+ return res;
54
+ }
55
+ return originalWriteHead(...args);
56
+ });
57
+ res.write = ((...args) => {
58
+ if (discarded) return true;
59
+ if (!settled) {
60
+ buffered.push(["write", args]);
61
+ return true;
62
+ }
63
+ return originalWrite(...args);
64
+ });
65
+ res.end = ((...args) => {
66
+ if (discarded) return res;
67
+ if (!settled) {
68
+ buffered.push(["end", args]);
69
+ endCalled();
70
+ return res;
71
+ }
72
+ return originalEnd(...args);
73
+ });
74
+ next();
75
+ const outcome = await raceTimeout(endPromise);
76
+ if (outcome === HANDLER_TIMEOUT) {
77
+ discarded = true;
78
+ return {
79
+ status: 504,
80
+ setResponseHeader: (name, value) => {
81
+ if (!res.headersSent) res.setHeader(name, value);
82
+ },
83
+ sendResponse: () => {
84
+ if (res.headersSent) return;
85
+ originalWriteHead(504, { "Content-Type": "application/json" });
86
+ originalEnd(TIMEOUT_BODY);
87
+ },
88
+ discardResponse: () => {
89
+ }
90
+ };
91
+ }
92
+ return {
93
+ status: res.statusCode,
94
+ setResponseHeader: (name, value) => res.setHeader(name, value),
95
+ sendResponse: () => {
96
+ settled = true;
97
+ restore();
98
+ for (const [method, args] of buffered) {
99
+ if (method === "writeHead") originalWriteHead(...args);
100
+ else if (method === "write") originalWrite(...args);
101
+ else if (method === "end") originalEnd(...args);
102
+ }
103
+ },
104
+ discardResponse: () => {
105
+ settled = true;
106
+ restore();
107
+ }
108
+ };
109
+ }
110
+ };
111
+
112
+ // src/express/index.ts
113
+ function paymentMiddleware(config) {
114
+ const middleware = createPaymentMiddleware(config);
115
+ return async (req, res, next) => {
116
+ const result = await middleware(new ExpressAdapter(req, res, next));
117
+ if ("pass" in result) {
118
+ if (result.handlerRan) return;
119
+ return next();
120
+ }
121
+ for (const [key, value] of Object.entries(result.headers)) {
122
+ res.setHeader(key, value);
123
+ }
124
+ res.status(result.status).json(result.body);
125
+ };
126
+ }
127
+
128
+ export { ExpressAdapter, paymentMiddleware };
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
4
+ var fp = require('fastify-plugin');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var fp__default = /*#__PURE__*/_interopDefault(fp);
9
+
10
+ // src/fastify/adapter.ts
11
+ var FastifyAdapter = class {
12
+ constructor(req) {
13
+ this.req = req;
14
+ }
15
+ req;
16
+ getHeader(name) {
17
+ const value = this.req.headers[name.toLowerCase()];
18
+ return Array.isArray(value) ? value[0] : value;
19
+ }
20
+ getMethod() {
21
+ return this.req.method;
22
+ }
23
+ getPath() {
24
+ return this.req.url.split("?")[0] ?? "/";
25
+ }
26
+ getUrl() {
27
+ return `${this.req.protocol}://${this.req.host || this.req.hostname}${this.req.url}`;
28
+ }
29
+ };
30
+
31
+ // src/fastify/index.ts
32
+ function paymentMiddleware(config) {
33
+ return fp__default.default(async (fastify) => {
34
+ const gate = chunkW3SMR5LQ_cjs.createPaymentGate(config);
35
+ const settleMap = /* @__PURE__ */ new WeakMap();
36
+ fastify.addHook("onRequest", async (req, reply) => {
37
+ const gateResult = await gate(new FastifyAdapter(req));
38
+ if (gateResult.type === "pass") return;
39
+ if (gateResult.type === "error") {
40
+ for (const [key, value] of Object.entries(gateResult.result.headers)) {
41
+ reply.header(key, value);
42
+ }
43
+ reply.status(gateResult.result.status).send(gateResult.result.body);
44
+ return;
45
+ }
46
+ settleMap.set(req, gateResult.settle);
47
+ });
48
+ fastify.addHook("onSend", async (req, reply, payload) => {
49
+ const settle = settleMap.get(req);
50
+ if (!settle || reply.statusCode < 200 || reply.statusCode >= 300) {
51
+ return payload;
52
+ }
53
+ let settled = false;
54
+ try {
55
+ const settleResponse = await settle();
56
+ if (settleResponse.success) {
57
+ reply.header("payment-response", chunkW3SMR5LQ_cjs.encodeBase64(settleResponse));
58
+ reply.header("access-control-expose-headers", "payment-response");
59
+ settled = true;
60
+ }
61
+ } catch {
62
+ }
63
+ if (!settled) {
64
+ const body = JSON.stringify({
65
+ error: "PAYMENT_SETTLEMENT_FAILED",
66
+ message: "Payment could not be confirmed after multiple attempts. Please retry."
67
+ });
68
+ reply.status(402);
69
+ reply.header("Content-Type", "application/json");
70
+ reply.header("Content-Length", Buffer.byteLength(body));
71
+ return body;
72
+ }
73
+ return payload;
74
+ });
75
+ });
76
+ }
77
+
78
+ exports.FastifyAdapter = FastifyAdapter;
79
+ exports.paymentMiddleware = paymentMiddleware;
@@ -0,0 +1,16 @@
1
+ import { FastifyRequest, FastifyPluginAsync } from 'fastify';
2
+ import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CUi55YSx.cjs';
3
+ import 'viem';
4
+
5
+ declare class FastifyAdapter implements HTTPAdapter {
6
+ private readonly req;
7
+ constructor(req: FastifyRequest);
8
+ getHeader(name: string): string | undefined;
9
+ getMethod(): string;
10
+ getPath(): string;
11
+ getUrl(): string;
12
+ }
13
+
14
+ declare function paymentMiddleware(config: PaymentMiddlewareConfig): FastifyPluginAsync;
15
+
16
+ export { FastifyAdapter, paymentMiddleware };
@@ -0,0 +1,16 @@
1
+ import { FastifyRequest, FastifyPluginAsync } from 'fastify';
2
+ import { H as HTTPAdapter, P as PaymentMiddlewareConfig } from './types-CUi55YSx.js';
3
+ import 'viem';
4
+
5
+ declare class FastifyAdapter implements HTTPAdapter {
6
+ private readonly req;
7
+ constructor(req: FastifyRequest);
8
+ getHeader(name: string): string | undefined;
9
+ getMethod(): string;
10
+ getPath(): string;
11
+ getUrl(): string;
12
+ }
13
+
14
+ declare function paymentMiddleware(config: PaymentMiddlewareConfig): FastifyPluginAsync;
15
+
16
+ export { FastifyAdapter, paymentMiddleware };
@@ -0,0 +1,72 @@
1
+ import { createPaymentGate, encodeBase64 } from './chunk-FDQULXKG.js';
2
+ import fp from 'fastify-plugin';
3
+
4
+ // src/fastify/adapter.ts
5
+ var FastifyAdapter = class {
6
+ constructor(req) {
7
+ this.req = req;
8
+ }
9
+ req;
10
+ getHeader(name) {
11
+ const value = this.req.headers[name.toLowerCase()];
12
+ return Array.isArray(value) ? value[0] : value;
13
+ }
14
+ getMethod() {
15
+ return this.req.method;
16
+ }
17
+ getPath() {
18
+ return this.req.url.split("?")[0] ?? "/";
19
+ }
20
+ getUrl() {
21
+ return `${this.req.protocol}://${this.req.host || this.req.hostname}${this.req.url}`;
22
+ }
23
+ };
24
+
25
+ // src/fastify/index.ts
26
+ function paymentMiddleware(config) {
27
+ return fp(async (fastify) => {
28
+ const gate = createPaymentGate(config);
29
+ const settleMap = /* @__PURE__ */ new WeakMap();
30
+ fastify.addHook("onRequest", async (req, reply) => {
31
+ const gateResult = await gate(new FastifyAdapter(req));
32
+ if (gateResult.type === "pass") return;
33
+ if (gateResult.type === "error") {
34
+ for (const [key, value] of Object.entries(gateResult.result.headers)) {
35
+ reply.header(key, value);
36
+ }
37
+ reply.status(gateResult.result.status).send(gateResult.result.body);
38
+ return;
39
+ }
40
+ settleMap.set(req, gateResult.settle);
41
+ });
42
+ fastify.addHook("onSend", async (req, reply, payload) => {
43
+ const settle = settleMap.get(req);
44
+ if (!settle || reply.statusCode < 200 || reply.statusCode >= 300) {
45
+ return payload;
46
+ }
47
+ let settled = false;
48
+ try {
49
+ const settleResponse = await settle();
50
+ if (settleResponse.success) {
51
+ reply.header("payment-response", encodeBase64(settleResponse));
52
+ reply.header("access-control-expose-headers", "payment-response");
53
+ settled = true;
54
+ }
55
+ } catch {
56
+ }
57
+ if (!settled) {
58
+ const body = JSON.stringify({
59
+ error: "PAYMENT_SETTLEMENT_FAILED",
60
+ message: "Payment could not be confirmed after multiple attempts. Please retry."
61
+ });
62
+ reply.status(402);
63
+ reply.header("Content-Type", "application/json");
64
+ reply.header("Content-Length", Buffer.byteLength(body));
65
+ return body;
66
+ }
67
+ return payload;
68
+ });
69
+ });
70
+ }
71
+
72
+ export { FastifyAdapter, paymentMiddleware };
package/dist/hono.cjs ADDED
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var chunkXUNNMCO5_cjs = require('./chunk-XUNNMCO5.cjs');
4
+ var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
5
+
6
+ // src/hono/adapter.ts
7
+ var TIMEOUT_BODY = JSON.stringify({
8
+ error: "HANDLER_TIMEOUT",
9
+ message: "The resource handler did not respond in time."
10
+ });
11
+ var HonoAdapter = class {
12
+ constructor(c, next) {
13
+ this.c = c;
14
+ this.next = next;
15
+ }
16
+ c;
17
+ next;
18
+ getHeader(name) {
19
+ return this.c.req.header(name);
20
+ }
21
+ getMethod() {
22
+ return this.c.req.method;
23
+ }
24
+ getPath() {
25
+ return this.c.req.path;
26
+ }
27
+ getUrl() {
28
+ return this.c.req.url;
29
+ }
30
+ async runHandler() {
31
+ const outcome = await chunkXUNNMCO5_cjs.raceTimeout(this.next());
32
+ if (outcome === chunkXUNNMCO5_cjs.HANDLER_TIMEOUT) {
33
+ return {
34
+ status: 504,
35
+ setResponseHeader: () => {
36
+ },
37
+ sendResponse: () => {
38
+ this.c.res = new Response(TIMEOUT_BODY, {
39
+ status: 504,
40
+ headers: { "Content-Type": "application/json" }
41
+ });
42
+ },
43
+ discardResponse: () => {
44
+ }
45
+ };
46
+ }
47
+ const res = this.c.res;
48
+ return {
49
+ status: res.status,
50
+ setResponseHeader: (name, value) => res.headers.set(name, value),
51
+ sendResponse: () => {
52
+ },
53
+ discardResponse: () => {
54
+ }
55
+ };
56
+ }
57
+ };
58
+
59
+ // src/hono/index.ts
60
+ function paymentMiddleware(config) {
61
+ const middleware = chunkW3SMR5LQ_cjs.createPaymentMiddleware(config);
62
+ return async (c, next) => {
63
+ const result = await middleware(new HonoAdapter(c, next));
64
+ if ("pass" in result) {
65
+ if (result.handlerRan) return;
66
+ await next();
67
+ return;
68
+ }
69
+ return new Response(JSON.stringify(result.body), {
70
+ status: result.status,
71
+ headers: { ...result.headers, "Content-Type": "application/json" }
72
+ });
73
+ };
74
+ }
75
+
76
+ exports.HonoAdapter = HonoAdapter;
77
+ exports.paymentMiddleware = paymentMiddleware;
@@ -0,0 +1,18 @@
1
+ import { Context, Next, MiddlewareHandler } from 'hono';
2
+ import { H as HTTPAdapter, R as RunHandlerResult, P as PaymentMiddlewareConfig } from './types-CUi55YSx.cjs';
3
+ import 'viem';
4
+
5
+ declare class HonoAdapter implements HTTPAdapter {
6
+ private readonly c;
7
+ private readonly next;
8
+ constructor(c: Context, next: Next);
9
+ getHeader(name: string): string | undefined;
10
+ getMethod(): string;
11
+ getPath(): string;
12
+ getUrl(): string;
13
+ runHandler(): Promise<RunHandlerResult>;
14
+ }
15
+
16
+ declare function paymentMiddleware(config: PaymentMiddlewareConfig): MiddlewareHandler;
17
+
18
+ export { HonoAdapter, paymentMiddleware };
package/dist/hono.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Context, Next, MiddlewareHandler } from 'hono';
2
+ import { H as HTTPAdapter, R as RunHandlerResult, P as PaymentMiddlewareConfig } from './types-CUi55YSx.js';
3
+ import 'viem';
4
+
5
+ declare class HonoAdapter implements HTTPAdapter {
6
+ private readonly c;
7
+ private readonly next;
8
+ constructor(c: Context, next: Next);
9
+ getHeader(name: string): string | undefined;
10
+ getMethod(): string;
11
+ getPath(): string;
12
+ getUrl(): string;
13
+ runHandler(): Promise<RunHandlerResult>;
14
+ }
15
+
16
+ declare function paymentMiddleware(config: PaymentMiddlewareConfig): MiddlewareHandler;
17
+
18
+ export { HonoAdapter, paymentMiddleware };
package/dist/hono.js ADDED
@@ -0,0 +1,74 @@
1
+ import { raceTimeout, HANDLER_TIMEOUT } from './chunk-2UEAVMCH.js';
2
+ import { createPaymentMiddleware } from './chunk-FDQULXKG.js';
3
+
4
+ // src/hono/adapter.ts
5
+ var TIMEOUT_BODY = JSON.stringify({
6
+ error: "HANDLER_TIMEOUT",
7
+ message: "The resource handler did not respond in time."
8
+ });
9
+ var HonoAdapter = class {
10
+ constructor(c, next) {
11
+ this.c = c;
12
+ this.next = next;
13
+ }
14
+ c;
15
+ next;
16
+ getHeader(name) {
17
+ return this.c.req.header(name);
18
+ }
19
+ getMethod() {
20
+ return this.c.req.method;
21
+ }
22
+ getPath() {
23
+ return this.c.req.path;
24
+ }
25
+ getUrl() {
26
+ return this.c.req.url;
27
+ }
28
+ async runHandler() {
29
+ const outcome = await raceTimeout(this.next());
30
+ if (outcome === HANDLER_TIMEOUT) {
31
+ return {
32
+ status: 504,
33
+ setResponseHeader: () => {
34
+ },
35
+ sendResponse: () => {
36
+ this.c.res = new Response(TIMEOUT_BODY, {
37
+ status: 504,
38
+ headers: { "Content-Type": "application/json" }
39
+ });
40
+ },
41
+ discardResponse: () => {
42
+ }
43
+ };
44
+ }
45
+ const res = this.c.res;
46
+ return {
47
+ status: res.status,
48
+ setResponseHeader: (name, value) => res.headers.set(name, value),
49
+ sendResponse: () => {
50
+ },
51
+ discardResponse: () => {
52
+ }
53
+ };
54
+ }
55
+ };
56
+
57
+ // src/hono/index.ts
58
+ function paymentMiddleware(config) {
59
+ const middleware = createPaymentMiddleware(config);
60
+ return async (c, next) => {
61
+ const result = await middleware(new HonoAdapter(c, next));
62
+ if ("pass" in result) {
63
+ if (result.handlerRan) return;
64
+ await next();
65
+ return;
66
+ }
67
+ return new Response(JSON.stringify(result.body), {
68
+ status: result.status,
69
+ headers: { ...result.headers, "Content-Type": "application/json" }
70
+ });
71
+ };
72
+ }
73
+
74
+ export { HonoAdapter, paymentMiddleware };
package/dist/index.cjs ADDED
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "FacilitatorClient", {
8
+ enumerable: true,
9
+ get: function () { return chunkW3SMR5LQ_cjs.FacilitatorClient; }
10
+ });
11
+ Object.defineProperty(exports, "PARALLEL_TOKENS", {
12
+ enumerable: true,
13
+ get: function () { return chunkW3SMR5LQ_cjs.PARALLEL_TOKENS; }
14
+ });
15
+ Object.defineProperty(exports, "X402ConfigError", {
16
+ enumerable: true,
17
+ get: function () { return chunkW3SMR5LQ_cjs.X402ConfigError; }
18
+ });
19
+ Object.defineProperty(exports, "X402RuntimeError", {
20
+ enumerable: true,
21
+ get: function () { return chunkW3SMR5LQ_cjs.X402RuntimeError; }
22
+ });
23
+ Object.defineProperty(exports, "X402_ERROR_CODES", {
24
+ enumerable: true,
25
+ get: function () { return chunkW3SMR5LQ_cjs.X402_ERROR_CODES; }
26
+ });
27
+ Object.defineProperty(exports, "createPaymentGate", {
28
+ enumerable: true,
29
+ get: function () { return chunkW3SMR5LQ_cjs.createPaymentGate; }
30
+ });
31
+ Object.defineProperty(exports, "createPaymentMiddleware", {
32
+ enumerable: true,
33
+ get: function () { return chunkW3SMR5LQ_cjs.createPaymentMiddleware; }
34
+ });
35
+ Object.defineProperty(exports, "encodeBase64", {
36
+ enumerable: true,
37
+ get: function () { return chunkW3SMR5LQ_cjs.encodeBase64; }
38
+ });
39
+ Object.defineProperty(exports, "getDefaultAcceptedTokens", {
40
+ enumerable: true,
41
+ get: function () { return chunkW3SMR5LQ_cjs.getDefaultAcceptedTokens; }
42
+ });
43
+ Object.defineProperty(exports, "parsePrice", {
44
+ enumerable: true,
45
+ get: function () { return chunkW3SMR5LQ_cjs.parsePrice; }
46
+ });
47
+ Object.defineProperty(exports, "toEip155Network", {
48
+ enumerable: true,
49
+ get: function () { return chunkW3SMR5LQ_cjs.toEip155Network; }
50
+ });
51
+ Object.defineProperty(exports, "validateAddress", {
52
+ enumerable: true,
53
+ get: function () { return chunkW3SMR5LQ_cjs.validateAddress; }
54
+ });
@@ -0,0 +1,52 @@
1
+ import { F as FacilitatorConfig, a as FacilitatorPaymentRequirements, b as FacilitatorResponse, P as PaymentMiddlewareConfig, H as HTTPAdapter, c as PaymentGateResult, M as MiddlewareResult, d as PassResult } from './types-CUi55YSx.cjs';
2
+ export { e as PaymentConfirmation, f as PaymentFailure, g as PaymentRequired, h as PaymentRequirements, i as ResourceInfo, j as RouteConfig, R as RunHandlerResult } from './types-CUi55YSx.cjs';
3
+ import { Address } from 'viem';
4
+
5
+ declare class FacilitatorClient {
6
+ private readonly config;
7
+ constructor(config: FacilitatorConfig);
8
+ verify(paymentHeader: string, paymentRequirements: FacilitatorPaymentRequirements): Promise<void>;
9
+ settle(paymentHeader: string, paymentRequirements: FacilitatorPaymentRequirements): Promise<FacilitatorResponse>;
10
+ pay(paymentHeader: string): Promise<FacilitatorResponse>;
11
+ private buildHeaders;
12
+ }
13
+
14
+ declare const X402_ERROR_CODES: {
15
+ readonly FACILITATOR_UNAVAILABLE: "FACILITATOR_UNAVAILABLE";
16
+ readonly FACILITATOR_INVALID_RESPONSE: "FACILITATOR_INVALID_RESPONSE";
17
+ readonly INVALID_PAYMENT: "INVALID_PAYMENT";
18
+ };
19
+ type X402ErrorCode = (typeof X402_ERROR_CODES)[keyof typeof X402_ERROR_CODES];
20
+ declare class X402ConfigError extends Error {
21
+ constructor(message: string, cause?: unknown);
22
+ }
23
+ declare class X402RuntimeError extends Error {
24
+ readonly code: string;
25
+ constructor(code: string);
26
+ }
27
+
28
+ declare function createPaymentGate(config: PaymentMiddlewareConfig): (adapter: Pick<HTTPAdapter, "getHeader" | "getPath" | "getUrl" | "getMethod">) => Promise<PaymentGateResult>;
29
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): (adapter: HTTPAdapter) => Promise<MiddlewareResult | PassResult>;
30
+
31
+ type ParallelNetwork = "ethereum" | "base" | "avalanche" | "hyperevm";
32
+ type ChainTokens = {
33
+ usdp: Address;
34
+ susdp: Address;
35
+ usdc: Address;
36
+ frxUSD?: Address;
37
+ sfrxUSD?: Address;
38
+ USDe?: Address;
39
+ sUSDe?: Address;
40
+ USDS?: Address;
41
+ sUSDS?: Address;
42
+ ygamiUSDC?: Address;
43
+ };
44
+ declare const PARALLEL_TOKENS: Record<ParallelNetwork, ChainTokens>;
45
+ declare function getDefaultAcceptedTokens(network: string): [Address, Address, Address] | undefined;
46
+
47
+ declare function parsePrice(price: string | bigint, decimals?: number): bigint;
48
+ declare function validateAddress(address: string): address is Address;
49
+ declare function toEip155Network(network: string): string;
50
+ declare function encodeBase64(obj: unknown): string;
51
+
52
+ export { FacilitatorClient, FacilitatorConfig, FacilitatorPaymentRequirements, FacilitatorResponse, HTTPAdapter, MiddlewareResult, PARALLEL_TOKENS, type ParallelNetwork, PassResult, PaymentGateResult, PaymentMiddlewareConfig, X402ConfigError, type X402ErrorCode, X402RuntimeError, X402_ERROR_CODES, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, toEip155Network, validateAddress };
@@ -0,0 +1,52 @@
1
+ import { F as FacilitatorConfig, a as FacilitatorPaymentRequirements, b as FacilitatorResponse, P as PaymentMiddlewareConfig, H as HTTPAdapter, c as PaymentGateResult, M as MiddlewareResult, d as PassResult } from './types-CUi55YSx.js';
2
+ export { e as PaymentConfirmation, f as PaymentFailure, g as PaymentRequired, h as PaymentRequirements, i as ResourceInfo, j as RouteConfig, R as RunHandlerResult } from './types-CUi55YSx.js';
3
+ import { Address } from 'viem';
4
+
5
+ declare class FacilitatorClient {
6
+ private readonly config;
7
+ constructor(config: FacilitatorConfig);
8
+ verify(paymentHeader: string, paymentRequirements: FacilitatorPaymentRequirements): Promise<void>;
9
+ settle(paymentHeader: string, paymentRequirements: FacilitatorPaymentRequirements): Promise<FacilitatorResponse>;
10
+ pay(paymentHeader: string): Promise<FacilitatorResponse>;
11
+ private buildHeaders;
12
+ }
13
+
14
+ declare const X402_ERROR_CODES: {
15
+ readonly FACILITATOR_UNAVAILABLE: "FACILITATOR_UNAVAILABLE";
16
+ readonly FACILITATOR_INVALID_RESPONSE: "FACILITATOR_INVALID_RESPONSE";
17
+ readonly INVALID_PAYMENT: "INVALID_PAYMENT";
18
+ };
19
+ type X402ErrorCode = (typeof X402_ERROR_CODES)[keyof typeof X402_ERROR_CODES];
20
+ declare class X402ConfigError extends Error {
21
+ constructor(message: string, cause?: unknown);
22
+ }
23
+ declare class X402RuntimeError extends Error {
24
+ readonly code: string;
25
+ constructor(code: string);
26
+ }
27
+
28
+ declare function createPaymentGate(config: PaymentMiddlewareConfig): (adapter: Pick<HTTPAdapter, "getHeader" | "getPath" | "getUrl" | "getMethod">) => Promise<PaymentGateResult>;
29
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): (adapter: HTTPAdapter) => Promise<MiddlewareResult | PassResult>;
30
+
31
+ type ParallelNetwork = "ethereum" | "base" | "avalanche" | "hyperevm";
32
+ type ChainTokens = {
33
+ usdp: Address;
34
+ susdp: Address;
35
+ usdc: Address;
36
+ frxUSD?: Address;
37
+ sfrxUSD?: Address;
38
+ USDe?: Address;
39
+ sUSDe?: Address;
40
+ USDS?: Address;
41
+ sUSDS?: Address;
42
+ ygamiUSDC?: Address;
43
+ };
44
+ declare const PARALLEL_TOKENS: Record<ParallelNetwork, ChainTokens>;
45
+ declare function getDefaultAcceptedTokens(network: string): [Address, Address, Address] | undefined;
46
+
47
+ declare function parsePrice(price: string | bigint, decimals?: number): bigint;
48
+ declare function validateAddress(address: string): address is Address;
49
+ declare function toEip155Network(network: string): string;
50
+ declare function encodeBase64(obj: unknown): string;
51
+
52
+ export { FacilitatorClient, FacilitatorConfig, FacilitatorPaymentRequirements, FacilitatorResponse, HTTPAdapter, MiddlewareResult, PARALLEL_TOKENS, type ParallelNetwork, PassResult, PaymentGateResult, PaymentMiddlewareConfig, X402ConfigError, type X402ErrorCode, X402RuntimeError, X402_ERROR_CODES, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, toEip155Network, validateAddress };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { FacilitatorClient, PARALLEL_TOKENS, X402ConfigError, X402RuntimeError, X402_ERROR_CODES, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, toEip155Network, validateAddress } from './chunk-FDQULXKG.js';