@dexterai/x402 3.8.0 → 3.9.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.
@@ -1,6 +1,6 @@
1
1
  import { RequestHandler } from 'express';
2
2
  import { ChannelStorage } from '@x402/evm/batch-settlement/server';
3
- import { b as CloseReceipt } from './types-DllrEG_Z.js';
3
+ import { b as CloseReceipt } from './types-CTl7yVq6.js';
4
4
 
5
5
  /**
6
6
  * Result of closing one channel from the seller side. Either a settlement
@@ -302,6 +302,25 @@ declare class EvmAdapter implements ChainAdapter {
302
302
  private getChainId;
303
303
  getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
304
304
  private encodeBalanceOf;
305
+ /**
306
+ * Confirm an EVM payment settled on-chain, after a post-payment timeout.
307
+ *
308
+ * EIP-3009 (`exact`): calls the token contract's
309
+ * `authorizationState(authorizer, nonce)` view — `true` means our exact
310
+ * signed authorization was consumed, i.e. the transfer settled. The nonce
311
+ * is the 32-byte value the SDK itself generated, so this is a definitive,
312
+ * surgical yes/no.
313
+ *
314
+ * Permit2: calls `Permit2.nonceBitmap(owner, wordPos)` and tests the bit
315
+ * for our nonce. A set bit means the Permit2 transfer was executed.
316
+ *
317
+ * For any other scheme (e.g. exact-approval) there is no clean
318
+ * nonce-consumed check — this throws, which the strategy reads as
319
+ * "unknown" and maps to `payment_unconfirmed`.
320
+ */
321
+ confirmSettlement(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
322
+ /** Raw `eth_call` returning the result hex word. Throws on RPC error. */
323
+ private ethCall;
305
324
  buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
306
325
  /**
307
326
  * Build a payment transaction for chains that use the approval-based scheme.
@@ -392,6 +411,26 @@ declare class SolanaAdapter implements ChainAdapter {
392
411
  isConnected(wallet: unknown): boolean;
393
412
  getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
394
413
  buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
414
+ /**
415
+ * Confirm a Solana payment settled on-chain, after a post-payment timeout.
416
+ *
417
+ * Solana has no EIP-3009-style "was this nonce consumed" view. Instead we
418
+ * scan recent signatures on the merchant's destination ATA and look for a
419
+ * transfer of exactly the expected amount. The window is naturally bounded:
420
+ * the payment transaction is only valid for ~150 slots (~60s) after the
421
+ * blockhash it was built against, so a settling transfer — if it happened —
422
+ * is among the most recent signatures on that account. We cap the scan at
423
+ * the 25 most recent signatures.
424
+ *
425
+ * This is strong but not surgical: it matches on (destination ATA, amount),
426
+ * not a unique nonce. A same-amount transfer to the same merchant inside
427
+ * the window from an unrelated payer could in principle match. In practice
428
+ * the blockhash window makes that vanishingly unlikely, and a false
429
+ * positive here only means we tell the caller "paid" when they were not —
430
+ * which is the safe direction (it discourages a retry; the caller verifies
431
+ * against their own wallet). A false negative maps to `payment_unconfirmed`.
432
+ */
433
+ confirmSettlement(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
395
434
  }
396
435
  /**
397
436
  * Create a Solana adapter instance
@@ -408,6 +447,50 @@ interface GenericWallet {
408
447
  /** Whether the wallet is connected and ready */
409
448
  connected: boolean;
410
449
  }
450
+ /**
451
+ * Everything an adapter needs to ask the chain "did this exact payment
452
+ * settle?" after the fact — without trusting the facilitator or the merchant.
453
+ *
454
+ * `buildTransaction` populates this on the {@link SignedTransaction} it
455
+ * returns. If a post-payment timeout fires, the strategy hands it back to
456
+ * {@link ChainAdapter.confirmSettlement}. A scheme that has no clean on-chain
457
+ * "was this consumed" check (e.g. EVM exact-approval) leaves it `undefined`,
458
+ * and the strategy falls back to reporting `payment_unconfirmed`.
459
+ */
460
+ type SettlementProbe = {
461
+ /** EVM EIP-3009 `transferWithAuthorization` — the default `exact` scheme. */
462
+ kind: 'eip3009';
463
+ /** The authorizer (payer) address — `authorization.from`. */
464
+ from: string;
465
+ /** The 32-byte authorization nonce the SDK generated. The unique key. */
466
+ nonce: string;
467
+ /** The token contract (USDC) — also the EIP-3009 contract exposing `authorizationState`. */
468
+ asset: string;
469
+ /** EVM chain id, decimal. */
470
+ chainId: number;
471
+ } | {
472
+ /** EVM Permit2 `permitWitnessTransferFrom`. */
473
+ kind: 'permit2';
474
+ /** The payer address — Permit2 nonces are namespaced per owner. */
475
+ from: string;
476
+ /** The Permit2 nonce (256-bit, decimal string). */
477
+ nonce: string;
478
+ /** EVM chain id, decimal. */
479
+ chainId: number;
480
+ } | {
481
+ /** Solana SPL transfer. No nonce-consumed view — confirmed by a windowed scan. */
482
+ kind: 'solana';
483
+ /** The buyer's source associated-token-account. */
484
+ sourceAta: string;
485
+ /** The merchant's destination associated-token-account — the address we scan. */
486
+ destinationAta: string;
487
+ /** The token mint. */
488
+ asset: string;
489
+ /** Atomic amount, as a string. */
490
+ amount: string;
491
+ /** The transaction's recent blockhash — bounds how far back the scan need look. */
492
+ blockhash: string;
493
+ };
411
494
  /**
412
495
  * Result of building and signing a transaction.
413
496
  *
@@ -423,6 +506,21 @@ interface SignedTransaction {
423
506
  signature?: string;
424
507
  /** Protocol extensions (e.g., erc20ApprovalGasSponsoring) to attach to the payment payload */
425
508
  extensions?: Record<string, unknown>;
509
+ /**
510
+ * Data needed to confirm settlement on-chain after a post-payment timeout.
511
+ * `undefined` for schemes with no clean on-chain confirmation check.
512
+ * See {@link SettlementProbe} and {@link ChainAdapter.confirmSettlement}.
513
+ */
514
+ settlementProbe?: SettlementProbe;
515
+ }
516
+ /**
517
+ * Outcome of an on-chain settlement check.
518
+ */
519
+ interface SettlementConfirmation {
520
+ /** True if the payment is confirmed settled on-chain. */
521
+ settled: boolean;
522
+ /** The settling transaction hash, when the check can recover it. */
523
+ txSignature?: string;
426
524
  }
427
525
  /**
428
526
  * Chain adapter interface - each chain implements this
@@ -476,6 +574,29 @@ interface ChainAdapter {
476
574
  * @param network - CAIP-2 network identifier
477
575
  */
478
576
  getDefaultRpcUrl(network: string): string;
577
+ /**
578
+ * Ask the chain whether a specific payment settled.
579
+ *
580
+ * Called after a post-payment timeout: the SDK sent the payment
581
+ * authorization, the merchant never responded, and we need to know whether
582
+ * the money actually moved before deciding what to tell the caller. This
583
+ * consults the chain directly via `rpcUrl` — it does not trust the
584
+ * facilitator or the merchant.
585
+ *
586
+ * Optional: an adapter that cannot confirm a given scheme may omit this
587
+ * method (or return `{ settled: false }` is wrong — see below). When the
588
+ * method is absent, or the {@link SettlementProbe} was `undefined`, the
589
+ * strategy falls back to reporting `payment_unconfirmed`.
590
+ *
591
+ * @param probe - The {@link SettlementProbe} captured at build time.
592
+ * @param rpcUrl - The RPC endpoint to query.
593
+ * @returns settled true/false, plus the tx hash when recoverable. An
594
+ * implementation that genuinely cannot tell should THROW rather than
595
+ * return `{ settled: false }` — a thrown error is treated as "unknown"
596
+ * (→ `payment_unconfirmed`), whereas `{ settled: false }` is treated as
597
+ * a definitive "the money did not move."
598
+ */
599
+ confirmSettlement?(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
479
600
  }
480
601
  /**
481
602
  * Configuration for creating a chain adapter
@@ -514,4 +635,4 @@ interface BalanceInfo {
514
635
  asset: string;
515
636
  }
516
637
 
517
- export { type AccessPassClientConfig as A, type BalanceInfo as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, type PaymentAccept as P, type SolanaWallet as S, type VerifyResponse as V, type WalletSet as W, X402Error as X, createEvmAdapter as a, type AccessPassTier as b, createSolanaAdapter as c, type AccessPassInfo as d, type SettleResponse as e, type PayToProvider as f, type PaymentRequired as g, type PayToContext as h, type PayToProviderDefaults as i, type AccessPassClaims as j, SolanaAdapter as k, EvmAdapter as l, type AdapterConfig as m, type SignedTransaction as n, isSolanaWallet as o, isEvmWallet as p };
638
+ export { type AccessPassClientConfig as A, type BalanceInfo as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, type PaymentAccept as P, type SettlementProbe as S, type VerifyResponse as V, type WalletSet as W, X402Error as X, type SolanaWallet as a, createEvmAdapter as b, createSolanaAdapter as c, type AccessPassTier as d, type AccessPassInfo as e, type SettleResponse as f, type PayToProvider as g, type PaymentRequired as h, type PayToContext as i, type PayToProviderDefaults as j, type AccessPassClaims as k, SolanaAdapter as l, EvmAdapter as m, type AdapterConfig as n, type SignedTransaction as o, isSolanaWallet as p, isEvmWallet as q };
@@ -302,6 +302,25 @@ declare class EvmAdapter implements ChainAdapter {
302
302
  private getChainId;
303
303
  getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
304
304
  private encodeBalanceOf;
305
+ /**
306
+ * Confirm an EVM payment settled on-chain, after a post-payment timeout.
307
+ *
308
+ * EIP-3009 (`exact`): calls the token contract's
309
+ * `authorizationState(authorizer, nonce)` view — `true` means our exact
310
+ * signed authorization was consumed, i.e. the transfer settled. The nonce
311
+ * is the 32-byte value the SDK itself generated, so this is a definitive,
312
+ * surgical yes/no.
313
+ *
314
+ * Permit2: calls `Permit2.nonceBitmap(owner, wordPos)` and tests the bit
315
+ * for our nonce. A set bit means the Permit2 transfer was executed.
316
+ *
317
+ * For any other scheme (e.g. exact-approval) there is no clean
318
+ * nonce-consumed check — this throws, which the strategy reads as
319
+ * "unknown" and maps to `payment_unconfirmed`.
320
+ */
321
+ confirmSettlement(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
322
+ /** Raw `eth_call` returning the result hex word. Throws on RPC error. */
323
+ private ethCall;
305
324
  buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
306
325
  /**
307
326
  * Build a payment transaction for chains that use the approval-based scheme.
@@ -392,6 +411,26 @@ declare class SolanaAdapter implements ChainAdapter {
392
411
  isConnected(wallet: unknown): boolean;
393
412
  getBalance(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<number>;
394
413
  buildTransaction(accept: PaymentAccept, wallet: unknown, rpcUrl?: string): Promise<SignedTransaction>;
414
+ /**
415
+ * Confirm a Solana payment settled on-chain, after a post-payment timeout.
416
+ *
417
+ * Solana has no EIP-3009-style "was this nonce consumed" view. Instead we
418
+ * scan recent signatures on the merchant's destination ATA and look for a
419
+ * transfer of exactly the expected amount. The window is naturally bounded:
420
+ * the payment transaction is only valid for ~150 slots (~60s) after the
421
+ * blockhash it was built against, so a settling transfer — if it happened —
422
+ * is among the most recent signatures on that account. We cap the scan at
423
+ * the 25 most recent signatures.
424
+ *
425
+ * This is strong but not surgical: it matches on (destination ATA, amount),
426
+ * not a unique nonce. A same-amount transfer to the same merchant inside
427
+ * the window from an unrelated payer could in principle match. In practice
428
+ * the blockhash window makes that vanishingly unlikely, and a false
429
+ * positive here only means we tell the caller "paid" when they were not —
430
+ * which is the safe direction (it discourages a retry; the caller verifies
431
+ * against their own wallet). A false negative maps to `payment_unconfirmed`.
432
+ */
433
+ confirmSettlement(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
395
434
  }
396
435
  /**
397
436
  * Create a Solana adapter instance
@@ -408,6 +447,50 @@ interface GenericWallet {
408
447
  /** Whether the wallet is connected and ready */
409
448
  connected: boolean;
410
449
  }
450
+ /**
451
+ * Everything an adapter needs to ask the chain "did this exact payment
452
+ * settle?" after the fact — without trusting the facilitator or the merchant.
453
+ *
454
+ * `buildTransaction` populates this on the {@link SignedTransaction} it
455
+ * returns. If a post-payment timeout fires, the strategy hands it back to
456
+ * {@link ChainAdapter.confirmSettlement}. A scheme that has no clean on-chain
457
+ * "was this consumed" check (e.g. EVM exact-approval) leaves it `undefined`,
458
+ * and the strategy falls back to reporting `payment_unconfirmed`.
459
+ */
460
+ type SettlementProbe = {
461
+ /** EVM EIP-3009 `transferWithAuthorization` — the default `exact` scheme. */
462
+ kind: 'eip3009';
463
+ /** The authorizer (payer) address — `authorization.from`. */
464
+ from: string;
465
+ /** The 32-byte authorization nonce the SDK generated. The unique key. */
466
+ nonce: string;
467
+ /** The token contract (USDC) — also the EIP-3009 contract exposing `authorizationState`. */
468
+ asset: string;
469
+ /** EVM chain id, decimal. */
470
+ chainId: number;
471
+ } | {
472
+ /** EVM Permit2 `permitWitnessTransferFrom`. */
473
+ kind: 'permit2';
474
+ /** The payer address — Permit2 nonces are namespaced per owner. */
475
+ from: string;
476
+ /** The Permit2 nonce (256-bit, decimal string). */
477
+ nonce: string;
478
+ /** EVM chain id, decimal. */
479
+ chainId: number;
480
+ } | {
481
+ /** Solana SPL transfer. No nonce-consumed view — confirmed by a windowed scan. */
482
+ kind: 'solana';
483
+ /** The buyer's source associated-token-account. */
484
+ sourceAta: string;
485
+ /** The merchant's destination associated-token-account — the address we scan. */
486
+ destinationAta: string;
487
+ /** The token mint. */
488
+ asset: string;
489
+ /** Atomic amount, as a string. */
490
+ amount: string;
491
+ /** The transaction's recent blockhash — bounds how far back the scan need look. */
492
+ blockhash: string;
493
+ };
411
494
  /**
412
495
  * Result of building and signing a transaction.
413
496
  *
@@ -423,6 +506,21 @@ interface SignedTransaction {
423
506
  signature?: string;
424
507
  /** Protocol extensions (e.g., erc20ApprovalGasSponsoring) to attach to the payment payload */
425
508
  extensions?: Record<string, unknown>;
509
+ /**
510
+ * Data needed to confirm settlement on-chain after a post-payment timeout.
511
+ * `undefined` for schemes with no clean on-chain confirmation check.
512
+ * See {@link SettlementProbe} and {@link ChainAdapter.confirmSettlement}.
513
+ */
514
+ settlementProbe?: SettlementProbe;
515
+ }
516
+ /**
517
+ * Outcome of an on-chain settlement check.
518
+ */
519
+ interface SettlementConfirmation {
520
+ /** True if the payment is confirmed settled on-chain. */
521
+ settled: boolean;
522
+ /** The settling transaction hash, when the check can recover it. */
523
+ txSignature?: string;
426
524
  }
427
525
  /**
428
526
  * Chain adapter interface - each chain implements this
@@ -476,6 +574,29 @@ interface ChainAdapter {
476
574
  * @param network - CAIP-2 network identifier
477
575
  */
478
576
  getDefaultRpcUrl(network: string): string;
577
+ /**
578
+ * Ask the chain whether a specific payment settled.
579
+ *
580
+ * Called after a post-payment timeout: the SDK sent the payment
581
+ * authorization, the merchant never responded, and we need to know whether
582
+ * the money actually moved before deciding what to tell the caller. This
583
+ * consults the chain directly via `rpcUrl` — it does not trust the
584
+ * facilitator or the merchant.
585
+ *
586
+ * Optional: an adapter that cannot confirm a given scheme may omit this
587
+ * method (or return `{ settled: false }` is wrong — see below). When the
588
+ * method is absent, or the {@link SettlementProbe} was `undefined`, the
589
+ * strategy falls back to reporting `payment_unconfirmed`.
590
+ *
591
+ * @param probe - The {@link SettlementProbe} captured at build time.
592
+ * @param rpcUrl - The RPC endpoint to query.
593
+ * @returns settled true/false, plus the tx hash when recoverable. An
594
+ * implementation that genuinely cannot tell should THROW rather than
595
+ * return `{ settled: false }` — a thrown error is treated as "unknown"
596
+ * (→ `payment_unconfirmed`), whereas `{ settled: false }` is treated as
597
+ * a definitive "the money did not move."
598
+ */
599
+ confirmSettlement?(probe: SettlementProbe, rpcUrl: string): Promise<SettlementConfirmation>;
479
600
  }
480
601
  /**
481
602
  * Configuration for creating a chain adapter
@@ -514,4 +635,4 @@ interface BalanceInfo {
514
635
  asset: string;
515
636
  }
516
637
 
517
- export { type AccessPassClientConfig as A, type BalanceInfo as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, type PaymentAccept as P, type SolanaWallet as S, type VerifyResponse as V, type WalletSet as W, X402Error as X, createEvmAdapter as a, type AccessPassTier as b, createSolanaAdapter as c, type AccessPassInfo as d, type SettleResponse as e, type PayToProvider as f, type PaymentRequired as g, type PayToContext as h, type PayToProviderDefaults as i, type AccessPassClaims as j, SolanaAdapter as k, EvmAdapter as l, type AdapterConfig as m, type SignedTransaction as n, isSolanaWallet as o, isEvmWallet as p };
638
+ export { type AccessPassClientConfig as A, type BalanceInfo as B, type ChainAdapter as C, type EvmWallet as E, type GenericWallet as G, type PaymentAccept as P, type SettlementProbe as S, type VerifyResponse as V, type WalletSet as W, X402Error as X, type SolanaWallet as a, createEvmAdapter as b, createSolanaAdapter as c, type AccessPassTier as d, type AccessPassInfo as e, type SettleResponse as f, type PayToProvider as g, type PaymentRequired as h, type PayToContext as i, type PayToProviderDefaults as j, type AccessPassClaims as k, SolanaAdapter as l, EvmAdapter as m, type AdapterConfig as n, type SignedTransaction as o, isSolanaWallet as p, isEvmWallet as q };
@@ -1,9 +1,83 @@
1
- import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept } from './types-htvWHuW3.js';
2
1
  import { SponsoredRecommendation, SponsoredAccessSettlementInfo } from '@dexterai/x402-ads-types';
2
+ import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept, S as SettlementProbe } from './types-RxdlGPaG.cjs';
3
+
4
+ /**
5
+ * Sponsored Access (Ads for Agents) — Client Helpers
6
+ *
7
+ * Extract sponsored recommendations from x402 payment receipts and
8
+ * fire impression beacons to confirm delivery to the ad network.
9
+ *
10
+ * Recommendations are injected by the facilitator after settlement
11
+ * via the `extensions["sponsored-access"]` field. Publishers who enable
12
+ * `sponsoredAccess: true` in their middleware also inject them into
13
+ * the JSON response body as `_x402_sponsored`.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { wrapFetch, getSponsoredRecommendations, fireImpressionBeacon } from '@dexterai/x402/client';
18
+ *
19
+ * const x402Fetch = wrapFetch(fetch, { walletPrivateKey: key });
20
+ * const response = await x402Fetch('https://api.example.com/data');
21
+ *
22
+ * const recs = getSponsoredRecommendations(response);
23
+ * if (recs) {
24
+ * console.log('Sponsored:', recs.map(r => `${r.sponsor}: ${r.description}`));
25
+ * await fireImpressionBeacon(response); // Confirm delivery to ad network
26
+ * }
27
+ * ```
28
+ */
29
+
30
+ /**
31
+ * Extract the full sponsored-access extension data from a payment receipt.
32
+ * Returns undefined if no sponsored-access extension is present.
33
+ */
34
+ declare function getSponsoredAccessInfo(response: Response): SponsoredAccessSettlementInfo | undefined;
35
+ /**
36
+ * Extract sponsored recommendations from an x402 payment response.
37
+ * Returns the recommendations array, or undefined if none present.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const recs = getSponsoredRecommendations(response);
42
+ * if (recs) {
43
+ * for (const rec of recs) {
44
+ * console.log(`${rec.sponsor}: ${rec.description} — ${rec.resourceUrl}`);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ declare function getSponsoredRecommendations(response: Response): SponsoredRecommendation[] | undefined;
50
+ /**
51
+ * Fire the impression beacon to confirm recommendation delivery to the ad network.
52
+ * This is a fire-and-forget GET request — failures are silently ignored.
53
+ *
54
+ * Call this after you've read the recommendations to help the ad network
55
+ * track delivery rates and verify impressions.
56
+ *
57
+ * @returns true if the beacon was fired (regardless of response), false if no beacon URL
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const recs = getSponsoredRecommendations(response);
62
+ * if (recs) {
63
+ * // Process recommendations...
64
+ * await fireImpressionBeacon(response);
65
+ * }
66
+ * ```
67
+ */
68
+ declare function fireImpressionBeacon(response: Response): Promise<boolean>;
3
69
 
4
70
  /**
5
71
  * x402 v2 Client
6
72
  *
73
+ * `createX402Client`, `X402Client`, and `X402ClientConfig` are
74
+ * @deprecated — slated for removal in `@dexterai/x402` 5.0 (~6 months out;
75
+ * longer cycle than the 4.0 batch because there are real consumers). Use
76
+ * `payAndFetch` from `@dexterai/x402/client` instead — it's the version-
77
+ * agnostic 2026+ client with a discriminated-union return type. The
78
+ * `getPaymentReceipt` helper and `PaymentReceipt` type in this file are NOT
79
+ * deprecated; they continue to support receipt-reading on any paid response.
80
+ *
7
81
  * Chain-agnostic client for x402 v2 payments.
8
82
  * Automatically detects 402 responses, finds a matching payment option,
9
83
  * builds the transaction with the appropriate chain adapter, and retries.
@@ -58,6 +132,9 @@ interface PaymentReceipt {
58
132
  declare function getPaymentReceipt(response: Response): PaymentReceipt | undefined;
59
133
  /**
60
134
  * Client configuration
135
+ *
136
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0 alongside
137
+ * `createX402Client` and `X402Client`. Use `PayAndFetchOptions` instead.
61
138
  */
62
139
  interface X402ClientConfig {
63
140
  /**
@@ -121,6 +198,24 @@ interface X402ClientConfig {
121
198
  * ```
122
199
  */
123
200
  onPaymentRequired?: (requirements: PaymentAccept) => boolean | Promise<boolean>;
201
+ /**
202
+ * Called the instant the signed payment authorization is sent to the
203
+ * merchant — after `buildTransaction`, immediately before the paid retry
204
+ * fetch. This is the point past which a timeout can no longer be treated
205
+ * as "no money moved": the facilitator may settle at any time once the
206
+ * authorization is in its hands.
207
+ *
208
+ * The callback receives the `accept` it is paying against (network, asset,
209
+ * amount, payTo) and the `settlementProbe` the adapter produced (or
210
+ * `undefined` for schemes with no on-chain confirmation). `payAndFetch`
211
+ * uses this to mark a payment as dispatched — so a post-payment abort is
212
+ * not misreported as a plain timeout — and keeps the probe so it can
213
+ * confirm settlement on-chain if the merchant never responds.
214
+ *
215
+ * Fire-and-forget — the return value is ignored, and a throw is swallowed
216
+ * (the payment proceeds regardless). Do not do slow work here.
217
+ */
218
+ onPaymentDispatched?: (accept: PaymentAccept, settlementProbe?: SettlementProbe) => void;
124
219
  /**
125
220
  * Maximum retry attempts for transient failures (network errors, 502/503).
126
221
  * Does not cause double payments — EIP-3009 nonces prevent replay.
@@ -135,6 +230,9 @@ interface X402ClientConfig {
135
230
  }
136
231
  /**
137
232
  * x402 Client interface
233
+ *
234
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0. Use `payAndFetch`
235
+ * directly instead of constructing a client object.
138
236
  */
139
237
  interface X402Client {
140
238
  /**
@@ -145,73 +243,26 @@ interface X402Client {
145
243
  }
146
244
  /**
147
245
  * Create an x402 v2 client
148
- */
149
- declare function createX402Client(config: X402ClientConfig): X402Client;
150
-
151
- /**
152
- * Sponsored Access (Ads for Agents) — Client Helpers
153
- *
154
- * Extract sponsored recommendations from x402 payment receipts and
155
- * fire impression beacons to confirm delivery to the ad network.
156
246
  *
157
- * Recommendations are injected by the facilitator after settlement
158
- * via the `extensions["sponsored-access"]` field. Publishers who enable
159
- * `sponsoredAccess: true` in their middleware also inject them into
160
- * the JSON response body as `_x402_sponsored`.
247
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0 (~6 months out — long
248
+ * cycle because of real production consumers). Use `payAndFetch` from
249
+ * `@dexterai/x402/client` instead it's version-agnostic across x402 v1 and
250
+ * v2 and returns a discriminated union for cleaner error handling.
161
251
  *
162
- * @example
252
+ * Migration:
163
253
  * ```typescript
164
- * import { wrapFetch, getSponsoredRecommendations, fireImpressionBeacon } from '@dexterai/x402/client';
165
- *
166
- * const x402Fetch = wrapFetch(fetch, { walletPrivateKey: key });
167
- * const response = await x402Fetch('https://api.example.com/data');
254
+ * // Before
255
+ * const client = createX402Client({ wallets });
256
+ * const res = await client.fetch(url);
168
257
  *
169
- * const recs = getSponsoredRecommendations(response);
170
- * if (recs) {
171
- * console.log('Sponsored:', recs.map(r => `${r.sponsor}: ${r.description}`));
172
- * await fireImpressionBeacon(response); // Confirm delivery to ad network
258
+ * // After
259
+ * import { payAndFetch } from '@dexterai/x402/client';
260
+ * const result = await payAndFetch(url, undefined, wallets);
261
+ * if (result.ok) {
262
+ * const res = result.response;
173
263
  * }
174
264
  * ```
175
265
  */
266
+ declare function createX402Client(config: X402ClientConfig): X402Client;
176
267
 
177
- /**
178
- * Extract the full sponsored-access extension data from a payment receipt.
179
- * Returns undefined if no sponsored-access extension is present.
180
- */
181
- declare function getSponsoredAccessInfo(response: Response): SponsoredAccessSettlementInfo | undefined;
182
- /**
183
- * Extract sponsored recommendations from an x402 payment response.
184
- * Returns the recommendations array, or undefined if none present.
185
- *
186
- * @example
187
- * ```typescript
188
- * const recs = getSponsoredRecommendations(response);
189
- * if (recs) {
190
- * for (const rec of recs) {
191
- * console.log(`${rec.sponsor}: ${rec.description} — ${rec.resourceUrl}`);
192
- * }
193
- * }
194
- * ```
195
- */
196
- declare function getSponsoredRecommendations(response: Response): SponsoredRecommendation[] | undefined;
197
- /**
198
- * Fire the impression beacon to confirm recommendation delivery to the ad network.
199
- * This is a fire-and-forget GET request — failures are silently ignored.
200
- *
201
- * Call this after you've read the recommendations to help the ad network
202
- * track delivery rates and verify impressions.
203
- *
204
- * @returns true if the beacon was fired (regardless of response), false if no beacon URL
205
- *
206
- * @example
207
- * ```typescript
208
- * const recs = getSponsoredRecommendations(response);
209
- * if (recs) {
210
- * // Process recommendations...
211
- * await fireImpressionBeacon(response);
212
- * }
213
- * ```
214
- */
215
- declare function fireImpressionBeacon(response: Response): Promise<boolean>;
216
-
217
- export { type PaymentReceipt as P, type X402ClientConfig as X, type X402Client as a, getSponsoredRecommendations as b, createX402Client as c, getSponsoredAccessInfo as d, fireImpressionBeacon as f, getPaymentReceipt as g };
268
+ export { type PaymentReceipt as P, type X402ClientConfig as X, getSponsoredAccessInfo as a, getPaymentReceipt as b, createX402Client as c, type X402Client as d, fireImpressionBeacon as f, getSponsoredRecommendations as g };