@inflowpayai/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.
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/extensions/index.cjs +78 -0
- package/dist/extensions/index.cjs.map +1 -0
- package/dist/extensions/index.d.cts +32 -0
- package/dist/extensions/index.d.ts +32 -0
- package/dist/extensions/index.js +66 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extras/index.cjs +17 -0
- package/dist/extras/index.cjs.map +1 -0
- package/dist/extras/index.d.cts +23 -0
- package/dist/extras/index.d.ts +23 -0
- package/dist/extras/index.js +14 -0
- package/dist/extras/index.js.map +1 -0
- package/dist/index.cjs +421 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +571 -0
- package/dist/index.d.ts +571 -0
- package/dist/index.js +401 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-identifier-BNYznClf.d.cts +103 -0
- package/dist/payment-identifier-BNYznClf.d.ts +103 -0
- package/dist/security/index.cjs +17 -0
- package/dist/security/index.cjs.map +1 -0
- package/dist/security/index.d.cts +14 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/index.js +15 -0
- package/dist/security/index.js.map +1 -0
- package/package.json +97 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
export { h as generatePaymentId, v as validatePaymentId } from './payment-identifier-BNYznClf.cjs';
|
|
2
|
+
import { ResourceInfo } from '@x402/core/types';
|
|
3
|
+
export { ResourceInfo, VerifyResponse } from '@x402/core/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* X402 protocol version emitted on every outbound SDK request and required on every inbound response. Responses
|
|
7
|
+
* advertising a different version are rejected at the boundary with {@link X402VersionMismatchError}.
|
|
8
|
+
*/
|
|
9
|
+
declare const X402_VERSION: 2;
|
|
10
|
+
/**
|
|
11
|
+
* V2 spec header names. Emitted verbatim on the write path; read via {@link readHeader} (case-insensitive). Header
|
|
12
|
+
* values use the standard base64 alphabet (`A-Z`, `a-z`, `0-9`, `+`, `/`) with `=` padding — not base64url.
|
|
13
|
+
*/
|
|
14
|
+
declare const HEADERS: {
|
|
15
|
+
readonly PAYMENT_REQUIRED: "PAYMENT-REQUIRED";
|
|
16
|
+
readonly PAYMENT_RESPONSE: "PAYMENT-RESPONSE";
|
|
17
|
+
readonly PAYMENT_SIGNATURE: "PAYMENT-SIGNATURE";
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Payment-scheme identifiers carried in `PaymentRequirements.scheme` and `PaymentPayload.accepted.scheme`.
|
|
21
|
+
*
|
|
22
|
+
* `INSTRUMENT` is a reserved value: it is present in the type union for forward compatibility, and the SDK rejects it
|
|
23
|
+
* at runtime with a typed error if reached.
|
|
24
|
+
*/
|
|
25
|
+
declare const SCHEMES: {
|
|
26
|
+
readonly BALANCE: "balance";
|
|
27
|
+
readonly EXACT: "exact";
|
|
28
|
+
readonly INSTRUMENT: "instrument";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Canonical Permit2Proxy and Permit2 addresses. Identical on every supported EVM chain (CREATE2-deployed). Use for the
|
|
32
|
+
* buyer-side verification fallback when `PaymentRequirements.extra.permit2Proxy` is absent.
|
|
33
|
+
*/
|
|
34
|
+
declare const CONTRACTS: {
|
|
35
|
+
readonly PERMIT2_PROXY: "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
|
|
36
|
+
readonly PERMIT2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Reserved network identifiers. CAIP-2 shaped `<namespace>:<reference>`. Only InFlow's internal ledger is enumerated;
|
|
40
|
+
* on-chain network ids (`eip155:8453`, `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`, …) are sourced at runtime from
|
|
41
|
+
* `X402ConfigResponse.assets[*].network` and `wallets[*].network`.
|
|
42
|
+
*/
|
|
43
|
+
declare const NETWORKS: {
|
|
44
|
+
readonly INFLOW: "inflow:1";
|
|
45
|
+
};
|
|
46
|
+
/** Well-known keys read from `PaymentRequirements.extra` and `PaymentMethodInfo.extra`. */
|
|
47
|
+
declare const EXTRA_KEYS: {
|
|
48
|
+
readonly ASSET_TRANSFER_METHOD: "assetTransferMethod";
|
|
49
|
+
readonly FEE_PAYER: "feePayer";
|
|
50
|
+
readonly NAME: "name";
|
|
51
|
+
readonly PERMIT2_PROXY: "permit2Proxy";
|
|
52
|
+
readonly VERSION: "version";
|
|
53
|
+
};
|
|
54
|
+
/** Well-known keys read from `PaymentPayload.payload`. */
|
|
55
|
+
declare const PAYLOAD_KEYS: {
|
|
56
|
+
readonly TRANSACTION_ID: "transactionId";
|
|
57
|
+
};
|
|
58
|
+
/** Values that can appear in `PaymentRequirements.extra.assetTransferMethod`. */
|
|
59
|
+
declare const ASSET_TRANSFER_METHODS: {
|
|
60
|
+
readonly EIP3009: "eip3009";
|
|
61
|
+
readonly PERMIT2: "permit2";
|
|
62
|
+
readonly SOLANA: "solana";
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Header bag accepted by {@link readHeader}. Covers WHATWG `Headers`, Node's `IncomingHttpHeaders`-style records (where
|
|
66
|
+
* values may be string arrays or undefined), and plain string-valued records.
|
|
67
|
+
*/
|
|
68
|
+
type HeaderBag = Headers | Record<string, string | readonly string[] | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Read a single header value case-insensitively. Returns `undefined` when the header is absent. For Node-style headers
|
|
71
|
+
* whose value is an array, returns the first element.
|
|
72
|
+
*
|
|
73
|
+
* @param headers - The header bag to read from.
|
|
74
|
+
* @param name - The header name. Matched case-insensitively against the keys in `headers`.
|
|
75
|
+
* @returns The header value, or `undefined` if missing.
|
|
76
|
+
*/
|
|
77
|
+
declare function readHeader(headers: HeaderBag, name: string): string | undefined;
|
|
78
|
+
|
|
79
|
+
/** Public InFlow environments addressable by the SDK without an explicit `baseUrl` override. */
|
|
80
|
+
type Environment = 'production' | 'sandbox';
|
|
81
|
+
/** Options consumed by {@link resolveBaseUrl}. */
|
|
82
|
+
interface ResolveBaseUrlOptions {
|
|
83
|
+
/** Selects one of the public environments. Defaults to `'production'`. */
|
|
84
|
+
environment?: Environment;
|
|
85
|
+
/** Override the environment-derived URL entirely. Trailing slashes are stripped. Takes precedence over `environment`. */
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve the InFlow API base URL the SDK will issue requests against.
|
|
90
|
+
*
|
|
91
|
+
* @param options - {@link ResolveBaseUrlOptions}. `baseUrl` wins over `environment`. With neither set, falls back to the
|
|
92
|
+
* production URL.
|
|
93
|
+
* @returns The base URL with any trailing slashes stripped, suitable for appending request paths.
|
|
94
|
+
*/
|
|
95
|
+
declare function resolveBaseUrl(options?: ResolveBaseUrlOptions): string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Constructor parameters for {@link InflowApiError}. Every field except `message` corresponds to an attribute carried on
|
|
99
|
+
* the resulting error instance.
|
|
100
|
+
*/
|
|
101
|
+
interface InflowApiErrorInit {
|
|
102
|
+
/**
|
|
103
|
+
* Application-level error code extracted from the response body's `code` field. Falls back to `'UNEXPECTED_ERROR'`
|
|
104
|
+
* when the body did not carry a code. Specific values consumers may branch on include `INSUFFICIENT_FUNDS`,
|
|
105
|
+
* `PARAMETER_REQUIRED`, `PARAMETER_INVALID`, `BLOCKCHAIN_NOT_FOUND`, and `USER_NOT_FOUND`.
|
|
106
|
+
*/
|
|
107
|
+
code: string;
|
|
108
|
+
/** HTTP status of the failing response. */
|
|
109
|
+
httpStatus: number;
|
|
110
|
+
/** Endpoint path (relative to the base URL) that produced the failure. */
|
|
111
|
+
endpoint: string;
|
|
112
|
+
/**
|
|
113
|
+
* Server-issued correlation ID, read from `X-Request-Id` on the response. `undefined` when the server did not emit
|
|
114
|
+
* one.
|
|
115
|
+
*/
|
|
116
|
+
requestId?: string;
|
|
117
|
+
/** Underlying error (e.g. a `fetch` rejection) when this wraps another. */
|
|
118
|
+
cause?: unknown;
|
|
119
|
+
/** Parsed JSON body when the response was JSON; raw text otherwise. */
|
|
120
|
+
body?: unknown;
|
|
121
|
+
/** Response headers with sensitive entries (`authorization`, `cookie`, `set-cookie`, `x-api-key`) stripped. */
|
|
122
|
+
headers?: Headers | Record<string, string | readonly string[] | undefined>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Error thrown by every {@link InflowHttpClient} call on a non-2xx response. Carries the server-issued correlation ID
|
|
126
|
+
* when available and the (sanitized) response body and headers for diagnostics.
|
|
127
|
+
*/
|
|
128
|
+
declare class InflowApiError extends Error {
|
|
129
|
+
/** {@inheritDoc InflowApiErrorInit.code} */
|
|
130
|
+
readonly code: string;
|
|
131
|
+
/** {@inheritDoc InflowApiErrorInit.httpStatus} */
|
|
132
|
+
readonly httpStatus: number;
|
|
133
|
+
/** {@inheritDoc InflowApiErrorInit.endpoint} */
|
|
134
|
+
readonly endpoint: string;
|
|
135
|
+
/** {@inheritDoc InflowApiErrorInit.requestId} */
|
|
136
|
+
readonly requestId?: string;
|
|
137
|
+
/** {@inheritDoc InflowApiErrorInit.body} */
|
|
138
|
+
readonly body?: unknown;
|
|
139
|
+
/** {@inheritDoc InflowApiErrorInit.headers} */
|
|
140
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
141
|
+
/**
|
|
142
|
+
* @param message - Human-readable message. Callers should prefer the factory {@link InflowApiError.from} which
|
|
143
|
+
* composes a standard message shape including endpoint, status, code, and request ID.
|
|
144
|
+
* @param init - Structured fields carried on the resulting instance.
|
|
145
|
+
*/
|
|
146
|
+
constructor(message: string, init: InflowApiErrorInit);
|
|
147
|
+
/**
|
|
148
|
+
* Compose an {@link InflowApiError} with a standard message shape.
|
|
149
|
+
*
|
|
150
|
+
* Format: `[<requestId>] <endpoint>: <httpStatus> <code> — <bodyMessage>`, where `<requestId>` is omitted when
|
|
151
|
+
* missing and `<bodyMessage>` falls back to a generic `request failed` when the body had no `message` field.
|
|
152
|
+
*/
|
|
153
|
+
static from(init: InflowApiErrorInit): InflowApiError;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Thrown when a response advertises an `x402Version` other than the SDK's supported version ({@link X402_VERSION} = 2).
|
|
157
|
+
* The SDK does not attempt version negotiation: only V2 is supported and any other value is a hard error so consumers
|
|
158
|
+
* see the mismatch at the boundary instead of as a silent decode failure deeper in.
|
|
159
|
+
*/
|
|
160
|
+
declare class X402VersionMismatchError extends Error {
|
|
161
|
+
/** Version reported by the server (or `unknown` when the field was absent). */
|
|
162
|
+
readonly receivedVersion: number | 'unknown';
|
|
163
|
+
/** Endpoint or context that produced the mismatched payload. */
|
|
164
|
+
readonly endpoint: string;
|
|
165
|
+
/**
|
|
166
|
+
* @param receivedVersion - The `x402Version` value the response carried, or the string `'unknown'` when the field was
|
|
167
|
+
* missing or not a number.
|
|
168
|
+
* @param endpoint - The endpoint path or context the SDK was processing when it saw the version field, used in the
|
|
169
|
+
* generated message.
|
|
170
|
+
*/
|
|
171
|
+
constructor(receivedVersion: number | 'unknown', endpoint: string);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Options accepted by {@link InflowHttpClient}'s constructor and shared by higher-level facilitator and signer clients
|
|
176
|
+
* in the seller and buyer packages.
|
|
177
|
+
*/
|
|
178
|
+
interface InflowClientOptions {
|
|
179
|
+
/** InFlow API key sent on every request as `X-API-KEY`. */
|
|
180
|
+
apiKey: string;
|
|
181
|
+
/** Selects one of the public environments. Defaults to `'production'`. */
|
|
182
|
+
environment?: Environment;
|
|
183
|
+
/** Override the environment-derived URL. Takes precedence over `environment`. */
|
|
184
|
+
baseUrl?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Per-request timeout, milliseconds. Defaults to 30 000. The timer covers the whole `fetch` plus body read; on expiry
|
|
187
|
+
* the request is aborted and an `InflowApiError` with `code: 'TIMEOUT'` is thrown.
|
|
188
|
+
*/
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Optional `fetch` implementation. Defaults to `globalThis.fetch`. Useful for routing through a corporate proxy,
|
|
192
|
+
* attaching OpenTelemetry instrumentation, or stubbing at the SDK boundary in tests. The injected function must
|
|
193
|
+
* conform to the WHATWG fetch API.
|
|
194
|
+
*/
|
|
195
|
+
fetch?: typeof fetch;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Options accepted by {@link InflowHttpClient} when constructed without an API key. Only used by the seller-side
|
|
199
|
+
* `createUnauthenticatedInflowFacilitator` factory; buyer-side flows and the seller client never construct anonymous
|
|
200
|
+
* transports. Sends no `X-API-KEY` header on outbound requests.
|
|
201
|
+
*/
|
|
202
|
+
interface InflowAnonymousClientOptions {
|
|
203
|
+
/** Marker field — must be omitted or `undefined`. */
|
|
204
|
+
apiKey?: undefined;
|
|
205
|
+
/** Selects one of the public environments. Defaults to `'production'`. */
|
|
206
|
+
environment?: Environment;
|
|
207
|
+
/** Override the environment-derived URL. Takes precedence over `environment`. */
|
|
208
|
+
baseUrl?: string;
|
|
209
|
+
/** Per-request timeout, milliseconds. Defaults to 30 000. */
|
|
210
|
+
timeoutMs?: number;
|
|
211
|
+
/** Optional `fetch` implementation. Defaults to `globalThis.fetch`. */
|
|
212
|
+
fetch?: typeof fetch;
|
|
213
|
+
}
|
|
214
|
+
/** Per-call overrides accepted by {@link InflowHttpClient}'s request methods. */
|
|
215
|
+
interface RequestOptions {
|
|
216
|
+
/**
|
|
217
|
+
* Maximum retry attempts on transient failures (HTTP 429, 502, 503, 504, and network errors). Capped at 3. Pass `0`
|
|
218
|
+
* to disable retries — used by the buyer signer's polling loop, where the outer poller controls retry semantics.
|
|
219
|
+
*/
|
|
220
|
+
retries?: number;
|
|
221
|
+
/** Override the client-level `timeoutMs` for this call. */
|
|
222
|
+
timeoutMs?: number;
|
|
223
|
+
/** Additional headers merged on top of the SDK's standard headers. */
|
|
224
|
+
headers?: Record<string, string>;
|
|
225
|
+
/**
|
|
226
|
+
* AbortSignal for caller-driven cancellation. Composes with the request-internal timeout signal; whichever fires
|
|
227
|
+
* first aborts the request.
|
|
228
|
+
*/
|
|
229
|
+
signal?: AbortSignal;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* HTTP client used by every other package in this monorepo to talk to `api.inflowpay.ai`. Carries `apiKey` injection,
|
|
233
|
+
* retry on transient statuses (429, 502, 503, 504) with exponential backoff capped at three attempts, request timeout,
|
|
234
|
+
* JSON parsing, and error mapping into {@link InflowApiError}.
|
|
235
|
+
*
|
|
236
|
+
* Construct one instance per `(apiKey, environment)` pair and share it across requests.
|
|
237
|
+
*/
|
|
238
|
+
declare class InflowHttpClient {
|
|
239
|
+
/** Resolved base URL (no trailing slash). */
|
|
240
|
+
readonly baseUrl: string;
|
|
241
|
+
private readonly apiKey;
|
|
242
|
+
private readonly defaultTimeoutMs;
|
|
243
|
+
private readonly fetchImpl;
|
|
244
|
+
/**
|
|
245
|
+
* @param options - {@link InflowClientOptions} or {@link InflowAnonymousClientOptions}. The authed form requires
|
|
246
|
+
* `apiKey` to be a non-empty string; the anonymous form omits it entirely and sends no `X-API-KEY` header.
|
|
247
|
+
* Anonymous mode is used only by `createUnauthenticatedInflowFacilitator` in `@inflowpayai/x402-seller`.
|
|
248
|
+
* @throws {Error} When `apiKey` is present but empty. (Server-side codes are mapped to {@link InflowApiError}; this is
|
|
249
|
+
* a local precondition failure.)
|
|
250
|
+
*/
|
|
251
|
+
constructor(options: InflowClientOptions | InflowAnonymousClientOptions);
|
|
252
|
+
/**
|
|
253
|
+
* Issue a `GET` to `path` (relative to {@link InflowHttpClient.baseUrl}) and parse the JSON body.
|
|
254
|
+
*
|
|
255
|
+
* @typeParam T - Expected shape of the parsed body. Not validated at runtime; callers are responsible for narrowing.
|
|
256
|
+
* @param path - Path including leading slash, e.g. `'/v1/x402/config'`.
|
|
257
|
+
* @param options - Per-call overrides.
|
|
258
|
+
* @returns Parsed JSON body cast to `T`.
|
|
259
|
+
* @throws {@link InflowApiError} On any non-2xx response or terminal network error.
|
|
260
|
+
*/
|
|
261
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
262
|
+
/**
|
|
263
|
+
* Issue a `POST` to `path` with a JSON body and parse the JSON response.
|
|
264
|
+
*
|
|
265
|
+
* @typeParam T - Expected shape of the parsed body.
|
|
266
|
+
* @param path - Path including leading slash.
|
|
267
|
+
* @param body - Value serialized via `JSON.stringify`. Pass `undefined` to send an empty body.
|
|
268
|
+
* @param options - Per-call overrides.
|
|
269
|
+
* @returns Parsed JSON body cast to `T`.
|
|
270
|
+
* @throws {@link InflowApiError} On any non-2xx response or terminal network error.
|
|
271
|
+
*/
|
|
272
|
+
post<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
273
|
+
/**
|
|
274
|
+
* Lower-level entry point. Prefer {@link InflowHttpClient.get} / {@link InflowHttpClient.post} unless the verb is one
|
|
275
|
+
* neither covers.
|
|
276
|
+
*
|
|
277
|
+
* @typeParam T - Expected shape of the parsed body.
|
|
278
|
+
* @param method - HTTP verb.
|
|
279
|
+
* @param path - Path including leading slash.
|
|
280
|
+
* @param body - Optional value serialized via `JSON.stringify`.
|
|
281
|
+
* @param options - Per-call overrides.
|
|
282
|
+
* @returns Parsed JSON body cast to `T`.
|
|
283
|
+
*/
|
|
284
|
+
request<T>(method: string, path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
285
|
+
private sendOnce;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Payment-scheme identifier carried on the wire. `'exact'` covers EIP-3009 and Permit2 EVM transfers as well as non-EVM
|
|
290
|
+
* signed transfers; `'balance'` covers InFlow internal balance transfers; `'instrument'` is reserved.
|
|
291
|
+
*
|
|
292
|
+
* The `(string & {})` branch keeps editor autocomplete focused on the known values while still accepting any string at
|
|
293
|
+
* runtime, so consumers can interoperate with future schemes the SDK hasn't yet enumerated.
|
|
294
|
+
*/
|
|
295
|
+
type PaymentScheme = 'exact' | 'balance' | 'instrument' | (string & {});
|
|
296
|
+
/** Funding-source type carried in `instrument`-scheme payloads and extras. Reserved for future use. */
|
|
297
|
+
type InstrumentType = 'card' | 'bank' | (string & {});
|
|
298
|
+
/**
|
|
299
|
+
* A single entry in `PaymentRequired.accepts[]`. Describes one acceptable way for a buyer to pay the protected
|
|
300
|
+
* resource: a scheme, a network, the payee address, the asset (when applicable), the atomic-unit amount, and
|
|
301
|
+
* scheme-specific extras.
|
|
302
|
+
*/
|
|
303
|
+
interface PaymentRequirements {
|
|
304
|
+
/** Payment scheme — `'exact'`, `'balance'`, or `'instrument'`. */
|
|
305
|
+
scheme: PaymentScheme;
|
|
306
|
+
/**
|
|
307
|
+
* CAIP-2 network identifier. `'eip155:8453'` and `'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'` for blockchain networks;
|
|
308
|
+
* `'inflow:1'` for InFlow's internal ledger (balance and reserved instrument schemes).
|
|
309
|
+
*/
|
|
310
|
+
network: string;
|
|
311
|
+
/** On-chain contract address or mint. Empty string when not applicable. */
|
|
312
|
+
asset: string;
|
|
313
|
+
/** Amount in atomic units of `asset` (or the method's own decimal scale). */
|
|
314
|
+
amount: string;
|
|
315
|
+
/** Recipient — wallet address for blockchain schemes, seller UUID for balance/instrument. */
|
|
316
|
+
payTo: string;
|
|
317
|
+
/** Maximum lifetime (seconds) the requirement is valid for. */
|
|
318
|
+
maxTimeoutSeconds: number;
|
|
319
|
+
/**
|
|
320
|
+
* Scheme-specific extras (EIP-712 domain, asset transfer method, fee payer, etc.). Optional on the wire — the server
|
|
321
|
+
* omits it when no extras apply (e.g. some `balance`-scheme entries). Use the typed accessors in
|
|
322
|
+
* `@inflowpayai/x402/extras` for safe reads under `noUncheckedIndexedAccess`.
|
|
323
|
+
*/
|
|
324
|
+
extra?: Record<string, unknown>;
|
|
325
|
+
}
|
|
326
|
+
/** The 402-response body. Sent by the seller as a base64 JSON encoding in the `PAYMENT-REQUIRED` header. */
|
|
327
|
+
interface PaymentRequired {
|
|
328
|
+
/** Protocol version — always `2`. */
|
|
329
|
+
x402Version: number;
|
|
330
|
+
/** Optional human-readable error context attached by the seller. */
|
|
331
|
+
error?: string;
|
|
332
|
+
/** Information about the protected resource. */
|
|
333
|
+
resource: ResourceInfo;
|
|
334
|
+
/** The set of acceptable payment options. The buyer chooses one. */
|
|
335
|
+
accepts: PaymentRequirements[];
|
|
336
|
+
/** Per-response extension declarations, keyed by extension name. */
|
|
337
|
+
extensions?: Record<string, unknown>;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Inner payload shape for the `'balance'` scheme. Balance payments are not cryptographically signed because settlement
|
|
341
|
+
* is an internal ledger transfer rather than a verifiable on-chain action.
|
|
342
|
+
*/
|
|
343
|
+
interface BalancePayloadData {
|
|
344
|
+
/** InFlow transaction UUID — the only field carried on the wire. */
|
|
345
|
+
transactionId: string;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* EIP-3009 (`transferWithAuthorization`) wire shape of the `'exact'` scheme. The Permit2 variant lives on
|
|
349
|
+
* {@link Permit2PayloadData}.
|
|
350
|
+
*/
|
|
351
|
+
interface ExactPayloadData {
|
|
352
|
+
/** EIP-3009 `TransferWithAuthorization` typed-data message. */
|
|
353
|
+
authorization: {
|
|
354
|
+
/** Payer address; signs `authorization`. */
|
|
355
|
+
from: string;
|
|
356
|
+
/** Recipient (the seller's `payTo`). */
|
|
357
|
+
to: string;
|
|
358
|
+
/** Atomic-unit amount (decimal string). */
|
|
359
|
+
value: string;
|
|
360
|
+
/** Unix-seconds lower bound for facilitator submission. */
|
|
361
|
+
validAfter: string;
|
|
362
|
+
/** Unix-seconds upper bound (matches `maxTimeoutSeconds`). */
|
|
363
|
+
validBefore: string;
|
|
364
|
+
/** 32-byte hex; the payer must not have used it before. */
|
|
365
|
+
nonce: string;
|
|
366
|
+
};
|
|
367
|
+
/** 65-byte EIP-712 ECDSA signature over `authorization`. */
|
|
368
|
+
signature: string;
|
|
369
|
+
}
|
|
370
|
+
/** Inner payload shape for the `'instrument'` scheme. Reserved. */
|
|
371
|
+
interface InstrumentPayloadData {
|
|
372
|
+
transactionId: string;
|
|
373
|
+
signature: string;
|
|
374
|
+
instrumentId?: string;
|
|
375
|
+
instrumentType?: InstrumentType;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Permit2 variant of the `'exact'` scheme inner payload. See the [x402 EVM exact scheme
|
|
379
|
+
* spec](https://github.com/coinbase/x402/blob/main/specs/schemes/exact/scheme_exact_evm.md). `spender` must be the
|
|
380
|
+
* canonical x402ExactPermit2Proxy (see {@link CONTRACTS}); the InFlow facilitator rejects custom spenders.
|
|
381
|
+
*/
|
|
382
|
+
interface Permit2PayloadData {
|
|
383
|
+
signature: string;
|
|
384
|
+
permit2Authorization: {
|
|
385
|
+
permitted: {
|
|
386
|
+
token: string;
|
|
387
|
+
amount: string;
|
|
388
|
+
};
|
|
389
|
+
from: string;
|
|
390
|
+
spender: string;
|
|
391
|
+
nonce: string;
|
|
392
|
+
deadline: string;
|
|
393
|
+
witness: {
|
|
394
|
+
to: string;
|
|
395
|
+
validAfter: string;
|
|
396
|
+
extra: string;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Discriminated union of known inner-payload shapes. The catch-all `Record<string, unknown>` branch keeps the type open
|
|
402
|
+
* for forward- compatible schemes the SDK hasn't yet enumerated.
|
|
403
|
+
*/
|
|
404
|
+
type InflowPaymentPayloadData = BalancePayloadData | ExactPayloadData | Permit2PayloadData | InstrumentPayloadData | Record<string, unknown>;
|
|
405
|
+
/**
|
|
406
|
+
* The signed payment envelope a buyer sends to the seller in the `PAYMENT-SIGNATURE` header (base64 JSON). Narrow on
|
|
407
|
+
* `accepted.scheme` to discriminate `payload`.
|
|
408
|
+
*/
|
|
409
|
+
interface InflowPaymentPayload {
|
|
410
|
+
/** Protocol version — always `2`. */
|
|
411
|
+
x402Version: number;
|
|
412
|
+
/** The {@link PaymentRequirements} the buyer chose. */
|
|
413
|
+
accepted: PaymentRequirements;
|
|
414
|
+
/** Scheme-specific signed (or pseudo-signed) inner payload. */
|
|
415
|
+
payload: InflowPaymentPayloadData;
|
|
416
|
+
/** Per-payload extension data, keyed by extension name. */
|
|
417
|
+
extensions?: Record<string, unknown>;
|
|
418
|
+
/** Optional resource info echoed back by the buyer. */
|
|
419
|
+
resource?: ResourceInfo;
|
|
420
|
+
}
|
|
421
|
+
/** Narrows to the `'balance'` scheme branch. */
|
|
422
|
+
declare function isBalancePayload(p: InflowPaymentPayload): p is InflowPaymentPayload & {
|
|
423
|
+
payload: BalancePayloadData;
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Narrows to the EIP-3009 variant of the `'exact'` scheme. The two `'exact'` variants split on transfer method — use
|
|
427
|
+
* alongside {@link isPermit2Payload}.
|
|
428
|
+
*/
|
|
429
|
+
declare function isExactPayload(p: InflowPaymentPayload): p is InflowPaymentPayload & {
|
|
430
|
+
payload: ExactPayloadData;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Narrows to the Permit2 variant of the `'exact'` scheme. The two `'exact'` variants split on transfer method — use
|
|
434
|
+
* alongside {@link isExactPayload}.
|
|
435
|
+
*/
|
|
436
|
+
declare function isPermit2Payload(p: InflowPaymentPayload): p is InflowPaymentPayload & {
|
|
437
|
+
payload: Permit2PayloadData;
|
|
438
|
+
};
|
|
439
|
+
/** Narrows to the reserved `'instrument'` scheme branch. Returns `false` for all production traffic today. */
|
|
440
|
+
declare function isInstrumentPayload(p: InflowPaymentPayload): p is InflowPaymentPayload & {
|
|
441
|
+
payload: InstrumentPayloadData;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Settlement-result envelope returned by the facilitator after a settle call. `network` is CAIP-2 for blockchain
|
|
445
|
+
* settlements and `'inflow:1'` for balance settlements.
|
|
446
|
+
*
|
|
447
|
+
* `transaction` is always present: a non-empty on-chain hash (or settlement reference for `'balance'`) on success, the
|
|
448
|
+
* empty string on failure. Check `success` before treating the value as a real reference.
|
|
449
|
+
*/
|
|
450
|
+
interface SettleResponse {
|
|
451
|
+
success: boolean;
|
|
452
|
+
errorReason?: string;
|
|
453
|
+
errorMessage?: string;
|
|
454
|
+
payer?: string;
|
|
455
|
+
/** On-chain hash on success, empty string on failure. Always present. */
|
|
456
|
+
transaction: string;
|
|
457
|
+
network: string;
|
|
458
|
+
amount?: string;
|
|
459
|
+
/** Per-extension entries returned by the facilitator. */
|
|
460
|
+
extensions?: Record<string, unknown>;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Per-`(scheme, network)` capability advertised by a facilitator. The optional `extra` map carries scheme- or
|
|
464
|
+
* operator-specific metadata; the SDK does not interpret it.
|
|
465
|
+
*/
|
|
466
|
+
interface X402SupportedKind {
|
|
467
|
+
network: string;
|
|
468
|
+
scheme: PaymentScheme;
|
|
469
|
+
x402Version: number;
|
|
470
|
+
extra?: Record<string, unknown>;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Facilitator-wide capability response. Returned by `GET /v1/x402/supported`.
|
|
474
|
+
*
|
|
475
|
+
* `signers` carries the operator wallet addresses that sign settlement on the facilitator side, used by sellers for
|
|
476
|
+
* trust verification of the settlement source. `extensions` enumerates the facilitator-wide extension names so
|
|
477
|
+
* `inflowAccepts` can dispatch to the right handlers.
|
|
478
|
+
*/
|
|
479
|
+
interface X402FacilitatorSupportedResponse {
|
|
480
|
+
kinds: X402SupportedKind[];
|
|
481
|
+
extensions?: string[];
|
|
482
|
+
signers?: Record<string, string[]>;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Buyer-facing capability response. Returned by `GET /v1/transactions/x402-supported`. Deliberately narrower than
|
|
486
|
+
* {@link X402FacilitatorSupportedResponse}: facilitator-wide extension declarations and operator signer addresses have
|
|
487
|
+
* no actionable meaning on the buyer side and are intentionally omitted.
|
|
488
|
+
*/
|
|
489
|
+
interface X402BuyerSupportedResponse {
|
|
490
|
+
kinds: X402SupportedKind[];
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* On-chain asset metadata, per `(blockchain, currency)` pair. Read from `X402ConfigResponse.assets[]` by
|
|
494
|
+
* `inflowAccepts` when constructing `'exact'`-scheme entries.
|
|
495
|
+
*/
|
|
496
|
+
interface X402AssetInfo {
|
|
497
|
+
/**
|
|
498
|
+
* Default transfer method for this asset. `'eip3009'` and `'permit2'` for EVM assets; `'solana'` for Solana. The
|
|
499
|
+
* `(string & {})` branch leaves room for forward-compatible methods the SDK hasn't enumerated yet (e.g.
|
|
500
|
+
* `'erc7710'`).
|
|
501
|
+
*/
|
|
502
|
+
assetTransferMethod?: 'eip3009' | 'permit2' | 'solana' | (string & {});
|
|
503
|
+
/** Contract address (EVM) or mint (Solana). */
|
|
504
|
+
assetId: string;
|
|
505
|
+
/** Blockchain enum name as serialized in the config response. Opaque to the SDK. */
|
|
506
|
+
blockchain: string;
|
|
507
|
+
/** Currency code — e.g. `'USDC'`, `'USDT'`, `'PYUSD'`. */
|
|
508
|
+
currency: string;
|
|
509
|
+
/** On-chain decimal places for this asset (e.g. `6` for USDC on Base). */
|
|
510
|
+
decimals: number;
|
|
511
|
+
/** CAIP-2 network identifier (e.g. `'eip155:8453'`). Opaque to the SDK. */
|
|
512
|
+
network: string;
|
|
513
|
+
/**
|
|
514
|
+
* Permit2 spender address the facilitator will sign settlements through. Present on EVM assets that support Permit2;
|
|
515
|
+
* absent when the canonical x402ExactPermit2Proxy isn't deployed on the chain. Buyers should verify this equals
|
|
516
|
+
* {@link CONTRACTS.PERMIT2_PROXY} before signing.
|
|
517
|
+
*/
|
|
518
|
+
permit2Proxy?: string;
|
|
519
|
+
/** EIP-712 domain name. Present only for EVM assets. */
|
|
520
|
+
tokenName?: string;
|
|
521
|
+
/** EIP-712 domain version. Present only for EVM assets. */
|
|
522
|
+
tokenVersion?: string;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Receiving-wallet metadata, per blockchain. Read from `X402ConfigResponse.wallets[]` by `inflowAccepts` to fill the
|
|
526
|
+
* `payTo` field on `'exact'`-scheme entries.
|
|
527
|
+
*/
|
|
528
|
+
interface X402WalletInfo {
|
|
529
|
+
/** Chain-native address (EVM hex or Solana base58); used as `payTo` on `'exact'` entries. */
|
|
530
|
+
address: string;
|
|
531
|
+
/** Blockchain enum name — joins to `X402AssetInfo.blockchain`. Opaque to the SDK. */
|
|
532
|
+
blockchain: string;
|
|
533
|
+
/** Solana-only fee-payer address. */
|
|
534
|
+
feePayer?: string;
|
|
535
|
+
/** CAIP-2 network identifier (e.g. `'eip155:8453'`); matches `X402AssetInfo.network`. */
|
|
536
|
+
network: string;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Non-blockchain payment method metadata. Read from `X402ConfigResponse.paymentMethods[]` by `inflowAccepts` when
|
|
540
|
+
* constructing `'balance'` and (reserved) `'instrument'` entries.
|
|
541
|
+
*/
|
|
542
|
+
interface PaymentMethodInfo {
|
|
543
|
+
/** Scheme this method handles — `'balance'` today, `'instrument'` reserved. */
|
|
544
|
+
scheme: PaymentScheme;
|
|
545
|
+
/** Network identifier for the method. `'inflow:1'` for `'balance'`; CAIP-2 for any future on-chain method. */
|
|
546
|
+
network: string;
|
|
547
|
+
/** Recipient identifier — the seller UUID for `'balance'` / `'instrument'`. */
|
|
548
|
+
payTo: string;
|
|
549
|
+
/** Per-method decimal scale. */
|
|
550
|
+
decimals: number;
|
|
551
|
+
/** Method-specific extras. Optional on the wire. */
|
|
552
|
+
extra?: Record<string, unknown>;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Stateless seller config response. Returned by `GET /v1/x402/config`. The seller middleware consumes this to construct
|
|
556
|
+
* `PaymentRequired.accepts[]` at request time without per-route hard-coding.
|
|
557
|
+
*/
|
|
558
|
+
interface X402ConfigResponse {
|
|
559
|
+
/** Per-`(blockchain, currency)` on-chain asset metadata. */
|
|
560
|
+
assets: X402AssetInfo[];
|
|
561
|
+
/** Non-blockchain methods — `'balance'` and (reserved) `'instrument'`. */
|
|
562
|
+
paymentMethods: PaymentMethodInfo[];
|
|
563
|
+
/** Seller UUID — also the `payTo` value for non-blockchain schemes. */
|
|
564
|
+
sellerId: string;
|
|
565
|
+
/** Facilitator capabilities mirrored on the seller's config response. */
|
|
566
|
+
supported: X402SupportedKind[];
|
|
567
|
+
/** Per-blockchain receiving wallets. */
|
|
568
|
+
wallets: X402WalletInfo[];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export { ASSET_TRANSFER_METHODS, type BalancePayloadData, CONTRACTS, EXTRA_KEYS, type Environment, type ExactPayloadData, HEADERS, type HeaderBag, type InflowAnonymousClientOptions, InflowApiError, type InflowApiErrorInit, type InflowClientOptions, InflowHttpClient, type InflowPaymentPayload, type InflowPaymentPayloadData, type InstrumentPayloadData, type InstrumentType, NETWORKS, PAYLOAD_KEYS, type PaymentMethodInfo, type PaymentRequired, type PaymentRequirements, type PaymentScheme, type Permit2PayloadData, type RequestOptions, type ResolveBaseUrlOptions, SCHEMES, type SettleResponse, type X402AssetInfo, type X402BuyerSupportedResponse, type X402ConfigResponse, type X402FacilitatorSupportedResponse, type X402SupportedKind, X402VersionMismatchError, type X402WalletInfo, X402_VERSION, isBalancePayload, isExactPayload, isInstrumentPayload, isPermit2Payload, readHeader, resolveBaseUrl };
|