@lunora/x402 1.0.0-alpha.9 → 1.0.0-alpha.90
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.md +18 -0
- package/README.md +22 -4
- package/dist/charge/index.d.mts +82 -47
- package/dist/charge/index.d.ts +82 -47
- package/dist/charge/index.mjs +1 -1
- package/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-CX67Ktyc.mjs +1 -0
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-CwbBEtp1.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-DyOEuTCT.mjs +1 -0
- package/dist/packem_shared/createProcedureChargeGate-BidGWCmf.mjs +1 -0
- package/dist/packem_shared/{config.d-B-NYmHgG.d.ts → index.d-A-g7yKuO.d.mts} +122 -130
- package/dist/packem_shared/{config.d-B-NYmHgG.d.mts → index.d-A-g7yKuO.d.ts} +122 -130
- package/dist/packem_shared/optional-peer-BBhVxozi.mjs +1 -0
- package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
- package/dist/packem_shared/withX402-mUrRb9a2.mjs +1 -0
- package/dist/pay/index.d.mts +9 -58
- package/dist/pay/index.d.ts +9 -58
- package/dist/pay/index.mjs +1 -1
- package/package.json +21 -9
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-lUtljfJI.mjs +0 -1
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-gY9zXmGa.mjs +0 -1
- package/dist/packem_shared/EVM_NETWORKS-XOms9Rtk.mjs +0 -1
- package/dist/packem_shared/createChargeMiddleware-MQhSA6Wt.mjs +0 -1
- package/dist/packem_shared/createFacilitatorClient-Dj4Ll9xQ.mjs +0 -1
- package/dist/packem_shared/createPayFetch-CDZJaS13.mjs +0 -1
- package/dist/packem_shared/createProcedureChargeGate-Cfm5mD2y.mjs +0 -1
- package/dist/packem_shared/registerWallet-Cu4qF5tj.mjs +0 -1
- package/dist/packem_shared/toPaymentEventRow-D_kRVcb3.mjs +0 -1
- package/dist/packem_shared/withX402-D10895ct.mjs +0 -1
|
@@ -1,14 +1,72 @@
|
|
|
1
|
-
import { ClientEvmSigner } from '@x402/evm';
|
|
2
|
-
import { ClientSvmSigner } from '@x402/svm';
|
|
3
|
-
import { ProcessSettleSuccessResponse } from '@x402/core/http';
|
|
4
|
-
import { BeforePaymentCreationHook, PaymentPolicy, OnPaymentCreationFailureHook } from '@x402/core/client';
|
|
5
1
|
import { PaymentRequirements } from '@x402/core/types';
|
|
2
|
+
import { TransactionSigner } from '@solana/accounts';
|
|
3
|
+
/**
|
|
4
|
+
* ClientEvmSigner - Used by x402 clients to sign payment authorizations.
|
|
5
|
+
*
|
|
6
|
+
* Typically a viem LocalAccount:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const account = privateKeyToAccount('0x...');
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Or composed via `toClientEvmSigner(account, publicClient)`.
|
|
12
|
+
*/
|
|
13
|
+
type ClientEvmSigner = {
|
|
14
|
+
readonly address: `0x${string}`;
|
|
15
|
+
signTypedData(message: {
|
|
16
|
+
domain: Record<string, unknown>;
|
|
17
|
+
types: Record<string, unknown>;
|
|
18
|
+
primaryType: string;
|
|
19
|
+
message: Record<string, unknown>;
|
|
20
|
+
}): Promise<`0x${string}`>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional on-chain reads.
|
|
23
|
+
* Required only for extension enrichment (EIP-2612 / ERC-20 approval).
|
|
24
|
+
*/
|
|
25
|
+
readContract?(args: {
|
|
26
|
+
address: `0x${string}`;
|
|
27
|
+
abi: readonly unknown[];
|
|
28
|
+
functionName: string;
|
|
29
|
+
args?: readonly unknown[];
|
|
30
|
+
}): Promise<unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional: Signs a raw EIP-1559 transaction without broadcasting.
|
|
33
|
+
* Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.
|
|
34
|
+
*/
|
|
35
|
+
signTransaction?(args: {
|
|
36
|
+
to: `0x${string}`;
|
|
37
|
+
data: `0x${string}`;
|
|
38
|
+
nonce: number;
|
|
39
|
+
gas: bigint;
|
|
40
|
+
maxFeePerGas: bigint;
|
|
41
|
+
maxPriorityFeePerGas: bigint;
|
|
42
|
+
chainId: number;
|
|
43
|
+
}): Promise<`0x${string}`>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional: Gets the current transaction count (nonce) for an address.
|
|
46
|
+
* Required for ERC-20 approval gas sponsoring.
|
|
47
|
+
*/
|
|
48
|
+
getTransactionCount?(args: {
|
|
49
|
+
address: `0x${string}`;
|
|
50
|
+
}): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Optional: Estimates current gas fees per gas.
|
|
53
|
+
* Required for ERC-20 approval gas sponsoring.
|
|
54
|
+
*/
|
|
55
|
+
estimateFeesPerGas?(): Promise<{
|
|
56
|
+
maxFeePerGas: bigint;
|
|
57
|
+
maxPriorityFeePerGas: bigint;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Client-side signer for creating and signing Solana transactions
|
|
62
|
+
* This is a wrapper around TransactionSigner from @solana/kit
|
|
63
|
+
*/
|
|
64
|
+
type ClientSvmSigner = TransactionSigner;
|
|
6
65
|
/**
|
|
7
66
|
* A normalised record of one settled x402 payment. The settled `amount` is kept
|
|
8
67
|
* as its exact on-chain atomic-unit string (USDC has 6 decimals) — never coerced
|
|
9
68
|
* to a fractional-dollar number — so no precision is lost crossing the reporting
|
|
10
69
|
* seam.
|
|
11
|
-
* @experimental
|
|
12
70
|
*/
|
|
13
71
|
interface X402Receipt {
|
|
14
72
|
/** Settled amount in the asset's atomic base units (USDC: 6 decimals), as an exact string. */
|
|
@@ -34,26 +92,12 @@ interface X402Receipt {
|
|
|
34
92
|
* settlement, does not block the paid response on it, and swallows any error it
|
|
35
93
|
* throws — so a sink must never rely on being awaited or on its failures
|
|
36
94
|
* surfacing.
|
|
37
|
-
* @experimental
|
|
38
95
|
*/
|
|
39
96
|
type X402ReceiptSink = (receipt: X402Receipt) => Promise<void> | void;
|
|
40
|
-
/**
|
|
41
|
-
* Normalise a successful facilitator settlement into an {@link X402Receipt}.
|
|
42
|
-
* `resource` (the gated URL or procedure id) and `ts` are supplied by the caller —
|
|
43
|
-
* the settlement result carries neither. Prefers the actual settled `amount`
|
|
44
|
-
* (present for `upto`-scheme partial settlements) and falls back to the route's
|
|
45
|
-
* required amount for `exact`.
|
|
46
|
-
* @experimental
|
|
47
|
-
*/
|
|
48
|
-
declare const toReceipt: (settlement: ProcessSettleSuccessResponse, context: {
|
|
49
|
-
readonly resource: string;
|
|
50
|
-
readonly ts: number;
|
|
51
|
-
}) => X402Receipt;
|
|
52
97
|
/**
|
|
53
98
|
* A row for `@lunora/payment`'s durable `events` table. Deliberately a plain
|
|
54
99
|
* structural type — building one imports nothing from `@lunora/payment`, so the
|
|
55
100
|
* rails stay decoupled.
|
|
56
|
-
* @experimental
|
|
57
101
|
*/
|
|
58
102
|
interface PaymentEventRow {
|
|
59
103
|
/** Epoch milliseconds the settlement was recorded. */
|
|
@@ -81,47 +125,25 @@ interface PaymentEventRow {
|
|
|
81
125
|
* table (`packages/payment/src/schema.ts`). Amount / from / to / resource are
|
|
82
126
|
* intentionally not on this row — that card renders none of them; read them off
|
|
83
127
|
* the {@link X402Receipt} (e.g. into your own revenue table) if you need them.
|
|
84
|
-
* @experimental
|
|
85
128
|
*/
|
|
86
129
|
declare const toPaymentEventRow: (receipt: X402Receipt) => PaymentEventRow;
|
|
87
|
-
/**
|
|
88
|
-
* Network identity for `@lunora/x402`.
|
|
89
|
-
*
|
|
90
|
-
* `@x402/core` v2 speaks **CAIP-2** chain ids (`eip155:8453` for Base,
|
|
91
|
-
* `solana:5eyk…` for Solana mainnet) — `type Network = ` `${string}:${string}` ``.
|
|
92
|
-
* Lunora keeps ergonomic **friendly** names (`"base"`, `"base-sepolia"`) as the
|
|
93
|
-
* public surface and maps them to CAIP-2 here, at the single seam where we hand a
|
|
94
|
-
* network to the SDK. A raw CAIP-2 string is also accepted as a power-user escape
|
|
95
|
-
* hatch (e.g. a chain we don't yet have a friendly alias for).
|
|
96
|
-
*
|
|
97
|
-
* The friendly set is intentionally scoped to chains `@x402/evm` / `@x402/svm`
|
|
98
|
-
* can settle the ergonomic `price:"$0.01"` path on out of the box (i.e. chains in
|
|
99
|
-
* their `DEFAULT_STABLECOINS` registry). Notably that excludes Optimism and
|
|
100
|
-
* Avalanche today — advertising them would 500 at settlement — so they are not
|
|
101
|
-
* friendly aliases; a caller who needs them can still pass a raw CAIP-2 id with an
|
|
102
|
-
* explicit asset.
|
|
103
|
-
*/
|
|
104
130
|
/**
|
|
105
131
|
* A CAIP-2 chain identifier, e.g. `"eip155:8453"` (Base) or `"solana:5eyk…"`.
|
|
106
|
-
* @experimental
|
|
107
132
|
*/
|
|
108
133
|
type Caip2 = `${string}:${string}`;
|
|
109
134
|
/**
|
|
110
135
|
* Friendly network names Lunora maps to CAIP-2 for `@x402/core`.
|
|
111
|
-
* @experimental
|
|
112
136
|
*/
|
|
113
137
|
type FriendlyNetwork = "arbitrum" | "arbitrum-sepolia" | "base" | "base-sepolia" | "ethereum" | "polygon" | "solana" | "solana-devnet";
|
|
114
138
|
/**
|
|
115
139
|
* A network Lunora can settle on: a {@link FriendlyNetwork} alias (mapped to
|
|
116
140
|
* CAIP-2 internally) or a raw {@link Caip2} id for chains without a friendly name.
|
|
117
|
-
* @experimental
|
|
118
141
|
*/
|
|
119
142
|
type X402Network = Caip2 | FriendlyNetwork;
|
|
120
143
|
/**
|
|
121
144
|
* Friendly name → CAIP-2 id. Values verified against `@x402/evm` and `@x402/svm`
|
|
122
145
|
* `DEFAULT_STABLECOINS` at 2.17.0. `base` / `base-sepolia` are the primary
|
|
123
146
|
* prod / test pair.
|
|
124
|
-
* @experimental
|
|
125
147
|
*/
|
|
126
148
|
declare const NETWORK_TO_CAIP2: {
|
|
127
149
|
readonly arbitrum: "eip155:42161";
|
|
@@ -135,55 +157,100 @@ declare const NETWORK_TO_CAIP2: {
|
|
|
135
157
|
};
|
|
136
158
|
/**
|
|
137
159
|
* EVM friendly networks (signed via `@x402/evm` + viem).
|
|
138
|
-
* @experimental
|
|
139
160
|
*/
|
|
140
161
|
declare const EVM_NETWORKS: readonly ["arbitrum", "arbitrum-sepolia", "base", "base-sepolia", "ethereum", "polygon"];
|
|
141
162
|
/**
|
|
142
163
|
* Solana friendly networks (signed via `@x402/svm`).
|
|
143
|
-
* @experimental
|
|
144
164
|
*/
|
|
145
165
|
declare const SVM_NETWORKS: readonly ["solana", "solana-devnet"];
|
|
146
166
|
/**
|
|
147
167
|
* Resolve a network to its CAIP-2 id. Friendly aliases are looked up; a value
|
|
148
168
|
* that already looks like CAIP-2 (`namespace:reference`) passes through.
|
|
149
|
-
* @experimental
|
|
150
169
|
*/
|
|
151
170
|
declare const toCaip2: (network: X402Network) => Caip2;
|
|
152
171
|
/**
|
|
153
172
|
* True when `network` settles on an EVM chain (viem signer path).
|
|
154
|
-
* @experimental
|
|
155
173
|
*/
|
|
156
174
|
declare const isEvmNetwork: (network: X402Network) => boolean;
|
|
157
175
|
/**
|
|
158
176
|
* True when `network` settles on Solana (`@x402/svm` signer path).
|
|
159
|
-
* @experimental
|
|
160
177
|
*/
|
|
161
178
|
declare const isSvmNetwork: (network: X402Network) => boolean;
|
|
162
179
|
/**
|
|
163
|
-
* USDC
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
180
|
+
* USDC uses 6 decimals, so a USD price converts to atomic base units at `10 ** 6`.
|
|
181
|
+
* This is only the *default* for the standalone {@link usdToAtomic} helper —
|
|
182
|
+
* a spend policy never assumes it, and scales each requirement by the decimals of
|
|
183
|
+
* the asset it actually names (see {@link SpendPolicy.allowedAssets}).
|
|
167
184
|
*/
|
|
168
185
|
declare const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
186
|
+
/**
|
|
187
|
+
* A stablecoin an agent wallet may pay in, and the decimals its atomic amounts are
|
|
188
|
+
* denominated in.
|
|
189
|
+
*
|
|
190
|
+
* `decimals` is required and explicit: a 402 server names the token contract to
|
|
191
|
+
* transfer, and the same atomic amount means a wildly different sum in a 6-decimal
|
|
192
|
+
* versus an 18-decimal token. Assuming a decimal count is how a tiny USD cap comes
|
|
193
|
+
* to authorise a large transfer, so the caller states it per asset. Note
|
|
194
|
+
* `@x402/evm`'s own `DEFAULT_STABLECOINS` registry is *not* uniformly 6-decimal
|
|
195
|
+
* (MegaUSD and Mezo USD are 18), which is exactly why it can't be trusted as a gate.
|
|
196
|
+
*/
|
|
197
|
+
interface AllowedAsset {
|
|
198
|
+
/** Token contract (EVM) or mint (SVM) address. Matched case-insensitively on EVM, exactly on SVM. */
|
|
199
|
+
readonly asset: string;
|
|
200
|
+
/** Atomic base-unit decimals for this asset. Used to scale the USD caps — must match the token on chain. */
|
|
201
|
+
readonly decimals: number;
|
|
202
|
+
/** The network this asset lives on. Friendly names are resolved to CAIP-2. */
|
|
203
|
+
readonly network: X402Network;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The assets a policy allows when it doesn't name its own — the canonical
|
|
207
|
+
* 6-decimal, dollar-pegged USDC on each network Lunora has a friendly alias for.
|
|
208
|
+
*
|
|
209
|
+
* Deliberately a small hand-mirrored table rather than `@x402/evm`'s
|
|
210
|
+
* `DEFAULT_STABLECOINS`: that registry mixes 6- and 18-decimal assets, and importing
|
|
211
|
+
* it would pull viem into every bundle that touches a policy (the scheme modules are
|
|
212
|
+
* dynamically imported for exactly that reason — see `wallet.ts`). Addresses verified
|
|
213
|
+
* against `@x402/evm` `DEFAULT_STABLECOINS` and `@x402/svm` `USDC_*_ADDRESS` at 2.19.0.
|
|
214
|
+
*
|
|
215
|
+
* `ethereum` (`eip155:1`) is absent — the SDK ships no default stablecoin for it, so
|
|
216
|
+
* paying there needs an explicit {@link SpendPolicy.allowedAssets} entry.
|
|
217
|
+
*/
|
|
218
|
+
declare const DEFAULT_ALLOWED_ASSETS: ReadonlyArray<AllowedAsset>;
|
|
169
219
|
/**
|
|
170
220
|
* Spend limits and approval gates for an agent wallet. At least one bound must be
|
|
171
221
|
* set — see {@link assertBoundedPolicy} — or the pay rail refuses to build.
|
|
172
222
|
*
|
|
173
223
|
* Caps are denominated in USD (the stablecoin's dollar value); addresses and
|
|
174
224
|
* networks are matched against the requirement the server offers.
|
|
175
|
-
* @experimental
|
|
176
225
|
*/
|
|
177
226
|
interface SpendPolicy {
|
|
227
|
+
/**
|
|
228
|
+
* Asset allowlist, each entry carrying its own `decimals` (defaults to
|
|
229
|
+
* {@link DEFAULT_ALLOWED_ASSETS} — canonical USDC per friendly network).
|
|
230
|
+
*
|
|
231
|
+
* This is a **security gate, not a convenience**: the server picks which token
|
|
232
|
+
* contract gets transferred, so a policy that only caps a USD amount caps nothing
|
|
233
|
+
* until the asset behind that amount is pinned. A requirement naming an asset
|
|
234
|
+
* outside this list is refused, and the USD caps are scaled by the matched entry's
|
|
235
|
+
* `decimals` — never by an assumed decimal count.
|
|
236
|
+
*
|
|
237
|
+
* Every entry must be dollar-pegged: the caps are USD, and the per-run ledger sums
|
|
238
|
+
* atomic units across payments, so a non-$1 asset silently mis-prices both.
|
|
239
|
+
*/
|
|
240
|
+
readonly allowedAssets?: ReadonlyArray<AllowedAsset>;
|
|
178
241
|
/** Network allowlist. When set, only these networks may be paid on. */
|
|
179
242
|
readonly allowedNetworks?: ReadonlyArray<X402Network>;
|
|
180
243
|
/** Recipient allowlist. When set, only these `payTo` addresses may be paid. */
|
|
181
244
|
readonly allowedRecipients?: ReadonlyArray<string>;
|
|
182
|
-
/** Stablecoin decimals for USD→atomic conversion (default {@link DEFAULT_STABLECOIN_DECIMALS}). */
|
|
183
|
-
readonly decimals?: number;
|
|
184
245
|
/** Hard ceiling on a single payment, in USD. */
|
|
185
246
|
readonly maxPerCall?: X402Price;
|
|
186
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* Hard ceiling on cumulative spend by one pay rail, in USD. The ledger lives
|
|
249
|
+
* in memory on the rail, so the cap covers one `createX402Pay` result, and for
|
|
250
|
+
* `ctx.x402` one function invocation (codegen builds a rail per ctx). It is not
|
|
251
|
+
* a budget across invocations: for that, keep a counter in durable state (a
|
|
252
|
+
* Durable Object, a table) and check it in `onPaymentRequired`.
|
|
253
|
+
*/
|
|
187
254
|
readonly maxPerRun?: X402Price;
|
|
188
255
|
/**
|
|
189
256
|
* Approval gate. Called with the selected requirement before signing; return
|
|
@@ -192,87 +259,20 @@ interface SpendPolicy {
|
|
|
192
259
|
*/
|
|
193
260
|
readonly onPaymentRequired?: (requirement: PaymentRequirements) => Promise<boolean> | boolean;
|
|
194
261
|
}
|
|
195
|
-
/**
|
|
196
|
-
* A running spend ledger the per-run cap is measured (and reserved) against.
|
|
197
|
-
* @experimental
|
|
198
|
-
*/
|
|
199
|
-
interface SpendState {
|
|
200
|
-
/** Reserve a payment (atomic base units) against the running total, before it is signed. */
|
|
201
|
-
readonly add: (amount: bigint) => void;
|
|
202
|
-
/** Release a previously reserved amount (atomic base units) — e.g. a declined or failed payment. Clamps at 0. */
|
|
203
|
-
readonly release: (amount: bigint) => void;
|
|
204
|
-
/** Cumulative spend so far, in atomic base units. */
|
|
205
|
-
readonly spentAtomic: bigint;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* A fresh spend ledger. One per wallet instance; the guard reserves into it and
|
|
209
|
-
* releases from it.
|
|
210
|
-
* @experimental
|
|
211
|
-
*/
|
|
212
|
-
declare const createSpendState: () => SpendState;
|
|
213
262
|
/**
|
|
214
263
|
* Convert a USD amount (`0.01`, `"0.01"`, or the `"$0.01"` shorthand) to atomic
|
|
215
264
|
* stablecoin base units, exactly — parsed digit-by-digit so no binary-float drift
|
|
216
265
|
* can round a cap the wrong way. Throws on a malformed amount (including
|
|
217
266
|
* exponential notation like `"1e-7"`, which a decimal string never needs).
|
|
218
|
-
* @experimental
|
|
219
267
|
*/
|
|
220
268
|
declare const usdToAtomic: (usd: X402Price, decimals?: number) => bigint;
|
|
221
|
-
/**
|
|
222
|
-
* A `PaymentPolicy` that narrows the server's offered requirements to those a
|
|
223
|
-
* bounded wallet may pay: within the per-call cap, to an allowed recipient, on an
|
|
224
|
-
* allowed network. An empty result means the client cannot pay — fail-closed.
|
|
225
|
-
* @experimental
|
|
226
|
-
*/
|
|
227
|
-
declare const buildSpendPolicy: (policy: SpendPolicy) => PaymentPolicy;
|
|
228
|
-
/**
|
|
229
|
-
* A `BeforePaymentCreationHook` enforcing the stateful bounds the stateless
|
|
230
|
-
* {@link buildSpendPolicy} filter can't: the cumulative per-run cap and the async
|
|
231
|
-
* confirmation gate. Aborts (no signature) when either would be violated.
|
|
232
|
-
*
|
|
233
|
-
* The per-run cap is *reserved* into `state` as soon as the check passes — before
|
|
234
|
-
* the `await policy.onPaymentRequired` below, and before `@x402/core` ever attempts
|
|
235
|
-
* to sign — not recorded afterwards. This closes a check-then-act race: without an
|
|
236
|
-
* atomic reserve, N concurrent payments could each read the same `spentAtomic`,
|
|
237
|
-
* all pass the cap check, and all record, overspending the cap by up to
|
|
238
|
-
* (N−1)×maxPerCall. A declined confirmation releases the reservation before this
|
|
239
|
-
* hook returns; {@link releaseSpendOnFailure} releases it if the signature itself
|
|
240
|
-
* later fails. The reservation is intentionally *not* released on success — a
|
|
241
|
-
* committed payment stays counted.
|
|
242
|
-
* @experimental
|
|
243
|
-
*/
|
|
244
|
-
declare const buildPaymentGuard: (policy: SpendPolicy, state: SpendState) => BeforePaymentCreationHook;
|
|
245
|
-
/**
|
|
246
|
-
* An `OnPaymentCreationFailureHook` that releases a reservation
|
|
247
|
-
* {@link buildPaymentGuard} made when the scheme's signature creation itself
|
|
248
|
-
* throws (network error, wallet error, …) after the guard already approved and
|
|
249
|
-
* reserved the amount. Without this, a failed signature would permanently
|
|
250
|
-
* over-count against the per-run cap for the rest of the run — fail-closed, but
|
|
251
|
-
* needlessly so when the client (`wrapFetchWithPayment`) may retry.
|
|
252
|
-
* @experimental
|
|
253
|
-
*/
|
|
254
|
-
declare const releaseSpendOnFailure: (state: SpendState) => OnPaymentCreationFailureHook;
|
|
255
|
-
/**
|
|
256
|
-
* Guard at wallet-build time: refuse a policy with no bound whatsoever. Signing
|
|
257
|
-
* money on an agent's behalf with unlimited spend authority is never the intent,
|
|
258
|
-
* so this fails loudly rather than defaulting to unbounded.
|
|
259
|
-
*
|
|
260
|
-
* `allowedNetworks` / `allowedRecipients` narrow *where* a payment can go, but
|
|
261
|
-
* neither caps *how much* — a policy with only an allowlist still authorises
|
|
262
|
-
* unlimited spend to any recipient it permits. Only `maxPerCall`, `maxPerRun`, or
|
|
263
|
-
* a dynamic `onPaymentRequired` gate actually bound spend, so only those count here.
|
|
264
|
-
* @experimental
|
|
265
|
-
*/
|
|
266
|
-
declare const assertBoundedPolicy: (policy: SpendPolicy) => void;
|
|
267
269
|
/**
|
|
268
270
|
* The public, Coinbase-operated facilitator (verify + settle). It needs no API
|
|
269
271
|
* key. Override with a self-hosted or CDP facilitator via {@link FacilitatorConfig}.
|
|
270
|
-
* @experimental
|
|
271
272
|
*/
|
|
272
273
|
declare const DEFAULT_FACILITATOR_URL = "https://x402.org/facilitator";
|
|
273
274
|
/**
|
|
274
275
|
* How to reach a facilitator's `/verify` + `/settle` endpoints.
|
|
275
|
-
* @experimental
|
|
276
276
|
*/
|
|
277
277
|
interface FacilitatorConfig {
|
|
278
278
|
/** Extra headers for a private facilitator (e.g. a CDP bearer token). */
|
|
@@ -286,17 +286,14 @@ interface FacilitatorConfig {
|
|
|
286
286
|
* to the network's stablecoin base units (USDC has 6 decimals) at challenge
|
|
287
287
|
* time. (Kept `number | string` rather than a `` `$${string}` `` template
|
|
288
288
|
* member — the template is subsumed by `string`, so it only adds noise.)
|
|
289
|
-
* @experimental
|
|
290
289
|
*/
|
|
291
290
|
type X402Price = number | string;
|
|
292
291
|
/**
|
|
293
292
|
* An EVM recipient address (the merchant wallet that receives settlement).
|
|
294
|
-
* @experimental
|
|
295
293
|
*/
|
|
296
294
|
type EvmAddress = `0x${string}`;
|
|
297
295
|
/**
|
|
298
296
|
* Recipient wallet the facilitator settles payments to, per network family.
|
|
299
|
-
* @experimental
|
|
300
297
|
*/
|
|
301
298
|
interface X402Recipient {
|
|
302
299
|
/** EVM payout address (required for EVM networks). */
|
|
@@ -307,7 +304,6 @@ interface X402Recipient {
|
|
|
307
304
|
/**
|
|
308
305
|
* Server-side (charge rail) config. The server needs only a **recipient
|
|
309
306
|
* address** — no private key — because the facilitator performs settlement.
|
|
310
|
-
* @experimental
|
|
311
307
|
*/
|
|
312
308
|
interface X402ChargeConfig {
|
|
313
309
|
readonly facilitator?: FacilitatorConfig;
|
|
@@ -329,7 +325,6 @@ interface X402ChargeConfig {
|
|
|
329
325
|
* Client-side (pay rail) config. The signer holds spending authority, so the
|
|
330
326
|
* pay rail is ActionCtx-only and MUST be paired with a spend `policy` — the pay
|
|
331
327
|
* rail refuses to build if the policy is unbounded.
|
|
332
|
-
* @experimental
|
|
333
328
|
*/
|
|
334
329
|
interface X402PayConfig {
|
|
335
330
|
/** Network to transact on. Determines the signer family (EVM vs SVM). */
|
|
@@ -349,7 +344,6 @@ interface X402PayConfig {
|
|
|
349
344
|
* custody is `@coinbase/cdp-sdk`.) EVM only today; for CDP on Solana, build a
|
|
350
345
|
* `@solana/kit` signer around your CDP account and pass it via the `"signer"`
|
|
351
346
|
* escape hatch.
|
|
352
|
-
* @experimental
|
|
353
347
|
*/
|
|
354
348
|
interface X402CdpSignerConfig {
|
|
355
349
|
/** CDP account name to get-or-create and sign with. */
|
|
@@ -381,7 +375,6 @@ interface X402CdpSignerConfig {
|
|
|
381
375
|
* Wired today: raw-key (EVM + SVM), the user-supplied signer (both families),
|
|
382
376
|
* and CDP-managed EVM custody. CDP on Solana is not yet wired — use the escape
|
|
383
377
|
* hatch.
|
|
384
|
-
* @experimental
|
|
385
378
|
*/
|
|
386
379
|
type X402SignerConfig = X402CdpSignerConfig | {
|
|
387
380
|
/** Name of the `ctx.secrets` entry holding the private key. */
|
|
@@ -398,7 +391,6 @@ type X402SignerConfig = X402CdpSignerConfig | {
|
|
|
398
391
|
};
|
|
399
392
|
/**
|
|
400
393
|
* Resolve a facilitator's base URL, applying the public default.
|
|
401
|
-
* @experimental
|
|
402
394
|
*/
|
|
403
395
|
declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
|
|
404
|
-
export { Caip2 as C,
|
|
396
|
+
export { AllowedAsset as A, type Caip2 as C, DEFAULT_ALLOWED_ASSETS as D, EvmAddress as E, type FacilitatorConfig as F, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, type SpendPolicy as S, X402PayConfig as X, DEFAULT_FACILITATOR_URL as a, DEFAULT_STABLECOIN_DECIMALS as b, type X402CdpSignerConfig as c, type X402Network as d, type X402Price as e, type X402SignerConfig as f, type isSvmNetwork as g, X402ChargeConfig as h, isEvmNetwork as i, X402Receipt as j, X402ReceiptSink as k, X402Recipient as l, toPaymentEventRow as m, EVM_NETWORKS as n, FriendlyNetwork as o, SVM_NETWORKS as p, resolveFacilitatorUrl as r, toCaip2 as t, usdToAtomic as u };
|