@x402x/extensions 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Chain, Address as Address$1 } from 'viem';
2
- import { PaymentRequirements, ResourceServerExtension, Network, SchemeNetworkFacilitator, PaymentPayload } from '@x402/core/types';
1
+ import { Network, PaymentRequirements, ResourceServerExtension, SchemeNetworkFacilitator, PaymentPayload, SchemeNetworkClient } from '@x402/core/types';
3
2
  export { Network, PaymentPayload, PaymentRequirements } from '@x402/core/types';
3
+ import { Chain, Address as Address$1 } from 'viem';
4
4
  import { x402ResourceServer } from '@x402/core/server';
5
+ import { x402Client } from '@x402/core/client';
5
6
 
6
7
  /**
7
8
  * Type definitions for @x402x/extensions
@@ -316,69 +317,100 @@ declare function validateCommitmentParams(params: CommitmentParams): void;
316
317
  * Network configuration for x402x
317
318
  *
318
319
  * Contains deployed contract addresses and configuration for each supported network.
319
- * Uses official x402 v2 CAIP-2 network identifiers.
320
+ * Uses official x402 v2 CAIP-2 network identifiers as keys.
320
321
  */
321
322
 
322
323
  /**
323
324
  * Network configurations for all supported networks
324
325
  *
325
- * Uses getNetworkId() and getDefaultAsset() to ensure consistency
326
- * with CAIP-2 network identifiers.
326
+ * Uses CAIP-2 format as keys for consistency with x402 v2 protocol.
327
+ * This ensures compatibility across different ecosystems and simplifies
328
+ * adding new networks (only need chain ID).
327
329
  */
328
- declare const networks: Record<string, NetworkConfig>;
330
+ declare const networks: Record<Network, NetworkConfig>;
329
331
  /**
330
- * Get network configuration by network name
332
+ * Get network configuration by network identifier
333
+ *
334
+ * Accepts both CAIP-2 format (preferred) and human-readable network names (legacy).
335
+ * This provides backward compatibility while encouraging migration to CAIP-2.
331
336
  *
332
- * @param network - Network name (e.g., 'base-sepolia', 'skale-base-sepolia')
337
+ * @param network - Network identifier, accepts either:
338
+ * - CAIP-2 format (preferred): 'eip155:84532', 'eip155:8453'
339
+ * - Human-readable name (legacy): 'base-sepolia', 'base'
333
340
  * @returns Network configuration
334
341
  * @throws Error if network is not supported
335
342
  *
336
343
  * @example
337
344
  * ```typescript
338
- * const config = getNetworkConfig('base-sepolia');
345
+ * // Preferred: CAIP-2 format
346
+ * const config = getNetworkConfig('eip155:84532');
347
+ *
348
+ * // Legacy: human-readable name
349
+ * const config2 = getNetworkConfig('base-sepolia');
350
+ *
339
351
  * console.log(config.settlementRouter);
340
352
  * ```
341
353
  */
342
- declare function getNetworkConfig(network: string): NetworkConfig;
354
+ declare function getNetworkConfig(network: string | Network): NetworkConfig;
343
355
  /**
344
356
  * Check if a network is supported
345
357
  *
346
- * @param network - Network name to check
358
+ * Accepts both CAIP-2 format and human-readable network names.
359
+ *
360
+ * @param network - Network identifier (CAIP-2 or human-readable name)
347
361
  * @returns True if network is supported
348
362
  *
349
363
  * @example
350
364
  * ```typescript
351
- * if (isNetworkSupported('base-sepolia')) {
365
+ * if (isNetworkSupported('eip155:84532')) {
352
366
  * // proceed...
353
367
  * }
368
+ *
369
+ * if (isNetworkSupported('base-sepolia')) {
370
+ * // also works...
371
+ * }
354
372
  * ```
355
373
  */
356
- declare function isNetworkSupported(network: string): boolean;
374
+ declare function isNetworkSupported(network: string | Network): boolean;
357
375
  /**
358
- * Get list of all supported network names (human-readable identifiers)
376
+ * Get list of all supported network aliases (v1 configuration names)
359
377
  *
360
- * Returns user-friendly network names like "base-sepolia", "base", etc.
378
+ * Returns user-friendly network aliases like "base-sepolia", "base", etc.
379
+ * These aliases are used for configuration files and backward compatibility.
361
380
  * Use this for UI display, configuration, and user-facing operations.
362
381
  *
363
- * @returns Array of supported network names
382
+ * This function provides backward compatibility by returning v1 aliases
383
+ * even though the internal storage uses CAIP-2 format.
384
+ *
385
+ * @returns Array of v1 network aliases
364
386
  *
365
387
  * @example
366
388
  * ```typescript
367
- * const networks = getSupportedNetworkNames();
389
+ * const aliases = getSupportedNetworkAliases();
368
390
  * // => ['base-sepolia', 'base', 'x-layer-testnet', ...]
369
391
  *
370
392
  * // For UI dropdown
371
393
  * <select>
372
- * {networks.map(name => <option key={name}>{name}</option>)}
394
+ * {aliases.map(alias => <option key={alias}>{alias}</option>)}
373
395
  * </select>
374
396
  * ```
375
397
  */
376
- declare function getSupportedNetworkNames(): string[];
398
+ declare function getSupportedNetworkAliases(): string[];
377
399
  /**
378
- * @deprecated Use getSupportedNetworkNames() instead for clarity
379
- * Get list of all supported networks
400
+ * Get list of all supported networks (CAIP-2 format)
401
+ *
402
+ * Returns network identifiers in CAIP-2 format (e.g., "eip155:84532").
403
+ * This is the canonical format used internally and in x402 v2.
404
+ *
405
+ * @returns Array of CAIP-2 network identifiers
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * const networks = getSupportedNetworks();
410
+ * // => ['eip155:84532', 'eip155:8453', 'eip155:1952', ...]
411
+ * ```
380
412
  */
381
- declare function getSupportedNetworks(): string[];
413
+ declare function getSupportedNetworks(): Network[];
382
414
 
383
415
  /**
384
416
  * Chain definitions for x402x supported networks
@@ -388,24 +420,27 @@ declare function getSupportedNetworks(): string[];
388
420
  */
389
421
 
390
422
  /**
391
- * Get viem chain configuration for a network name
423
+ * Get viem chain configuration for a network
392
424
  *
425
+ * Accepts both CAIP-2 format (preferred) and human-readable network names (legacy).
393
426
  * Checks custom chains first, then falls back to viem's standard chains.
394
427
  *
395
- * @param network - Network name (e.g., "base-sepolia", "x-layer-testnet")
428
+ * @param network - Network identifier (CAIP-2 or human-readable name)
396
429
  * @returns Viem chain configuration
397
430
  * @throws Error if network is not supported
398
431
  *
399
432
  * @example
400
433
  * ```typescript
401
- * const chain = getChain("x-layer-testnet");
434
+ * // Preferred: CAIP-2 format
435
+ * const chain = getChain("eip155:1952");
402
436
  * // => { id: 1952, name: "X Layer Testnet", ... }
403
437
  *
438
+ * // Legacy: human-readable name
404
439
  * const baseChain = getChain("base-sepolia");
405
440
  * // => { id: 84532, name: "Base Sepolia", ... }
406
441
  * ```
407
442
  */
408
- declare function getChain(network: string): Chain;
443
+ declare function getChain(network: string | Network): Chain;
409
444
  /**
410
445
  * Get viem chain configuration by chain ID
411
446
  *
@@ -536,17 +571,24 @@ declare namespace TransferHook {
536
571
  /**
537
572
  * Get TransferHook address for a specific network
538
573
  *
539
- * @param network - Network name (e.g., 'base-sepolia')
574
+ * Accepts both CAIP-2 format (preferred) and human-readable network names (legacy).
575
+ *
576
+ * @param network - Network identifier (CAIP-2 or human-readable name)
540
577
  * @returns TransferHook contract address
541
578
  * @throws Error if network is not supported
542
579
  *
543
580
  * @example
544
581
  * ```typescript
545
- * const address = TransferHook.getAddress('base-sepolia');
582
+ * // Preferred: CAIP-2 format
583
+ * const address = TransferHook.getAddress('eip155:84532');
584
+ * // => '0x4DE234059C6CcC94B8fE1eb1BD24804794083569'
585
+ *
586
+ * // Legacy: human-readable name
587
+ * const address2 = TransferHook.getAddress('base-sepolia');
546
588
  * // => '0x4DE234059C6CcC94B8fE1eb1BD24804794083569'
547
589
  * ```
548
590
  */
549
- function getAddress(network: string): string;
591
+ function getAddress(network: string | Network): string;
550
592
  }
551
593
 
552
594
  /**
@@ -577,21 +619,24 @@ declare namespace NFTMintHook {
577
619
  /**
578
620
  * Get NFTMintHook contract address for a specific network
579
621
  *
580
- * @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
622
+ * Accepts both CAIP-2 format and human-readable network names.
623
+ *
624
+ * @param network - Network identifier (CAIP-2 or human-readable name)
581
625
  * @returns The contract address for the specified network
582
626
  * @throws Error if demo hooks are not configured for the network
583
627
  */
584
- function getAddress(network: string): `0x${string}`;
628
+ function getAddress(network: string | Network): `0x${string}`;
585
629
  /**
586
630
  * Get the NFT contract address for a specific network
587
631
  *
588
632
  * This is the address of the ERC721 contract that will be minted from.
633
+ * Accepts both CAIP-2 format and human-readable network names.
589
634
  *
590
- * @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
635
+ * @param network - Network identifier (CAIP-2 or human-readable name)
591
636
  * @returns The NFT contract address for the specified network
592
637
  * @throws Error if demo hooks are not configured for the network
593
638
  */
594
- function getNFTContractAddress(network: string): `0x${string}`;
639
+ function getNFTContractAddress(network: string | Network): `0x${string}`;
595
640
  /**
596
641
  * Encode MintConfig into hookData for NFTMintHook
597
642
  *
@@ -610,21 +655,24 @@ declare namespace RewardHook {
610
655
  /**
611
656
  * Get RewardHook contract address for a specific network
612
657
  *
613
- * @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
658
+ * Accepts both CAIP-2 format and human-readable network names.
659
+ *
660
+ * @param network - Network identifier (CAIP-2 or human-readable name)
614
661
  * @returns The contract address for the specified network
615
662
  * @throws Error if demo hooks are not configured for the network
616
663
  */
617
- function getAddress(network: string): `0x${string}`;
664
+ function getAddress(network: string | Network): `0x${string}`;
618
665
  /**
619
666
  * Get the reward token (ERC20) address for a specific network
620
667
  *
621
668
  * This is the address of the ERC20 contract that will be distributed as rewards.
669
+ * Accepts both CAIP-2 format and human-readable network names.
622
670
  *
623
- * @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
671
+ * @param network - Network identifier (CAIP-2 or human-readable name)
624
672
  * @returns The reward token contract address for the specified network
625
673
  * @throws Error if demo hooks are not configured for the network
626
674
  */
627
- function getTokenAddress(network: string): `0x${string}`;
675
+ function getTokenAddress(network: string | Network): `0x${string}`;
628
676
  /**
629
677
  * Encode RewardConfig into hookData for RewardHook
630
678
  *
@@ -725,6 +773,7 @@ interface RouterSettlementExtension {
725
773
  * @param params - Extension parameters
726
774
  * @param params.description - Optional description of the extension
727
775
  * @param params.schema - Optional JSON schema for validation
776
+ * @param params.salt - Optional salt (will be auto-generated by enrichDeclaration if not provided)
728
777
  * @param params.settlementRouter - Settlement router contract address
729
778
  * @param params.hook - Hook contract address
730
779
  * @param params.hookData - Encoded hook parameters
@@ -740,7 +789,8 @@ interface RouterSettlementExtension {
740
789
  * hook: "0x...",
741
790
  * hookData: "0x",
742
791
  * finalPayTo: "0x...",
743
- * facilitatorFee: "0"
792
+ * facilitatorFee: "0",
793
+ * salt: "0x..." // Optional, will be auto-generated if not provided
744
794
  * });
745
795
  *
746
796
  * const paymentRequired = {
@@ -756,6 +806,7 @@ interface RouterSettlementExtension {
756
806
  declare function createRouterSettlementExtension(params?: {
757
807
  description?: string;
758
808
  schema?: Record<string, unknown>;
809
+ salt?: string;
759
810
  settlementRouter?: string;
760
811
  hook?: string;
761
812
  hookData?: string;
@@ -820,7 +871,8 @@ declare const routerSettlementServerExtension: ResourceServerExtension;
820
871
  * hook: "0x...",
821
872
  * hookData: "0x",
822
873
  * finalPayTo: "0x...",
823
- * facilitatorFee: "0"
874
+ * facilitatorFee: "0",
875
+ * salt: "0x..." // Optional, will be auto-generated if not provided
824
876
  * })
825
877
  * }
826
878
  * };
@@ -834,6 +886,7 @@ declare function createExtensionDeclaration(params?: {
834
886
  hookData?: string;
835
887
  finalPayTo?: string;
836
888
  facilitatorFee?: string;
889
+ salt?: string;
837
890
  }): Record<string, unknown>;
838
891
 
839
892
  /**
@@ -842,6 +895,8 @@ declare function createExtensionDeclaration(params?: {
842
895
  * Provides utilities for creating route configurations with router settlement support.
843
896
  * This module bridges the gap between x402 v2 official SDK's RoutesConfig and x402x
844
897
  * settlement requirements.
898
+ *
899
+ * Key Design: Use AssetAmount with x402x default assets to bypass official SDK's hardcoded default asset table.
845
900
  */
846
901
 
847
902
  /**
@@ -865,15 +920,25 @@ interface SettlementRouteConfig {
865
920
  }
866
921
  /**
867
922
  * Payment option from @x402/core
923
+ * Enhanced to support dynamic price generation with x402x assets
868
924
  */
869
925
  interface SettlementPaymentOption {
870
926
  scheme: string;
871
927
  network: string;
872
928
  payTo: string | ((context: unknown) => string | Promise<string>);
873
- price: string | ((context: unknown) => string | Promise<string>);
929
+ price: string | number | AssetAmount | ((context: unknown) => string | number | AssetAmount | Promise<string | number | AssetAmount>);
874
930
  maxTimeoutSeconds?: number;
875
931
  extra?: Record<string, unknown>;
876
932
  }
933
+ /**
934
+ * AssetAmount type from @x402/core
935
+ * Represents explicit asset/amount specification bypassing default asset lookup
936
+ */
937
+ interface AssetAmount {
938
+ asset: string;
939
+ amount: string;
940
+ extra?: Record<string, unknown>;
941
+ }
877
942
  /**
878
943
  * Settlement options for route configuration
879
944
  */
@@ -882,12 +947,22 @@ interface SettlementOptions {
882
947
  hook?: string;
883
948
  /** Encoded hook data (optional, defaults to TransferHook.encode()) */
884
949
  hookData?: string;
885
- /** Facilitator fee amount (optional, will be dynamically calculated if not provided) */
950
+ /**
951
+ * Facilitator fee amount (optional).
952
+ * - If not provided, will be dynamically calculated by calling facilitator /calculate-fee endpoint
953
+ * - If provided, will be used as fixed fee for all networks
954
+ */
886
955
  facilitatorFee?: string;
887
- /** Final recipient address (the actual merchant/payee) */
888
- finalPayTo: string;
956
+ /** Final recipient address (optional, defaults to original option.payTo before settlementRouter override) */
957
+ finalPayTo?: string;
889
958
  /** Optional description for the extension */
890
959
  description?: string;
960
+ /**
961
+ * Facilitator service URL for dynamic fee calculation (optional)
962
+ * Defaults to https://facilitator.x402x.dev
963
+ * Only used when facilitatorFee is not explicitly provided
964
+ */
965
+ facilitatorUrl?: string;
891
966
  }
892
967
  /**
893
968
  * Configuration for settlement hooks
@@ -904,35 +979,59 @@ interface SettlementHooksConfig {
904
979
  * This helper wraps the standard x402 RouteConfig and adds settlement-specific
905
980
  * configuration including hooks, settlement router address, and dynamic extensions.
906
981
  *
907
- * The key insight: We add settlement info to the `extra` field of PaymentRequirements,
908
- * which gets passed through verify/settle. The extension generates dynamic salt per request.
982
+ * Key Design (v2 + x402x + dynamic fee):
983
+ * - Uses DynamicPrice to enable probe-quote-replay flow:
984
+ * - First request (no payment): generates salt + queries facilitator fee → returns AssetAmount
985
+ * - Retry (with payment): decodes paymentPayload.accepted and replays it → ensures deepEqual match
986
+ * - Converts Money price to AssetAmount using x402x default asset config per network
987
+ * - Embeds EIP-712 domain + x402x settlement info into price.extra
988
+ * - This bypasses official SDK's hardcoded getDefaultAsset() and allows x402x to define assets for all networks
909
989
  *
910
- * @param baseConfig - Base route configuration
911
- * @param settlementOptions - Settlement-specific options
912
- * @returns Enhanced route configuration with settlement support
990
+ * @param baseConfig - Base route configuration (accepts can use Money price like "$1.00")
991
+ * @param settlementOptions - Settlement-specific options (all fields optional with sensible defaults)
992
+ * @returns Enhanced route configuration with dynamic AssetAmount prices containing full x402x context
913
993
  *
914
- * @example
994
+ * @example Minimal usage (all defaults, dynamic fee from facilitator)
915
995
  * ```typescript
916
- * import { createSettlementRouteConfig, TransferHook } from "@x402x/extensions";
917
- *
918
996
  * const routes = {
919
997
  * "POST /api/purchase": createSettlementRouteConfig({
920
- * accepts: {
998
+ * accepts: supportedNetworks.map(network => ({
921
999
  * scheme: "exact",
922
- * network: "eip155:84532",
923
- * payTo: "0x...", // Will be overridden with settlementRouter
1000
+ * network,
1001
+ * payTo: merchantAddress, // Used as finalPayTo, overridden to settlementRouter
924
1002
  * price: "$1.00",
925
- * },
1003
+ * })),
1004
+ * description: "Purchase endpoint",
1005
+ * })
1006
+ * // settlementOptions omitted: uses DEFAULT_FACILITATOR_URL for fee query
1007
+ * };
1008
+ * ```
1009
+ *
1010
+ * @example With custom facilitator URL
1011
+ * ```typescript
1012
+ * const routes = {
1013
+ * "POST /api/purchase": createSettlementRouteConfig({
1014
+ * accepts: [...],
1015
+ * description: "Purchase endpoint",
1016
+ * }, {
1017
+ * facilitatorUrl: "https://custom-facilitator.example.com",
1018
+ * })
1019
+ * };
1020
+ * ```
1021
+ *
1022
+ * @example With fixed facilitator fee (no dynamic query)
1023
+ * ```typescript
1024
+ * const routes = {
1025
+ * "POST /api/purchase": createSettlementRouteConfig({
1026
+ * accepts: [...],
926
1027
  * description: "Purchase endpoint",
927
1028
  * }, {
928
- * hook: TransferHook.getAddress("base-sepolia"),
929
- * hookData: TransferHook.encode(),
930
- * finalPayTo: "0xMerchantAddress",
1029
+ * facilitatorFee: "1000", // Fixed fee, skips dynamic calculation
931
1030
  * })
932
1031
  * };
933
1032
  * ```
934
1033
  */
935
- declare function createSettlementRouteConfig(baseConfig: SettlementRouteConfig, settlementOptions: SettlementOptions): SettlementRouteConfig;
1034
+ declare function createSettlementRouteConfig(baseConfig: SettlementRouteConfig, settlementOptions?: SettlementOptions): SettlementRouteConfig;
936
1035
  /**
937
1036
  * Register settlement-specific hooks with the resource server
938
1037
  *
@@ -1651,103 +1750,6 @@ declare const SETTLEMENT_ROUTER_ABI: readonly [{
1651
1750
  readonly stateMutability: "nonpayable";
1652
1751
  }];
1653
1752
 
1654
- /**
1655
- * Legacy compatibility types and stubs for x402x v2 middleware
1656
- *
1657
- * These provide compatibility shims for patterns from x402 v1 that are not
1658
- * part of the v2 API but are needed by x402x middleware implementations.
1659
- */
1660
-
1661
- /**
1662
- * Supported EVM networks (legacy v1 pattern)
1663
- * In v2, networks use CAIP-2 format (e.g., 'eip155:84532')
1664
- */
1665
- declare const SupportedEVMNetworks: Network[];
1666
- /**
1667
- * Money schema validator (legacy v1 pattern)
1668
- * In v2, validation is typically done through zod schemas in @x402/core
1669
- */
1670
- declare const moneySchema: {
1671
- parse: (value: unknown) => string | number;
1672
- };
1673
- /**
1674
- * Settle response header name (legacy v1 pattern)
1675
- * In v2, this is typically handled by x402HTTPResourceServer
1676
- */
1677
- declare const settleResponseHeader = "X-Payment-Response";
1678
- /**
1679
- * EVM utilities placeholder (legacy v1 pattern)
1680
- * In v2, EVM functionality is provided by @x402/evm package
1681
- */
1682
- declare const evm: {
1683
- /**
1684
- * Check if a value is a valid EVM address
1685
- */
1686
- isAddress: (value: unknown) => boolean;
1687
- };
1688
- /**
1689
- * Payment scheme stub (legacy v1 pattern)
1690
- * In v2, schemes are implemented as classes extending SchemeNetworkClient/Server
1691
- */
1692
- declare const exact: {
1693
- name: "exact";
1694
- };
1695
- /**
1696
- * Chain ID to network mapping (legacy v1 pattern)
1697
- */
1698
- declare const ChainIdToNetwork: Record<number, Network>;
1699
- /**
1700
- * Check if a signer is a multi-network signer
1701
- */
1702
- declare function isMultiNetworkSigner(signer: unknown): boolean;
1703
- /**
1704
- * Check if a signer is an SVM (Solana) signer wallet
1705
- */
1706
- declare function isSvmSignerWallet(signer: unknown): boolean;
1707
- /**
1708
- * Multi-network signer interface (legacy v1 pattern)
1709
- */
1710
- interface MultiNetworkSigner {
1711
- address?: string;
1712
- signTransaction?: (tx: unknown) => Promise<unknown>;
1713
- [key: string]: unknown;
1714
- }
1715
- /**
1716
- * X402 configuration interface (legacy v1 pattern)
1717
- */
1718
- interface X402Config {
1719
- signer?: MultiNetworkSigner;
1720
- [key: string]: unknown;
1721
- }
1722
- /**
1723
- * Payment requirements selector type (legacy v1 pattern)
1724
- */
1725
- type PaymentRequirementsSelector = (requirements: unknown[]) => unknown;
1726
- /**
1727
- * Create payment header (legacy v1 stub)
1728
- * In v2, this is handled by x402Client.createPaymentPayload()
1729
- */
1730
- declare function createPaymentHeader(_requirements: unknown, _signer: unknown): Promise<string>;
1731
- /**
1732
- * Select payment requirements (legacy v1 stub)
1733
- * In v2, this is handled by x402Client.createPaymentPayload()
1734
- */
1735
- declare function selectPaymentRequirements(_requirements: unknown[], _selector?: PaymentRequirementsSelector): unknown;
1736
- /**
1737
- * Decode X-Payment-Response header (legacy v1 stub)
1738
- * In v2, response handling is done through x402HTTPClient
1739
- */
1740
- declare function decodeXPaymentResponse(_header: string): unknown;
1741
- /**
1742
- * Use facilitator for verification (legacy v1 stub)
1743
- * In v2, this is handled through FacilitatorClient
1744
- */
1745
- declare function useFacilitator(_config: unknown): void;
1746
- /**
1747
- * Create a signer instance (legacy v1 stub)
1748
- */
1749
- declare function createSigner(_config: unknown): unknown;
1750
-
1751
1753
  /**
1752
1754
  * Network utility functions for x402x core_v2
1753
1755
  *
@@ -1767,31 +1769,39 @@ interface AssetInfo {
1767
1769
  };
1768
1770
  }
1769
1771
  /**
1770
- * Get CAIP-2 network ID from network name
1772
+ * Primary mapping from human-readable network names to CAIP-2 identifiers
1771
1773
  *
1772
- * @param networkName - Network name (e.g., 'base-sepolia', 'base')
1773
- * @returns CAIP-2 network identifier (e.g., 'eip155:84532')
1774
- * @throws Error if network name is not supported
1774
+ * This is the SINGLE SOURCE OF TRUTH for network name mappings.
1775
+ * When adding a new network, only update this mapping and the corresponding
1776
+ * entries in networks.ts and DEFAULT_ASSETS.
1777
+ */
1778
+ declare const NETWORK_ALIASES_V1_TO_V2: Record<string, Network>;
1779
+ /**
1780
+ * CAIP-2 network ID to network alias mapping (reverse lookup)
1775
1781
  *
1776
- * @example
1777
- * ```typescript
1778
- * const networkId = getNetworkId('base-sepolia'); // 'eip155:84532'
1779
- * ```
1782
+ * Maps CAIP-2 identifiers to v1 configuration aliases (e.g., "eip155:84532" → "base-sepolia").
1783
+ * These aliases are used in configuration files and for backward compatibility.
1784
+ *
1785
+ * Automatically generated from NETWORK_ALIASES_V1_TO_V2.
1786
+ * DO NOT edit this manually - it will be regenerated.
1780
1787
  */
1781
- declare function getNetworkId(networkName: string): Network;
1788
+ declare const NETWORK_ALIASES: Record<Network, string>;
1782
1789
  /**
1783
- * Get network name from CAIP-2 network ID
1790
+ * Get network alias from CAIP-2 network ID
1791
+ *
1792
+ * Returns the v1 configuration alias (e.g., "base-sepolia") for a given CAIP-2 identifier.
1793
+ * These aliases are used in configuration files and for backward compatibility.
1784
1794
  *
1785
1795
  * @param network - CAIP-2 network identifier (e.g., 'eip155:84532')
1786
- * @returns Network name (e.g., 'base-sepolia')
1796
+ * @returns Network alias (e.g., 'base-sepolia')
1787
1797
  * @throws Error if network ID is not supported
1788
1798
  *
1789
1799
  * @example
1790
1800
  * ```typescript
1791
- * const networkName = getNetworkName('eip155:84532'); // 'base-sepolia'
1801
+ * const alias = getNetworkAlias('eip155:84532'); // 'base-sepolia'
1792
1802
  * ```
1793
1803
  */
1794
- declare function getNetworkName(network: Network): string;
1804
+ declare function getNetworkAlias(network: Network): string;
1795
1805
  /**
1796
1806
  * Get default asset (USDC) information for a network
1797
1807
  *
@@ -1827,11 +1837,6 @@ declare function processPriceToAtomicAmount(price: string | number, network: Net
1827
1837
  } | {
1828
1838
  error: string;
1829
1839
  };
1830
- /**
1831
- * Alias mapping from v1 network names to v2 CAIP-2 identifiers
1832
- * This provides backward compatibility for v1 network names
1833
- */
1834
- declare const NETWORK_ALIASES_V1_TO_V2: Record<string, Network>;
1835
1840
  /**
1836
1841
  * Get list of all supported network IDs (CAIP-2 identifiers)
1837
1842
  *
@@ -1852,11 +1857,6 @@ declare const NETWORK_ALIASES_V1_TO_V2: Record<string, Network>;
1852
1857
  * ```
1853
1858
  */
1854
1859
  declare function getSupportedNetworkIds(): Network[];
1855
- /**
1856
- * @deprecated Use getSupportedNetworkIds() instead for clarity
1857
- * Get list of all supported networks using v2 CAIP-2 identifiers
1858
- */
1859
- declare function getSupportedNetworksV2(): Network[];
1860
1860
  /**
1861
1861
  * Get the alias mapping from v1 network names to v2 CAIP-2 identifiers
1862
1862
  *
@@ -1888,4 +1888,183 @@ declare function getNetworkAliasesV1ToV2(): Record<string, Network>;
1888
1888
  */
1889
1889
  declare function toCanonicalNetworkKey(network: string): Network;
1890
1890
 
1891
- export { type Address, AmountError, ChainIdToNetwork, type CommitmentParams, type DemoHooks, type FacilitatorConfig, type SettleResponse$1 as FacilitatorSettleResponse, FacilitatorValidationError, type VerifyResponse$1 as FacilitatorVerifyResponse, type FeeCalculationResult, type RouteConfig as LegacyRouteConfig, type MintConfig, type Money, type MultiNetworkSigner, NETWORK_ALIASES_V1_TO_V2, NFTMintHook, type NetworkConfig, type PaymentRequirementsSelector, ROUTER_SETTLEMENT_KEY, type Resource, type RewardConfig, RewardHook, type RoutePattern, type RouterSettlementExtension, type RouterSettlementExtensionInfo, type RoutesConfig, SETTLEMENT_ROUTER_ABI, type SettleResponse, type SettlementExtra, type SettlementExtraCore, SettlementExtraError, type SettlementHooksConfig, type SettlementOptions, type SettlementPaymentOption, type SettlementRouteConfig, SettlementRouterError, type SettlementRouterParams, type Signer, SupportedEVMNetworks, TransferHook, type ValidationResult, type VerifyResponse, type WithRouterSettlementOptions, type X402Config, addSettlementExtra, assertValidSettlementExtra, calculateCommitment, calculateFacilitatorFee, clearFeeCache, computeRoutePatterns, createExtensionDeclaration, createPaymentHeader, createRouterSettlementExtension, createSettlementRouteConfig, createSigner, createX402xFacilitator, decodeXPaymentResponse, evm, exact, findMatchingPaymentRequirements, findMatchingRoute, formatDefaultAssetAmount, generateSalt, getChain, getChainById, getCustomChains, getDefaultAsset, getNetworkAliasesV1ToV2, getNetworkConfig, getNetworkId, getNetworkName, getRouterSettlementExtensionKey, getSupportedNetworkIds, getSupportedNetworkNames, getSupportedNetworks, getSupportedNetworksV2, isCustomChain, isMultiNetworkSigner, isNetworkSupported, isRouterSettlement, isSettlementMode, isSvmSignerWallet, isValid32ByteHex, isValidAddress, isValidHex, isValidNumericString, moneySchema, networks, parseDefaultAssetAmount, parseSettlementExtra, processPriceToAtomicAmount, registerRouterSettlement, registerSettlementHooks, routerSettlementServerExtension, selectPaymentRequirements, settle, settleResponseHeader, toCanonicalNetworkKey, toJsonSafe, useFacilitator, validateCommitmentParams, validateSettlementExtra, verify, withRouterSettlement };
1891
+ /**
1892
+ * x402x EVM Client Scheme with Router Settlement
1893
+ *
1894
+ * This scheme extends the standard EVM exact scheme to support x402x router settlement.
1895
+ * The key difference is using a commitment hash (binding all settlement parameters)
1896
+ * as the EIP-3009 nonce instead of a random value.
1897
+ */
1898
+
1899
+ /**
1900
+ * Client EVM signer interface
1901
+ * Compatible with viem WalletClient and LocalAccount
1902
+ */
1903
+ type ClientEvmSigner = {
1904
+ readonly address: `0x${string}`;
1905
+ signTypedData(message: {
1906
+ domain: Record<string, unknown>;
1907
+ types: Record<string, unknown>;
1908
+ primaryType: string;
1909
+ message: Record<string, unknown>;
1910
+ }): Promise<`0x${string}`>;
1911
+ };
1912
+ /**
1913
+ * EVM client implementation for the Exact payment scheme with x402x router settlement.
1914
+ *
1915
+ * This scheme uses a commitment hash as the EIP-3009 nonce to cryptographically bind
1916
+ * all settlement parameters (salt, hook, hookData, etc.) to the user's signature,
1917
+ * preventing parameter tampering attacks.
1918
+ *
1919
+ * @example
1920
+ * ```typescript
1921
+ * import { ExactEvmSchemeWithRouterSettlement } from '@x402x/extensions/client';
1922
+ * import { x402Client } from '@x402/core/client';
1923
+ *
1924
+ * const signer = { address, signTypedData }; // viem WalletClient or LocalAccount
1925
+ * const scheme = new ExactEvmSchemeWithRouterSettlement(signer);
1926
+ *
1927
+ * const client = new x402Client()
1928
+ * .register('eip155:84532', scheme);
1929
+ * ```
1930
+ */
1931
+ declare class ExactEvmSchemeWithRouterSettlement implements SchemeNetworkClient {
1932
+ private readonly signer;
1933
+ readonly scheme = "exact";
1934
+ /**
1935
+ * Per-request router settlement extension (typically sourced from PaymentRequired.extensions).
1936
+ *
1937
+ * IMPORTANT: We do NOT put this on `paymentRequirements.extra`, because for x402 v2 the
1938
+ * server matches paid requests by deep-equality between `paymentPayload.accepted` and the
1939
+ * server-side `accepts[]`. Mutating `accepted` will cause "No matching payment requirements".
1940
+ */
1941
+ private routerSettlementFromPaymentRequired?;
1942
+ /**
1943
+ * Creates a new ExactEvmSchemeWithRouterSettlement instance.
1944
+ *
1945
+ * @param signer - The EVM signer for client operations (viem WalletClient or LocalAccount)
1946
+ */
1947
+ constructor(signer: ClientEvmSigner);
1948
+ /**
1949
+ * Set router-settlement extension data for the next payment payload creation.
1950
+ *
1951
+ * Intended to be called from an `x402Client.onBeforePaymentCreation` hook, which has access
1952
+ * to `paymentRequired.extensions`.
1953
+ */
1954
+ setRouterSettlementExtensionFromPaymentRequired(ext: unknown | undefined): void;
1955
+ /**
1956
+ * Creates a payment payload for the Exact scheme with router settlement.
1957
+ *
1958
+ * This method:
1959
+ * 1. Extracts settlement parameters from PaymentRequired.extensions
1960
+ * 2. Calculates a commitment hash binding all parameters
1961
+ * 3. Uses the commitment as the EIP-3009 nonce
1962
+ * 4. Signs with settlementRouter as the 'to' address
1963
+ *
1964
+ * @param x402Version - The x402 protocol version (must be 2)
1965
+ * @param paymentRequirements - The payment requirements from the server
1966
+ * @returns Promise resolving to a payment payload
1967
+ *
1968
+ * @throws Error if x402Version is not 2
1969
+ * @throws Error if x402x-router-settlement extension is missing
1970
+ * @throws Error if required settlement parameters are missing
1971
+ */
1972
+ createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
1973
+ /**
1974
+ * Sign the EIP-3009 authorization using EIP-712
1975
+ *
1976
+ * @param authorization - The authorization to sign
1977
+ * @param requirements - The payment requirements
1978
+ * @param chainId - The chain ID
1979
+ * @returns Promise resolving to the signature
1980
+ */
1981
+ private signAuthorization;
1982
+ }
1983
+
1984
+ /**
1985
+ * x402x Extension Handler
1986
+ *
1987
+ * Provides utilities to integrate x402x router settlement with official x402 SDK.
1988
+ *
1989
+ * The challenge: x402 v2 spec places extensions at root level in PaymentRequired,
1990
+ * but x402x scheme needs settlement parameters from PaymentRequirements.extra.
1991
+ *
1992
+ * Solution: Provide two-layer API:
1993
+ * 1. High-level: registerX402xScheme() - one line setup (recommended)
1994
+ * 2. Low-level: injectX402xExtensionHandler() - flexible configuration
1995
+ */
1996
+
1997
+ /**
1998
+ * Injects x402x extension handler into x402Client (Low-level API).
1999
+ *
2000
+ * IMPORTANT (x402 v2 + x402x multi-network):
2001
+ * - Server returns per-option x402x info in `accepts[i].extra["x402x-router-settlement"]`
2002
+ * - x402Client only passes `PaymentRequirements` to scheme (no root extensions)
2003
+ * - Facilitator v2 reads from `paymentPayload.extensions["x402x-router-settlement"]`
2004
+ *
2005
+ * Solution: Copy the selected option's x402x info from `selectedRequirements.extra`
2006
+ * into `paymentRequired.extensions` so it gets included in `paymentPayload.extensions`.
2007
+ *
2008
+ * This does NOT mutate `selectedRequirements` (which becomes `paymentPayload.accepted`),
2009
+ * so v2 deepEqual matching still works.
2010
+ *
2011
+ * @param client - x402Client instance to inject handler into
2012
+ * @param onRouterSettlementExtension - Callback to receive the per-request extension object
2013
+ * @returns The same client instance for chaining
2014
+ *
2015
+ * @example Low-level API (for advanced users)
2016
+ * ```typescript
2017
+ * import { x402Client } from '@x402/core/client';
2018
+ * import {
2019
+ * injectX402xExtensionHandler,
2020
+ * ExactEvmSchemeWithRouterSettlement
2021
+ * } from '@x402x/extensions';
2022
+ *
2023
+ * const client = new x402Client();
2024
+ * const scheme = new ExactEvmSchemeWithRouterSettlement(signer);
2025
+ * injectX402xExtensionHandler(client, (ext) => scheme.setRouterSettlementExtensionFromPaymentRequired(ext))
2026
+ * .register('eip155:84532', scheme);
2027
+ * ```
2028
+ */
2029
+ declare function injectX402xExtensionHandler(client: x402Client, onRouterSettlementExtension?: (extension: unknown | undefined) => void): x402Client;
2030
+ /**
2031
+ * Register x402x router settlement scheme with automatic extension handling (High-level API).
2032
+ *
2033
+ * This is the recommended way to set up x402x payments. It combines:
2034
+ * 1. Extension handler injection (injectX402xExtensionHandler)
2035
+ * 2. Scheme registration (ExactEvmSchemeWithRouterSettlement)
2036
+ *
2037
+ * Use this for the simplest integration - just provide your signer and network.
2038
+ *
2039
+ * @param client - x402Client instance
2040
+ * @param network - Network identifier in CAIP-2 format (e.g., "eip155:84532")
2041
+ * @param signer - EVM signer with address and signTypedData method
2042
+ * @returns The client instance for chaining
2043
+ *
2044
+ * @example High-level API (recommended)
2045
+ * ```typescript
2046
+ * import { x402Client } from '@x402/core/client';
2047
+ * import { registerX402xScheme } from '@x402x/extensions';
2048
+ * import { useWalletClient } from 'wagmi';
2049
+ *
2050
+ * const { data: walletClient } = useWalletClient();
2051
+ *
2052
+ * const client = new x402Client();
2053
+ * registerX402xScheme(client, 'eip155:84532', {
2054
+ * address: walletClient.account.address,
2055
+ * signTypedData: walletClient.signTypedData,
2056
+ * });
2057
+ *
2058
+ * // That's it! Client is ready for x402x payments
2059
+ * ```
2060
+ *
2061
+ * @example Multiple networks
2062
+ * ```typescript
2063
+ * const client = new x402Client();
2064
+ * registerX402xScheme(client, 'eip155:84532', signer); // Base Sepolia
2065
+ * registerX402xScheme(client, 'eip155:8453', signer); // Base Mainnet
2066
+ * ```
2067
+ */
2068
+ declare function registerX402xScheme(client: x402Client, network: Network, signer: ClientEvmSigner): x402Client;
2069
+
2070
+ export { type Address, AmountError, type ClientEvmSigner, type CommitmentParams, type DemoHooks, ExactEvmSchemeWithRouterSettlement, type FacilitatorConfig, type SettleResponse$1 as FacilitatorSettleResponse, FacilitatorValidationError, type VerifyResponse$1 as FacilitatorVerifyResponse, type FeeCalculationResult, type RouteConfig as LegacyRouteConfig, type MintConfig, type Money, NETWORK_ALIASES, NETWORK_ALIASES_V1_TO_V2, NFTMintHook, type NetworkConfig, ROUTER_SETTLEMENT_KEY, type Resource, type RewardConfig, RewardHook, type RoutePattern, type RouterSettlementExtension, type RouterSettlementExtensionInfo, type RoutesConfig, SETTLEMENT_ROUTER_ABI, type SettleResponse, type SettlementExtra, type SettlementExtraCore, SettlementExtraError, type SettlementHooksConfig, type SettlementOptions, type SettlementPaymentOption, type SettlementRouteConfig, SettlementRouterError, type SettlementRouterParams, type Signer, TransferHook, type ValidationResult, type VerifyResponse, type WithRouterSettlementOptions, addSettlementExtra, assertValidSettlementExtra, calculateCommitment, calculateFacilitatorFee, clearFeeCache, computeRoutePatterns, createExtensionDeclaration, createRouterSettlementExtension, createSettlementRouteConfig, createX402xFacilitator, findMatchingPaymentRequirements, findMatchingRoute, formatDefaultAssetAmount, generateSalt, getChain, getChainById, getCustomChains, getDefaultAsset, getNetworkAlias, getNetworkAliasesV1ToV2, getNetworkConfig, getRouterSettlementExtensionKey, getSupportedNetworkAliases, getSupportedNetworkIds, getSupportedNetworks, injectX402xExtensionHandler, isCustomChain, isNetworkSupported, isRouterSettlement, isSettlementMode, isValid32ByteHex, isValidAddress, isValidHex, isValidNumericString, networks, parseDefaultAssetAmount, parseSettlementExtra, processPriceToAtomicAmount, registerRouterSettlement, registerSettlementHooks, registerX402xScheme, routerSettlementServerExtension, settle, toCanonicalNetworkKey, toJsonSafe, validateCommitmentParams, validateSettlementExtra, verify, withRouterSettlement };